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-04-20 03:46:44 +00:00
|
|
|
import pkg/dagger/discovery
|
2022-04-13 16:32:35 +00:00
|
|
|
|
|
|
|
type
|
2022-04-20 03:46:44 +00:00
|
|
|
MockDiscovery* = ref object of Discovery
|
|
|
|
findBlockProvidersHandler*: proc(d: MockDiscovery, cid: Cid): seq[SignedPeerRecord] {.gcsafe.}
|
|
|
|
publishProvideHandler*: proc(d: MockDiscovery, cid: Cid) {.gcsafe.}
|
2022-04-13 16:32:35 +00:00
|
|
|
|
|
|
|
proc new*(
|
2022-04-20 03:46:44 +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-04-20 03:46:44 +00:00
|
|
|
method findBlockProviders*(
|
|
|
|
d: MockDiscovery,
|
2022-04-13 16:32:35 +00:00
|
|
|
cid: Cid): Future[seq[SignedPeerRecord]] {.async.} =
|
2022-04-20 03:46:44 +00:00
|
|
|
if isNil(d.findBlockProvidersHandler): return
|
2022-04-13 16:32:35 +00:00
|
|
|
|
2022-04-20 03:46:44 +00:00
|
|
|
return d.findBlockProvidersHandler(d, cid)
|
2022-04-13 16:32:35 +00:00
|
|
|
|
2022-04-20 03:46:44 +00:00
|
|
|
method provideBlock*(d: MockDiscovery, cid: Cid) {.async.} =
|
|
|
|
if isNil(d.publishProvideHandler): return
|
|
|
|
d.publishProvideHandler(d, cid)
|
2022-04-13 16:32:35 +00:00
|
|
|
|
|
|
|
proc start*(d: Discovery) {.async.} =
|
|
|
|
discard
|
|
|
|
|
|
|
|
proc stop*(d: Discovery) {.async.} =
|
|
|
|
discard
|