Peer resultification and defect only (#245)

* Peer resultification and defect only

* Fixing some tests

* test fixes

* Rename peer into peerid

* better result error message in identify

* further merge fixes
This commit is contained in:
Giovanni Petrantoni
2020-07-01 15:25:09 +09:00
committed by GitHub
parent c788a6a3c0
commit ec00c7fc50
29 changed files with 103 additions and 83 deletions

View File

@@ -12,7 +12,7 @@ import chronos, chronicles
import ../protobuf/minprotobuf,
../peerinfo,
../stream/connection,
../peer,
../peerid,
../crypto/crypto,
../multiaddress,
../protocols/protocol,
@@ -142,16 +142,18 @@ proc identify*(p: Identify,
if not isNil(remotePeerInfo) and result.pubKey.isSome:
let peer = PeerID.init(result.pubKey.get())
if peer.isErr:
raise newException(IdentityInvalidMsgError, $peer.error)
else:
# do a string comaprison of the ids,
# because that is the only thing we
# have in most cases
if peer.get() != remotePeerInfo.peerId:
trace "Peer ids don't match",
remote = peer.get().pretty(),
local = remotePeerInfo.id
# do a string comparison of the ids,
# because that is the only thing we
# have in most cases
if peer != remotePeerInfo.peerId:
trace "Peer ids don't match",
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)