Improving proc/func formatting consistency (#454)
* Fixes/workarounds for nimsuggest failures in codex.nim. * remove rng prefix - it appears to work now * format new's to be more consistent * making proc formatting a bit more consistent
This commit is contained in:
parent
2a92dc9702
commit
e47b38af11
|
@ -253,8 +253,11 @@ proc new*(
|
|||
discoveryLoopSleep = DefaultDiscoveryLoopSleep,
|
||||
advertiseLoopSleep = DefaultAdvertiseLoopSleep,
|
||||
minPeersPerBlock = DefaultMinPeersPerBlock,
|
||||
advertiseType = BlockType.Both): DiscoveryEngine =
|
||||
T(
|
||||
advertiseType = BlockType.Both
|
||||
): DiscoveryEngine =
|
||||
## Create a discovery engine instance for advertising services
|
||||
##
|
||||
DiscoveryEngine(
|
||||
localStore: localStore,
|
||||
peers: peers,
|
||||
network: network,
|
||||
|
|
|
@ -504,7 +504,10 @@ proc new*(
|
|||
peerStore: PeerCtxStore,
|
||||
pendingBlocks: PendingBlocksManager,
|
||||
concurrentTasks = DefaultConcurrentTasks,
|
||||
peersPerRequest = DefaultMaxPeersPerRequest): T =
|
||||
peersPerRequest = DefaultMaxPeersPerRequest
|
||||
): BlockExcEngine =
|
||||
## Create new block exchange engine instance
|
||||
##
|
||||
|
||||
let
|
||||
engine = BlockExcEngine(
|
||||
|
|
|
@ -37,7 +37,8 @@ proc getWantHandle*(
|
|||
p: PendingBlocksManager,
|
||||
cid: Cid,
|
||||
timeout = DefaultBlockTimeout,
|
||||
inFlight = false): Future[Block] {.async.} =
|
||||
inFlight = false
|
||||
): Future[Block] {.async.} =
|
||||
## Add an event for a block
|
||||
##
|
||||
|
||||
|
@ -60,8 +61,7 @@ proc getWantHandle*(
|
|||
finally:
|
||||
p.blocks.del(cid)
|
||||
|
||||
proc resolve*(
|
||||
p: PendingBlocksManager,
|
||||
proc resolve*(p: PendingBlocksManager,
|
||||
blocks: seq[Block]) =
|
||||
## Resolve pending blocks
|
||||
##
|
||||
|
@ -73,28 +73,25 @@ proc resolve*(
|
|||
trace "Resolving block", cid = blk.cid
|
||||
pending[].handle.complete(blk)
|
||||
|
||||
proc setInFlight*(
|
||||
p: PendingBlocksManager,
|
||||
proc setInFlight*(p: PendingBlocksManager,
|
||||
cid: Cid,
|
||||
inFlight = true) =
|
||||
p.blocks.withValue(cid, pending):
|
||||
pending[].inFlight = inFlight
|
||||
trace "Setting inflight", cid, inFlight = pending[].inFlight
|
||||
|
||||
proc isInFlight*(
|
||||
p: PendingBlocksManager,
|
||||
cid: Cid): bool =
|
||||
proc isInFlight*(p: PendingBlocksManager,
|
||||
cid: Cid
|
||||
): bool =
|
||||
p.blocks.withValue(cid, pending):
|
||||
result = pending[].inFlight
|
||||
trace "Getting inflight", cid, inFlight = result
|
||||
|
||||
proc pending*(
|
||||
p: PendingBlocksManager,
|
||||
cid: Cid): bool = cid in p.blocks
|
||||
proc pending*(p: PendingBlocksManager, cid: Cid): bool =
|
||||
cid in p.blocks
|
||||
|
||||
proc contains*(
|
||||
p: PendingBlocksManager,
|
||||
cid: Cid): bool = p.pending(cid)
|
||||
proc contains*(p: PendingBlocksManager, cid: Cid): bool =
|
||||
p.pending(cid)
|
||||
|
||||
iterator wantList*(p: PendingBlocksManager): Cid =
|
||||
for k in p.blocks.keys:
|
||||
|
@ -107,5 +104,5 @@ iterator wantHandles*(p: PendingBlocksManager): Future[Block] =
|
|||
func len*(p: PendingBlocksManager): int =
|
||||
p.blocks.len
|
||||
|
||||
func new*(T: type PendingBlocksManager): T =
|
||||
T()
|
||||
func new*(T: type PendingBlocksManager): PendingBlocksManager =
|
||||
PendingBlocksManager()
|
||||
|
|
|
@ -107,7 +107,11 @@ proc makeWantList*(
|
|||
cancel: bool = false,
|
||||
wantType: WantType = WantType.WantHave,
|
||||
full: bool = false,
|
||||
sendDontHave: bool = false): Wantlist =
|
||||
sendDontHave: bool = false
|
||||
): Wantlist =
|
||||
## make list of wanted entries
|
||||
##
|
||||
|
||||
Wantlist(
|
||||
entries: cids.mapIt(
|
||||
Entry(
|
||||
|
@ -126,7 +130,8 @@ proc sendWantList*(
|
|||
cancel: bool = false,
|
||||
wantType: WantType = WantType.WantHave,
|
||||
full: bool = false,
|
||||
sendDontHave: bool = false): Future[void] =
|
||||
sendDontHave: bool = false
|
||||
): Future[void] =
|
||||
## Send a want message to peer
|
||||
##
|
||||
|
||||
|
@ -144,7 +149,8 @@ proc sendWantList*(
|
|||
proc handleBlocks(
|
||||
b: BlockExcNetwork,
|
||||
peer: NetworkPeer,
|
||||
blocks: seq[pb.Block]) {.async.} =
|
||||
blocks: seq[pb.Block]
|
||||
) {.async.} =
|
||||
## Handle incoming blocks
|
||||
##
|
||||
|
||||
|
@ -205,7 +211,8 @@ proc sendBlockPresence*(
|
|||
proc handleAccount(
|
||||
network: BlockExcNetwork,
|
||||
peer: NetworkPeer,
|
||||
account: Account) {.async.} =
|
||||
account: Account
|
||||
) {.async.} =
|
||||
## Handle account info
|
||||
##
|
||||
|
||||
|
@ -215,7 +222,8 @@ proc handleAccount(
|
|||
proc sendAccount*(
|
||||
b: BlockExcNetwork,
|
||||
id: PeerId,
|
||||
account: Account): Future[void] =
|
||||
account: Account
|
||||
): Future[void] =
|
||||
## Send account info to remote
|
||||
##
|
||||
|
||||
|
@ -224,7 +232,8 @@ proc sendAccount*(
|
|||
proc sendPayment*(
|
||||
b: BlockExcNetwork,
|
||||
id: PeerId,
|
||||
payment: SignedState): Future[void] =
|
||||
payment: SignedState
|
||||
): Future[void] =
|
||||
## Send payment to remote
|
||||
##
|
||||
|
||||
|
@ -233,14 +242,21 @@ proc sendPayment*(
|
|||
proc handlePayment(
|
||||
network: BlockExcNetwork,
|
||||
peer: NetworkPeer,
|
||||
payment: SignedState) {.async.} =
|
||||
payment: SignedState
|
||||
) {.async.} =
|
||||
## Handle payment
|
||||
##
|
||||
|
||||
if not network.handlers.onPayment.isNil:
|
||||
await network.handlers.onPayment(peer.id, payment)
|
||||
|
||||
proc rpcHandler(b: BlockExcNetwork, peer: NetworkPeer, msg: Message) {.async.} =
|
||||
proc rpcHandler(
|
||||
b: BlockExcNetwork,
|
||||
peer: NetworkPeer,
|
||||
msg: Message
|
||||
) {.async.} =
|
||||
## handle rpc messages
|
||||
##
|
||||
try:
|
||||
if msg.wantlist.entries.len > 0:
|
||||
asyncSpawn b.handleWantList(peer, msg.wantlist)
|
||||
|
@ -328,7 +344,8 @@ proc new*(
|
|||
T: type BlockExcNetwork,
|
||||
switch: Switch,
|
||||
connProvider: ConnProvider = nil,
|
||||
maxInflight = MaxInflight): T =
|
||||
maxInflight = MaxInflight
|
||||
): BlockExcNetwork =
|
||||
## Create a new BlockExcNetwork instance
|
||||
##
|
||||
|
||||
|
|
|
@ -85,7 +85,8 @@ func new*(
|
|||
T: type NetworkPeer,
|
||||
peer: PeerId,
|
||||
connProvider: ConnProvider,
|
||||
rpcHandler: RPCHandler): T =
|
||||
rpcHandler: RPCHandler
|
||||
): NetworkPeer =
|
||||
|
||||
doAssert(not isNil(connProvider),
|
||||
"should supply connection provider")
|
||||
|
|
|
@ -93,5 +93,5 @@ func selectCheapest*(self: PeerCtxStore, cid: Cid): seq[BlockExcPeerCtx] =
|
|||
return peers
|
||||
|
||||
proc new*(T: type PeerCtxStore): PeerCtxStore =
|
||||
T(
|
||||
peers: initOrderedTable[PeerId, BlockExcPeerCtx]())
|
||||
## create new instance of a peer context store
|
||||
PeerCtxStore(peers: initOrderedTable[PeerId, BlockExcPeerCtx]())
|
||||
|
|
|
@ -130,7 +130,10 @@ func new*(
|
|||
data: openArray[byte] = [],
|
||||
version = CIDv1,
|
||||
mcodec = multiCodec("sha2-256"),
|
||||
codec = multiCodec("raw")): ?!T =
|
||||
codec = multiCodec("raw")
|
||||
): ?!Block =
|
||||
## creates a new block for both storage and network IO
|
||||
##
|
||||
|
||||
let
|
||||
hash = ? MultiHash.digest($mcodec, data).mapFailure
|
||||
|
@ -146,7 +149,10 @@ func new*(
|
|||
T: type Block,
|
||||
cid: Cid,
|
||||
data: openArray[byte],
|
||||
verify: bool = true): ?!T =
|
||||
verify: bool = true
|
||||
): ?!Block =
|
||||
## creates a new block for both storage and network IO
|
||||
##
|
||||
|
||||
let
|
||||
mhash = ? cid.mhash.mapFailure
|
||||
|
|
|
@ -63,9 +63,12 @@ func new*(
|
|||
T: type Chunker,
|
||||
reader: Reader,
|
||||
chunkSize = DefaultChunkSize,
|
||||
pad = true): T =
|
||||
|
||||
T(reader: reader,
|
||||
pad = true
|
||||
): Chunker =
|
||||
## create a new Chunker instance
|
||||
##
|
||||
Chunker(
|
||||
reader: reader,
|
||||
offset: 0,
|
||||
chunkSize: chunkSize,
|
||||
pad: pad)
|
||||
|
@ -74,7 +77,8 @@ proc new*(
|
|||
T: type LPStreamChunker,
|
||||
stream: LPStream,
|
||||
chunkSize = DefaultChunkSize,
|
||||
pad = true): T =
|
||||
pad = true
|
||||
): LPStreamChunker =
|
||||
## create the default File chunker
|
||||
##
|
||||
|
||||
|
@ -92,7 +96,7 @@ proc new*(
|
|||
|
||||
return res
|
||||
|
||||
T.new(
|
||||
LPStreamChunker.new(
|
||||
reader = reader,
|
||||
chunkSize = chunkSize,
|
||||
pad = pad)
|
||||
|
@ -101,7 +105,8 @@ proc new*(
|
|||
T: type FileChunker,
|
||||
file: File,
|
||||
chunkSize = DefaultChunkSize,
|
||||
pad = true): T =
|
||||
pad = true
|
||||
): FileChunker =
|
||||
## create the default File chunker
|
||||
##
|
||||
|
||||
|
@ -123,7 +128,7 @@ proc new*(
|
|||
|
||||
return total
|
||||
|
||||
T.new(
|
||||
FileChunker.new(
|
||||
reader = reader,
|
||||
chunkSize = chunkSize,
|
||||
pad = pad)
|
||||
|
|
|
@ -51,7 +51,13 @@ type
|
|||
|
||||
CodexPrivateKey* = libp2p.PrivateKey # alias
|
||||
|
||||
proc bootstrapInteractions(config: CodexConf, repo: RepoStore): Future[Contracts] {.async.} =
|
||||
proc bootstrapInteractions(
|
||||
config: CodexConf,
|
||||
repo: RepoStore
|
||||
): Future[Contracts] {.async.} =
|
||||
## bootstrap interactions and return contracts
|
||||
## using clients, hosts, validators pairings
|
||||
##
|
||||
|
||||
if not config.persistence and not config.validator:
|
||||
if config.ethAccount.isSome:
|
||||
|
@ -150,7 +156,8 @@ proc stop*(s: CodexServer) {.async.} =
|
|||
proc new*(
|
||||
T: type CodexServer,
|
||||
config: CodexConf,
|
||||
privateKey: CodexPrivateKey): CodexServer =
|
||||
privateKey: CodexPrivateKey
|
||||
): CodexServer =
|
||||
## create CodexServer including setting up datastore, repostore, etc
|
||||
let
|
||||
switch = SwitchBuilder
|
||||
|
@ -231,9 +238,10 @@ proc new*(
|
|||
|
||||
switch.mount(network)
|
||||
|
||||
T(
|
||||
CodexServer(
|
||||
config: config,
|
||||
codexNode: codexNode,
|
||||
restServer: restServer,
|
||||
repoStore: repoStore,
|
||||
maintenance: maintenance)
|
||||
maintenance: maintenance
|
||||
)
|
||||
|
|
|
@ -14,10 +14,14 @@ type
|
|||
sales*: Sales
|
||||
proving*: Proving
|
||||
|
||||
proc new*(_: type HostInteractions,
|
||||
proc new*(
|
||||
_: type HostInteractions,
|
||||
clock: OnChainClock,
|
||||
sales: Sales,
|
||||
proving: Proving): HostInteractions =
|
||||
proving: Proving
|
||||
): HostInteractions =
|
||||
## Create a new HostInteractions instance
|
||||
##
|
||||
HostInteractions(clock: clock, sales: sales, proving: proving)
|
||||
|
||||
method start*(self: HostInteractions) {.async.} =
|
||||
|
|
|
@ -100,8 +100,7 @@ method getHost(market: OnChainMarket,
|
|||
else:
|
||||
return none Address
|
||||
|
||||
method getActiveSlot*(
|
||||
market: OnChainMarket,
|
||||
method getActiveSlot*(market: OnChainMarket,
|
||||
slotId: SlotId): Future[?Slot] {.async.} =
|
||||
|
||||
try:
|
||||
|
@ -154,9 +153,11 @@ method markProofAsMissing*(market: OnChainMarket,
|
|||
period: Period) {.async.} =
|
||||
await market.contract.markProofAsMissing(id, period)
|
||||
|
||||
method canProofBeMarkedAsMissing*(market: OnChainMarket,
|
||||
method canProofBeMarkedAsMissing*(
|
||||
market: OnChainMarket,
|
||||
id: SlotId,
|
||||
period: Period): Future[bool] {.async.} =
|
||||
period: Period
|
||||
): Future[bool] {.async.} =
|
||||
let provider = market.contract.provider
|
||||
let contractWithoutSigner = market.contract.connect(provider)
|
||||
let overrides = CallOverrides(blockTag: some BlockTag.pending)
|
||||
|
|
|
@ -57,22 +57,24 @@ proc toNodeId*(host: ca.Address): NodeId =
|
|||
|
||||
proc findPeer*(
|
||||
d: Discovery,
|
||||
peerId: PeerId): Future[?PeerRecord] {.async.} =
|
||||
peerId: PeerId
|
||||
): Future[?PeerRecord] {.async.} =
|
||||
trace "protocol.resolve..."
|
||||
## Find peer using the given Discovery object
|
||||
##
|
||||
let
|
||||
node = await d.protocol.resolve(toNodeId(peerId))
|
||||
|
||||
return
|
||||
if node.isSome():
|
||||
trace "protocol.resolve some data"
|
||||
node.get().record.data.some
|
||||
else:
|
||||
trace "protocol.resolve none"
|
||||
PeerRecord.none
|
||||
|
||||
method find*(
|
||||
d: Discovery,
|
||||
cid: Cid): Future[seq[SignedPeerRecord]] {.async, base.} =
|
||||
cid: Cid
|
||||
): Future[seq[SignedPeerRecord]] {.async, base.} =
|
||||
## Find block providers
|
||||
##
|
||||
|
||||
|
@ -99,7 +101,8 @@ method provide*(d: Discovery, cid: Cid) {.async, base.} =
|
|||
|
||||
method find*(
|
||||
d: Discovery,
|
||||
host: ca.Address): Future[seq[SignedPeerRecord]] {.async, base.} =
|
||||
host: ca.Address
|
||||
): Future[seq[SignedPeerRecord]] {.async, base.} =
|
||||
## Find host providers
|
||||
##
|
||||
|
||||
|
@ -129,11 +132,20 @@ method provide*(d: Discovery, host: ca.Address) {.async, base.} =
|
|||
if nodes.len > 0:
|
||||
trace "Provided to nodes", nodes = nodes.len
|
||||
|
||||
method removeProvider*(d: Discovery, peerId: PeerId): Future[void] {.base.} =
|
||||
method removeProvider*(
|
||||
d: Discovery,
|
||||
peerId: PeerId
|
||||
): Future[void] {.base.} =
|
||||
## Remove provider from providers table
|
||||
##
|
||||
|
||||
trace "Removing provider", peerId
|
||||
d.protocol.removeProvidersLocal(peerId)
|
||||
|
||||
proc updateAnnounceRecord*(d: Discovery, addrs: openArray[MultiAddress]) =
|
||||
## Update providers record
|
||||
##
|
||||
|
||||
d.announceAddrs = @addrs
|
||||
|
||||
trace "Updating announce record", addrs = d.announceAddrs
|
||||
|
@ -146,6 +158,9 @@ proc updateAnnounceRecord*(d: Discovery, addrs: openArray[MultiAddress]) =
|
|||
.expect("Should update SPR")
|
||||
|
||||
proc updateDhtRecord*(d: Discovery, ip: ValidIpAddress, port: Port) =
|
||||
## Update providers record
|
||||
##
|
||||
|
||||
trace "Updating Dht record", ip, port = $port
|
||||
d.dhtRecord = SignedPeerRecord.init(
|
||||
d.key, PeerRecord.init(d.peerId, @[
|
||||
|
@ -154,10 +169,6 @@ proc updateDhtRecord*(d: Discovery, ip: ValidIpAddress, port: Port) =
|
|||
IpTransportProtocol.udpProtocol,
|
||||
port)])).expect("Should construct signed record").some
|
||||
|
||||
if not d.protocol.isNil:
|
||||
d.protocol.updateRecord(d.dhtRecord)
|
||||
.expect("Should update SPR")
|
||||
|
||||
proc start*(d: Discovery) {.async.} =
|
||||
d.protocol.open()
|
||||
await d.protocol.start()
|
||||
|
@ -172,11 +183,13 @@ proc new*(
|
|||
bindPort = 0.Port,
|
||||
announceAddrs: openArray[MultiAddress],
|
||||
bootstrapNodes: openArray[SignedPeerRecord] = [],
|
||||
store: Datastore = SQLiteDatastore.new(Memory)
|
||||
.expect("Should not fail!")): T =
|
||||
store: Datastore = SQLiteDatastore.new(Memory).expect("Should not fail!")
|
||||
): Discovery =
|
||||
## Create a new Discovery node instance for the given key and datastore
|
||||
##
|
||||
|
||||
var
|
||||
self = T(
|
||||
self = Discovery(
|
||||
key: key,
|
||||
peerId: PeerId.init(key).expect("Should construct PeerId"))
|
||||
|
||||
|
|
|
@ -12,8 +12,14 @@ import ./erasure/backends/leopard
|
|||
|
||||
export erasure
|
||||
|
||||
func leoEncoderProvider*(size, buffers, parity: int): EncoderBackend {.raises: [Defect].} =
|
||||
func leoEncoderProvider*(
|
||||
size, buffers, parity: int
|
||||
): EncoderBackend {.raises: [Defect].} =
|
||||
## create new Leo Encoder
|
||||
LeoEncoderBackend.new(size, buffers, parity)
|
||||
|
||||
func leoDecoderProvider*(size, buffers, parity: int): DecoderBackend {.raises: [Defect].} =
|
||||
func leoDecoderProvider*(
|
||||
size, buffers, parity: int
|
||||
): DecoderBackend {.raises: [Defect].} =
|
||||
## create new Leo Decoder
|
||||
LeoDecoderBackend.new(size, buffers, parity)
|
||||
|
|
|
@ -23,17 +23,25 @@ type
|
|||
DecoderBackend* = ref object of Backend
|
||||
|
||||
method release*(self: Backend) {.base.} =
|
||||
## release the backend
|
||||
##
|
||||
raiseAssert("not implemented!")
|
||||
|
||||
method encode*(
|
||||
self: EncoderBackend,
|
||||
buffers,
|
||||
parity: var openArray[seq[byte]]): Result[void, cstring] {.base.} =
|
||||
parity: var openArray[seq[byte]]
|
||||
): Result[void, cstring] {.base.} =
|
||||
## encode buffers using a backend
|
||||
##
|
||||
raiseAssert("not implemented!")
|
||||
|
||||
method decode*(
|
||||
self: DecoderBackend,
|
||||
buffers,
|
||||
parity,
|
||||
recovered: var openArray[seq[byte]]): Result[void, cstring] {.base.} =
|
||||
recovered: var openArray[seq[byte]]
|
||||
): Result[void, cstring] {.base.} =
|
||||
## decode buffers using a backend
|
||||
##
|
||||
raiseAssert("not implemented!")
|
||||
|
|
|
@ -24,7 +24,9 @@ type
|
|||
method encode*(
|
||||
self: LeoEncoderBackend,
|
||||
data,
|
||||
parity: var openArray[seq[byte]]): Result[void, cstring] =
|
||||
parity: var openArray[seq[byte]]
|
||||
): Result[void, cstring] =
|
||||
## Encode data using Leopard backend
|
||||
|
||||
if parity.len == 0:
|
||||
return ok()
|
||||
|
@ -44,9 +46,12 @@ method decode*(
|
|||
self: LeoDecoderBackend,
|
||||
data,
|
||||
parity,
|
||||
recovered: var openArray[seq[byte]]): Result[void, cstring] =
|
||||
recovered: var openArray[seq[byte]]
|
||||
): Result[void, cstring] =
|
||||
## Decode data using given Leopard backend
|
||||
|
||||
var decoder = if self.decoder.isNone:
|
||||
var decoder =
|
||||
if self.decoder.isNone:
|
||||
self.decoder = (? LeoDecoder.init(
|
||||
self.blockSize,
|
||||
self.buffers,
|
||||
|
@ -65,22 +70,28 @@ method release*(self: LeoDecoderBackend) =
|
|||
if self.decoder.isSome:
|
||||
self.decoder.get().free()
|
||||
|
||||
func new*(
|
||||
proc new*(
|
||||
T: type LeoEncoderBackend,
|
||||
blockSize,
|
||||
buffers,
|
||||
parity: int): T =
|
||||
T(
|
||||
parity: int
|
||||
): LeoEncoderBackend =
|
||||
## Create an instance of an Leopard Encoder backend
|
||||
##
|
||||
LeoEncoderBackend(
|
||||
blockSize: blockSize,
|
||||
buffers: buffers,
|
||||
parity: parity)
|
||||
|
||||
func new*(
|
||||
proc new*(
|
||||
T: type LeoDecoderBackend,
|
||||
blockSize,
|
||||
buffers,
|
||||
parity: int): T =
|
||||
T(
|
||||
parity: int
|
||||
): LeoDecoderBackend =
|
||||
## Create an instance of an Leopard Decoder backend
|
||||
##
|
||||
LeoDecoderBackend(
|
||||
blockSize: blockSize,
|
||||
buffers: buffers,
|
||||
parity: parity)
|
||||
|
|
|
@ -66,7 +66,8 @@ proc encode*(
|
|||
self: Erasure,
|
||||
manifest: Manifest,
|
||||
blocks: int,
|
||||
parity: int): Future[?!Manifest] {.async.} =
|
||||
parity: int
|
||||
): Future[?!Manifest] {.async.} =
|
||||
## Encode a manifest into one that is erasure protected.
|
||||
##
|
||||
## `manifest` - the original manifest to be encoded
|
||||
|
@ -154,7 +155,8 @@ proc encode*(
|
|||
|
||||
proc decode*(
|
||||
self: Erasure,
|
||||
encoded: Manifest): Future[?!Manifest] {.async.} =
|
||||
encoded: Manifest
|
||||
): Future[?!Manifest] {.async.} =
|
||||
## Decode a protected manifest into it's original
|
||||
## manifest
|
||||
##
|
||||
|
@ -268,7 +270,9 @@ proc new*(
|
|||
T: type Erasure,
|
||||
store: BlockStore,
|
||||
encoderProvider: EncoderProvider,
|
||||
decoderProvider: DecoderProvider): Erasure =
|
||||
decoderProvider: DecoderProvider
|
||||
): Erasure =
|
||||
## Create a new Erasure instance for encoding and decoding manifests
|
||||
|
||||
Erasure(
|
||||
store: store,
|
||||
|
|
|
@ -15,7 +15,8 @@ type
|
|||
|
||||
template mapFailure*(
|
||||
exp: untyped,
|
||||
exc: typed = type CodexError): untyped =
|
||||
exc: typed = type CodexError
|
||||
): untyped =
|
||||
## Convert `Result[T, E]` to `Result[E, ref CatchableError]`
|
||||
##
|
||||
|
||||
|
|
|
@ -167,7 +167,8 @@ func decode*(_: DagPBCoder, data: openArray[byte]): ?!Manifest =
|
|||
|
||||
proc encode*(
|
||||
self: Manifest,
|
||||
encoder = ManifestContainers[$DagPBCodec]): ?!seq[byte] =
|
||||
encoder = ManifestContainers[$DagPBCodec]
|
||||
): ?!seq[byte] =
|
||||
## Encode a manifest using `encoder`
|
||||
##
|
||||
|
||||
|
@ -179,7 +180,8 @@ proc encode*(
|
|||
func decode*(
|
||||
_: type Manifest,
|
||||
data: openArray[byte],
|
||||
decoder = ManifestContainers[$DagPBCodec]): ?!Manifest =
|
||||
decoder = ManifestContainers[$DagPBCodec]
|
||||
): ?!Manifest =
|
||||
## Decode a manifest using `decoder`
|
||||
##
|
||||
|
||||
|
|
|
@ -165,8 +165,9 @@ proc new*(
|
|||
version = CIDv1,
|
||||
hcodec = multiCodec("sha2-256"),
|
||||
codec = multiCodec("raw"),
|
||||
blockSize = BlockSize): ?!T =
|
||||
## Create a manifest using array of `Cid`s
|
||||
blockSize = BlockSize
|
||||
): ?!Manifest =
|
||||
## Create a manifest using an array of `Cid`s
|
||||
##
|
||||
|
||||
if hcodec notin EmptyDigests[version]:
|
||||
|
@ -184,7 +185,8 @@ proc new*(
|
|||
proc new*(
|
||||
T: type Manifest,
|
||||
manifest: Manifest,
|
||||
ecK, ecM: int): ?!Manifest =
|
||||
ecK, ecM: int
|
||||
): ?!Manifest =
|
||||
## Create an erasure protected dataset from an
|
||||
## un-protected one
|
||||
##
|
||||
|
@ -223,5 +225,8 @@ proc new*(
|
|||
proc new*(
|
||||
T: type Manifest,
|
||||
data: openArray[byte],
|
||||
decoder = ManifestContainers[$DagPBCodec]): ?!T =
|
||||
decoder = ManifestContainers[$DagPBCodec]
|
||||
): ?!Manifest =
|
||||
## Create a manifest instance from given data
|
||||
##
|
||||
Manifest.decode(data, decoder)
|
||||
|
|
|
@ -60,18 +60,23 @@ type
|
|||
|
||||
proc findPeer*(
|
||||
node: CodexNodeRef,
|
||||
peerId: PeerId): Future[?PeerRecord] {.async.} =
|
||||
peerId: PeerId
|
||||
): Future[?PeerRecord] {.async.} =
|
||||
## Find peer using the discovery service from the given CodexNode
|
||||
##
|
||||
return await node.discovery.findPeer(peerId)
|
||||
|
||||
proc connect*(
|
||||
node: CodexNodeRef,
|
||||
peerId: PeerId,
|
||||
addrs: seq[MultiAddress]): Future[void] =
|
||||
addrs: seq[MultiAddress]
|
||||
): Future[void] =
|
||||
node.switch.connect(peerId, addrs)
|
||||
|
||||
proc fetchManifest*(
|
||||
node: CodexNodeRef,
|
||||
cid: Cid): Future[?!Manifest] {.async.} =
|
||||
cid: Cid
|
||||
): Future[?!Manifest] {.async.} =
|
||||
## Fetch and decode a manifest block
|
||||
##
|
||||
|
||||
|
@ -96,7 +101,8 @@ proc fetchBatched*(
|
|||
node: CodexNodeRef,
|
||||
manifest: Manifest,
|
||||
batchSize = FetchBatch,
|
||||
onBatch: BatchProc = nil): Future[?!void] {.async, gcsafe.} =
|
||||
onBatch: BatchProc = nil
|
||||
): Future[?!void] {.async, gcsafe.} =
|
||||
## Fetch manifest in batches of `batchSize`
|
||||
##
|
||||
|
||||
|
@ -123,7 +129,8 @@ proc fetchBatched*(
|
|||
|
||||
proc retrieve*(
|
||||
node: CodexNodeRef,
|
||||
cid: Cid): Future[?!LPStream] {.async.} =
|
||||
cid: Cid
|
||||
): Future[?!LPStream] {.async.} =
|
||||
## Retrieve by Cid a single block or an entire dataset described by manifest
|
||||
##
|
||||
|
||||
|
@ -177,7 +184,8 @@ proc retrieve*(
|
|||
proc store*(
|
||||
self: CodexNodeRef,
|
||||
stream: LPStream,
|
||||
blockSize = BlockSize): Future[?!Cid] {.async.} =
|
||||
blockSize = BlockSize
|
||||
): Future[?!Cid] {.async.} =
|
||||
## Save stream contents as dataset with given blockSize
|
||||
## to nodes's BlockStore, and return Cid of its manifest
|
||||
##
|
||||
|
@ -238,7 +246,8 @@ proc store*(
|
|||
|
||||
return manifest.cid.success
|
||||
|
||||
proc requestStorage*(self: CodexNodeRef,
|
||||
proc requestStorage*(
|
||||
self: CodexNodeRef,
|
||||
cid: Cid,
|
||||
duration: UInt256,
|
||||
proofProbability: UInt256,
|
||||
|
@ -246,7 +255,8 @@ proc requestStorage*(self: CodexNodeRef,
|
|||
tolerance: uint,
|
||||
reward: UInt256,
|
||||
collateral: UInt256,
|
||||
expiry = UInt256.none): Future[?!PurchaseId] {.async.} =
|
||||
expiry = UInt256.none
|
||||
): Future[?!PurchaseId] {.async.} =
|
||||
## Initiate a request for storage sequence, this might
|
||||
## be a multistep procedure.
|
||||
##
|
||||
|
@ -317,8 +327,11 @@ proc new*(
|
|||
engine: BlockExcEngine,
|
||||
erasure: Erasure,
|
||||
discovery: Discovery,
|
||||
contracts = Contracts.default): T =
|
||||
T(
|
||||
contracts = Contracts.default
|
||||
): CodexNodeRef =
|
||||
## Create new instance of a Codex node, call `start` to run it
|
||||
##
|
||||
CodexNodeRef(
|
||||
switch: switch,
|
||||
blockStore: store,
|
||||
engine: engine,
|
||||
|
|
|
@ -47,7 +47,8 @@ proc stop*(purchasing: Purchasing) {.async.} =
|
|||
discard
|
||||
|
||||
proc populate*(purchasing: Purchasing,
|
||||
request: StorageRequest): Future[StorageRequest] {.async.} =
|
||||
request: StorageRequest
|
||||
): Future[StorageRequest] {.async.} =
|
||||
result = request
|
||||
if result.ask.proofProbability == 0.u256:
|
||||
result.ask.proofProbability = purchasing.proofProbability
|
||||
|
@ -60,7 +61,8 @@ proc populate*(purchasing: Purchasing,
|
|||
result.client = await purchasing.market.getSigner()
|
||||
|
||||
proc purchase*(purchasing: Purchasing,
|
||||
request: StorageRequest): Future[Purchase] {.async.} =
|
||||
request: StorageRequest
|
||||
): Future[Purchase] {.async.} =
|
||||
let request = await purchasing.populate(request)
|
||||
let purchase = Purchase.new(request, purchasing.market, purchasing.clock)
|
||||
purchase.start()
|
||||
|
|
|
@ -24,10 +24,14 @@ export Purchase
|
|||
export purchaseid
|
||||
export statemachine
|
||||
|
||||
func new*(_: type Purchase,
|
||||
func new*(
|
||||
_: type Purchase,
|
||||
requestId: RequestId,
|
||||
market: Market,
|
||||
clock: Clock): Purchase =
|
||||
clock: Clock
|
||||
): Purchase =
|
||||
## create a new instance of a Purchase
|
||||
##
|
||||
Purchase(
|
||||
future: Future[void].new(),
|
||||
requestId: requestId,
|
||||
|
@ -35,10 +39,13 @@ func new*(_: type Purchase,
|
|||
clock: clock
|
||||
)
|
||||
|
||||
func new*(_: type Purchase,
|
||||
func new*(
|
||||
_: type Purchase,
|
||||
request: StorageRequest,
|
||||
market: Market,
|
||||
clock: Clock): Purchase =
|
||||
clock: Clock
|
||||
): Purchase =
|
||||
## Create a new purchase using the given market and clock
|
||||
let purchase = Purchase.new(request.id, market, clock)
|
||||
purchase.request = some request
|
||||
return purchase
|
||||
|
|
|
@ -18,7 +18,10 @@ type
|
|||
nodes*: ?uint
|
||||
tolerance*: ?uint
|
||||
|
||||
proc fromJson*(_: type Availability, bytes: seq[byte]): ?!Availability =
|
||||
proc fromJson*(
|
||||
_: type Availability,
|
||||
bytes: seq[byte]
|
||||
): ?!Availability =
|
||||
let json = ?catch parseJson(string.fromBytes(bytes))
|
||||
let size = ?catch UInt256.fromDecimal(json["size"].getStr)
|
||||
let duration = ?catch UInt256.fromDecimal(json["duration"].getStr)
|
||||
|
@ -26,8 +29,10 @@ proc fromJson*(_: type Availability, bytes: seq[byte]): ?!Availability =
|
|||
let maxCollateral = ?catch UInt256.fromDecimal(json["maxCollateral"].getStr)
|
||||
success Availability.init(size, duration, minPrice, maxCollateral)
|
||||
|
||||
proc fromJson*(_: type StorageRequestParams,
|
||||
bytes: seq[byte]): ?! StorageRequestParams =
|
||||
proc fromJson*(
|
||||
_: type StorageRequestParams,
|
||||
bytes: seq[byte]
|
||||
): ?! StorageRequestParams =
|
||||
let json = ?catch parseJson(string.fromBytes(bytes))
|
||||
let duration = ?catch UInt256.fromDecimal(json["duration"].getStr)
|
||||
let proofProbability = ?catch UInt256.fromDecimal(json["proofProbability"].getStr)
|
||||
|
|
|
@ -58,8 +58,7 @@ const
|
|||
SalesKey = (CodexMetaKey / "sales").tryGet # TODO: move to sales module
|
||||
ReservationsKey = (SalesKey / "reservations").tryGet
|
||||
|
||||
proc new*(
|
||||
T: type Reservations,
|
||||
proc new*(T: type Reservations,
|
||||
repo: RepoStore): Reservations =
|
||||
|
||||
T(repo: repo)
|
||||
|
|
|
@ -324,7 +324,8 @@ proc generateProof*(
|
|||
stream: SeekableStream,
|
||||
q: seq[QElement],
|
||||
authenticators: seq[blst_p1],
|
||||
s: int64): Future[Proof] {.async.} =
|
||||
s: int64
|
||||
): Future[Proof] {.async.} =
|
||||
## Generata BLS proofs for a given query
|
||||
##
|
||||
|
||||
|
@ -436,7 +437,8 @@ proc init*(
|
|||
stream: SeekableStream,
|
||||
ssk: SecretKey,
|
||||
spk: PublicKey,
|
||||
blockSize: int64): Future[PoR] {.async.} =
|
||||
blockSize: int64
|
||||
): Future[PoR] {.async.} =
|
||||
## Set up the POR scheme by generating tags and metadata
|
||||
##
|
||||
|
||||
|
|
|
@ -35,7 +35,8 @@ proc upload*(
|
|||
self: StorageProofs,
|
||||
cid: Cid,
|
||||
indexes: seq[int],
|
||||
host: ca.Address): Future[?!void] {.async.} =
|
||||
host: ca.Address
|
||||
): Future[?!void] {.async.} =
|
||||
## Upload authenticators
|
||||
##
|
||||
|
||||
|
@ -57,7 +58,8 @@ proc upload*(
|
|||
|
||||
proc setupProofs*(
|
||||
self: StorageProofs,
|
||||
manifest: Manifest): Future[?!void] {.async.} =
|
||||
manifest: Manifest
|
||||
): Future[?!void] {.async.} =
|
||||
## Setup storage authentication
|
||||
##
|
||||
|
||||
|
@ -78,7 +80,8 @@ proc init*(
|
|||
T: type StorageProofs,
|
||||
network: StpNetwork,
|
||||
store: BlockStore,
|
||||
stpStore: StpStore): StorageProofs =
|
||||
stpStore: StpStore
|
||||
): StorageProofs =
|
||||
|
||||
var
|
||||
self = T(
|
||||
|
|
|
@ -40,7 +40,8 @@ proc uploadTags*(
|
|||
cid: Cid,
|
||||
indexes: seq[int],
|
||||
tags: seq[seq[byte]],
|
||||
host: ca.Address): Future[?!void] {.async.} =
|
||||
host: ca.Address
|
||||
): Future[?!void] {.async.} =
|
||||
# Upload tags to `host`
|
||||
#
|
||||
|
||||
|
@ -93,7 +94,9 @@ method init*(self: StpNetwork) =
|
|||
proc new*(
|
||||
T: type StpNetwork,
|
||||
switch: Switch,
|
||||
discovery: Discovery): StpNetwork =
|
||||
discovery: Discovery
|
||||
): StpNetwork =
|
||||
## create a new StpNetwork instance
|
||||
let
|
||||
self = StpNetwork(
|
||||
switch: switch,
|
||||
|
|
|
@ -33,7 +33,8 @@ template stpPath*(self: StpStore, cid: Cid): string =
|
|||
|
||||
proc retrieve*(
|
||||
self: StpStore,
|
||||
cid: Cid): Future[?!PorMessage] {.async.} =
|
||||
cid: Cid
|
||||
): Future[?!PorMessage] {.async.} =
|
||||
## Retrieve authenticators from data store
|
||||
##
|
||||
|
||||
|
@ -51,7 +52,8 @@ proc retrieve*(
|
|||
proc store*(
|
||||
self: StpStore,
|
||||
por: PorMessage,
|
||||
cid: Cid): Future[?!void] {.async.} =
|
||||
cid: Cid
|
||||
): Future[?!void] {.async.} =
|
||||
## Persist storage proofs
|
||||
##
|
||||
|
||||
|
@ -76,7 +78,8 @@ proc store*(
|
|||
proc retrieve*(
|
||||
self: StpStore,
|
||||
cid: Cid,
|
||||
blocks: seq[int]): Future[?!seq[Tag]] {.async.} =
|
||||
blocks: seq[int]
|
||||
): Future[?!seq[Tag]] {.async.} =
|
||||
var tags: seq[Tag]
|
||||
for b in blocks:
|
||||
var tag = Tag(idx: b)
|
||||
|
@ -94,7 +97,8 @@ proc retrieve*(
|
|||
proc store*(
|
||||
self: StpStore,
|
||||
tags: seq[Tag],
|
||||
cid: Cid): Future[?!void] {.async.} =
|
||||
cid: Cid
|
||||
): Future[?!void] {.async.} =
|
||||
let
|
||||
dir = self.stpPath(cid)
|
||||
|
||||
|
@ -117,7 +121,10 @@ proc store*(
|
|||
proc init*(
|
||||
T: type StpStore,
|
||||
authDir: string,
|
||||
postfixLen: int = 2): StpStore =
|
||||
T(
|
||||
postfixLen: int = 2
|
||||
): StpStore =
|
||||
## Init StpStore
|
||||
##
|
||||
StpStore(
|
||||
authDir: authDir,
|
||||
postfixLen: postfixLen)
|
||||
|
|
|
@ -47,7 +47,8 @@ method getBlock*(self: BlockStore, cid: Cid): Future[?!Block] {.base.} =
|
|||
method putBlock*(
|
||||
self: BlockStore,
|
||||
blk: Block,
|
||||
ttl = Duration.none): Future[?!void] {.base.} =
|
||||
ttl = Duration.none
|
||||
): Future[?!void] {.base.} =
|
||||
## Put a block to the blockstore
|
||||
##
|
||||
|
||||
|
|
|
@ -80,7 +80,8 @@ func cids(self: CacheStore): (iterator: Cid {.gcsafe.}) =
|
|||
|
||||
method listBlocks*(
|
||||
self: CacheStore,
|
||||
blockType = BlockType.Manifest): Future[?!BlocksIter] {.async.} =
|
||||
blockType = BlockType.Manifest
|
||||
): Future[?!BlocksIter] {.async.} =
|
||||
## Get the list of blocks in the BlockStore. This is an intensive operation
|
||||
##
|
||||
|
||||
|
@ -194,6 +195,10 @@ func new*(
|
|||
cacheSize: Positive = DefaultCacheSize, # in bytes
|
||||
chunkSize: Positive = DefaultChunkSize # in bytes
|
||||
): CacheStore {.raises: [Defect, ValueError].} =
|
||||
## Create a new CacheStore instance
|
||||
##
|
||||
## `cacheSize` and `chunkSize` are both in bytes
|
||||
##
|
||||
|
||||
if cacheSize < chunkSize:
|
||||
raise newException(ValueError, "cacheSize cannot be less than chunkSize")
|
||||
|
|
|
@ -33,14 +33,19 @@ type
|
|||
numberOfBlocksPerInterval: int
|
||||
offset: int
|
||||
|
||||
proc new*(T: type BlockMaintainer,
|
||||
proc new*(
|
||||
T: type BlockMaintainer,
|
||||
repoStore: RepoStore,
|
||||
interval: Duration,
|
||||
numberOfBlocksPerInterval = 100,
|
||||
timer = Timer.new(),
|
||||
clock: Clock = SystemClock.new()
|
||||
): T =
|
||||
T(
|
||||
): BlockMaintainer =
|
||||
## Create new BlockMaintainer instance
|
||||
##
|
||||
## Call `start` to begin looking for for expired blocks
|
||||
##
|
||||
BlockMaintainer(
|
||||
repoStore: repoStore,
|
||||
interval: interval,
|
||||
numberOfBlocksPerInterval: numberOfBlocksPerInterval,
|
||||
|
|
|
@ -49,7 +49,8 @@ method getBlock*(self: NetworkStore, cid: Cid): Future[?!bt.Block] {.async.} =
|
|||
method putBlock*(
|
||||
self: NetworkStore,
|
||||
blk: bt.Block,
|
||||
ttl = Duration.none): Future[?!void] {.async.} =
|
||||
ttl = Duration.none
|
||||
): Future[?!void] {.async.} =
|
||||
## Store block locally and notify the network
|
||||
##
|
||||
|
||||
|
@ -88,11 +89,10 @@ method close*(self: NetworkStore): Future[void] {.async.} =
|
|||
proc new*(
|
||||
T: type NetworkStore,
|
||||
engine: BlockExcEngine,
|
||||
localStore: BlockStore): T =
|
||||
|
||||
let
|
||||
self = NetworkStore(
|
||||
localStore: BlockStore
|
||||
): NetworkStore =
|
||||
## Create new instance of a NetworkStore
|
||||
##
|
||||
NetworkStore(
|
||||
localStore: localStore,
|
||||
engine: engine)
|
||||
|
||||
return self
|
||||
|
|
|
@ -92,7 +92,13 @@ proc getBlockExpirationTimestamp(self: RepoStore, ttl: ?Duration): SecondsSince1
|
|||
let duration = ttl |? self.blockTtl
|
||||
self.clock.now() + duration.seconds
|
||||
|
||||
proc getBlockExpirationEntry(self: RepoStore, batch: var seq[BatchEntry], cid: Cid, ttl: ?Duration): ?!BatchEntry =
|
||||
proc getBlockExpirationEntry(
|
||||
self: RepoStore,
|
||||
batch: var seq[BatchEntry],
|
||||
cid: Cid,
|
||||
ttl: ?Duration
|
||||
): ?!BatchEntry =
|
||||
## Get an expiration entry for a batch
|
||||
without key =? createBlockExpirationMetadataKey(cid), err:
|
||||
return failure(err)
|
||||
|
||||
|
@ -102,7 +108,8 @@ proc getBlockExpirationEntry(self: RepoStore, batch: var seq[BatchEntry], cid: C
|
|||
method putBlock*(
|
||||
self: RepoStore,
|
||||
blk: Block,
|
||||
ttl = Duration.none): Future[?!void] {.async.} =
|
||||
ttl = Duration.none
|
||||
): Future[?!void] {.async.} =
|
||||
## Put a block to the blockstore
|
||||
##
|
||||
|
||||
|
@ -202,7 +209,8 @@ method hasBlock*(self: RepoStore, cid: Cid): Future[?!bool] {.async.} =
|
|||
|
||||
method listBlocks*(
|
||||
self: RepoStore,
|
||||
blockType = BlockType.Manifest): Future[?!BlocksIter] {.async.} =
|
||||
blockType = BlockType.Manifest
|
||||
): Future[?!BlocksIter] {.async.} =
|
||||
## Get the list of blocks in the RepoStore.
|
||||
## This is an intensive operation
|
||||
##
|
||||
|
@ -237,7 +245,13 @@ proc createBlockExpirationQuery(maxNumber: int, offset: int): ?!Query =
|
|||
let queryKey = ? createBlockExpirationMetadataQueryKey()
|
||||
success Query.init(queryKey, offset = offset, limit = maxNumber)
|
||||
|
||||
method getBlockExpirations*(self: RepoStore, maxNumber: int, offset: int): Future[?!BlockExpirationIter] {.async, base.} =
|
||||
method getBlockExpirations*(
|
||||
self: RepoStore,
|
||||
maxNumber: int,
|
||||
offset: int
|
||||
): Future[?!BlockExpirationIter] {.async, base.} =
|
||||
## Get block experiartions from the given RepoStore
|
||||
##
|
||||
without query =? createBlockExpirationQuery(maxNumber, offset), err:
|
||||
trace "Unable to format block expirations query"
|
||||
return failure(err)
|
||||
|
@ -394,8 +408,11 @@ func new*(
|
|||
clock: Clock = SystemClock.new(),
|
||||
postFixLen = 2,
|
||||
quotaMaxBytes = DefaultQuotaBytes,
|
||||
blockTtl = DefaultBlockTtl): T =
|
||||
T(
|
||||
blockTtl = DefaultBlockTtl
|
||||
): RepoStore =
|
||||
## Create new instance of a RepoStore
|
||||
##
|
||||
RepoStore(
|
||||
repoDs: repoDs,
|
||||
metaDs: metaDs,
|
||||
clock: clock,
|
||||
|
|
|
@ -34,7 +34,10 @@ method initStream*(self: AsyncStreamWrapper) =
|
|||
proc new*(
|
||||
C: type AsyncStreamWrapper,
|
||||
reader: AsyncStreamReader = nil,
|
||||
writer: AsyncStreamWriter = nil): AsyncStreamWrapper =
|
||||
writer: AsyncStreamWriter = nil
|
||||
): AsyncStreamWrapper =
|
||||
## Create new instance of an asynchronous stream wrapper
|
||||
##
|
||||
let
|
||||
stream = C(reader: reader, writer: writer)
|
||||
|
||||
|
@ -59,7 +62,8 @@ template withExceptions(body: untyped) =
|
|||
method readOnce*(
|
||||
self: AsyncStreamWrapper,
|
||||
pbytes: pointer,
|
||||
nbytes: int): Future[int] {.async.} =
|
||||
nbytes: int
|
||||
): Future[int] {.async.} =
|
||||
|
||||
trace "Reading bytes from reader", bytes = nbytes
|
||||
if isNil(self.reader):
|
||||
|
@ -75,7 +79,8 @@ method readOnce*(
|
|||
proc completeWrite(
|
||||
self: AsyncStreamWrapper,
|
||||
fut: Future[void],
|
||||
msgLen: int): Future[void] {.async.} =
|
||||
msgLen: int
|
||||
): Future[void] {.async.} =
|
||||
|
||||
withExceptions:
|
||||
await fut
|
||||
|
|
|
@ -41,9 +41,11 @@ proc new*(
|
|||
T: type StoreStream,
|
||||
store: BlockStore,
|
||||
manifest: Manifest,
|
||||
pad = true): T =
|
||||
|
||||
result = T(
|
||||
pad = true
|
||||
): StoreStream =
|
||||
## Create a new StoreStream instance for a given store and manifest
|
||||
##
|
||||
result = StoreStream(
|
||||
store: store,
|
||||
manifest: manifest,
|
||||
pad: pad,
|
||||
|
@ -64,10 +66,12 @@ method atEof*(self: StoreStream): bool =
|
|||
method readOnce*(
|
||||
self: StoreStream,
|
||||
pbytes: pointer,
|
||||
nbytes: int): Future[int] {.async.} =
|
||||
nbytes: int
|
||||
): Future[int] {.async.} =
|
||||
## Read `nbytes` from current position in the StoreStream into output buffer pointed by `pbytes`.
|
||||
## Return how many bytes were actually read before EOF was encountered.
|
||||
## Raise exception if we are already at EOF.
|
||||
##
|
||||
|
||||
trace "Reading from manifest", cid = self.manifest.cid.get(), blocks = self.manifest.len
|
||||
if self.atEof:
|
||||
|
|
|
@ -19,7 +19,8 @@ import pkg/stew/shims/net
|
|||
func remapAddr*(
|
||||
address: MultiAddress,
|
||||
ip: Option[ValidIpAddress] = ValidIpAddress.none,
|
||||
port: Option[Port] = Port.none): MultiAddress =
|
||||
port: Option[Port] = Port.none
|
||||
): MultiAddress =
|
||||
## Remap addresses to new IP and/or Port
|
||||
##
|
||||
|
||||
|
|
|
@ -35,7 +35,8 @@ type
|
|||
|
||||
proc newAsyncHeapQueue*[T](
|
||||
maxsize: int = 0,
|
||||
queueType: QueueType = QueueType.Min): AsyncHeapQueue[T] =
|
||||
queueType: QueueType = QueueType.Min
|
||||
): AsyncHeapQueue[T] =
|
||||
## Creates a new asynchronous queue ``AsyncHeapQueue``.
|
||||
##
|
||||
|
||||
|
|
|
@ -22,10 +22,9 @@ type
|
|||
name: string
|
||||
loopFuture: Future[void]
|
||||
|
||||
proc new*(T: type Timer, timerName = "Unnamed Timer"): T =
|
||||
T(
|
||||
name: timerName
|
||||
)
|
||||
proc new*(T: type Timer, timerName = "Unnamed Timer"): Timer =
|
||||
## Create a new Timer intance with the given name
|
||||
Timer(name: timerName)
|
||||
|
||||
proc timerLoop(timer: Timer) {.async.} =
|
||||
try:
|
||||
|
|
|
@ -22,10 +22,13 @@ type
|
|||
logScope:
|
||||
topics = "codex validator"
|
||||
|
||||
proc new*(_: type Validation,
|
||||
proc new*(
|
||||
_: type Validation,
|
||||
clock: Clock,
|
||||
market: Market,
|
||||
maxSlots: int): Validation =
|
||||
maxSlots: int
|
||||
): Validation =
|
||||
## Create a new Validation instance
|
||||
Validation(clock: clock, market: market, maxSlots: maxSlots)
|
||||
|
||||
proc slots*(validation: Validation): seq[SlotId] =
|
||||
|
|
|
@ -33,7 +33,8 @@ proc lenPrefix*(msg: openArray[byte]): seq[byte] =
|
|||
proc corruptBlocks*(
|
||||
store: BlockStore,
|
||||
manifest: Manifest,
|
||||
blks, bytes: int): Future[seq[int]] {.async.} =
|
||||
blks, bytes: int
|
||||
): Future[seq[int]] {.async.} =
|
||||
var pos: seq[int]
|
||||
|
||||
doAssert blks < manifest.len
|
||||
|
|
|
@ -12,8 +12,11 @@ type
|
|||
until: SecondsSince1970
|
||||
future: Future[void]
|
||||
|
||||
func new*(_: type MockClock,
|
||||
time: SecondsSince1970 = getTime().toUnix): MockClock =
|
||||
func new*(
|
||||
_: type MockClock,
|
||||
time: SecondsSince1970 = getTime().toUnix
|
||||
): MockClock =
|
||||
## Create a mock clock instance
|
||||
MockClock(time: time)
|
||||
|
||||
proc set*(clock: MockClock, time: SecondsSince1970) =
|
||||
|
|
|
@ -24,17 +24,21 @@ type
|
|||
publishHostProvideHandler*: proc(d: MockDiscovery, host: ca.Address):
|
||||
Future[void] {.gcsafe.}
|
||||
|
||||
proc new*(T: type MockDiscovery): T =
|
||||
T()
|
||||
proc new*(T: type MockDiscovery): MockDiscovery =
|
||||
MockDiscovery()
|
||||
|
||||
proc findPeer*(
|
||||
d: Discovery,
|
||||
peerId: PeerId): Future[?PeerRecord] {.async.} =
|
||||
peerId: PeerId
|
||||
): Future[?PeerRecord] {.async.} =
|
||||
## mock find a peer - always return none
|
||||
##
|
||||
return none(PeerRecord)
|
||||
|
||||
method find*(
|
||||
d: MockDiscovery,
|
||||
cid: Cid): Future[seq[SignedPeerRecord]] {.async.} =
|
||||
cid: Cid
|
||||
): Future[seq[SignedPeerRecord]] {.async.} =
|
||||
if isNil(d.findBlockProvidersHandler):
|
||||
return
|
||||
|
||||
|
@ -48,7 +52,8 @@ method provide*(d: MockDiscovery, cid: Cid): Future[void] {.async.} =
|
|||
|
||||
method find*(
|
||||
d: MockDiscovery,
|
||||
host: ca.Address): Future[seq[SignedPeerRecord]] {.async.} =
|
||||
host: ca.Address
|
||||
): Future[seq[SignedPeerRecord]] {.async.} =
|
||||
if isNil(d.findHostProvidersHandler):
|
||||
return
|
||||
|
||||
|
|
|
@ -82,6 +82,8 @@ proc hash*(requestId: RequestId): Hash =
|
|||
hash(requestId.toArray)
|
||||
|
||||
proc new*(_: type MockMarket): MockMarket =
|
||||
## Create a new mocked Market instance
|
||||
##
|
||||
let config = MarketplaceConfig(
|
||||
collateral: CollateralConfig(
|
||||
repairRewardPercentage: 10,
|
||||
|
|
|
@ -18,13 +18,18 @@ type
|
|||
mockInterval*: Duration
|
||||
mockCallback: timer.TimerCallback
|
||||
|
||||
proc new*(T: type MockTimer): T =
|
||||
T(
|
||||
proc new*(T: type MockTimer): MockTimer =
|
||||
## Create a mocked Timer instance
|
||||
MockTimer(
|
||||
startCalled: 0,
|
||||
stopCalled: 0
|
||||
)
|
||||
|
||||
method start*(mockTimer: MockTimer, callback: timer.TimerCallback, interval: Duration) =
|
||||
method start*(
|
||||
mockTimer: MockTimer,
|
||||
callback: timer.TimerCallback,
|
||||
interval: Duration
|
||||
) =
|
||||
mockTimer.mockCallback = callback
|
||||
mockTimer.mockInterval = interval
|
||||
inc mockTimer.startCalled
|
||||
|
|
|
@ -25,7 +25,8 @@ type
|
|||
|
||||
proc generateNodes*(
|
||||
num: Natural,
|
||||
blocks: openArray[bt.Block] = []): seq[NodesComponents] =
|
||||
blocks: openArray[bt.Block] = []
|
||||
): seq[NodesComponents] =
|
||||
for i in 0..<num:
|
||||
let
|
||||
switch = newStandardSwitch(transportFlags = {ServerFlags.ReuseAddr})
|
||||
|
|
|
@ -15,9 +15,9 @@ proc new*(
|
|||
rng: Rng,
|
||||
chunkSize = DefaultChunkSize,
|
||||
size: int,
|
||||
pad = false): T =
|
||||
## create a chunker that produces
|
||||
## random data
|
||||
pad = false
|
||||
): RandomChunker =
|
||||
## Create a chunker that produces random data
|
||||
##
|
||||
|
||||
var consumed = 0
|
||||
|
|
|
@ -18,8 +18,7 @@ type
|
|||
Before* = proc(): Future[void] {.gcsafe.}
|
||||
After* = proc(): Future[void] {.gcsafe.}
|
||||
|
||||
proc commonBlockStoreTests*(
|
||||
name: string,
|
||||
proc commonBlockStoreTests*(name: string,
|
||||
provider: StoreProvider,
|
||||
before: Before = nil,
|
||||
after: After = nil) =
|
||||
|
|
|
@ -26,13 +26,17 @@ proc upload*(client: CodexClient, contents: string): string =
|
|||
assert response.status == "200 OK"
|
||||
response.body
|
||||
|
||||
proc requestStorage*(client: CodexClient,
|
||||
proc requestStorage*(
|
||||
client: CodexClient,
|
||||
cid: string,
|
||||
duration: uint64,
|
||||
reward: uint64,
|
||||
proofProbability: uint64,
|
||||
expiry: UInt256,
|
||||
collateral: uint64): string =
|
||||
collateral: uint64
|
||||
): string =
|
||||
## Call request storage REST endpoint
|
||||
##
|
||||
let url = client.baseurl & "/storage/request/" & cid
|
||||
let json = %*{
|
||||
"duration": $duration,
|
||||
|
@ -55,8 +59,13 @@ proc getSlots*(client: CodexClient): JsonNode =
|
|||
let body = client.http.getContent(url)
|
||||
parseJson(body).catch |? nil
|
||||
|
||||
proc postAvailability*(client: CodexClient,
|
||||
size, duration, minPrice: uint64, maxCollateral: uint64): JsonNode =
|
||||
proc postAvailability*(
|
||||
client: CodexClient,
|
||||
size, duration, minPrice: uint64,
|
||||
maxCollateral: uint64
|
||||
): JsonNode =
|
||||
## Post sales availability endpoint
|
||||
##
|
||||
let url = client.baseurl & "/sales/availability"
|
||||
let json = %*{
|
||||
"size": $size,
|
||||
|
@ -69,6 +78,7 @@ proc postAvailability*(client: CodexClient,
|
|||
parseJson(response.body)
|
||||
|
||||
proc getAvailabilities*(client: CodexClient): JsonNode =
|
||||
## Call sales availability REST endpoint
|
||||
let url = client.baseurl & "/sales/availability"
|
||||
let body = client.http.getContent(url)
|
||||
parseJson(body)
|
||||
|
|
Loading…
Reference in New Issue