mirror of https://github.com/status-im/nim-eth.git
Fix several compiler warnings
Mostly replacing deprecated calls
This commit is contained in:
parent
bcb58216d1
commit
755729c6a1
|
@ -26,8 +26,6 @@ proc newPeerPool*(network: EthereumNode,
|
|||
result.observers = initTable[int, PeerObserver]()
|
||||
result.listenPort = listenPort
|
||||
|
||||
template ensureFuture(f: untyped) = asyncCheck f
|
||||
|
||||
proc nodesToConnect(p: PeerPool): seq[Node] {.inline.} =
|
||||
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)
|
||||
# return None
|
||||
|
||||
proc lookupRandomNode(p: PeerPool) {.async.} =
|
||||
# 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()
|
||||
except: # OperationCancelled
|
||||
discard
|
||||
proc lookupRandomNode(p: PeerPool) {.async, raises: [Defect].} =
|
||||
discard await p.discovery.lookupRandom()
|
||||
p.lastLookupTime = epochTime()
|
||||
|
||||
proc getRandomBootnode(p: PeerPool): Option[Node] =
|
||||
|
@ -149,7 +142,7 @@ proc maybeConnectToMorePeers(p: PeerPool) {.async.} =
|
|||
return
|
||||
|
||||
if p.lastLookupTime + lookupInterval < epochTime():
|
||||
ensureFuture p.lookupRandomNode()
|
||||
asyncSpawn p.lookupRandomNode()
|
||||
|
||||
let debugEnode = getEnv("ETH_DEBUG_ENODE")
|
||||
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):
|
||||
await p.connectToNode(n.get())
|
||||
|
||||
proc run(p: PeerPool) {.async.} =
|
||||
proc run(p: PeerPool) {.async, raises: [Defect].} =
|
||||
trace "Running PeerPool..."
|
||||
p.running = true
|
||||
while p.running:
|
||||
|
@ -184,7 +177,7 @@ proc run(p: PeerPool) {.async.} =
|
|||
|
||||
proc start*(p: PeerPool) =
|
||||
if not p.running:
|
||||
asyncCheck p.run()
|
||||
asyncSpawn p.run()
|
||||
|
||||
proc len*(p: PeerPool): int = p.connectedNodes.len
|
||||
# @property
|
||||
|
|
|
@ -140,7 +140,8 @@ type
|
|||
MessageHandlerDecorator* = proc(msgId: int, n: NimNode): NimNode
|
||||
ThunkProc* = proc(x: Peer, msgId: int, data: Rlp): Future[void]
|
||||
{.gcsafe, raises: [RlpError, Defect].}
|
||||
MessageContentPrinter* = proc(msg: pointer): string {.gcsafe.}
|
||||
MessageContentPrinter* = proc(msg: pointer): string
|
||||
{.gcsafe, raises: [Defect].}
|
||||
RequestResolver* = proc(msg: pointer, future: FutureBase)
|
||||
{.gcsafe, raises: [Defect].}
|
||||
NextMsgResolver* = proc(msgData: Rlp, future: FutureBase)
|
||||
|
|
|
@ -370,7 +370,7 @@ proc registerRequest(peer: Peer,
|
|||
proc timeoutExpired(udata: pointer) {.gcsafe, raises:[Defect].} =
|
||||
requestResolver(nil, responseFuture)
|
||||
|
||||
addTimer(timeoutAt, timeoutExpired, nil)
|
||||
discard setTimer(timeoutAt, timeoutExpired, nil)
|
||||
|
||||
proc resolveResponseFuture(peer: Peer, msgId: int, msg: pointer, reqId: int) =
|
||||
logScope:
|
||||
|
@ -994,7 +994,12 @@ proc postHelloSteps(peer: Peer, h: DevP2P.hello) {.async.} =
|
|||
# The handshake may involve multiple async steps, so we wait
|
||||
# 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
|
||||
# we need to raise so that rlpxConnect/rlpxAccept fails.
|
||||
|
|
|
@ -316,7 +316,7 @@ proc acceptRequest*(network: LesNetwork, peer: LesPeer,
|
|||
network.updateFlowControl t
|
||||
|
||||
while not network.canServeRequest:
|
||||
await sleepAsync(10)
|
||||
await sleepAsync(10.milliseconds)
|
||||
|
||||
if peer notin network.peers:
|
||||
# The peer was disconnected or the network
|
||||
|
|
|
@ -9,11 +9,14 @@
|
|||
#
|
||||
|
||||
import
|
||||
std/[algorithm, bitops, math, options, tables, times, strutils, hashes],
|
||||
std/[algorithm, bitops, math, options, tables, times, hashes],
|
||||
chronicles, stew/[byteutils, endians2], metrics, bearssl,
|
||||
nimcrypto/[bcmode, hash, keccak, rijndael],
|
||||
".."/../../[keys, rlp, p2p], ../../ecies
|
||||
|
||||
when chronicles.enabledLogLevel == LogLevel.TRACE:
|
||||
import std/strutils
|
||||
|
||||
logScope:
|
||||
topics = "whisper_types"
|
||||
|
||||
|
|
|
@ -314,7 +314,13 @@ proc run(node: EthereumNode, network: WhisperNetwork) {.async, raises: [Defect].
|
|||
proc sendP2PMessage(node: EthereumNode, peerId: NodeId, env: Envelope): bool =
|
||||
for peer in node.peers(Whisper):
|
||||
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
|
||||
|
||||
proc queueMessage(node: EthereumNode, msg: Message): bool =
|
||||
|
|
|
@ -10,4 +10,5 @@ import
|
|||
./test_shh_config,
|
||||
./test_shh_connect,
|
||||
./test_protocol_handlers,
|
||||
./les/test_flow_control
|
||||
./les/test_flow_control
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import
|
||||
std/[unittest, strutils],
|
||||
chronos, nimcrypto, bearssl,
|
||||
std/strutils,
|
||||
chronos, bearssl,
|
||||
../../eth/[keys, p2p], ../../eth/p2p/[discovery, enode]
|
||||
|
||||
var nextPort = 30303
|
||||
|
|
Loading…
Reference in New Issue