fix: removing timeouts from conn

This commit is contained in:
Dmitriy Ryajov 2020-02-05 18:54:03 +01:00
parent 2232ca598e
commit 88a030d8fb
3 changed files with 9 additions and 17 deletions

View File

@ -16,27 +16,23 @@ import peerinfo,
vbuffer vbuffer
const DefaultReadSize*: uint = 64 * 1024 const DefaultReadSize*: uint = 64 * 1024
const DefaultRWTimeout*: Duration = 2.minutes
type type
Connection* = ref object of LPStream Connection* = ref object of LPStream
peerInfo*: PeerInfo peerInfo*: PeerInfo
stream*: LPStream stream*: LPStream
observedAddrs*: Multiaddress observedAddrs*: Multiaddress
timeout*: Duration
InvalidVarintException = object of LPStreamError InvalidVarintException = object of LPStreamError
proc newInvalidVarintException*(): ref InvalidVarintException = proc newInvalidVarintException*(): ref InvalidVarintException =
newException(InvalidVarintException, "unable to prase varint") newException(InvalidVarintException, "unable to prase varint")
proc newConnection*(stream: LPStream, proc newConnection*(stream: LPStream): Connection =
timeout: Duration = DefaultRWTimeout): 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.closeEvent = newAsyncEvent() result.closeEvent = newAsyncEvent()
result.timeout = timeout
# bind stream's close event to connection's close # bind stream's close event to connection's close
# to ensure correct close propagation # to ensure correct close propagation
@ -49,50 +45,50 @@ proc newConnection*(stream: LPStream,
asyncCheck this.close() asyncCheck this.close()
method read*(s: Connection, n = -1): Future[seq[byte]] {.gcsafe.} = method read*(s: Connection, n = -1): Future[seq[byte]] {.gcsafe.} =
wait(s.stream.read(n), s.timeout) s.stream.read(n)
method readExactly*(s: Connection, method readExactly*(s: Connection,
pbytes: pointer, pbytes: pointer,
nbytes: int): nbytes: int):
Future[void] {.gcsafe.} = Future[void] {.gcsafe.} =
wait(s.stream.readExactly(pbytes, nbytes), s.timeout) s.stream.readExactly(pbytes, nbytes)
method readLine*(s: Connection, method readLine*(s: Connection,
limit = 0, limit = 0,
sep = "\r\n"): sep = "\r\n"):
Future[string] {.gcsafe.} = Future[string] {.gcsafe.} =
wait(s.stream.readLine(limit, sep), s.timeout) s.stream.readLine(limit, sep)
method readOnce*(s: Connection, method readOnce*(s: Connection,
pbytes: pointer, pbytes: pointer,
nbytes: int): nbytes: int):
Future[int] {.gcsafe.} = Future[int] {.gcsafe.} =
wait(s.stream.readOnce(pbytes, nbytes), s.timeout) s.stream.readOnce(pbytes, nbytes)
method readUntil*(s: Connection, method readUntil*(s: Connection,
pbytes: pointer, pbytes: pointer,
nbytes: int, nbytes: int,
sep: seq[byte]): sep: seq[byte]):
Future[int] {.gcsafe.} = Future[int] {.gcsafe.} =
wait(s.stream.readUntil(pbytes, nbytes, sep), s.timeout) s.stream.readUntil(pbytes, nbytes, sep)
method write*(s: Connection, method write*(s: Connection,
pbytes: pointer, pbytes: pointer,
nbytes: int): nbytes: int):
Future[void] {.gcsafe.} = Future[void] {.gcsafe.} =
wait(s.stream.write(pbytes, nbytes), s.timeout) s.stream.write(pbytes, nbytes)
method write*(s: Connection, method write*(s: Connection,
msg: string, msg: string,
msglen = -1): msglen = -1):
Future[void] {.gcsafe.} = Future[void] {.gcsafe.} =
wait(s.stream.write(msg, msglen), s.timeout) s.stream.write(msg, msglen)
method write*(s: Connection, method write*(s: Connection,
msg: seq[byte], msg: seq[byte],
msglen = -1): msglen = -1):
Future[void] {.gcsafe.} = Future[void] {.gcsafe.} =
wait(s.stream.write(msg, msglen), s.timeout) s.stream.write(msg, msglen)
method closed*(s: Connection): bool = method closed*(s: Connection): bool =
if isNil(s.stream): if isNil(s.stream):

View File

@ -43,8 +43,6 @@ proc isConnected*(p: PubSubPeer): bool =
proc `conn=`*(p: PubSubPeer, conn: Connection) = proc `conn=`*(p: PubSubPeer, conn: Connection) =
trace "attaching send connection for peer", peer = p.id trace "attaching send connection for peer", peer = p.id
p.sendConn = conn p.sendConn = conn
p.sendConn.timeout = InfiniteDuration
p.onConnect.fire() p.onConnect.fire()
proc handle*(p: PubSubPeer, conn: Connection) {.async.} = proc handle*(p: PubSubPeer, conn: Connection) {.async.} =

View File

@ -31,7 +31,6 @@ const
SecioExchanges = "P-256,P-384,P-521" SecioExchanges = "P-256,P-384,P-521"
SecioCiphers = "TwofishCTR,AES-256,AES-128" SecioCiphers = "TwofishCTR,AES-256,AES-128"
SecioHashes = "SHA256,SHA512" SecioHashes = "SHA256,SHA512"
SecioRWTimeout = 2.minutes
type type
Secio = ref object of Secure Secio = ref object of Secure
@ -234,7 +233,6 @@ proc newSecureConnection(conn: Connection,
new result new result
result.stream = conn result.stream = conn
result.timeout = SecioRWTimeout
result.closeEvent = newAsyncEvent() result.closeEvent = newAsyncEvent()
let i0 = if order < 0: 1 else: 0 let i0 = if order < 0: 1 else: 0