pcp
pcp copied to clipboard
Enhance hole punching
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).
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 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.
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?
yes, try to create direct connection is one way to check hole-punch is completed, I don't think there is other better way.
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
Good idea, I didn't thought tracer can be used in these ways, but it should work. :)