Move to autonatv2

This commit is contained in:
Arnaud 2026-04-15 10:11:37 +04:00
parent e349568833
commit 42ced01893
No known key found for this signature in database
GPG Key ID: A6C7C781817146FA
2 changed files with 20 additions and 14 deletions

View File

@ -23,7 +23,7 @@ import pkg/confutils
import pkg/libp2p
import pkg/libp2p/routing_record
import pkg/libp2p/protocols/connectivity/autonat/service
import pkg/libp2p/protocols/connectivity/autonatv2/service
import pkg/codexdht/discv5/spr as spr
import ../logutils
@ -561,7 +561,7 @@ proc initNodeApi(node: StorageNodeRef, conf: StorageConf, router: var RestRouter
proc initDebugApi(
node: StorageNodeRef,
conf: StorageConf,
autonat: AutonatService,
autonat: AutonatV2Service,
router: var RestRouter,
) =
let allowedOrigin = router.allowedOrigin
@ -644,7 +644,7 @@ proc initRestApi*(
node: StorageNodeRef,
conf: StorageConf,
repoStore: RepoStore,
autonat: AutonatService,
autonat: AutonatV2Service,
corsAllowedOrigin: ?string,
): RestRouter =
var router = RestRouter.init(validate, corsAllowedOrigin)

View File

@ -17,7 +17,7 @@ import pkg/chronos
import pkg/taskpools
import pkg/presto
import pkg/libp2p
import pkg/libp2p/protocols/connectivity/autonat/[service, client]
import pkg/libp2p/protocols/connectivity/autonatv2/[service, client]
import pkg/confutils
import pkg/confutils/defs
import pkg/stew/io2
@ -53,7 +53,7 @@ type
repoStore: RepoStore
maintenance: BlockMaintainer
taskpool: Taskpool
autonatService*: AutonatService
autonatService*: AutonatV2Service
isStarted: bool
StoragePrivateKey* = libp2p.PrivateKey # alias
@ -195,14 +195,17 @@ proc new*(
## create StorageServer including setting up datastore, repostore, etc
let listenMultiAddr = getMultiAddrWithIpAndTcpPort(config.listenIp, config.listenPort)
let autonatService = AutonatService.new(
autonatClient = AutonatClient.new(),
let autonatClient = AutonatV2Client.new(random.Rng.instance())
let autonatService = AutonatV2Service.new(
rng = random.Rng.instance(),
scheduleInterval = Opt.some(config.natScheduleInterval),
askNewConnectedPeers = true,
numPeersToAsk = config.natNumPeersToAsk,
maxQueueSize = config.natMaxQueueSize,
minConfidence = config.natMinConfidence,
client = autonatClient,
config = AutonatV2ServiceConfig.new(
scheduleInterval = Opt.some(config.natScheduleInterval),
askNewConnectedPeers = true,
numPeersToAsk = config.natNumPeersToAsk,
maxQueueSize = config.natMaxQueueSize,
minConfidence = config.natMinConfidence,
),
)
let switch = SwitchBuilder
@ -216,10 +219,13 @@ proc new*(
.withAgentVersion(config.agentString)
.withSignedPeerRecord(true)
.withTcpTransport({ServerFlags.ReuseAddr, ServerFlags.TcpNoDelay})
.withAutonat()
.withAutonatV2Server()
.withServices(@[Service(autonatService)])
.build()
autonatClient.setup(switch)
switch.mount(autonatClient)
var
cache: CacheStore = nil
taskPool: Taskpool
@ -338,7 +344,7 @@ proc new*(
switch.mount(network)
switch.mount(manifestProto)
autonatService.statusAndConfidenceHandler(
autonatService.setStatusAndConfidenceHandler(
proc(
networkReachability: NetworkReachability, confidence: Opt[float]
) {.async: (raises: [CancelledError]).} =