Fix a bunch of compiler hints and warnings in uTP and discv5 (#652)

* Fix a bunch of compiler hints and warnings in uTP and discv5

* Leave in the cancel() for now
This commit is contained in:
Kim De Mey 2024-01-12 09:49:06 +01:00 committed by GitHub
parent 0fc5dc03c5
commit 11049fb87d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 21 additions and 23 deletions

View File

@ -470,7 +470,7 @@ proc processClient(transp: DatagramTransport, raddr: TransportAddress):
# TODO: should we use `peekMessage()` to avoid allocation? # TODO: should we use `peekMessage()` to avoid allocation?
let buf = try: transp.getMessage() let buf = try: transp.getMessage()
except TransportOsError as e: except TransportError as e:
# This is likely to be local network connection issues. # This is likely to be local network connection issues.
warn "Transport getMessage", exception = e.name, msg = e.msg warn "Transport getMessage", exception = e.name, msg = e.msg
return return

View File

@ -59,7 +59,7 @@ proc talkReqDirect(
reqId = RequestId.init(p.rng[]) reqId = RequestId.init(p.rng[])
message = encodeMessage( message = encodeMessage(
TalkReqMessage(protocol: protocol, request: request), reqId) TalkReqMessage(protocol: protocol, request: request), reqId)
(data, nonce) = encodeMessagePacket( (data, _) = encodeMessagePacket(
p.rng[], p.codec, n.nodeId, n.address, message) p.rng[], p.codec, n.nodeId, n.address, message)
trace "Send message packet", trace "Send message packet",

View File

@ -67,7 +67,8 @@ proc processDatagram(transp: DatagramTransport, raddr: TransportAddress):
let router = getUserData[UtpRouter[TransportAddress]](transp) let router = getUserData[UtpRouter[TransportAddress]](transp)
# TODO: should we use `peekMessage()` to avoid allocation? # TODO: should we use `peekMessage()` to avoid allocation?
let buf = try: transp.getMessage() let buf = try: transp.getMessage()
except TransportOsError as e: except TransportError as e:
trace "Error reading datagram msg: ", error = e.msg
# This is likely to be local network connection issues. # This is likely to be local network connection issues.
return return
await processIncomingBytes[TransportAddress](router, buf, raddr) await processIncomingBytes[TransportAddress](router, buf, raddr)

View File

@ -360,4 +360,4 @@ proc shutdownWait*[A](r: UtpRouter[A]) {.async.} =
activeSockets.add(s) activeSockets.add(s)
for s in activeSockets: for s in activeSockets:
yield s.destroyWait() await s.destroyWait()

View File

@ -623,7 +623,7 @@ proc checkTimeouts(socket: UtpSocket) =
socket.slowStart = true socket.slowStart = true
# Note: with selective acks enabled, every selectively acked packet resets # Note: with selective acks enabled, every selectively acked packet resets
# the timeout timer and removes te packet from the outBuffer. # the timeout timer and removes the packet from the outBuffer.
markAllPacketAsLost(socket) markAllPacketAsLost(socket)
let oldestPacketSeqNr = socket.seqNr - socket.curWindowPackets let oldestPacketSeqNr = socket.seqNr - socket.curWindowPackets
@ -673,7 +673,7 @@ proc handleDataWrite(socket: UtpSocket, data: seq[byte]): int =
let lastIndex = i + pSize - 1 let lastIndex = i + pSize - 1
let lastOrEnd = min(lastIndex, endIndex) let lastOrEnd = min(lastIndex, endIndex)
let dataSlice = data[i..lastOrEnd] let dataSlice = data[i..lastOrEnd]
let payloadLength = uint32(len(dataSlice)) let payloadLength = uint32(len(dataSlice))
if (socket.outBufferBytes + payloadLength <= socket.socketConfig.optSndBuffer): if (socket.outBufferBytes + payloadLength <= socket.socketConfig.optSndBuffer):
let wndSize = socket.getRcvWindowSize() let wndSize = socket.getRcvWindowSize()
let dataPacket = let dataPacket =
@ -995,8 +995,6 @@ proc selectiveAckPackets(
dec bits dec bits
continue continue
let pkt = maybePacket.unsafeGet()
if bitSet: if bitSet:
debug "Packet acked by selective ack", debug "Packet acked by selective ack",
pkSeqNr = v pkSeqNr = v

View File

@ -46,7 +46,7 @@ procSuite "Utp protocol over discovery v5 tests":
rng, PrivateKey.random(rng[]), localAddress(20303)) rng, PrivateKey.random(rng[]), localAddress(20303))
utp1 = UtpDiscv5Protocol.new(node1, utpProtId, registerIncomingSocketCallback(queue)) utp1 = UtpDiscv5Protocol.new(node1, utpProtId, registerIncomingSocketCallback(queue))
utp2 = UtpDiscv5Protocol.new(node2, utpProtId, registerIncomingSocketCallback(queue)) utp2 {.used.} = UtpDiscv5Protocol.new(node2, utpProtId, registerIncomingSocketCallback(queue))
# nodes must have session between each other # nodes must have session between each other
check: check:
@ -81,7 +81,7 @@ procSuite "Utp protocol over discovery v5 tests":
# constructor which uses connection callback and user data pointer as ref # constructor which uses connection callback and user data pointer as ref
utp1 = UtpDiscv5Protocol.new(node1, utpProtId, cbUserData, queue) utp1 = UtpDiscv5Protocol.new(node1, utpProtId, cbUserData, queue)
utp2 = UtpDiscv5Protocol.new(node2, utpProtId, cbUserData, queue) utp2 {.used.} = UtpDiscv5Protocol.new(node2, utpProtId, cbUserData, queue)
# nodes must have session between each other # nodes must have session between each other
check: check:
@ -111,7 +111,7 @@ procSuite "Utp protocol over discovery v5 tests":
rng, PrivateKey.random(rng[]), localAddress(20303)) rng, PrivateKey.random(rng[]), localAddress(20303))
utp1 = UtpDiscv5Protocol.new(node1, utpProtId, registerIncomingSocketCallback(queue)) utp1 = UtpDiscv5Protocol.new(node1, utpProtId, registerIncomingSocketCallback(queue))
utp2 = UtpDiscv5Protocol.new(node2, utpProtId, registerIncomingSocketCallback(queue)) utp2 {.used.} = UtpDiscv5Protocol.new(node2, utpProtId, registerIncomingSocketCallback(queue))
# nodes must have session between each other # nodes must have session between each other
check: check:
@ -154,7 +154,7 @@ procSuite "Utp protocol over discovery v5 tests":
utpProtId, utpProtId,
registerIncomingSocketCallback(queue), registerIncomingSocketCallback(queue),
socketConfig = SocketConfig.init(lowSynTimeout)) socketConfig = SocketConfig.init(lowSynTimeout))
utp2 = utp2 {.used.} =
UtpDiscv5Protocol.new( UtpDiscv5Protocol.new(
node2, node2,
utpProtId, utpProtId,
@ -195,7 +195,7 @@ procSuite "Utp protocol over discovery v5 tests":
rng, PrivateKey.random(rng[]), localAddress(20303)) rng, PrivateKey.random(rng[]), localAddress(20303))
utp1 = UtpDiscv5Protocol.new(node1, utpProtId, registerIncomingSocketCallback(queue)) utp1 = UtpDiscv5Protocol.new(node1, utpProtId, registerIncomingSocketCallback(queue))
utp2 = UtpDiscv5Protocol.new( utp2 {.used.} = UtpDiscv5Protocol.new(
node2, node2,
utpProtId, utpProtId,
registerIncomingSocketCallback(queue), registerIncomingSocketCallback(queue),

View File

@ -223,7 +223,7 @@ procSuite "Utp protocol over udp tests":
# this future will be completed when we called accepted connection callback # this future will be completed when we called accepted connection callback
await server2Called.wait() await server2Called.wait()
yield futSock discard (await futSock)
check: check:
futSock.finished() and (not futSock.failed()) and (not futSock.cancelled()) futSock.finished() and (not futSock.failed()) and (not futSock.cancelled())

View File

@ -56,7 +56,7 @@ procSuite "Utp router unit tests":
initialRemoteSeq: uint16): (UtpSocket[int], Packet)= initialRemoteSeq: uint16): (UtpSocket[int], Packet)=
let connectFuture = router.connectTo(remote) let connectFuture = router.connectTo(remote)
let (initialPacket, sender) = await pq.get() let (initialPacket, _) = await pq.get()
check: check:
initialPacket.header.pType == ST_SYN initialPacket.header.pType == ST_SYN
@ -440,7 +440,7 @@ procSuite "Utp router unit tests":
let router = UtpRouter[int].new(registerIncomingSocketCallback(q), SocketConfig.init(), rng) let router = UtpRouter[int].new(registerIncomingSocketCallback(q), SocketConfig.init(), rng)
router.sendCb = initTestSnd(pq) router.sendCb = initTestSnd(pq)
let (outgoingSocket, initialSyn) = router.connectOutgoing(testSender2, pq, 30'u16) let (_, initialSyn) = router.connectOutgoing(testSender2, pq, 30'u16)
check: check:
router.len() == 1 router.len() == 1

View File

@ -444,8 +444,8 @@ procSuite "uTP socket tests":
outgoingSocket.destroy() outgoingSocket.destroy()
yield writeFut1 discard await writeFut1
yield writeFut2 discard await writeFut2
check: check:
writeFut1.completed() writeFut1.completed()
@ -485,13 +485,12 @@ procSuite "uTP socket tests":
await outgoingSocket.processPacket(someAckFromRemote) await outgoingSocket.processPacket(someAckFromRemote)
yield writeFut1 discard await writeFut1
yield writeFut2 discard await writeFut3
yield writeFut3
check: check:
writeFut1.completed() writeFut1.completed()
writeFut2.cancelled() writeFut2.cancelled() # TODO: This might not always be the case?
writeFut3.completed() writeFut3.completed()
let p1 = await q.get() let p1 = await q.get()
@ -1250,7 +1249,7 @@ procSuite "uTP socket tests":
# write should progress # write should progress
await outgoingSocket.processPacket(someAckFromRemote) await outgoingSocket.processPacket(someAckFromRemote)
yield writeFut2 discard await writeFut2
let secondPacket = await q.get() let secondPacket = await q.get()