Add absolutely minimal implementation of a DHT routing table
This commit is contained in:
parent
7b15a6ae83
commit
b3f5599925
|
@ -0,0 +1,11 @@
|
|||
import pkg/libp2p
|
||||
|
||||
type
|
||||
RoutingTable* = object
|
||||
peers: seq[PeerInfo]
|
||||
|
||||
proc add*(table: var RoutingTable, peer: PeerInfo) =
|
||||
table.peers.add(peer)
|
||||
|
||||
proc closest*(table: RoutingTable, id: Cid): seq[PeerInfo] =
|
||||
table.peers
|
|
@ -0,0 +1,17 @@
|
|||
import std/unittest
|
||||
import pkg/libp2p
|
||||
import pkg/ipfs/ipfsobject
|
||||
import pkg/ipfs/dht/routing
|
||||
|
||||
suite "DHT routing table":
|
||||
|
||||
test "finds peers closest to some content":
|
||||
let peer1 = PeerInfo(peer: PeerId(data: @[1'u8]))
|
||||
let peer2 = PeerInfo(peer: PeerId(data: @[2'u8]))
|
||||
let contentId = IpfsObject(data: @[]).cid
|
||||
|
||||
var table = RoutingTable()
|
||||
table.add(peer1)
|
||||
table.add(peer2)
|
||||
|
||||
check table.closest(contentId) == @[peer1, peer2]
|
|
@ -1,6 +1,7 @@
|
|||
import ./ipfs/testObject
|
||||
import ./ipfs/testChunking
|
||||
import ./ipfs/testRepo
|
||||
import ./ipfs/testDhtRouting
|
||||
import ./ipfs/testIpfs
|
||||
|
||||
{.warning[UnusedImport]: off.}
|
||||
|
|
Loading…
Reference in New Issue