mirror of
https://github.com/logos-storage/logos-storage-network-crawler.git
synced 2026-01-07 16:03:08 +00:00
formatting
This commit is contained in:
parent
5fa90c5c2f
commit
c1f25f10cc
@ -12,8 +12,7 @@ import ../state
|
|||||||
import ../utils/datastoreutils
|
import ../utils/datastoreutils
|
||||||
import ../utils/asyncdataevent
|
import ../utils/asyncdataevent
|
||||||
|
|
||||||
const
|
const nodestoreName = "nodestore"
|
||||||
nodestoreName = "nodestore"
|
|
||||||
|
|
||||||
type
|
type
|
||||||
NodeEntry* = object
|
NodeEntry* = object
|
||||||
@ -66,10 +65,7 @@ proc storeNodeIsNew(s: NodeStore, nid: Nid): Future[?!bool] {.async.} =
|
|||||||
return failure(err)
|
return failure(err)
|
||||||
|
|
||||||
if not exists:
|
if not exists:
|
||||||
let entry = NodeEntry(
|
let entry = NodeEntry(id: nid, lastVisit: 0)
|
||||||
id: nid,
|
|
||||||
lastVisit: 0
|
|
||||||
)
|
|
||||||
?await s.store.put(key, entry)
|
?await s.store.put(key, entry)
|
||||||
|
|
||||||
return success(not exists)
|
return success(not exists)
|
||||||
@ -88,7 +84,7 @@ proc processFoundNodes(s: NodeStore, nids: seq[Nid]): Future[?!void] {.async.} =
|
|||||||
newNodes.add(nid)
|
newNodes.add(nid)
|
||||||
|
|
||||||
if newNodes.len > 0:
|
if newNodes.len > 0:
|
||||||
? await s.fireNewNodesDiscovered(newNodes)
|
?await s.fireNewNodesDiscovered(newNodes)
|
||||||
return success()
|
return success()
|
||||||
|
|
||||||
proc iterateAll*(s: NodeStore, onNode: OnNodeEntry): Future[?!void] {.async.} =
|
proc iterateAll*(s: NodeStore, onNode: OnNodeEntry): Future[?!void] {.async.} =
|
||||||
@ -119,15 +115,8 @@ method stop*(s: NodeStore): Future[?!void] {.async.} =
|
|||||||
await s.state.events.nodesFound.unsubscribe(s.sub)
|
await s.state.events.nodesFound.unsubscribe(s.sub)
|
||||||
return success()
|
return success()
|
||||||
|
|
||||||
proc new*(
|
proc new*(T: type NodeStore, state: State, store: TypedDatastore): NodeStore =
|
||||||
T: type NodeStore,
|
NodeStore(state: state, store: store)
|
||||||
state: State,
|
|
||||||
store: TypedDatastore
|
|
||||||
): NodeStore =
|
|
||||||
NodeStore(
|
|
||||||
state: state,
|
|
||||||
store: store
|
|
||||||
)
|
|
||||||
|
|
||||||
proc createNodeStore*(state: State): ?!NodeStore =
|
proc createNodeStore*(state: State): ?!NodeStore =
|
||||||
without ds =? createTypedDatastore(state.config.dataDir / "nodestore"), err:
|
without ds =? createTypedDatastore(state.config.dataDir / "nodestore"), err:
|
||||||
|
|||||||
@ -113,4 +113,3 @@ proc pop*(this: List): Future[?!Nid] {.async.} =
|
|||||||
|
|
||||||
proc len*(this: List): int =
|
proc len*(this: List): int =
|
||||||
this.items.len
|
this.items.len
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,9 @@ proc newAsyncDataEvent*[T](): AsyncDataEvent[T] =
|
|||||||
queue: newAsyncEventQueue[?T](), subscriptions: newSeq[AsyncDataEventSubscription]()
|
queue: newAsyncEventQueue[?T](), subscriptions: newSeq[AsyncDataEventSubscription]()
|
||||||
)
|
)
|
||||||
|
|
||||||
proc performUnsubscribe[T](event: AsyncDataEvent[T], subscription: AsyncDataEventSubscription) {.async.} =
|
proc performUnsubscribe[T](
|
||||||
|
event: AsyncDataEvent[T], subscription: AsyncDataEventSubscription
|
||||||
|
) {.async.} =
|
||||||
if subscription in event.subscriptions:
|
if subscription in event.subscriptions:
|
||||||
await subscription.listenFuture.cancelAndWait()
|
await subscription.listenFuture.cancelAndWait()
|
||||||
event.subscriptions.delete(event.subscriptions.find(subscription))
|
event.subscriptions.delete(event.subscriptions.find(subscription))
|
||||||
@ -35,7 +37,7 @@ proc subscribe*[T](
|
|||||||
listenFuture: newFuture[void](),
|
listenFuture: newFuture[void](),
|
||||||
fireEvent: newAsyncEvent(),
|
fireEvent: newAsyncEvent(),
|
||||||
inHandler: false,
|
inHandler: false,
|
||||||
delayedUnsubscribe: false
|
delayedUnsubscribe: false,
|
||||||
)
|
)
|
||||||
|
|
||||||
proc listener() {.async.} =
|
proc listener() {.async.} =
|
||||||
|
|||||||
@ -25,9 +25,7 @@ suite "Nodestore":
|
|||||||
ds = createTypedDatastore(dsPath).tryGet()
|
ds = createTypedDatastore(dsPath).tryGet()
|
||||||
state = createMockState()
|
state = createMockState()
|
||||||
|
|
||||||
store = NodeStore.new(
|
store = NodeStore.new(state, ds)
|
||||||
state, ds
|
|
||||||
)
|
|
||||||
|
|
||||||
(await store.start()).tryGet()
|
(await store.start()).tryGet()
|
||||||
|
|
||||||
@ -38,10 +36,7 @@ suite "Nodestore":
|
|||||||
removeDir(dsPath)
|
removeDir(dsPath)
|
||||||
|
|
||||||
test "nodeEntry encoding":
|
test "nodeEntry encoding":
|
||||||
let entry = NodeEntry(
|
let entry = NodeEntry(id: genNid(), lastVisit: 123.uint64)
|
||||||
id: genNid(),
|
|
||||||
lastVisit: 123.uint64
|
|
||||||
)
|
|
||||||
|
|
||||||
let
|
let
|
||||||
bytes = entry.encode()
|
bytes = entry.encode()
|
||||||
@ -83,8 +78,7 @@ suite "Nodestore":
|
|||||||
await state.events.newNodesDiscovered.unsubscribe(sub)
|
await state.events.newNodesDiscovered.unsubscribe(sub)
|
||||||
|
|
||||||
test "nodesFound event should not fire newNodesDiscovered for previously seen nodes":
|
test "nodesFound event should not fire newNodesDiscovered for previously seen nodes":
|
||||||
let
|
let nid = genNid()
|
||||||
nid = genNid()
|
|
||||||
|
|
||||||
# Make nid known first. Then subscribe.
|
# Make nid known first. Then subscribe.
|
||||||
(await state.events.nodesFound.fire(@[nid])).tryGet()
|
(await state.events.nodesFound.fire(@[nid])).tryGet()
|
||||||
@ -97,8 +91,7 @@ suite "Nodestore":
|
|||||||
inc count
|
inc count
|
||||||
return success()
|
return success()
|
||||||
|
|
||||||
let
|
let sub = state.events.newNodesDiscovered.subscribe(onNewNodes)
|
||||||
sub = state.events.newNodesDiscovered.subscribe(onNewNodes)
|
|
||||||
|
|
||||||
# Firing the event again should not trigger newNodesDiscovered for nid
|
# Firing the event again should not trigger newNodesDiscovered for nid
|
||||||
(await state.events.nodesFound.fire(@[nid])).tryGet()
|
(await state.events.nodesFound.fire(@[nid])).tryGet()
|
||||||
|
|||||||
@ -4,11 +4,7 @@ import ../../codexcrawler/utils/asyncdataevent
|
|||||||
import ../../codexcrawler/types
|
import ../../codexcrawler/types
|
||||||
import ../../codexcrawler/config
|
import ../../codexcrawler/config
|
||||||
|
|
||||||
type
|
type MockState* = ref object of State
|
||||||
MockState* = ref object of State
|
|
||||||
# config*: Config
|
|
||||||
# events*: Events
|
|
||||||
|
|
||||||
|
|
||||||
proc createMockState*(): MockState =
|
proc createMockState*(): MockState =
|
||||||
MockState(
|
MockState(
|
||||||
|
|||||||
@ -21,5 +21,3 @@ suite "Types":
|
|||||||
|
|
||||||
check:
|
check:
|
||||||
nid == Nid.fromBytes(bytes).tryGet()
|
nid == Nid.fromBytes(bytes).tryGet()
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user