dtls icon indicating copy to clipboard operation
dtls copied to clipboard

net.PacketConn

Open neilalexander opened this issue 4 years ago • 3 comments

I'm a little surprised to find that a DTLS implementation, which is specifically datagram-oriented, seems to expect a stream-oriented net.Conn rather than a datagram-oriented net.PacketConn as an input to Client() and Server().

Curious if there is a reason for this? It means that anything net.PacketConn-based has to be wrapped.

neilalexander avatar May 07 '21 12:05 neilalexander

@Sean-Der Do you know why this is? Looking at our code, the only thing we use from Conn that PacketConn doesn't have is the RemoteAddr, but since using ReadFrom on a PacketConn returns the info it doesn't seem necessary. Somewhat similarly we'd need to use WriteTo on a PacketConn, which in turn needs the address. But it feels like this is something we should just plop onto the ConnCtx.

I'm honestly a little confused myself now :sweat_smile:

daenney avatar May 07 '21 13:05 daenney

The other day I was listening to Adam Woodbeck, author of Network Programming with Go, during a gotime podcast (https://changelog.com/gotime/176) and he recommends to use net.PacketConn on UDP implementations.

igolaizola avatar May 07 '21 13:05 igolaizola

Just a design mistake! I am up for fixing this in the next major release. Maybe we could provide a nice helper to make net.Conn users migration easy.

This also would be a great chance to fix this as well. We shouldn't provide a Handshake function that is implicitly called on Read/Write. Right now we do it on conn creation which diverges from crypto/tls and causes issues.

Sean-Der avatar May 17 '21 02:05 Sean-Der

Assigned myself as this is being addressed as part of #558.

hasheddan avatar Aug 02 '23 17:08 hasheddan