Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions archivist/archivist.nim
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type
archivistNode: ArchivistNodeRef
repoStore: RepoStore
maintenance: BlockMaintainer
natTraversal: NatTraversal
taskpool: Taskpool

NodePrivateKey* = libp2p.PrivateKey # alias
Expand Down Expand Up @@ -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)
Copy link
Copy Markdown
Contributor

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?

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()
Expand All @@ -117,6 +121,7 @@ proc stop*(s: NodeServer) {.async.} =
s.archivistNode.stop(),
s.repoStore.stop(),
s.maintenance.stop(),
s.natTraversal.stop(),
]
)

Expand Down Expand Up @@ -219,6 +224,8 @@ proc new*(
maintenance =
BlockMaintainer.new(repoStore, interval = config.overlayMaintenanceInterval)

natTraversal = !NatTraversal.new(config.nat, config.natRenewal, tp)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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)
Expand Down Expand Up @@ -262,5 +269,6 @@ proc new*(
restServer: restServer,
repoStore: repoStore,
maintenance: maintenance,
natTraversal: natTraversal,
taskpool: tp,
)
7 changes: 7 additions & 0 deletions archivist/conf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ type
name: "nat"
.}: NatConfig

natRenewal* {.
desc: "Time interval for renewing port mappings (NAT-PMP, UPnP)",
defaultValue: 20.minutes,
defaultValueDesc: "20m",
name: "nat-renewal"
.}: Duration

discoveryPort* {.
desc: "Discovery (UDP) port",
defaultValue: 8090.Port,
Expand Down
Loading
Loading