From 9bb892de69617d2de74a153fc201dfa4a01309c4 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sat, 14 Sep 2019 07:55:52 -0600 Subject: [PATCH] wip: integrating and testing secio --- libp2p/multistream.nim | 55 ++++++++++++++++++--------- libp2p/muxers/mplex/lpchannel.nim | 2 +- libp2p/protocols/secure/plaintext.nim | 29 ++++++++++++++ libp2p/protocols/secure/secio.nim | 24 +++++++----- libp2p/protocols/secure/secure.nim | 22 ++--------- libp2p/switch.nim | 34 ++++++++++++----- tests/testswitch.nim | 6 ++- 7 files changed, 116 insertions(+), 56 deletions(-) create mode 100644 libp2p/protocols/secure/plaintext.nim diff --git a/libp2p/multistream.nim b/libp2p/multistream.nim index 2613fdc..fcb0e88 100644 --- a/libp2p/multistream.nim +++ b/libp2p/multistream.nim @@ -46,39 +46,39 @@ proc newMultistream*(): MultisteamSelect = proc select*(m: MultisteamSelect, conn: Connection, - proto: seq[string]): + proto: seq[string]): Future[string] {.async.} = - debug "select: initiating handshake", codec = m.codec + debug "initiating handshake", codec = m.codec ## select a remote protocol await conn.write(m.codec) # write handshake if proto.len() > 0: - debug "select: selecting proto", proto = proto + info "selecting proto", proto = proto await conn.writeLp((proto[0] & "\n")) # select proto result = cast[string](await conn.readLp()) # read ms header result.removeSuffix("\n") if result != Codec: - debug "select: handshake failed", codec = result + debug "handshake failed", codec = result return "" if proto.len() == 0: # no protocols, must be a handshake call return result = cast[string](await conn.readLp()) # read the first proto - debug "select: reading first requested proto" + info "reading first requested proto" result.removeSuffix("\n") if result == proto[0]: - debug "select: succesfully selected ", proto = proto + debug "succesfully selected ", proto = proto return if not result.len > 0: - debug "select: selecting one of several protos" + info "selecting one of several protos" for p in proto[1..