Pre-allocate localAddrsForUnspecified slice with known capacity
and use index assignment instead of append to avoid multiple
slice reallocations.
Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
This change maintains full backward compatibility while adopting
modern Go type alias conventions for better code clarity.
Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
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 change adapts pion/ice to use a new interface for most network
related operations. The interface was formerly a simple struct vnet.Net
which was originally intended to facilicate testing. By replacing it
with an interface we have greater flexibility and allow users to hook
into the networking stack by providing their own implementation of
the interface.
Go encourages short names. And a quick
survey through the Pion code bases reveals,
that we have been using buf more often than buffer.
So this change will harmonize the different spellings.
In #475, import low-level API (ReadMsgUDP) to determine
destination interface for packets received by UDPConn listen
at any(unspecified) address, to fix msg received by incorrect
candidate that shared same ufrags. But the api has compatibility
issues, also not reliable in some special network cases like
AWS/ECS.
So this pr revert that change, and make UDPMuxDefault not
accept Conn listen at unspecified address. Also provide a
NewMultiUDPMuxFromPort helper function to create a MultiUDPMux
to listen at all addresses.
For ice gather, it will use UDPMux's listen address to generate
canidates instead of create it from interfaces.
Udp mux need retrieve destination address to dispatch received
packet when listen at Any address. Windows use winsock APIs to
get that, but conn.FD() is not implement for windows, so
dispatch packet to first candidate, not ideally, but it will
work for ice connectin, wasm will have same result too.
When we have multiple host candidates and mux to a
single port, if these candidates share a same conn
(either tcp or udp), they might read other's msg
cause ice connection cost long time or failed.
A newline is automatically added by the DefaultLeveledLogger.
The current code-base used a mix of log statements w/o endlines.
This is misleading for custom loggers.
UDPMux before only worked with UDP4 traffic.
UDP6 traffic would simply be ignored.
This commit implements 2 connections per ufrag. When requesting a
connection for a ufrag the user must specify if they want IPv4 or IPv6.
Relates to pion/webrtc#1915