-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Is there to be an example about hole-punching? #2630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is not on the road map right now. However, https://docs.rs/libp2p/latest/libp2p/tutorials/hole_punching/index.html is a good introduction and maps well to the go implementation too. |
I also need it. Although I understand the principle, I cannot implement it using go-libp2p. Can someone provide a simple example? |
You don't need to implemenent anything. If you run go-libp2p with EnableHolepunching option it'll hole punch when it can. If you can share more specific questions around what you do not understand in https://docs.rs/libp2p/latest/libp2p/tutorials/hole_punching/index.html, I'd be happy to answer. |
Thank you! It seems that the examples are in Rust. Now i am using the GoLang and I got an example from the Internet that I've forked. I will try to finish it with your document and that example. Thanks for |
Can you share an example? |
Yes, you can go to my homepage to find it which I'v forked. |
For lack of something better you can look at Kubo's implementation: |
Thanks you for the lead!❤️ I'll try to make it happen~ |
Thank you! I've solved it. It just need an option
|
Hi!!! I have two questions, it was so hard for me to find some latest-version go-libp2p hole-puching guide, so can you help me!!!! Q1: Is the option Q2: Now I have Host A and Host B in diffrient NAT, and they all have a connection with the relay. What multiaddress should they use to connect each other? Now I'm using |
Q1: I'm fairly sure Q2.1: you can find the multiaddr by calling Q2.2: when you use a relay v2 with hole punching traffic is not sent on the relay, if you are using the latest release, NewStream will wait until a direct connection has been established (you can use a magic incantation to make it establish a stream on the relayed connection but you probably don't want to), if you are using a previous version NewStream will error if you try to use it before a direct connection has been established. Note on Q1: you shouldn't need to do the address yourself, take what |
Thank you! And I wanna know how to confirm that a hole-punching has happened. Now my code is like this destination := "/ip4/106.15.180.40/tcp/55555/p2p/12D3KooWL6LJYwzmLj9Ny4WRYeYg6T58HrMPuhChNs8RfkQuCJhf/p2p-circuit/p2p/" + peerid
maddr, _ := multiaddr.NewMultiaddr(destination)
info, _ := peer.AddrInfoFromP2pAddr(maddr)
(*local.host).Peerstore().AddAddr(info.ID, info.Addrs[0], peerstore.PermanentAddrTTL)
s, err := (*local.host).NewStream(a.ctx, info.ID, "/chat/1.0.0") The peerid is the receiver's p2pID, and I have set the |
s, err := (*local.host).NewStream(a.ctx, info.ID, "/chat/1.0.0") Do you get anything in ctx, cancel := context.WithTimeout(a.ctx, time.Second * 15)
defer cancel()
s, err := (*local.host).NewStream(ctx, info.ID, "/chat/1.0.0") |
There was no error when I run it. It seems that there no attempt to punch a hole, for the A immediately had a connection to B within 0.5s. But I am sure I set the |
How do you know no attempt to hole punch ? If yes can you please show: fmt.Println(s.Conn().RemoteMultiaddr()) |
Yes, the error is |
What versions of go-libp2p are you using ? |
Both on relay and client are go-libp2p v0.32.1, and the package used in relay is Is there something notification when the hole-punching happens? |
This is surprising NewStream should not open on the relayed connection, can you your code please ? |
Yes, my project is using the wails. So let me send the whole project for you. I am not familiar with the github operation so let me use the transfer website . It is here https://f.ws59.cn/f/cqx9od6cv1d , please just click the blue button "下载" to download it. The main code is in the file app.go. Thank you!❤ My relay is operated on the Alibaba Cloud, the relay's multiaddr has been inserted in the code. And below is the relay code:
|
The May you teach me how should I do to confirm a hole-puching action is actually happened when I ues I use these simply code below:
The result is |
Can you run the relay host without the NewStream won't wait for a hole punch if the relayed connection has no limits on the data exchanged. |
Yes, Thank you~ But that didn't work, I met this error Should I use the I found What dose |
No, it indicates that you allow the connection to be openned on the relay, if you DON'T use it, then the stream can only be open on reliable connection, such as direct connection (as you want). |
May I ask if this problem has been resolved? |
@kt5ttk99 Please reopen if you want to discuss it more. |
@xiguamee 你好,我遇到了一模一样的问题,请问一下你解决了吗?最后是怎么解决的? |
|
I need help, thank you!
The text was updated successfully, but these errors were encountered: