Fix several compiler warnings

Mostly replacing deprecated calls
This commit is contained in:
kdeme 2021-05-11 09:24:10 +02:00
parent bcb58216d1
commit 755729c6a1
No known key found for this signature in database
GPG Key ID: 4E8DD21420AF43F5
8 changed files with 30 additions and 21 deletions

View File

@ -26,8 +26,6 @@ proc newPeerPool*(network: EthereumNode,
result.observers = initTable[int, PeerObserver]() result.observers = initTable[int, PeerObserver]()
result.listenPort = listenPort result.listenPort = listenPort
template ensureFuture(f: untyped) = asyncCheck f
proc nodesToConnect(p: PeerPool): seq[Node] {.inline.} = proc nodesToConnect(p: PeerPool): seq[Node] {.inline.} =
p.discovery.randomNodes(p.minPeers).filterIt(it notin p.discovery.bootstrapNodes) p.discovery.randomNodes(p.minPeers).filterIt(it notin p.discovery.bootstrapNodes)
@ -95,13 +93,8 @@ proc connect(p: PeerPool, remote: Node): Future[Peer] {.async.} =
# self.logger.exception("Unexpected error during auth/p2p handshake with %s", remote) # self.logger.exception("Unexpected error during auth/p2p handshake with %s", remote)
# return None # return None
proc lookupRandomNode(p: PeerPool) {.async.} = proc lookupRandomNode(p: PeerPool) {.async, raises: [Defect].} =
# This method runs in the background, so we must catch OperationCancelled
# ere otherwise asyncio will warn that its exception was never retrieved.
try:
discard await p.discovery.lookupRandom() discard await p.discovery.lookupRandom()
except: # OperationCancelled
discard
p.lastLookupTime = epochTime() p.lastLookupTime = epochTime()
proc getRandomBootnode(p: PeerPool): Option[Node] = proc getRandomBootnode(p: PeerPool): Option[Node] =
@ -149,7 +142,7 @@ proc maybeConnectToMorePeers(p: PeerPool) {.async.} =
return return
if p.lastLookupTime + lookupInterval < epochTime(): if p.lastLookupTime + lookupInterval < epochTime():
ensureFuture p.lookupRandomNode() asyncSpawn p.lookupRandomNode()
let debugEnode = getEnv("ETH_DEBUG_ENODE") let debugEnode = getEnv("ETH_DEBUG_ENODE")
if debugEnode.len != 0: if debugEnode.len != 0:
@ -163,7 +156,7 @@ proc maybeConnectToMorePeers(p: PeerPool) {.async.} =
if p.connectedNodes.len == 0 and (let n = p.getRandomBootnode(); n.isSome): if p.connectedNodes.len == 0 and (let n = p.getRandomBootnode(); n.isSome):
await p.connectToNode(n.get()) await p.connectToNode(n.get())
proc run(p: PeerPool) {.async.} = proc run(p: PeerPool) {.async, raises: [Defect].} =
trace "Running PeerPool..." trace "Running PeerPool..."
p.running = true p.running = true
while p.running: while p.running:
@ -184,7 +177,7 @@ proc run(p: PeerPool) {.async.} =
proc start*(p: PeerPool) = proc start*(p: PeerPool) =
if not p.running: if not p.running:
asyncCheck p.run() asyncSpawn p.run()
proc len*(p: PeerPool): int = p.connectedNodes.len proc len*(p: PeerPool): int = p.connectedNodes.len
# @property # @property

View File

@ -140,7 +140,8 @@ type
MessageHandlerDecorator* = proc(msgId: int, n: NimNode): NimNode MessageHandlerDecorator* = proc(msgId: int, n: NimNode): NimNode
ThunkProc* = proc(x: Peer, msgId: int, data: Rlp): Future[void] ThunkProc* = proc(x: Peer, msgId: int, data: Rlp): Future[void]
{.gcsafe, raises: [RlpError, Defect].} {.gcsafe, raises: [RlpError, Defect].}
MessageContentPrinter* = proc(msg: pointer): string {.gcsafe.} MessageContentPrinter* = proc(msg: pointer): string
{.gcsafe, raises: [Defect].}
RequestResolver* = proc(msg: pointer, future: FutureBase) RequestResolver* = proc(msg: pointer, future: FutureBase)
{.gcsafe, raises: [Defect].} {.gcsafe, raises: [Defect].}
NextMsgResolver* = proc(msgData: Rlp, future: FutureBase) NextMsgResolver* = proc(msgData: Rlp, future: FutureBase)

View File

@ -370,7 +370,7 @@ proc registerRequest(peer: Peer,
proc timeoutExpired(udata: pointer) {.gcsafe, raises:[Defect].} = proc timeoutExpired(udata: pointer) {.gcsafe, raises:[Defect].} =
requestResolver(nil, responseFuture) requestResolver(nil, responseFuture)
addTimer(timeoutAt, timeoutExpired, nil) discard setTimer(timeoutAt, timeoutExpired, nil)
proc resolveResponseFuture(peer: Peer, msgId: int, msg: pointer, reqId: int) = proc resolveResponseFuture(peer: Peer, msgId: int, msg: pointer, reqId: int) =
logScope: logScope:
@ -994,7 +994,12 @@ proc postHelloSteps(peer: Peer, h: DevP2P.hello) {.async.} =
# The handshake may involve multiple async steps, so we wait # The handshake may involve multiple async steps, so we wait
# here for all of them to finish. # here for all of them to finish.
# #
await all(subProtocolsHandshakes) await allFutures(subProtocolsHandshakes)
for handshake in subProtocolsHandshakes:
doAssert(handshake.finished())
if handshake.failed():
raise handshake.error
# This is needed as a peer might have already disconnected. In this case # This is needed as a peer might have already disconnected. In this case
# we need to raise so that rlpxConnect/rlpxAccept fails. # we need to raise so that rlpxConnect/rlpxAccept fails.

View File

@ -316,7 +316,7 @@ proc acceptRequest*(network: LesNetwork, peer: LesPeer,
network.updateFlowControl t network.updateFlowControl t
while not network.canServeRequest: while not network.canServeRequest:
await sleepAsync(10) await sleepAsync(10.milliseconds)
if peer notin network.peers: if peer notin network.peers:
# The peer was disconnected or the network # The peer was disconnected or the network

View File

@ -9,11 +9,14 @@
# #
import import
std/[algorithm, bitops, math, options, tables, times, strutils, hashes], std/[algorithm, bitops, math, options, tables, times, hashes],
chronicles, stew/[byteutils, endians2], metrics, bearssl, chronicles, stew/[byteutils, endians2], metrics, bearssl,
nimcrypto/[bcmode, hash, keccak, rijndael], nimcrypto/[bcmode, hash, keccak, rijndael],
".."/../../[keys, rlp, p2p], ../../ecies ".."/../../[keys, rlp, p2p], ../../ecies
when chronicles.enabledLogLevel == LogLevel.TRACE:
import std/strutils
logScope: logScope:
topics = "whisper_types" topics = "whisper_types"

View File

@ -314,7 +314,13 @@ proc run(node: EthereumNode, network: WhisperNetwork) {.async, raises: [Defect].
proc sendP2PMessage(node: EthereumNode, peerId: NodeId, env: Envelope): bool = proc sendP2PMessage(node: EthereumNode, peerId: NodeId, env: Envelope): bool =
for peer in node.peers(Whisper): for peer in node.peers(Whisper):
if peer.remote.id == peerId: if peer.remote.id == peerId:
asyncCheck peer.p2pMessage(env) let f = peer.p2pMessage(env)
# Can't make p2pMessage not raise so this is the "best" option I can think
# of instead of using asyncSpawn and still keeping the call not async.
f.callback = proc(data: pointer) {.gcsafe, raises: [Defect].} =
if f.failed:
warn "P2PMessage send failed", msg = f.readError.msg
return true return true
proc queueMessage(node: EthereumNode, msg: Message): bool = proc queueMessage(node: EthereumNode, msg: Message): bool =

View File

@ -11,3 +11,4 @@ import
./test_shh_connect, ./test_shh_connect,
./test_protocol_handlers, ./test_protocol_handlers,
./les/test_flow_control ./les/test_flow_control

View File

@ -1,6 +1,6 @@
import import
std/[unittest, strutils], std/strutils,
chronos, nimcrypto, bearssl, chronos, bearssl,
../../eth/[keys, p2p], ../../eth/p2p/[discovery, enode] ../../eth/[keys, p2p], ../../eth/p2p/[discovery, enode]
var nextPort = 30303 var nextPort = 30303