Add ListenPacketConn to accept connections on a supplied PacketConn#837
Add ListenPacketConn to accept connections on a supplied PacketConn#837folbricht wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #837 +/- ##
==========================================
+ Coverage 82.35% 82.67% +0.32%
==========================================
Files 123 123
Lines 6999 7015 +16
==========================================
+ Hits 5764 5800 +36
+ Misses 820 807 -13
+ Partials 415 408 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
e5ecb0c to
d1ee218
Compare
|
The
|
|
@folbricht Hello we can maybe do a better API and break the current one, and keep this PR targeted at |
|
Either works for me. Just let me know what you prefer and how I can update it. There's no urgency to it. |
d1ee218 to
7834c87
Compare
|
@JoTurk Going with the first option, keeping this targeted at This is what I went with: // New: supplied-conn path as first-class functions
func ListenPacketConn(pconn net.PacketConn, config *Config) (net.Listener, error)
func ListenPacketConnWithOptions(pconn net.PacketConn, opts ...ServerOption) (net.Listener, error)
// Unchanged: address-based listening keeps its name and signature
func Listen(network string, laddr *net.UDPAddr, config *Config) (net.Listener, error) // Deprecated
func ListenWithOptions(network string, laddr *net.UDPAddr, opts ...ServerOption) (net.Listener, error)
// Unchanged: wrapping an existing demuxing PacketListener
func NewListener(inner dtlsnet.PacketListener, config *Config) (net.Listener, error) // Deprecated
func NewListenerWithOptions(inner dtlsnet.PacketListener, opts ...ServerOption) (net.Listener, error)If you prefer, this could work as well, just let me know: // The DTLS analogue would have been:
func Listen(pconn net.PacketConn, config *Config) (net.Listener, error) // BREAKING: same name, new meaning
func ListenWithOptions(pconn net.PacketConn, opts ...ServerOption) (net.Listener, error) // BREAKING
func ListenAddr(network string, laddr *net.UDPAddr, config *Config) (net.Listener, error) // old behavior, new name
func ListenAddrWithOptions(network string, laddr *net.UDPAddr, opts ...ServerOption) (net.Listener, error) |
7834c87 to
9d7e893
Compare
Description
Adds
ListenPacketConnandListenPacketConnWithOptions, which create a DTLS listener that accepts connections on a caller-suppliednet.PacketConninstead of opening a socket itself.This complements #802:
WithListenConfigcovers socket options viaControl, but some use cases need the socket created entirely outside the library, e.g. a socket created in another network namespace and passed overSCM_RIGHTS, or one bound/configured by other means.Following the review discussion, this makes the supplied-connection path a first-class entry point rather than a
ServerOption. Compared to the earlierWithPacketConnapproach, there are no ignorednetwork/addressarguments and no interaction withWithListenConfig. The split mirrorscrypto/tls, wheretls.NewListenerwraps an existing listener andtls.Listenis the convenience that opens the socket, and is similar toquic.Listentaking anet.PacketConn.Internally,
udp.ListenConfiggains aListenPacketConnmethod holding the listener construction, withListenreduced to opening the socket and delegating to it. The internaludp.listeneronly usesnet.PacketConnmethods, so itspConnfield is widened from*net.UDPConn, which also makes the*net.UDPConnassertion afterListenPacketunnecessary.The listener takes ownership of the supplied connection and closes it on
Close. The existing public API is unchanged, so this is purely additive and no longer depends on a breaking release.