diff --git a/.gitignore b/.gitignore index 9eaaf60..0314fb6 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ vendor/* NimBinaries .update.timestamp *.dSYM +*.vscode/* diff --git a/codexdht/private/eth/p2p/discoveryv5/encoding.nim b/codexdht/private/eth/p2p/discoveryv5/encoding.nim index 9bb5043..1743559 100644 --- a/codexdht/private/eth/p2p/discoveryv5/encoding.nim +++ b/codexdht/private/eth/p2p/discoveryv5/encoding.nim @@ -15,6 +15,7 @@ import std/[hashes, net, options, sugar, tables], + stew/endians2, bearssl/rand, chronicles, stew/[results, byteutils], @@ -200,7 +201,7 @@ proc hasHandshake*(c: Codec, key: HandshakeKey): bool = proc encodeStaticHeader*(flag: Flag, nonce: AESGCMNonce, authSize: int): seq[byte] = result.add(protocolId) - result.add(version.toBytesBE()) + result.add(endians2.toBytesBE(version)) result.add(byte(flag)) result.add(nonce) # TODO: assert on authSize of > 2^16? diff --git a/codexdht/private/eth/p2p/discoveryv5/messages_encoding.nim b/codexdht/private/eth/p2p/discoveryv5/messages_encoding.nim index 6de6596..707c325 100644 --- a/codexdht/private/eth/p2p/discoveryv5/messages_encoding.nim +++ b/codexdht/private/eth/p2p/discoveryv5/messages_encoding.nim @@ -11,6 +11,7 @@ import std/net, chronicles, + stew/endians2, libp2p/routing_record, libp2p/signed_envelope, "."/[messages, spr, node], @@ -98,7 +99,7 @@ proc getField*(pb: ProtoBuffer, field: int, if not(res): ok(false) else: - family = uint8.fromBytesBE(buffer).IpAddressFamily + family = endians2.fromBytesBE(uint8, buffer).IpAddressFamily ok(true) proc write*(pb: var ProtoBuffer, field: int, family: IpAddressFamily) = diff --git a/codexdht/private/eth/p2p/discoveryv5/protocol.nim b/codexdht/private/eth/p2p/discoveryv5/protocol.nim index aee006c..c3f0672 100644 --- a/codexdht/private/eth/p2p/discoveryv5/protocol.nim +++ b/codexdht/private/eth/p2p/discoveryv5/protocol.nim @@ -369,7 +369,7 @@ proc handleTalkReq(d: Protocol, fromId: NodeId, fromAddr: Address, proc addProviderLocal(p: Protocol, cId: NodeId, prov: SignedPeerRecord) {.async.} = trace "adding provider to local db", n = p.localNode, cId, prov - if (let res = (await p.providers.add(cid, prov)); res.isErr): + if (let res = (await p.providers.add(cId, prov)); res.isErr): trace "Unable to add provider", cid, peerId = prov.data.peerId proc handleAddProvider( diff --git a/codexdht/private/eth/p2p/discoveryv5/providers/maintenance.nim b/codexdht/private/eth/p2p/discoveryv5/providers/maintenance.nim index 713029e..61c9e26 100644 --- a/codexdht/private/eth/p2p/discoveryv5/providers/maintenance.nim +++ b/codexdht/private/eth/p2p/discoveryv5/providers/maintenance.nim @@ -10,6 +10,7 @@ import std/options import std/sequtils +import pkg/stew/endians2 import pkg/chronos import pkg/libp2p import pkg/datastore diff --git a/codexdht/private/eth/p2p/discoveryv5/providers/manager.nim b/codexdht/private/eth/p2p/discoveryv5/providers/manager.nim index 60ea57b..e4e6a7d 100644 --- a/codexdht/private/eth/p2p/discoveryv5/providers/manager.nim +++ b/codexdht/private/eth/p2p/discoveryv5/providers/manager.nim @@ -8,6 +8,7 @@ import std/sequtils import std/strutils +import pkg/stew/endians2 import pkg/datastore import pkg/chronos import pkg/libp2p @@ -79,7 +80,7 @@ proc add*( else: Moment.fromNow(self.ttl) - ZeroMoment - ttl = expires.microseconds.uint64.toBytesBE + ttl = endians2.toBytesBE(expires.microseconds.uint64) bytes: seq[byte] = if existing =? (await self.getProvByKey(provKey)) and diff --git a/tests/dht/test_providers.nim b/tests/dht/test_providers.nim index 1cc1154..de2b884 100644 --- a/tests/dht/test_providers.nim +++ b/tests/dht/test_providers.nim @@ -59,7 +59,7 @@ proc bootstrapNetwork( #waitFor bootNode.bootstrap() # immediate, since no bootnodes are defined above var res = await bootstrapNodes(nodecount - 1, - @[bootnode.localNode.record], + @[bootNode.localNode.record], rng, delay) res.insert((bootNode, bootNodeKey), 0)