parent
ee281310c0
commit
35ff99829e
|
@ -145,7 +145,7 @@ proc handle*(m: MultistreamSelect, conn: Connection) {.async, gcsafe.} =
|
||||||
await conn.writeLp((h.proto & "\n"))
|
await conn.writeLp((h.proto & "\n"))
|
||||||
await h.protocol.handler(conn, ms)
|
await h.protocol.handler(conn, ms)
|
||||||
return
|
return
|
||||||
warn "no handlers for ", protocol = ms
|
debug "no handlers for ", protocol = ms
|
||||||
await conn.write(Na)
|
await conn.write(Na)
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
trace "exception in multistream", exc = exc.msg
|
trace "exception in multistream", exc = exc.msg
|
||||||
|
|
|
@ -112,10 +112,15 @@ proc newIdentify*(peerInfo: PeerInfo): Identify =
|
||||||
|
|
||||||
method init*(p: Identify) =
|
method init*(p: Identify) =
|
||||||
proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} =
|
proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} =
|
||||||
|
try:
|
||||||
|
try:
|
||||||
trace "handling identify request"
|
trace "handling identify request"
|
||||||
var pb = encodeMsg(p.peerInfo, await conn.getObservedAddrs())
|
var pb = encodeMsg(p.peerInfo, await conn.getObservedAddrs())
|
||||||
await conn.writeLp(pb.buffer)
|
await conn.writeLp(pb.buffer)
|
||||||
# await conn.close() #TODO: investigate why this breaks
|
finally:
|
||||||
|
await conn.close()
|
||||||
|
except CatchableError as exc:
|
||||||
|
trace "exception in identify handler", exc = exc.msg
|
||||||
|
|
||||||
p.handler = handle
|
p.handler = handle
|
||||||
p.codec = IdentifyCodec
|
p.codec = IdentifyCodec
|
||||||
|
|
|
@ -110,6 +110,8 @@ proc mux(s: Switch, conn: Connection): Future[void] {.async, gcsafe.} =
|
||||||
|
|
||||||
# new stream for identify
|
# new stream for identify
|
||||||
var stream = await muxer.newStream()
|
var stream = await muxer.newStream()
|
||||||
|
# call muxer handler, this should
|
||||||
|
# not end until muxer ends
|
||||||
let handlerFut = muxer.handle()
|
let handlerFut = muxer.handle()
|
||||||
|
|
||||||
# add muxer handler cleanup proc
|
# add muxer handler cleanup proc
|
||||||
|
@ -117,10 +119,11 @@ proc mux(s: Switch, conn: Connection): Future[void] {.async, gcsafe.} =
|
||||||
trace "muxer handler completed for peer",
|
trace "muxer handler completed for peer",
|
||||||
peer = conn.peerInfo.id
|
peer = conn.peerInfo.id
|
||||||
|
|
||||||
|
try:
|
||||||
# do identify first, so that we have a
|
# do identify first, so that we have a
|
||||||
# PeerInfo in case we didn't before
|
# PeerInfo in case we didn't before
|
||||||
conn.peerInfo = await s.identify(stream)
|
conn.peerInfo = await s.identify(stream)
|
||||||
|
finally:
|
||||||
await stream.close() # close identify stream
|
await stream.close() # close identify stream
|
||||||
|
|
||||||
trace "connection's peerInfo", peerInfo = $conn.peerInfo
|
trace "connection's peerInfo", peerInfo = $conn.peerInfo
|
||||||
|
|
Loading…
Reference in New Issue