Improve performance of UDPMux map lookups

UDPMux is using a map to lookup addresses of each packets.
Unfortunately the key is based on a string and each time we
want to check the map, a conversion of the UDP address to string
is made (.String()) which is expensive.

This CR replace the string key by a binary key called ipPort. This
structure contains a netip.Addr field and ipPort could be used as
a map key
This commit is contained in:
sebapeti
2024-03-25 15:16:16 +01:00
committed by Sean DuBois
parent 52f2075c2e
commit 66051b6877
3 changed files with 60 additions and 22 deletions

View File

@@ -133,6 +133,8 @@ var (
errWriteSTUNMessage = errors.New("failed to send STUN message")
errWriteSTUNMessageToIceConn = errors.New("failed to write STUN message to ICE connection")
errXORMappedAddrTimeout = errors.New("timeout while waiting for XORMappedAddr")
errFailedToCastUDPAddr = errors.New("failed to cast net.Addr to net.UDPAddr")
errInvalidIPAddress = errors.New("invalid ip address")
// UDPMuxDefault should not listen on unspecified address, but to keep backward compatibility, don't return error now.
// will be used in the future.