Upgrade vendor nim-libp2p and related packages (#13)

* Upgrade nim-libp2p to latest

* Upgrade nim-chronos to latest (needed for nim-libp2p)

* Fix conn.readLp varint

* Fix standard switch API change

* WIP: Crypto resultification on v2

* Fix Result usage for SkPrivateKey

* Result fixes

Co-authored-by: kdeme <kim.demey@gmail.com>
This commit is contained in:
Oskar Thorén 2020-05-26 11:55:53 +08:00 committed by GitHub
parent 97d3119c33
commit b5006e482e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 15 deletions

View File

@ -1,9 +1,11 @@
# compile time options here
const
libp2p_secure {.strdefine.} = ""
libp2p_pubsub_sign {.booldefine.} = true
libp2p_pubsub_verify {.booldefine.} = true
import
options, tables, chronicles,
options, tables, chronicles, chronos,
libp2p/[switch, peer, peerinfo, connection, multiaddress, crypto/crypto],
libp2p/transports/[transport, tcptransport],
libp2p/muxers/[muxer, mplex/mplex, mplex/types],
@ -22,16 +24,19 @@ export
proc newStandardSwitch*(privKey = none(PrivateKey),
address = MultiAddress.init("/ip4/127.0.0.1/tcp/0"),
triggerSelf = false,
gossip = false): Switch =
gossip = false,
verifySignature = libp2p_pubsub_verify,
sign = libp2p_pubsub_sign,
transportFlags: set[ServerFlags] = {}): Switch =
info "newStandardSwitch"
proc createMplex(conn: Connection): Muxer =
result = newMplex(conn)
let
seckey = privKey.get(otherwise = PrivateKey.random(ECDSA))
seckey = privKey.get(otherwise = PrivateKey.random(ECDSA).tryGet())
peerInfo = PeerInfo.init(seckey, [address])
mplexProvider = newMuxerProvider(createMplex, MplexCodec)
transports = @[Transport(newTransport(TcpTransport))]
transports = @[Transport(TcpTransport.init(transportFlags))]
muxers = {MplexCodec: mplexProvider}.toTable
identify = newIdentify(peerInfo)
when libp2p_secure == "noise":

2
vendor/nim-chronos vendored

@ -1 +1 @@
Subproject commit 357baa52a0ea3da699c8229d97230c7f4340da92
Subproject commit bce0f878d16bea14395dc8944ff8dbdeffe33496

2
vendor/nim-libp2p vendored

@ -1 +1 @@
Subproject commit 8a22c073c772e4735f8eeb2d2d01ce985607bb8d
Subproject commit 9132f169278ce05fd6fe86dac65e8bec1e9d56c9

View File

@ -88,9 +88,7 @@ type
# NOTE: Signature is different here, we return PrivateKey and not KeyPair
nodekey* {.
desc: "P2P node private key as hex.",
# defaultValue: keys.KeyPair.random().tryGet()
# Use PrivateKey here instead
defaultValue: PrivateKey.random(Secp256k1)
defaultValue: PrivateKey.random(Secp256k1).tryGet()
name: "nodekey" }: PrivateKey
# TODO: Add nodekey file option
@ -141,7 +139,8 @@ type
# NOTE: Keys are different in nim-libp2p
proc parseCmdArg*(T: type PrivateKey, p: TaintedString): T =
try:
let key = SkPrivateKey.init(utils.fromHex(p))
let key = SkPrivateKey.init(utils.fromHex(p)).tryGet()
# XXX: Here at the moment
result = PrivateKey(scheme: Secp256k1, skkey: key)
except CatchableError as e:
raise newException(ConfigurationError, "Invalid private key")

View File

@ -29,12 +29,13 @@ type
# Ok cool so it is config.nim parseCmdArg, then use fromHex
proc initNodeCmd(shift: int, staticNodes: seq[string] = @[], master = false, label: string): NodeInfo =
let
key = SkPrivateKey.random()
key = SkPrivateKey.random()[] #assumes ok
hkey = key.getBytes().toHex()
rkey = SkPrivateKey.init(fromHex(hkey))
rkey = SkPrivateKey.init(fromHex(hkey))[] #assumes ok
privKey = PrivateKey(scheme: Secp256k1, skkey: rkey)
#privKey = PrivateKey.random(Secp256k1)
keys = KeyPair(seckey: privKey, pubkey: privKey.getKey())
pubkey = privKey.getKey()[] #assumes ok
keys = KeyPair(seckey: privKey, pubkey: pubkey)
peerInfo = PeerInfo.init(privKey)
# XXX
DefaultAddr = "/ip4/127.0.0.1/tcp/55505"

View File

@ -110,7 +110,7 @@ proc newWakuProto(switch: Switch): WakuProto =
var wakuproto = WakuProto(switch: switch, codec: WakuSubCodec)
proc handle(conn: Connection, proto: string) {.async, gcsafe.} =
let msg = cast[string](await conn.readLp())
let msg = cast[string](await conn.readLp(1024))
await conn.writeLp("Hello!")
await conn.close()
@ -137,7 +137,10 @@ proc run(config: WakuNodeConf) =
# Difference between announced and host address relevant for running behind NAT, however doesn't seem like nim-libp2p supports this. GHI?
# NOTE: This is a privatekey
nodekey = config.nodekey
keys = KeyPair(seckey: nodekey, pubkey: nodekey.getKey())
seckey = nodekey
pubkey = seckey.getKey.get()
keys = KeyPair(seckey: seckey, pubkey: pubkey)
peerInfo = PeerInfo.init(nodekey)
info "Initializing networking (host address and announced same)", address