mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-07 16:03:13 +00:00
Close the discovery store
This commit is contained in:
parent
60861d6af8
commit
831068e68e
@ -206,6 +206,7 @@ proc stop*(s: CodexServer) {.async.} =
|
|||||||
@[
|
@[
|
||||||
s.codexNode.switch.stop(),
|
s.codexNode.switch.stop(),
|
||||||
s.codexNode.stop(),
|
s.codexNode.stop(),
|
||||||
|
s.codexNode.discovery.stop(),
|
||||||
s.repoStore.stop(),
|
s.repoStore.stop(),
|
||||||
s.maintenance.stop(),
|
s.maintenance.stop(),
|
||||||
]
|
]
|
||||||
@ -220,7 +221,8 @@ proc stop*(s: CodexServer) {.async.} =
|
|||||||
raiseAssert "Failed to stop Storage node"
|
raiseAssert "Failed to stop Storage node"
|
||||||
|
|
||||||
proc close*(s: CodexServer) {.async.} =
|
proc close*(s: CodexServer) {.async.} =
|
||||||
var futures = @[s.codexNode.close(), s.repoStore.close()]
|
var futures =
|
||||||
|
@[s.codexNode.close(), s.repoStore.close(), s.codexNode.discovery.close()]
|
||||||
|
|
||||||
let res = await noCancel allFinishedFailed[void](futures)
|
let res = await noCancel allFinishedFailed[void](futures)
|
||||||
|
|
||||||
@ -282,12 +284,15 @@ proc new*(
|
|||||||
msg: "Unable to create discovery directory for block store: " & discoveryDir
|
msg: "Unable to create discovery directory for block store: " & discoveryDir
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let providersPath = config.dataDir / CodexDhtProvidersNamespace
|
||||||
|
let discoveryStoreRes = LevelDbDatastore.new(providersPath)
|
||||||
|
if discoveryStoreRes.isErr:
|
||||||
|
error "Failed to initialize discovery datastore",
|
||||||
|
path = providersPath, err = discoveryStoreRes.error.msg
|
||||||
|
|
||||||
let
|
let
|
||||||
discoveryStore = Datastore(
|
discoveryStore =
|
||||||
LevelDbDatastore.new(config.dataDir / CodexDhtProvidersNamespace).expect(
|
Datastore(discoveryStoreRes.expect("Should create discovery datastore!"))
|
||||||
"Should create discovery datastore!"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
discovery = Discovery.new(
|
discovery = Discovery.new(
|
||||||
switch.peerInfo.privateKey,
|
switch.peerInfo.privateKey,
|
||||||
|
|||||||
@ -44,6 +44,7 @@ type Discovery* = ref object of RootObj
|
|||||||
# address that the node can be connected on
|
# address that the node can be connected on
|
||||||
dhtRecord*: ?SignedPeerRecord # record to advertice DHT connection information
|
dhtRecord*: ?SignedPeerRecord # record to advertice DHT connection information
|
||||||
isStarted: bool
|
isStarted: bool
|
||||||
|
store: Datastore
|
||||||
|
|
||||||
proc toNodeId*(cid: Cid): NodeId =
|
proc toNodeId*(cid: Cid): NodeId =
|
||||||
## Cid to discovery id
|
## Cid to discovery id
|
||||||
@ -218,6 +219,11 @@ proc stop*(d: Discovery) {.async: (raises: []).} =
|
|||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
error "Error stopping discovery", exc = exc.msg
|
error "Error stopping discovery", exc = exc.msg
|
||||||
|
|
||||||
|
proc close*(d: Discovery) {.async: (raises: []).} =
|
||||||
|
let res = await noCancel d.store.close()
|
||||||
|
if res.isErr:
|
||||||
|
error "Error closing discovery store", error = res.error().msg
|
||||||
|
|
||||||
proc new*(
|
proc new*(
|
||||||
T: type Discovery,
|
T: type Discovery,
|
||||||
key: PrivateKey,
|
key: PrivateKey,
|
||||||
@ -230,8 +236,9 @@ proc new*(
|
|||||||
## Create a new Discovery node instance for the given key and datastore
|
## Create a new Discovery node instance for the given key and datastore
|
||||||
##
|
##
|
||||||
|
|
||||||
var self =
|
var self = Discovery(
|
||||||
Discovery(key: key, peerId: PeerId.init(key).expect("Should construct PeerId"))
|
key: key, peerId: PeerId.init(key).expect("Should construct PeerId"), store: store
|
||||||
|
)
|
||||||
|
|
||||||
self.updateAnnounceRecord(announceAddrs)
|
self.updateAnnounceRecord(announceAddrs)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user