Git Product home page Git Product logo

Comments (4)

mennanov avatar mennanov commented on June 18, 2024 3

Could you please point me to the example on how to setup a TCP connection between 2 nodes both behind NAT?
Something like node1_code.go, node2_code.go, external_server_code.go
Thanks!

from go-stun.

pixelbender avatar pixelbender commented on June 18, 2024

@isaachess Yes, It should work exactly you described, but currently stun.Discover uses net.Dial instead of Listen (so, the socket is associated with a STUN-server's address) and hole-punching does not work. I'll fix it, thanks.

from go-stun.

kenkeiter avatar kenkeiter commented on June 18, 2024

I just spent the better part of a day tearing my hair out over this, so I wanted to make sure that I documented exactly what's happening here, in the hopes that someone else won't have to.

Although @pixelbender fixed the issue with the fact that net.Listen* wasn't being used, the net.PacketConn returned by Discover() isn't actually relinquished in a way that allows it to be repurposed! When the Conn is created, an Agent is set up to handle it. Upon start, the Agent calls this method, which calls ReadFrom on the net.PacketConn to loop over/handle received messages. Turns out, when the net.PacketConn is handed back to you from Discover(), that loop is never actually stopped.

I guess that's what @pixelbender meant by the TODO: hijack comment 😜 Anyway, long story short, it turns out that this issue hasn't really been addressed.

from go-stun.

kenkeiter avatar kenkeiter commented on June 18, 2024

@isaachess That PR (#8) should allow you to use this library for hole-punching. The net.PacketConn you get back is now usable, so if you know the public address (host/port) of your peer, you can get them to try to send packets to one another at the same time.

For what it's worth, you'll do something like this for both clients (although you still need an external service to help them exchange addresses):

conn, externalAddr, err := stun.Discover(STUNServer)
if err != nil {
	return nil, errors.Wrap(err, "failed to set up public UDP socket")
}
peerExternalAddr := &net.UDPAddr{
	IP: net.ParseIP("<peer addr>"),
	Port: 1234,
}
conn.WriteTo([]byte("hello"), peerExternalAddr)

from go-stun.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.