-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Hole Punching Protocol #711
Conversation
go.mod
Outdated
github.com/libp2p/go-eventbus v0.1.0 | ||
github.com/libp2p/go-libp2p-autonat v0.1.0 | ||
github.com/libp2p/go-libp2p-blankhost v0.1.3 | ||
github.com/libp2p/go-libp2p-circuit v0.1.1 | ||
github.com/libp2p/go-libp2p-core v0.2.2 | ||
github.com/libp2p/go-libp2p-core v0.2.3-0.20190826112323-405451631c05 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just noting for when we need to propagate releases
fde49e1
to
d06bee2
Compare
Ping @marten-seemann @Stebalien for review. |
ping @vyzo for review . |
// attempts to make a direct connection with the remote peer of `relayConn` by co-ordinating a hole punch over | ||
// the given relay connection `relayConn`. | ||
func (hs *HolePunchService) holePunch(relayConn network.Conn) { | ||
rp := relayConn.RemotePeer() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aarshkshah1992 Hello! I'm looking forward to this PR being merged, as we are facing a lot of troubles with multiplexing with TCP transport. BTW, I've just run the bidirectional connections test from this issue: libp2p/go-libp2p-noise#70, and it fails: on the 4th-8th iteration |
@requilence That definitely sounds like a bug. I'll take a look ! |
@requilence There was a race in that test wherein a peer could check for peers it is connected to after that connection has been closed by the remote peer depending on when it hit that code path. I've fixed the test and you can follow this issue at #1041. Once this PR is merge, we can release simopen. |
@aarshkshah1992 can I clarify? Do both of them share the same connection? For each node, it seems that the connection has been initiated on their side and can be safely closed when the operation on their side is finished. Here is an example
|
dbd9c5e
to
749086f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is looking pretty good, a few comments.
Note: I can't green tick this one, as I originally opened the pr.
if cfg.EnableHolePunching && !cfg.Relay { | ||
return nil, errors.New("cannot enable hole punching; relay is not enabled") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will need to use the v2 relay instead of the legacy relay.
const ( | ||
protocol = "/libp2p/holepunch/1.0.0" | ||
maxMsgSize = 4 * 1024 // 4K | ||
holePunchTimeout = 2 * time.Minute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may exceed the limited relay timeout... maybe we need to increase the default for the latter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's 1min currently.
|
||
// short-circuit hole punching if a direct dial works. | ||
// attempt a direct connection ONLY if we have a public address for the remote peer | ||
for _, a := range hs.host.Peerstore().Addrs(rp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this kind of assumes that identify has completed for the peer, which may not be the case here.
} | ||
|
||
// hole punch | ||
s, err := hs.host.NewStream(hs.ctx, rp, protocol) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WithUseTransient(ctx)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
if msg.GetType() != holepunch_pb.HolePunch_CONNECT { | ||
s.Reset() | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's log this, probably Debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
// We plan to have a better address discovery and advertisement mechanism in the future. | ||
// See https://github.com/libp2p/go-libp2p-autonat/pull/98 | ||
repeated bytes ObsAddrs = 2; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newline....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
Note that this is getting quite messy in terms of commit history, we might have to squash it. |
We will want to integrate the circuit v2 pr here and change the libp2p constructor to use the new beast instead of the legacy one. |
Closed in favour of #1057. |
For #1039.
Implements the Hole Punching co-ordination protocol and upgrades dependencies to solve multi-stream simultaneous connect.
TODO