remove debug output; add less noisy output on server side
This commit is contained in:
parent
b65c4f4373
commit
c39ecc55ac
13
quicp2p.nim
13
quicp2p.nim
|
@ -66,10 +66,12 @@ proc onReceiveReset(stream: ptr quicly_stream_t, err: cint) {.cdecl.} =
|
||||||
|
|
||||||
proc onServerReceive(stream: ptr quicly_stream_t, offset: csize_t, src: pointer,
|
proc onServerReceive(stream: ptr quicly_stream_t, offset: csize_t, src: pointer,
|
||||||
len: csize_t) {.cdecl.} =
|
len: csize_t) {.cdecl.} =
|
||||||
echo "onServerReceive"
|
|
||||||
if quicly_streambuf_ingress_receive(stream, offset, src, len) != 0:
|
if quicly_streambuf_ingress_receive(stream, offset, src, len) != 0:
|
||||||
return
|
return
|
||||||
let input = quicly_streambuf_ingress_get(stream)
|
let input = quicly_streambuf_ingress_get(stream)
|
||||||
|
var msg = newString(input.len)
|
||||||
|
copyMem(addr msg[0], input.base, input.len)
|
||||||
|
echo &"received message from client: \"{msg}\""
|
||||||
if quicly_sendstate_is_open(addr stream.sendstate) != 0 and input.len > 0:
|
if quicly_sendstate_is_open(addr stream.sendstate) != 0 and input.len > 0:
|
||||||
discard quicly_streambuf_egress_write(stream, input.base, input.len)
|
discard quicly_streambuf_egress_write(stream, input.base, input.len)
|
||||||
if quicly_recvstate_transfer_complete(addr stream.recvstate) != 0:
|
if quicly_recvstate_transfer_complete(addr stream.recvstate) != 0:
|
||||||
|
@ -78,13 +80,12 @@ proc onServerReceive(stream: ptr quicly_stream_t, offset: csize_t, src: pointer,
|
||||||
|
|
||||||
proc onClientReceive(stream: ptr quicly_stream_t, offset: csize_t,
|
proc onClientReceive(stream: ptr quicly_stream_t, offset: csize_t,
|
||||||
src: pointer, len: csize_t) {.cdecl.} =
|
src: pointer, len: csize_t) {.cdecl.} =
|
||||||
echo "onClientReceive"
|
|
||||||
if quicly_streambuf_ingress_receive(stream, offset, src, len) != 0:
|
if quicly_streambuf_ingress_receive(stream, offset, src, len) != 0:
|
||||||
return
|
return
|
||||||
let input = quicly_streambuf_ingress_get(stream)
|
let input = quicly_streambuf_ingress_get(stream)
|
||||||
let msg = newString(input.len)
|
let msg = newString(input.len)
|
||||||
copyMem(msg.cstring, input.base, input.len)
|
copyMem(msg.cstring, input.base, input.len)
|
||||||
echo "received message from server: ", msg
|
echo &"received message from server: \"{msg}\""
|
||||||
if quicly_recvstate_transfer_complete(addr stream.recvstate) != 0:
|
if quicly_recvstate_transfer_complete(addr stream.recvstate) != 0:
|
||||||
discard quicly_close(stream.conn, 0, "")
|
discard quicly_close(stream.conn, 0, "")
|
||||||
quicly_streambuf_ingress_shift(stream, input.len)
|
quicly_streambuf_ingress_shift(stream, input.len)
|
||||||
|
@ -111,13 +112,11 @@ proc usage() =
|
||||||
|
|
||||||
proc onServerStreamOpen(self: ptr quicly_stream_open_t,
|
proc onServerStreamOpen(self: ptr quicly_stream_open_t,
|
||||||
stream: ptr quicly_stream_t): cint {.cdecl.} =
|
stream: ptr quicly_stream_t): cint {.cdecl.} =
|
||||||
echo "onServerStreamOpen"
|
|
||||||
result = quicly_streambuf_create(stream, sizeof(quicly_streambuf_t).csize_t)
|
result = quicly_streambuf_create(stream, sizeof(quicly_streambuf_t).csize_t)
|
||||||
stream.callbacks = addr streamCallbacksServer
|
stream.callbacks = addr streamCallbacksServer
|
||||||
|
|
||||||
proc onClientStreamOpen(self: ptr quicly_stream_open_t,
|
proc onClientStreamOpen(self: ptr quicly_stream_open_t,
|
||||||
stream: ptr quicly_stream_t): cint {.cdecl.} =
|
stream: ptr quicly_stream_t): cint {.cdecl.} =
|
||||||
echo "onClientStreamOpen"
|
|
||||||
result = quicly_streambuf_create(stream, sizeof(quicly_streambuf_t).csize_t)
|
result = quicly_streambuf_create(stream, sizeof(quicly_streambuf_t).csize_t)
|
||||||
stream.callbacks = addr streamCallbacksClient
|
stream.callbacks = addr streamCallbacksClient
|
||||||
let msg = "hello server"
|
let msg = "hello server"
|
||||||
|
@ -139,10 +138,8 @@ proc handleMsg(ctx: QuicP2PContext, msg: string, peerAddr: ptr SockAddr,
|
||||||
conn = c
|
conn = c
|
||||||
break
|
break
|
||||||
if conn != nil:
|
if conn != nil:
|
||||||
echo "quicly_receive"
|
|
||||||
discard quicly_receive(conn, nil, peerAddr, addr decoded)
|
discard quicly_receive(conn, nil, peerAddr, addr decoded)
|
||||||
elif isServer:
|
elif isServer:
|
||||||
echo "quicly_accept"
|
|
||||||
discard quicly_accept(addr conn, addr ctx.quiclyCtx, nil, peerAddr,
|
discard quicly_accept(addr conn, addr ctx.quiclyCtx, nil, peerAddr,
|
||||||
addr decoded, nil, addr ctx.nextCid, nil)
|
addr decoded, nil, addr ctx.nextCid, nil)
|
||||||
ctx.connections.add(conn)
|
ctx.connections.add(conn)
|
||||||
|
@ -187,7 +184,6 @@ proc sendPackets(ctx: QuicP2PContext) =
|
||||||
case sendResult:
|
case sendResult:
|
||||||
of 0:
|
of 0:
|
||||||
if dgramCount > 0:
|
if dgramCount > 0:
|
||||||
echo &"sending {dgramCount} datagrams"
|
|
||||||
for j in 0 .. dgramCount - 1:
|
for j in 0 .. dgramCount - 1:
|
||||||
var sockLen = quicly_get_socklen(addr dstAddr.sa)
|
var sockLen = quicly_get_socklen(addr dstAddr.sa)
|
||||||
# TODO: replace asyncdispatch.sendTo with asyncnet.sendTo (Nim 1.4 required)
|
# TODO: replace asyncdispatch.sendTo with asyncnet.sendTo (Nim 1.4 required)
|
||||||
|
@ -209,7 +205,6 @@ proc receive(ctx: QuicP2PContext, isServer: bool) {.async.} =
|
||||||
let msgLen = await recvFromInto(ctx.sock.getFd().AsyncFD, msg.cstring,
|
let msgLen = await recvFromInto(ctx.sock.getFd().AsyncFD, msg.cstring,
|
||||||
msg.len, cast[ptr SockAddr](addr peerAddr),
|
msg.len, cast[ptr SockAddr](addr peerAddr),
|
||||||
addr peerAddrLen)
|
addr peerAddrLen)
|
||||||
echo &"received {msgLen} bytes"
|
|
||||||
msg.setLen(msgLen)
|
msg.setLen(msgLen)
|
||||||
if msg.len > 0:
|
if msg.len > 0:
|
||||||
handleMsg(ctx, msg, cast[ptr SockAddr](addr peerAddr), isServer)
|
handleMsg(ctx, msg, cast[ptr SockAddr](addr peerAddr), isServer)
|
||||||
|
|
Loading…
Reference in New Issue