mirror of
https://github.com/status-im/nim-codex.git
synced 2025-01-09 18:36:29 +00:00
6c92b3dc25
* moving protobuf into bitswap * adding block type * reworking bitswap * adding chunker * adding license header * use 1.2.6 * adding fixed size chunker * add blockstore * add iterator to chunker * more bitswap changes * rename ipfs to dagger * rename to dagger * blockstore inherits from BlockProvider * wip - add core block handling logic * smal changes * use proper block store methods * adding asynq heapqueue * wip prepare for bitswap task runner * adding `$` * adding memory store and tests * fixed chunking * extracted desicion engine from bitswap * added helper random funcs * adding testing helpers * only handle seqs * add peer events * cleanup pending blocks on blockstore event * allow nil handlers * move protobuf type helpers * allow initializing block from Cid * testing and fixes * small fixes * expose `<` * spelling * default value * spelling * pending blocks manager * adding stores manager * more tests a wip around bitswap * small changes * merge bitswap and engine for now * for now run only the new poc's tests * add a more complete ci setup * use template in map * remove p2pd * remove go * dont use asyncCheck * few small changes * adding ability to update items * adding multiple task runners * handle cancelation properly * use Result instead of throwing * wip bitswap tests * moving things around * split out engine again * add request and handlers interface * fix tests * wip - engine tests * remove unused imports * fix tests * cleanup block requesting logic * add block request tests * more block requests * add support for max heap * don't use result * use max heap & send block presence in task handler * add task handler tests * rename store to localStore * cleanup & logging * cancel task on stop * don't depend on local store for events * dont use heap queue for wants * add chronicles * fix issue with peer wants * add test for delayed block sends * remove obsolete tests * wip chunker * run all tests * add todo * misc * remove irrelevant files * removing more files * adding helpers for bitswap tests * moved bitswap file * misc * make blocks timeout longer * adjust block timeout * speedup test * compile with threads * import missing crypto * misc * disable threads for now * fix 32 bit platforms * re-enable threads support in tests
50 lines
1.3 KiB
Nim
50 lines
1.3 KiB
Nim
import pkg/chronos
|
|
import pkg/libp2p/peerinfo
|
|
import pkg/libp2p/multiaddress
|
|
import ./ipfs/p2p/switch
|
|
import ./ipfs/repo
|
|
import ./ipfs/chunking
|
|
import ./ipfs/bitswap
|
|
|
|
export peerinfo except IPFS
|
|
export multiaddress except IPFS
|
|
|
|
type
|
|
Ipfs* = ref object
|
|
repo: Repo
|
|
switch: Switch
|
|
bitswap: Bitswap
|
|
|
|
proc info*(ipfs: Ipfs): PeerInfo =
|
|
ipfs.switch.peerInfo
|
|
|
|
proc start*(_: type Ipfs, addresses: seq[MultiAddress]): Future[Ipfs] {.async.} =
|
|
let repo = Repo()
|
|
let switch = Switch.create()
|
|
let bitswap = Bitswap.start(switch, repo)
|
|
switch.peerInfo.addrs.add(addresses)
|
|
discard await switch.start()
|
|
result = Ipfs(repo: repo, switch: switch, bitswap: bitswap)
|
|
|
|
proc start*(_: type Ipfs, address: MultiAddress): Future[Ipfs] {.async.} =
|
|
result = await Ipfs.start(@[address])
|
|
|
|
proc start*(_: type Ipfs): Future[Ipfs] {.async.} =
|
|
result = await Ipfs.start(@[])
|
|
|
|
proc connect*(peer: Ipfs, info: PeerInfo) {.async.} =
|
|
await peer.bitswap.connect(info)
|
|
|
|
proc add*(peer: Ipfs, input: File): Future[Cid] {.async.} =
|
|
let obj = createObject(input)
|
|
peer.repo.store(obj)
|
|
result = obj.cid
|
|
|
|
proc get*(peer: Ipfs, identifier: Cid, output: File) {.async.} =
|
|
let obj = await peer.bitswap.retrieve(identifier)
|
|
if obj.isSome:
|
|
obj.get().writeToFile(output)
|
|
|
|
proc stop*(peer: Ipfs) {.async.} =
|
|
await peer.switch.stop()
|