make peerinfo an optional type
This commit is contained in:
parent
9889bd9cbf
commit
f8a942ed67
|
@ -7,7 +7,7 @@
|
||||||
## This file may not be copied, modified, or distributed except according to
|
## This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
## those terms.
|
||||||
|
|
||||||
import chronos
|
import chronos, options
|
||||||
import peerinfo, multiaddress,
|
import peerinfo, multiaddress,
|
||||||
stream/lpstream, peerinfo,
|
stream/lpstream, peerinfo,
|
||||||
varint, vbuffer
|
varint, vbuffer
|
||||||
|
@ -16,13 +16,17 @@ const DefaultReadSize*: uint = 64 * 1024
|
||||||
|
|
||||||
type
|
type
|
||||||
Connection* = ref object of LPStream
|
Connection* = ref object of LPStream
|
||||||
peerInfo*: PeerInfo
|
peerInfo*: Option[PeerInfo]
|
||||||
stream*: LPStream
|
stream*: LPStream
|
||||||
|
|
||||||
proc newConnection*(stream: LPStream): Connection =
|
proc newConnection*(stream: LPStream): Connection =
|
||||||
## create a new Connection for the specified async reader/writer
|
## create a new Connection for the specified async reader/writer
|
||||||
new result
|
new result
|
||||||
result.stream = stream
|
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.} =
|
method read*(s: Connection, n = -1): Future[seq[byte]] {.gcsafe.} =
|
||||||
result = s.stream.read(n)
|
result = s.stream.read(n)
|
||||||
|
|
Loading…
Reference in New Issue