bump libp2p (#1267)

This commit is contained in:
Jacek Sieka 2020-07-01 13:41:40 +02:00 committed by GitHub
parent c19321e578
commit ef2f037571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 13 deletions

View File

@ -28,6 +28,7 @@ type Eth2Digest = digest.Eth2Digest
type type
RpcServer* = RpcHttpServer RpcServer* = RpcHttpServer
KeyPair* = eth2_network.KeyPair
BeaconNode* = ref object BeaconNode* = ref object
nickname*: string nickname*: string

View File

@ -11,7 +11,7 @@ import
json_serialization, json_serialization/std/[net, options], json_serialization, json_serialization/std/[net, options],
chronos, chronicles, metrics, chronos, chronicles, metrics,
# TODO: create simpler to use libp2p modules that use re-exports # TODO: create simpler to use libp2p modules that use re-exports
libp2p/[switch, standard_setup, peerinfo, peer, errors, libp2p/[switch, standard_setup, peerinfo, errors,
multiaddress, multicodec, crypto/crypto, crypto/secp, multiaddress, multicodec, crypto/crypto, crypto/secp,
protocols/identify, protocols/protocol], protocols/identify, protocols/protocol],
libp2p/protocols/secure/[secure, secio], libp2p/protocols/secure/[secure, secio],
@ -27,7 +27,7 @@ import
export export
version, multiaddress, peer_pool, peerinfo, p2pProtocol, version, multiaddress, peer_pool, peerinfo, p2pProtocol,
libp2p_json_serialization, ssz_serialization, peer, results libp2p_json_serialization, ssz_serialization, results
logScope: logScope:
topics = "networking" topics = "networking"
@ -694,7 +694,7 @@ proc toPeerInfo*(r: enr.TypedRecord): PeerInfo =
discard discard
if addresses.len > 0: if addresses.len > 0:
return PeerInfo.init(peerId, addresses) return PeerInfo.init(peerId.tryGet(), addresses)
proc toPeerInfo(r: Option[enr.TypedRecord]): PeerInfo = proc toPeerInfo(r: Option[enr.TypedRecord]): PeerInfo =
if r.isSome: if r.isSome:

View File

@ -6,8 +6,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
import sequtils, strutils, os, tables, options import sequtils, strutils, os, tables, options
import confutils, chronicles, chronos import confutils, chronicles, chronos
import libp2p/[switch, standard_setup, multiaddress, multicodec, import libp2p/[switch, standard_setup, multiaddress, multicodec, peerinfo]
peer, peerinfo, peer]
import libp2p/crypto/crypto as lcrypto import libp2p/crypto/crypto as lcrypto
import libp2p/crypto/secp as lsecp import libp2p/crypto/secp as lsecp
import eth/p2p/discoveryv5/enr as enr import eth/p2p/discoveryv5/enr as enr
@ -294,7 +293,9 @@ proc init*(p: typedesc[PeerInfo],
## Initialize PeerInfo using address which includes PeerID. ## Initialize PeerInfo using address which includes PeerID.
if IPFS.match(maddr): if IPFS.match(maddr):
let peerid = ? protoAddress(? maddr[2]) let peerid = ? protoAddress(? maddr[2])
result = ok(PeerInfo.init(PeerID.init(peerid), [(? maddr[0]) & (? maddr[1])])) result = ok(PeerInfo.init(
? (PeerID.init(peerid).mapErr(proc (v: cstring): string = $v)),
[(? maddr[0]) & (? maddr[1])]))
proc init*(p: typedesc[PeerInfo], proc init*(p: typedesc[PeerInfo],
enraddr: enr.Record): StrRes[PeerInfo] = enraddr: enr.Record): StrRes[PeerInfo] =
@ -326,7 +327,7 @@ proc init*(p: typedesc[PeerInfo],
let ma = (? MultiAddress.init(multiCodec("ip6"), trec.ip6.get())) & let ma = (? MultiAddress.init(multiCodec("ip6"), trec.ip6.get())) &
(? MultiAddress.init(multiCodec("udp"), trec.udp6.get())) (? MultiAddress.init(multiCodec("udp"), trec.udp6.get()))
mas.add(ma) mas.add(ma)
result = ok PeerInfo.init(peerid, mas) result = ok PeerInfo.init(peerid.tryGet(), mas)
except CatchableError as exc: except CatchableError as exc:
warn "Error", errMsg = exc.msg, record = enraddr.toUri() warn "Error", errMsg = exc.msg, record = enraddr.toUri()

View File

@ -5,15 +5,19 @@ proc writeValue*(writer: var JsonWriter, value: PeerID) {.inline.} =
writer.writeValue value.pretty writer.writeValue value.pretty
proc readValue*(reader: var JsonReader, value: var PeerID) {.inline.} = proc readValue*(reader: var JsonReader, value: var PeerID) {.inline.} =
value = PeerID.init reader.readValue(string) let res = PeerID.init reader.readValue(string)
if res.isOk:
value = res.get()
else:
raiseUnexpectedValue(reader, $res.error)
proc writeValue*(writer: var JsonWriter, value: MultiAddress) {.inline.} = proc writeValue*(writer: var JsonWriter, value: MultiAddress) {.inline.} =
writer.writeValue $value writer.writeValue $value
proc readValue*(reader: var JsonReader, value: var MultiAddress) {.inline.} = proc readValue*(reader: var JsonReader, value: var MultiAddress) {.inline.} =
let addressRes = MultiAddress.init reader.readValue(string) let res = MultiAddress.init reader.readValue(string)
if addressRes.isOk: if res.isOk:
value = addressRes.value value = res.value
else: else:
raiseUnexpectedValue(reader, "Invalid MultiAddress value") raiseUnexpectedValue(reader, $res.error)

2
vendor/nim-libp2p vendored

@ -1 +1 @@
Subproject commit c788a6a3c0ca614be4c67cc566aee6877da0250b Subproject commit b49c619ca851ec6e832243b633efee4c57af5e40