anacrolix / utp

Use anacrolix/go-libutp instead
https://github.com/anacrolix/go-libutp
Mozilla Public License 2.0
173 stars 35 forks source link

Ability to pass in a net.UDPConn #5

Closed AudriusButkevicius closed 9 years ago

AudriusButkevicius commented 9 years ago

So that we could do the STUN dance or whatever is required before wrapping it in UTP. Similarly how you can wrap and unwrap a TCP connection with tls.Server or tls.Client.

jbenet commented 9 years ago

Yes, this is pretty important. i'd imagine an interface like:

utpConn := utp.NewConn(udpConn)
anacrolix commented 9 years ago

Does the STUN dance take a net.PacketConn? You could create the utp.Socket, and pass it as a net.PacketConn to your STUN code. Not that I'm averse to creating a constructor that takes a net.PacketConn, but this has the advantage of threshing the net.PacketConn emulation in Socket. (Which is well tested in by my DHT/uTP combined usage in package torrent, but it's always good to try new use cases).

jbenet commented 9 years ago

@anacrolix no, most of these libs use sockets created by c++ libs. we usually have no way of creating them and passing them in. this is not just an interface problem, it is also because lots of nat libs will open many ports while trying to find one that works.

anacrolix commented 9 years ago

No problem. I'll add this in the next day or two, unless you want to make a pull request. It's very straightforward to adapt NewSocket to call your new function, and do most of the work in there instead.

AudriusButkevicius commented 8 years ago

FWIW this now works very nicely with https://github.com/ccding/go-stun

anacrolix commented 8 years ago

That's great to hear, thanks.