Ensure that the addresses is announced when Reachable

This commit is contained in:
Arnaud 2026-06-05 16:31:58 +04:00
parent 5548b8af5e
commit 8530e5e718
No known key found for this signature in database
GPG Key ID: A6C7C781817146FA

View File

@ -1,3 +1,4 @@
import std/algorithm
import std/json
import std/sequtils
import pkg/chronos
@ -25,6 +26,18 @@ proc checkNatStatus*(
let rr = nat["relayRunning"].getBool()
let ha = addrs.anyIt("p2p-circuit" in it)
let pm = nat["portMapping"].getStr()
let aa = info["announceAddresses"].getElems.mapIt(it.getStr)
# Reachable nodes must announce their dialable (non-circuit) addrs to
# the DHT (peerInfo observer); relayed nodes must announce their
# circuit addrs (onReservation).
let announceOk =
if reachability == "Reachable":
aa.len > 0 and aa.sorted == addrs.filterIt("p2p-circuit" notin it).sorted
elif relayRunning:
aa.len > 0 and aa.allIt("p2p-circuit" in it)
else:
true
# It is important to check all the conditions together to avoid race
# (new autonat iteration)
@ -33,10 +46,10 @@ proc checkNatStatus*(
"reachability=" & r & " (want " & reachability & ")" & " clientMode=" & $cm &
" (want " & $clientMode & ")" & " relayRunning=" & $rr & " (want " &
$relayRunning & ")" & " p2p-circuit=" & $ha & " (want " & $relayRunning & ")" &
" portMapping=" & pm
" portMapping=" & pm & " announceAddresses=" & $aa
)
r == reachability and cm == clientMode and rr == relayRunning and
ha == relayRunning,
ha == relayRunning and announceOk,
timeout = RelayTimeout,
pollInterval = PollInterval,
)