only let the puncher handle the packet if accept was not successful; add more debug output

master
Christian Ulrich 2020-11-17 23:17:19 +01:00
parent b4bc750e99
commit 154f5ec77b
No known key found for this signature in database
GPG Key ID: 8241BE099775A097
1 changed files with 14 additions and 11 deletions

View File

@ -300,11 +300,9 @@ proc handleMsg(ctx: QuicP2PContext, msg: string, peerId: string,
let decodeResult = quicly_decode_packet(addr ctx.quiclyCtx, addr decoded,
cast[ptr uint8](msg.cstring),
msg.len().csize_t, addr offset)
echo "decode_result: ", decode_result
if decode_result == csize_t.high:
# The puncher needs to be informed about this message because quicly not
# being able to decode it may indicate it's the peer's response to our
# initiate call.
ctx.puncher.handleMsg(msg, peerAddr[], peerSockLen)
echo "unable to decode packet"
return
var conn: ptr quicly_conn_t = nil
for c in ctx.connections:
@ -314,13 +312,15 @@ proc handleMsg(ctx: QuicP2PContext, msg: string, peerId: string,
if conn != nil:
discard quicly_receive(conn, nil, peerAddr, addr decoded)
elif peerId.len == 0:
# The puncher needs to be informed about this message because it may
# be the peer's response to our respond call. Quicly needs to be informed
# because we except the first QUIC handshake packet in it.
ctx.puncher.handleMsg(msg, peerAddr[], peerSockLen)
discard quicly_accept(addr conn, addr ctx.quiclyCtx, nil, peerAddr,
addr decoded, nil, addr ctx.nextCid, nil)
ctx.addConnection(conn, peerId)
let acceptResult = quicly_accept(addr conn, addr ctx.quiclyCtx, nil,
peerAddr, addr decoded, nil,
addr ctx.nextCid, nil)
if acceptResult == 0:
ctx.addConnection(conn, peerId)
else:
# The puncher needs to be informed about this message because it may
# be the peer's response to our respond call.
ctx.puncher.handleMsg(msg, peerAddr[], peerSockLen)
proc receive(ctx: QuicP2PContext, peerId: string) {.async.} =
while true:
@ -333,12 +333,14 @@ proc receive(ctx: QuicP2PContext, peerId: string) {.async.} =
addr peerAddrLen)
msg.setLen(msgLen)
if msg.len > 0:
echo "received msg, len: ", msg.len
handleMsg(ctx, msg, peerId, addr peerAddr, peerAddrLen)
proc handleNotification(ctx: QuicP2PContext, notification: NotifyPeer)
{.async.} =
let _ = await ctx.puncher.respond(notification.srcIp, notification.srcPort,
notification.probedsrcPorts)
echo "respond successful!"
proc runApp(ctx: QuicP2PContext, srcPort: Port, peerId: string) {.async.} =
let serverConn = await initServerConnection(rendezvousServers[0].hostname,
@ -375,6 +377,7 @@ proc runApp(ctx: QuicP2PContext, srcPort: Port, peerId: string) {.async.} =
discard await serverConn.sendRequest("notify-peer", req)
let peerPort = await ctx.puncher.initiate(peerInfo.ip, peerInfo.localPort,
peerInfo.probedPorts)
echo "initiate successful!"
initiateQuicConnection(ctx, peerId, peerInfo.ip, peerPort)
proc main() =