From 6cc3f4283a94070a3f5490ab5e4dae86355ffa96 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 23 Nov 2020 15:15:55 -0600 Subject: [PATCH] update conn peerinfo instead of replacing (#445) * update conn peerinfo instead of replacing * remove unnecesary peerid var --- libp2p/protocols/secure/noise.nim | 10 ++++++---- libp2p/protocols/secure/secio.nim | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libp2p/protocols/secure/noise.nim b/libp2p/protocols/secure/noise.nim index e4a4628c2..1a9cd5a4b 100644 --- a/libp2p/protocols/secure/noise.nim +++ b/libp2p/protocols/secure/noise.nim @@ -505,11 +505,13 @@ method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureCon received_key = $remotePubKey raise newException(NoiseHandshakeError, "Noise handshake, peer infos don't match! " & $pid & " != " & $conn.peerInfo.peerId) - let peerInfo = - if conn.peerInfo != nil: conn.peerInfo - else: PeerInfo.init(remotePubKey) + conn.peerInfo = + if conn.peerInfo != nil: + conn.peerInfo + else: + PeerInfo.init(PeerID.init(remotePubKey).tryGet()) - var tmp = NoiseConnection.init(conn, peerInfo, conn.observedAddr) + var tmp = NoiseConnection.init(conn, conn.peerInfo, conn.observedAddr) if initiator: tmp.readCs = handshakeRes.cs2 diff --git a/libp2p/protocols/secure/secio.nim b/libp2p/protocols/secure/secio.nim index 71bcb4dc2..ff22d44cd 100644 --- a/libp2p/protocols/secure/secio.nim +++ b/libp2p/protocols/secure/secio.nim @@ -255,11 +255,13 @@ proc newSecioConn(conn: Connection, ## cipher algorithm ``cipher``, stretched keys ``secrets`` and order ## ``order``. - let peerInfo = - if conn.peerInfo != nil: conn.peerInfo - else: PeerInfo.init(remotePubKey) + conn.peerInfo = + if conn.peerInfo != nil: + conn.peerInfo + else: + PeerInfo.init(PeerID.init(remotePubKey).tryGet()) - result = SecioConn.init(conn, peerInfo, conn.observedAddr) + result = SecioConn.init(conn, conn.peerInfo, conn.observedAddr) let i0 = if order < 0: 1 else: 0 let i1 = if order < 0: 0 else: 1