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