diff --git a/libp2p.nimble b/libp2p.nimble index 73ebfa361..914da3e2c 100644 --- a/libp2p.nimble +++ b/libp2p.nimble @@ -17,7 +17,7 @@ requires "nim >= 1.2.0", "stew >= 0.1.0" proc runTest(filename: string, verify: bool = true, sign: bool = true) = - var excstr: string = "nim c -r --opt:speed -d:debug --verbosity:0 --hints:off" + var excstr: string = "nim c -r --opt:speed -d:debug --verbosity:0 --hints:off -d:chronicles_log_level=info" excstr.add(" ") excstr.add("-d:libp2p_pubsub_sign=" & $sign) excstr.add(" ") diff --git a/libp2p/connection.nim b/libp2p/connection.nim index 11bc93ab9..5e39c45a3 100644 --- a/libp2p/connection.nim +++ b/libp2p/connection.nim @@ -29,7 +29,7 @@ type Connection* = ref object of LPStream peerInfo*: PeerInfo stream*: LPStream - observedAddrs*: Multiaddress + observedAddr*: Multiaddress ConnectionTracker* = ref object of TrackerBase opened*: uint64 @@ -117,8 +117,8 @@ method close*(s: Connection) {.async, gcsafe.} = s.isClosed = true trace "about to close connection", closed = s.closed, - conn = $s, - oid = s.oid + conn = $s, + oid = s.oid if not isNil(s.stream) and not s.stream.closed: @@ -137,7 +137,3 @@ method close*(s: Connection) {.async, gcsafe.} = libp2p_open_connection.dec() except CatchableError as exc: trace "exception closing connections", exc = exc.msg - -method getObservedAddrs*(c: Connection): Future[MultiAddress] {.base, async, gcsafe.} = - ## get resolved multiaddresses for the connection - result = c.observedAddrs diff --git a/libp2p/muxers/mplex/mplex.nim b/libp2p/muxers/mplex/mplex.nim index 7bddcf369..40e9bf12a 100644 --- a/libp2p/muxers/mplex/mplex.nim +++ b/libp2p/muxers/mplex/mplex.nim @@ -100,6 +100,7 @@ method handle*(m: Mplex) {.async, gcsafe.} = let stream = newConnection(channel) m.conns.add(stream) stream.peerInfo = m.connection.peerInfo + stream.observedAddr = m.connection.observedAddr var fut = newFuture[void]() proc handler() {.async.} = @@ -191,6 +192,7 @@ method newStream*(m: Mplex, await channel.open() result = newConnection(channel) result.peerInfo = m.connection.peerInfo + result.observedAddr = m.connection.observedAddr asyncCheck m.cleanupChann(channel) diff --git a/libp2p/protocols/identify.nim b/libp2p/protocols/identify.nim index 439b88af4..3f5300c40 100644 --- a/libp2p/protocols/identify.nim +++ b/libp2p/protocols/identify.nim @@ -44,7 +44,7 @@ type Identify* = ref object of LPProtocol peerInfo*: PeerInfo -proc encodeMsg*(peerInfo: PeerInfo, observedAddrs: Multiaddress): ProtoBuffer = +proc encodeMsg*(peerInfo: PeerInfo, observedAddr: Multiaddress): ProtoBuffer = result = initProtoBuffer() result.write(initProtoField(1, peerInfo.publicKey.get().getBytes().tryGet())) @@ -55,7 +55,7 @@ proc encodeMsg*(peerInfo: PeerInfo, observedAddrs: Multiaddress): ProtoBuffer = for proto in peerInfo.protocols: result.write(initProtoField(3, proto)) - result.write(initProtoField(4, observedAddrs.data.buffer)) + result.write(initProtoField(4, observedAddr.data.buffer)) let protoVersion = ProtoVersion result.write(initProtoField(5, protoVersion)) @@ -114,10 +114,11 @@ method init*(p: Identify) = proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} = try: try: - trace "handling identify request" - var pb = encodeMsg(p.peerInfo, await conn.getObservedAddrs()) + trace "handling identify request", oid = conn.oid + var pb = encodeMsg(p.peerInfo, conn.observedAddr) await conn.writeLp(pb.buffer) finally: + trace "exiting identify handler", oid = conn.oid await conn.close() except CatchableError as exc: trace "exception in identify handler", exc = exc.msg @@ -148,10 +149,9 @@ proc identify*(p: Identify, remote = peer.pretty(), local = remotePeerInfo.id - raise newException(IdentityNoMatchError, - "Peer ids don't match") + raise newException(IdentityNoMatchError, "Peer ids don't match") proc push*(p: Identify, conn: Connection) {.async.} = await conn.write(IdentifyPushCodec) - var pb = encodeMsg(p.peerInfo, await conn.getObservedAddrs()) + var pb = encodeMsg(p.peerInfo, conn.observedAddr) await conn.writeLp(pb.buffer) diff --git a/libp2p/protocols/secure/secure.nim b/libp2p/protocols/secure/secure.nim index fd1de092a..6854b2906 100644 --- a/libp2p/protocols/secure/secure.nim +++ b/libp2p/protocols/secure/secure.nim @@ -32,6 +32,7 @@ proc handleConn*(s: Secure, conn: Connection, initiator: bool): Future[Connectio var sconn = await s.handshake(conn, initiator) result = sconn + result.observedAddr = conn.observedAddr if not isNil(sconn.peerInfo) and sconn.peerInfo.publicKey.isSome: result.peerInfo = PeerInfo.init(sconn.peerInfo.publicKey.get()) diff --git a/libp2p/transports/tcptransport.nim b/libp2p/transports/tcptransport.nim index eb5862494..2c9ce576d 100644 --- a/libp2p/transports/tcptransport.nim +++ b/libp2p/transports/tcptransport.nim @@ -64,7 +64,7 @@ proc connHandler*(t: TcpTransport, initiator: bool): Connection = trace "handling connection", address = $client.remoteAddress let conn: Connection = newConnection(newChronosStream(client)) - conn.observedAddrs = MultiAddress.init(client.remoteAddress).tryGet() + conn.observedAddr = MultiAddress.init(client.remoteAddress).tryGet() if not initiator: if not isNil(t.handler): t.handlers &= t.handler(conn)