Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Support NAT traversal feature #30

Merged
merged 3 commits into from
Dec 19, 2022
Merged

Support NAT traversal feature #30

merged 3 commits into from
Dec 19, 2022

Conversation

matjazv
Copy link
Contributor

@matjazv matjazv commented Dec 14, 2022

What was the problem?

How was it solved?

  • AutoNAT feature is implemented (peer tries to detect if it has public IP or is inside a private network without public IP).
  • Circuit-relay feature is implemented (peer offers a circuit relay service to other peers so that peers behind NAT can be called by other peers in the network).
  • holepunching feature is implemented (If a peer which calls another peer via its relayer address has a public IP, then called peer drops this connection and directly call peer by its public IP address and they can communicate directly without any relayer peer inbetween. If both peers are behind NAT then holepunching is executed and if it is successfully performed, peers can communicate directly between each other without a relayer peer in between.).

How was it tested?

  • New unit tests were implemented.
  • Existing and new unit tests passed.

Note

All configuration options have default values from libp2p library. In issue #18 we might change them.

Logs for holepunching feature execution:

  • A peer which called another peer via relayer node has a public IP address (no holepunching is needed):
2022-12-14T11:30:45.526+0100    DEBUG   p2p-holepunch   holepunch/svc.go:95     waiting until we have at least one public addresspeer12D3KooWByJ2D6Rv7oe8oUAYTYARiszCAXWUgqkxNp1KbJTqL67E
2022-12-14T11:30:45.776+0100    DEBUG   p2p-holepunch   holepunch/svc.go:107    Host now has a public address. Starting holepunch protocol.
2022-12-14T11:32:07.240+0100    DEBUG   p2p-holepunch   holepunch/holepuncher.go:126    direct connection to peer successful, no need for a hole punch  {"peer": "12D3KooWNfXwDY2xjCF3BJDZniqKRHDZZNQMuVC3gQ1sYzVHvAVx"}
  • Both peers are behind NAT so holepunching is needed:
2022-12-14T11:36:31.526+0100    DEBUG   p2p-holepunch   holepunch/svc.go:95     waiting until we have at least one public addresspeer12D3KooWByJ2D6Rv7oe8oUAYTYARiszCAXWUgqkxNp1KbJTqL67E
2022-12-14T11:36:32.776+0100    DEBUG   p2p-holepunch   holepunch/svc.go:107    Host now has a public address. Starting holepunch protocol.
2022-12-14T11:36:33.467+0100    DEBUG   p2p-holepunch   holepunch/holepuncher.go:131    got inbound proxy conn  {"peer": "12D3KooWC9T9yjhAzhjJg48yTosrGxUvTPLm2mtimGZqxeCCdy99"}
2022-12-14T11:36:33.669+0100    DEBUG   p2p-holepunch   holepunch/holepuncher.go:142    peer RTT is 201.757382ms; starting hole punch in 100.878691ms
2022-12-14T11:36:34.066+0100    DEBUG   p2p-holepunch   holepunch/util.go:68    hole punch successful   {"peer": "12D3KooWC9T9yjhAzhjJg48yTosrGxUvTPLm2mtimGZqxeCCdy99"}
2022-12-14T11:36:34.066+0100    DEBUG   p2p-holepunch   holepunch/holepuncher.go:159    hole punching with successful   {"peer": "12D3KooWC9T9yjhAzhjJg48yTosrGxUvTPLm2mtimGZqxeCCdy99", "time": 0.296361071}

@matjazv matjazv requested review from shuse2 and hrmhatef December 14, 2022 13:39
@matjazv matjazv self-assigned this Dec 14, 2022
Makefile Show resolved Hide resolved
pkg/p2p/v2/p2p.go Show resolved Hide resolved
pkg/p2p/v2/p2p.go Show resolved Hide resolved
pkg/p2p/v2/peer.go Outdated Show resolved Hide resolved
pkg/p2p/v2/peer.go Outdated Show resolved Hide resolved
Copy link
Contributor

@hrmhatef hrmhatef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done.

I just have a small suggestion for one function.

pkg/p2p/v2/nat.go Outdated Show resolved Hide resolved
pkg/p2p/v2/nat.go Outdated Show resolved Hide resolved
@shuse2 shuse2 merged commit 6c7fa23 into main Dec 19, 2022
@shuse2 shuse2 deleted the 12-NAT-traversal branch December 19, 2022 20:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement NAT traversal feature
3 participants