Skip to content

Commit

Permalink
Fix a bunch of compiler hints and warnings in uTP and discv5 (#652)
Browse files Browse the repository at this point in the history
* Fix a bunch of compiler hints and warnings in uTP and discv5

* Leave in the cancel() for now
  • Loading branch information
kdeme authored Jan 12, 2024
1 parent 0fc5dc0 commit 11049fb
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion eth/p2p/discoveryv5/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ proc processClient(transp: DatagramTransport, raddr: TransportAddress):

# TODO: should we use `peekMessage()` to avoid allocation?
let buf = try: transp.getMessage()
except TransportOsError as e:
except TransportError as e:
# This is likely to be local network connection issues.
warn "Transport getMessage", exception = e.name, msg = e.msg
return
Expand Down
2 changes: 1 addition & 1 deletion eth/utp/utp_discv5_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ proc talkReqDirect(
reqId = RequestId.init(p.rng[])
message = encodeMessage(
TalkReqMessage(protocol: protocol, request: request), reqId)
(data, nonce) = encodeMessagePacket(
(data, _) = encodeMessagePacket(
p.rng[], p.codec, n.nodeId, n.address, message)

trace "Send message packet",
Expand Down
3 changes: 2 additions & 1 deletion eth/utp/utp_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ proc processDatagram(transp: DatagramTransport, raddr: TransportAddress):
let router = getUserData[UtpRouter[TransportAddress]](transp)
# TODO: should we use `peekMessage()` to avoid allocation?
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.
return
await processIncomingBytes[TransportAddress](router, buf, raddr)
Expand Down
2 changes: 1 addition & 1 deletion eth/utp/utp_router.nim
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,4 @@ proc shutdownWait*[A](r: UtpRouter[A]) {.async.} =
activeSockets.add(s)

for s in activeSockets:
yield s.destroyWait()
await s.destroyWait()
6 changes: 2 additions & 4 deletions eth/utp/utp_socket.nim
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ proc checkTimeouts(socket: UtpSocket) =
socket.slowStart = true

# 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)

let oldestPacketSeqNr = socket.seqNr - socket.curWindowPackets
Expand Down Expand Up @@ -673,7 +673,7 @@ proc handleDataWrite(socket: UtpSocket, data: seq[byte]): int =
let lastIndex = i + pSize - 1
let lastOrEnd = min(lastIndex, endIndex)
let dataSlice = data[i..lastOrEnd]
let payloadLength = uint32(len(dataSlice))
let payloadLength = uint32(len(dataSlice))
if (socket.outBufferBytes + payloadLength <= socket.socketConfig.optSndBuffer):
let wndSize = socket.getRcvWindowSize()
let dataPacket =
Expand Down Expand Up @@ -995,8 +995,6 @@ proc selectiveAckPackets(
dec bits
continue

let pkt = maybePacket.unsafeGet()

if bitSet:
debug "Packet acked by selective ack",
pkSeqNr = v
Expand Down
10 changes: 5 additions & 5 deletions tests/utp/test_discv5_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ procSuite "Utp protocol over discovery v5 tests":
rng, PrivateKey.random(rng[]), localAddress(20303))

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
check:
Expand Down Expand Up @@ -81,7 +81,7 @@ procSuite "Utp protocol over discovery v5 tests":

# constructor which uses connection callback and user data pointer as ref
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
check:
Expand Down Expand Up @@ -111,7 +111,7 @@ procSuite "Utp protocol over discovery v5 tests":
rng, PrivateKey.random(rng[]), localAddress(20303))

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
check:
Expand Down Expand Up @@ -154,7 +154,7 @@ procSuite "Utp protocol over discovery v5 tests":
utpProtId,
registerIncomingSocketCallback(queue),
socketConfig = SocketConfig.init(lowSynTimeout))
utp2 =
utp2 {.used.} =
UtpDiscv5Protocol.new(
node2,
utpProtId,
Expand Down Expand Up @@ -195,7 +195,7 @@ procSuite "Utp protocol over discovery v5 tests":
rng, PrivateKey.random(rng[]), localAddress(20303))

utp1 = UtpDiscv5Protocol.new(node1, utpProtId, registerIncomingSocketCallback(queue))
utp2 = UtpDiscv5Protocol.new(
utp2 {.used.} = UtpDiscv5Protocol.new(
node2,
utpProtId,
registerIncomingSocketCallback(queue),
Expand Down
2 changes: 1 addition & 1 deletion tests/utp/test_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ procSuite "Utp protocol over udp tests":
# this future will be completed when we called accepted connection callback
await server2Called.wait()

yield futSock
discard (await futSock)

check:
futSock.finished() and (not futSock.failed()) and (not futSock.cancelled())
Expand Down
4 changes: 2 additions & 2 deletions tests/utp/test_utp_router.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ procSuite "Utp router unit tests":
initialRemoteSeq: uint16): (UtpSocket[int], Packet)=
let connectFuture = router.connectTo(remote)

let (initialPacket, sender) = await pq.get()
let (initialPacket, _) = await pq.get()

check:
initialPacket.header.pType == ST_SYN
Expand Down Expand Up @@ -440,7 +440,7 @@ procSuite "Utp router unit tests":
let router = UtpRouter[int].new(registerIncomingSocketCallback(q), SocketConfig.init(), rng)
router.sendCb = initTestSnd(pq)

let (outgoingSocket, initialSyn) = router.connectOutgoing(testSender2, pq, 30'u16)
let (_, initialSyn) = router.connectOutgoing(testSender2, pq, 30'u16)

check:
router.len() == 1
Expand Down
13 changes: 6 additions & 7 deletions tests/utp/test_utp_socket.nim
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ procSuite "uTP socket tests":

outgoingSocket.destroy()

yield writeFut1
yield writeFut2
discard await writeFut1
discard await writeFut2

check:
writeFut1.completed()
Expand Down Expand Up @@ -485,13 +485,12 @@ procSuite "uTP socket tests":

await outgoingSocket.processPacket(someAckFromRemote)

yield writeFut1
yield writeFut2
yield writeFut3
discard await writeFut1
discard await writeFut3

check:
writeFut1.completed()
writeFut2.cancelled()
writeFut2.cancelled() # TODO: This might not always be the case?
writeFut3.completed()

let p1 = await q.get()
Expand Down Expand Up @@ -1250,7 +1249,7 @@ procSuite "uTP socket tests":
# write should progress
await outgoingSocket.processPacket(someAckFromRemote)

yield writeFut2
discard await writeFut2

let secondPacket = await q.get()

Expand Down

0 comments on commit 11049fb

Please sign in to comment.