From f8a942ed679294b2f5eb56228bd6aa397bb487aa Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 4 Sep 2019 15:21:12 -0600 Subject: [PATCH] make peerinfo an optional type --- libp2p/connection.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libp2p/connection.nim b/libp2p/connection.nim index 5d63e6720..087f6ee2a 100644 --- a/libp2p/connection.nim +++ b/libp2p/connection.nim @@ -7,7 +7,7 @@ ## This file may not be copied, modified, or distributed except according to ## those terms. -import chronos +import chronos, options import peerinfo, multiaddress, stream/lpstream, peerinfo, varint, vbuffer @@ -16,13 +16,17 @@ const DefaultReadSize*: uint = 64 * 1024 type Connection* = ref object of LPStream - peerInfo*: PeerInfo + peerInfo*: Option[PeerInfo] stream*: LPStream proc newConnection*(stream: LPStream): Connection = ## create a new Connection for the specified async reader/writer new result result.stream = stream + result.peerInfo = none(PeerInfo) + +proc `=peerInfo`*(s: Connection, peerInfo: PeerInfo) = + s.peerInfo = some(peerInfo) method read*(s: Connection, n = -1): Future[seq[byte]] {.gcsafe.} = result = s.stream.read(n)