activates dht. disables discv5 logging

This commit is contained in:
Ben 2025-02-06 10:33:11 +01:00
parent 44f7c9fc5d
commit cc36252a45
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
6 changed files with 16 additions and 12 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@ NimBinaries
.vscode/*
*.exe
crawler_data
dht

View File

@ -72,7 +72,7 @@ proc initializeLists(app: Application): Future[?!void] {.async.} =
return success()
proc initializeDht(app: Application): ?!void =
proc initializeDht(app: Application): Future[?!void] {.async.} =
without dhtStore =? app.createDatastore("dht"), err:
return failure(err)
let keyPath = app.config.dataDir / "privatekey"
@ -86,8 +86,10 @@ proc initializeDht(app: Application): ?!void =
bindPort = app.config.discPort,
announceAddrs = announceAddresses,
bootstrapNodes = app.config.bootNodes,
store = dhtStore
store = dhtStore,
)
await app.dht.start()
return success()
proc initializeApp(app: Application): Future[?!void] {.async.} =
@ -95,7 +97,7 @@ proc initializeApp(app: Application): Future[?!void] {.async.} =
error "Failed to initialize lists", err = err.msg
return failure(err)
if err =? app.initializeDht().errorOption:
if err =? (await app.initializeDht()).errorOption:
error "Failed to initialize DHT", err = err.msg
return failure(err)
@ -103,6 +105,7 @@ proc initializeApp(app: Application): Future[?!void] {.async.} =
proc stop*(app: Application) =
app.status = ApplicationStatus.Stopping
waitFor app.dht.stop()
proc run*(app: Application) =
app.config = parseConfig()

View File

@ -54,7 +54,7 @@ proc getBootNodeStrings(input: string): seq[string] =
return getDefaultTestnetBootNodes()
return input.split(";")
proc stringToSpr(uri: string): SignedPeerRecord =
proc stringToSpr(uri: string): SignedPeerRecord =
var res: SignedPeerRecord
try:
if not res.fromURI(uri):

View File

@ -86,8 +86,7 @@ proc new*(
bootstrapNodes: openArray[SignedPeerRecord] = [],
store: Datastore = SQLiteDatastore.new(Memory).expect("Should not fail!"),
): Dht =
var self =
Dht(key: key, peerId: PeerId.init(key).expect("Should construct PeerId"))
var self = Dht(key: key, peerId: PeerId.init(key).expect("Should construct PeerId"))
self.updateAnnounceRecord(announceAddrs)

View File

@ -44,8 +44,7 @@ proc checkSecureFile*(path: string): IoResult[bool] =
else:
ok (?getPermissionsSet(path) == {UserRead, UserWrite})
type
KeyError* = object of CatchableError
type KeyError* = object of CatchableError
proc setupKey*(path: string): ?!PrivateKey =
if not path.fileAccessible({AccessFlags.Find}):
@ -60,9 +59,7 @@ proc setupKey*(path: string): ?!PrivateKey =
info "Found a network private key"
if not ?checkSecureFile(path).mapFailure(KeyError):
warn "The network private key file is not safe, aborting"
return failure newException(
KeyError, "The network private key file is not safe"
)
return failure newException(KeyError, "The network private key file is not safe")
let kb = ?path.readAllBytes().mapFailure(KeyError)
return PrivateKey.init(kb).mapFailure(KeyError)

View File

@ -1,7 +1,11 @@
--define:
metrics
# switch("define", "chronicles_runtime_filtering=true")
# Sets TRACE logging for everything except DHT
switch("define", "chronicles_log_level=TRACE")
switch("define", "chronicles_disabled_topics:discv5")
when (NimMajor, NimMinor) >= (2, 0):
--mm:refc
--mm:
refc