From b1a34f478efe6d1212cfccecaf4dd8bf89fc2b1f Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Wed, 18 Mar 2020 20:40:51 +0900 Subject: [PATCH] Avoid 2 async consecutive writes in noise HS --- libp2p/protocols/secure/noise.nim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libp2p/protocols/secure/noise.nim b/libp2p/protocols/secure/noise.nim index cb928b3..0622f0d 100644 --- a/libp2p/protocols/secure/noise.nim +++ b/libp2p/protocols/secure/noise.nim @@ -273,9 +273,11 @@ proc sendHSMessage(sconn: Connection; buf: seq[byte]) {.async.} = var lesize = buf.len.uint16 besize = lesize.toBytesBE + outbuf = newSeqOfCap[byte](besize.len + buf.len) trace "sendHSMessage", size = lesize - await sconn.write(besize[0].addr, besize.len) - await sconn.write(buf) + outbuf &= besize + outbuf &= buf + await sconn.write(outbuf) proc packNoisePayload(payload: openarray[byte]): seq[byte] = let