From 6ae92eb21aa2f15200dea593c14086d47dfbf999 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Wed, 22 Apr 2020 23:36:59 +0900 Subject: [PATCH] Hotfix noise read usage, replace with readExactly --- libp2p/protocols/secure/noise.nim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libp2p/protocols/secure/noise.nim b/libp2p/protocols/secure/noise.nim index 369c737..16ee816 100644 --- a/libp2p/protocols/secure/noise.nim +++ b/libp2p/protocols/secure/noise.nim @@ -270,7 +270,9 @@ proc receiveHSMessage(sconn: Connection): Future[seq[byte]] {.async.} = await sconn.readExactly(addr besize[0], 2) let size = uint16.fromBytesBE(besize).int trace "receiveHSMessage", size - return await sconn.read(size) + var buffer = newSeq[byte](size) + await sconn.readExactly(addr buffer[0], size) + return buffer proc sendHSMessage(sconn: Connection; buf: seq[byte]) {.async.} = var @@ -422,9 +424,9 @@ method readMessage(sconn: NoiseConnection): Future[seq[byte]] {.async.} = trace "receiveEncryptedMessage", size, peer = $sconn.peerInfo if size == 0: return @[] - let - cipher = await sconn.read(size) - var plain = sconn.readCs.decryptWithAd([], cipher) + var buffer = newSeq[byte](size) + await sconn.readExactly(addr buffer[0], size) + var plain = sconn.readCs.decryptWithAd([], buffer) unpackNoisePayload(plain) return plain except LPStreamIncompleteError: