pcp icon indicating copy to clipboard operation
pcp copied to clipboard

Enhance hole punching

Open optman opened this issue 3 years ago • 6 comments

We can try to establish direct connection before transfer (while hole-punching is going on background). I also enable libp2p "p2p-holepunching" log when -debug flag set, so we can see why hole punching fail (in my case it will mostly timeout with the default dial timeout value).

optman avatar Feb 24 '22 06:02 optman

With the new decentralized hole punching, there is a connection reversal mechanism. I could imagine that this step here is not really necessary. I'll give it a try!

dennis-tra avatar Mar 10 '22 08:03 dennis-tra

@dennis-tra The reversal connection is auto start after the relay connection established, it may take several round trip time(maybe 10~60 seconds, depend on where the relay node is) . NewStream will settle on already available connection, it wouldn't wait the direct-connection, who know when it will be. So when transfer start immediately, it will always use the only (relay) connection.

optman avatar Mar 10 '22 08:03 optman

So you want to make sure we actually use a direct connection for the new stream that gets created a couple of lines later, right?

dennis-tra avatar Mar 10 '22 08:03 dennis-tra

yes, try to create direct connection is one way to check hole-punch is completed, I don't think there is other better way.

optman avatar Mar 10 '22 08:03 optman

There's the option to pass a tracer into the EnableHolePunch libp2p option. I thought of listening for the StartHolePunchEvt and EndHolePunchEvtevents:

https://github.com/libp2p/go-libp2p/blob/f0db9cc407a2982faa5a04563ad5fc48326932ce/p2p/protocol/holepunch/tracer.go#L90

dennis-tra avatar Mar 10 '22 09:03 dennis-tra

Good idea, I didn't thought tracer can be used in these ways, but it should work. :)

optman avatar Mar 10 '22 10:03 optman