2022-04-13 16:32:35 +00:00
|
|
|
## Nim-Dagger
|
|
|
|
## Copyright (c) 2022 Status Research & Development GmbH
|
|
|
|
## Licensed under either of
|
|
|
|
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
## at your option.
|
|
|
|
## This file may not be copied, modified, or distributed except according to
|
|
|
|
## those terms.
|
|
|
|
|
|
|
|
import pkg/chronos
|
|
|
|
import pkg/libp2p
|
|
|
|
import pkg/questionable
|
|
|
|
import pkg/questionable/results
|
|
|
|
import pkg/stew/shims/net
|
2022-05-12 21:52:03 +00:00
|
|
|
import pkg/dagger/discovery
|
2022-04-13 16:32:35 +00:00
|
|
|
|
|
|
|
type
|
2022-05-12 21:52:03 +00:00
|
|
|
MockDiscovery* = ref object of Discovery
|
2022-05-19 02:29:15 +00:00
|
|
|
findBlockProvidersHandler*: proc(d: MockDiscovery, cid: Cid):
|
|
|
|
Future[seq[SignedPeerRecord]] {.gcsafe.}
|
|
|
|
publishProvideHandler*: proc(d: MockDiscovery, cid: Cid):
|
|
|
|
Future[void] {.gcsafe.}
|
2022-04-13 16:32:35 +00:00
|
|
|
|
|
|
|
proc new*(
|
2022-05-12 21:52:03 +00:00
|
|
|
T: type MockDiscovery,
|
2022-04-13 16:32:35 +00:00
|
|
|
localInfo: PeerInfo,
|
|
|
|
discoveryPort: Port,
|
|
|
|
bootstrapNodes = newSeq[SignedPeerRecord](),
|
|
|
|
): T =
|
|
|
|
|
|
|
|
T()
|
|
|
|
|
|
|
|
proc findPeer*(
|
|
|
|
d: Discovery,
|
|
|
|
peerId: PeerID): Future[?PeerRecord] {.async.} =
|
|
|
|
return none(PeerRecord)
|
|
|
|
|
2022-05-12 21:52:03 +00:00
|
|
|
method findBlockProviders*(
|
|
|
|
d: MockDiscovery,
|
2022-04-13 16:32:35 +00:00
|
|
|
cid: Cid): Future[seq[SignedPeerRecord]] {.async.} =
|
2022-05-19 02:29:15 +00:00
|
|
|
if isNil(d.findBlockProvidersHandler):
|
|
|
|
return
|
2022-04-13 16:32:35 +00:00
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
return await d.findBlockProvidersHandler(d, cid)
|
2022-04-13 16:32:35 +00:00
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
method provideBlock*(d: MockDiscovery, cid: Cid): Future[void] {.async.} =
|
|
|
|
if isNil(d.publishProvideHandler):
|
|
|
|
return
|
|
|
|
|
|
|
|
await d.publishProvideHandler(d, cid)
|
2022-04-13 16:32:35 +00:00
|
|
|
|
|
|
|
proc start*(d: Discovery) {.async.} =
|
|
|
|
discard
|
|
|
|
|
|
|
|
proc stop*(d: Discovery) {.async.} =
|
|
|
|
discard
|