update conn peerinfo instead of replacing (#445)

* update conn peerinfo instead of replacing

* remove unnecesary peerid var
This commit is contained in:
Dmitriy Ryajov 2020-11-23 15:15:55 -06:00 committed by GitHub
parent 034a1e8b1b
commit 6cc3f4283a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -505,11 +505,13 @@ method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureCon
received_key = $remotePubKey received_key = $remotePubKey
raise newException(NoiseHandshakeError, "Noise handshake, peer infos don't match! " & $pid & " != " & $conn.peerInfo.peerId) raise newException(NoiseHandshakeError, "Noise handshake, peer infos don't match! " & $pid & " != " & $conn.peerInfo.peerId)
let peerInfo = conn.peerInfo =
if conn.peerInfo != nil: conn.peerInfo if conn.peerInfo != nil:
else: PeerInfo.init(remotePubKey) 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: if initiator:
tmp.readCs = handshakeRes.cs2 tmp.readCs = handshakeRes.cs2

View File

@ -255,11 +255,13 @@ proc newSecioConn(conn: Connection,
## cipher algorithm ``cipher``, stretched keys ``secrets`` and order ## cipher algorithm ``cipher``, stretched keys ``secrets`` and order
## ``order``. ## ``order``.
let peerInfo = conn.peerInfo =
if conn.peerInfo != nil: conn.peerInfo if conn.peerInfo != nil:
else: PeerInfo.init(remotePubKey) 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 i0 = if order < 0: 1 else: 0
let i1 = if order < 0: 0 else: 1 let i1 = if order < 0: 0 else: 1