-
Notifications
You must be signed in to change notification settings - Fork 2
refactor(nat): reimplement NAT Traversal #110
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
Open
markspanbroek
wants to merge
14
commits into
main
Choose a base branch
from
refactor-nat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6f79fae
refactor(nat): re-implementation of port mapping
markspanbroek 250f6d2
cleanup(nat): remove unnecessary nat traversal in repair test
markspanbroek e7414f0
cleanup(nat): fix warning about unused variable
markspanbroek db45b9e
chore(nat): add logging
markspanbroek faf3bf4
fix(nat): use 2 threads for taskpool in test
markspanbroek 443bf3d
fix(nat): register callback when mapping ports
markspanbroek 98e3713
fix(nat): do not use port 0 for port mapping
markspanbroek 7c948d9
chore(nat): add logging to see which nat strategy failed
markspanbroek d3ed561
fix(testbed): use external address 127.0.0.1 in tests
markspanbroek e082969
fix(nat): fix typo
markspanbroek 10c75fe
chore(nat): deduplicate port-mapped addresses
markspanbroek ebb1812
fix(nat): do no shutdown task pool
markspanbroek de2b008
feat(nat): configurable port mapping renewal interval
markspanbroek b44d6a9
chore(nat): formatting
markspanbroek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ type | |
| archivistNode: ArchivistNodeRef | ||
| repoStore: RepoStore | ||
| maintenance: BlockMaintainer | ||
| natTraversal: NatTraversal | ||
| taskpool: Taskpool | ||
|
|
||
| NodePrivateKey* = libp2p.PrivateKey # alias | ||
|
|
@@ -96,12 +97,15 @@ proc start*(s: NodeServer) {.async.} = | |
|
|
||
| await s.archivistNode.switch.start() | ||
|
|
||
| let (announceAddrs, discoveryAddrs) = nattedAddress( | ||
| s.config.nat, s.archivistNode.switch.peerInfo.addrs, s.config.discoveryPort | ||
| ) | ||
| await s.natTraversal.start() | ||
|
|
||
| s.archivistNode.discovery.updateAnnounceRecord(announceAddrs) | ||
| s.archivistNode.discovery.updateDhtRecord(discoveryAddrs) | ||
| let announceAddresses = s.archivistNode.switch.peerInfo.addrs | ||
| let discoveryPort = s.config.discoveryPort | ||
| let discoveryAddress = MultiAddress.init(IPv4_any(), udpProtocol, discoveryPort) | ||
| await s.natTraversal.mapPorts(@[discoveryAddress]) do(mapped: seq[MultiAddress]): | ||
| s.archivistNode.discovery.updateDhtRecord(mapped) | ||
| await s.natTraversal.mapPorts(announceAddresses) do(mapped: seq[MultiAddress]): | ||
| s.archivistNode.discovery.updateAnnounceRecord(mapped) | ||
|
|
||
| await s.connectMarketplace() | ||
| await s.archivistNode.start() | ||
|
|
@@ -117,6 +121,7 @@ proc stop*(s: NodeServer) {.async.} = | |
| s.archivistNode.stop(), | ||
| s.repoStore.stop(), | ||
| s.maintenance.stop(), | ||
| s.natTraversal.stop(), | ||
| ] | ||
| ) | ||
|
|
||
|
|
@@ -219,6 +224,8 @@ proc new*( | |
| maintenance = | ||
| BlockMaintainer.new(repoStore, interval = config.overlayMaintenanceInterval) | ||
|
|
||
| natTraversal = !NatTraversal.new(config.nat, config.natRenewal, tp) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nat should be best effort, we should not crash the node on nat failure to start. |
||
|
|
||
| peerStore = PeerCtxStore.new() | ||
| pendingBlocks = PendingBlocksManager.new() | ||
| advertiser = Advertiser.new(repoStore, discovery) | ||
|
|
@@ -262,5 +269,6 @@ proc new*( | |
| restServer: restServer, | ||
| repoStore: repoStore, | ||
| maintenance: maintenance, | ||
| natTraversal: natTraversal, | ||
| taskpool: tp, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why are we hardcoding the address family here? This should be derived from the mapped address, not hardcoded. Also, wouldn't
0.0.0.0, mess with the nat:none path, as it is right now?