Since there are too many refactoring needed in order to make NAT traversal compatible (see for example #1 ), we might also try to leverage other systems to do hole punch.
A promising solution is to create a "sidecar" proxy which does all the hole-punching work (below we call the real network node program p2p node program, the hole-punching program proxy). Whenever our p2p node program to connect to another peer, it connects to the proxy instead. This proxy tries to connect to the proxy running on the node of the other peer. When the connection between two proxies are successfully established, the proxies forward traffic to our p2p node program. This solution seems to be viable. We need to check the following things.
What kind of hole-punching system to use? libp2p seems to be a good candidate.
What is the best way to communicate between the p2p node program and the proxy? https://github.com/libp2p/go-libp2p-daemon seems to be a good example. The p2p node program connects to the proxy by unix socket. It issues RPC to the proxy. After the proxy receives RPC like NewStreamToPeer and successfully establishes a connection to remote peer, the unix socket connection from p2p node program to become a pipe that forwards traffic to remote peer.
How to expose the node addresses information to the underlying hole-punching system? https://github.com/mudler/edgevpn also needs to solve this. May be we can follow their solution.
Do we need to make this proxy transparent? We can do this on linux with IP_TRANSPARENT or bpf. What about other platforms?
Since there are too many refactoring needed in order to make NAT traversal compatible (see for example #1 ), we might also try to leverage other systems to do hole punch.
A promising solution is to create a "sidecar" proxy which does all the hole-punching work (below we call the real network node program p2p node program, the hole-punching program proxy). Whenever our p2p node program to connect to another peer, it connects to the proxy instead. This proxy tries to connect to the proxy running on the node of the other peer. When the connection between two proxies are successfully established, the proxies forward traffic to our p2p node program. This solution seems to be viable. We need to check the following things.
NewStreamToPeer
and successfully establishes a connection to remote peer, the unix socket connection from p2p node program to become a pipe that forwards traffic to remote peer.IP_TRANSPARENT
or bpf. What about other platforms?