mirror of https://github.com/status-im/nim-eth.git
Tackle some Nim warnings new since Nim 1.4 & 1.6 (#553)
This commit is contained in:
parent
70b83a4efb
commit
9b0f054b04
|
@ -321,7 +321,7 @@ type
|
|||
of true: extIp*: ValidIpAddress
|
||||
of false: nat*: NatStrategy
|
||||
|
||||
func parseCmdArg*(T: type NatConfig, p: TaintedString): T {.raises: [Defect, ConfigurationError].} =
|
||||
func parseCmdArg*(T: type NatConfig, p: string): T {.raises: [Defect, ConfigurationError].} =
|
||||
case p.toLowerAscii:
|
||||
of "any":
|
||||
NatConfig(hasExtIp: false, nat: NatAny)
|
||||
|
@ -343,7 +343,7 @@ func parseCmdArg*(T: type NatConfig, p: TaintedString): T {.raises: [Defect, Con
|
|||
let error = "Not a valid NAT option: " & p
|
||||
raise newException(ConfigurationError, error)
|
||||
|
||||
func completeCmdArg*(T: type NatConfig, val: TaintedString): seq[string] =
|
||||
func completeCmdArg*(T: type NatConfig, val: string): seq[string] =
|
||||
return @[]
|
||||
|
||||
proc setupAddress*(natConfig: NatConfig, bindIp: ValidIpAddress,
|
||||
|
|
|
@ -99,14 +99,14 @@ func defaultListenAddress*(conf: DiscoveryConf): ValidIpAddress =
|
|||
func defaultAdminListenAddress*(conf: DiscoveryConf): ValidIpAddress =
|
||||
(static ValidIpAddress.init("127.0.0.1"))
|
||||
|
||||
proc parseCmdArg*(T: type enr.Record, p: TaintedString): T =
|
||||
proc parseCmdArg*(T: type enr.Record, p: string): T =
|
||||
if not fromURI(result, p):
|
||||
raise newException(ConfigurationError, "Invalid ENR")
|
||||
|
||||
proc completeCmdArg*(T: type enr.Record, val: TaintedString): seq[string] =
|
||||
proc completeCmdArg*(T: type enr.Record, val: string): seq[string] =
|
||||
return @[]
|
||||
|
||||
proc parseCmdArg*(T: type Node, p: TaintedString): T =
|
||||
proc parseCmdArg*(T: type Node, p: string): T =
|
||||
var record: enr.Record
|
||||
if not fromURI(record, p):
|
||||
raise newException(ConfigurationError, "Invalid ENR")
|
||||
|
@ -120,16 +120,16 @@ proc parseCmdArg*(T: type Node, p: TaintedString): T =
|
|||
|
||||
n[]
|
||||
|
||||
proc completeCmdArg*(T: type Node, val: TaintedString): seq[string] =
|
||||
proc completeCmdArg*(T: type Node, val: string): seq[string] =
|
||||
return @[]
|
||||
|
||||
proc parseCmdArg*(T: type PrivateKey, p: TaintedString): T =
|
||||
proc parseCmdArg*(T: type PrivateKey, p: string): T =
|
||||
try:
|
||||
result = PrivateKey.fromHex(string(p)).tryGet()
|
||||
except CatchableError:
|
||||
raise newException(ConfigurationError, "Invalid private key")
|
||||
|
||||
proc completeCmdArg*(T: type PrivateKey, val: TaintedString): seq[string] =
|
||||
proc completeCmdArg*(T: type PrivateKey, val: string): seq[string] =
|
||||
return @[]
|
||||
|
||||
proc discover(d: discv5_protocol.Protocol) {.async.} =
|
||||
|
|
|
@ -300,7 +300,7 @@ proc update*(record: var Record, pk: PrivateKey,
|
|||
updated = true
|
||||
|
||||
if updated:
|
||||
if r.seqNum == high(r.seqNum): # highly unlikely
|
||||
if r.seqNum == high(type r.seqNum): # highly unlikely
|
||||
return err("Maximum sequence number reached")
|
||||
r.seqNum.inc()
|
||||
r.raw = ? makeEnrRaw(r.seqNum, pk, r.pairs)
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
import
|
||||
std/[tables, sets, options, math, sequtils, algorithm],
|
||||
stew/shims/net as stewNet, json_serialization/std/net,
|
||||
stew/[endians2, results], chronicles, chronos, stint, metrics,
|
||||
stew/results, chronicles, chronos, stint, metrics,
|
||||
".."/../[rlp, keys],
|
||||
"."/[messages_encoding, encoding, node, routing_table, enr, random2, sessions,
|
||||
ip_vote, nodes_verification]
|
||||
|
|
|
@ -597,7 +597,7 @@ proc recvPong*(k: KademliaProtocol, n: Node, token: seq[byte]) =
|
|||
future.complete(true)
|
||||
k.updateLastPongReceived(n, getTime())
|
||||
|
||||
proc recvPing*(k: KademliaProtocol, n: Node, msgHash: any)
|
||||
proc recvPing*(k: KademliaProtocol, n: Node, msgHash: auto)
|
||||
{.raises: [ValueError, Defect].} =
|
||||
trace "<<< ping from ", n
|
||||
k.wire.sendPong(n, msgHash)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
import
|
||||
std/[os, tables, times, random, sequtils, options],
|
||||
chronos, chronicles,
|
||||
".."/[rlp, keys, common],
|
||||
".."/[keys, common],
|
||||
./private/p2p_types, "."/[discovery, kademlia, rlpx, enode]
|
||||
|
||||
const
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
import
|
||||
std/[deques, tables],
|
||||
chronos,
|
||||
stew/results,
|
||||
".."/../[rlp, keys], ../../common/eth_types,
|
||||
".."/[enode, kademlia, discovery, rlpxcrypt]
|
||||
|
||||
|
|
|
@ -378,8 +378,8 @@ template compressMsg(peer: Peer, data: seq[byte]): seq[byte] =
|
|||
data
|
||||
|
||||
proc sendMsg*(peer: Peer, data: seq[byte]) {.gcsafe, async.} =
|
||||
var cipherText = encryptMsg(peer.compressMsg(data), peer.secretsState)
|
||||
try:
|
||||
var cipherText = encryptMsg(peer.compressMsg(data), peer.secretsState)
|
||||
var res = await peer.transport.write(cipherText)
|
||||
if res != len(cipherText):
|
||||
# This is ECONNRESET or EPIPE case when remote peer disconnected.
|
||||
|
|
|
@ -137,16 +137,13 @@ proc encrypt*(c: var SecretState, header: openArray[byte],
|
|||
ok()
|
||||
|
||||
proc encryptMsg*(msg: openArray[byte], secrets: var SecretState): seq[byte] =
|
||||
doAssert(uint32(msg.len) <= maxUInt24, "RLPx message size exceeds limit")
|
||||
|
||||
var header: RlpxHeader
|
||||
|
||||
if uint32(msg.len) > maxUInt24:
|
||||
raise newException(OverflowError, "RLPx message size exceeds limit")
|
||||
|
||||
# write the frame size in the first 3 bytes of the header
|
||||
header[0] = byte((msg.len shr 16) and 0xFF)
|
||||
header[1] = byte((msg.len shr 8) and 0xFF)
|
||||
header[2] = byte(msg.len and 0xFF)
|
||||
|
||||
# This is the [capability-id, context-id] in header-data
|
||||
# While not really used, this is checked in the Parity client.
|
||||
# Same as rlp.encode((0, 0))
|
||||
|
@ -154,11 +151,10 @@ proc encryptMsg*(msg: openArray[byte], secrets: var SecretState): seq[byte] =
|
|||
header[4] = 0x80
|
||||
header[5] = 0x80
|
||||
|
||||
# XXX:
|
||||
# This would be safer if we use a thread-local sequ for the temporary buffer
|
||||
result = newSeq[byte](encryptedLength(msg.len))
|
||||
let s = encrypt(secrets, header, msg, result)
|
||||
s.expect("always succeeds because we call with correct buffer")
|
||||
var res = newSeq[byte](encryptedLength(msg.len))
|
||||
encrypt(secrets, header, msg, res).expect(
|
||||
"always succeeds because we call with correct buffer")
|
||||
res
|
||||
|
||||
proc getBodySize*(a: RlpxHeader): int =
|
||||
(int(a[0]) shl 16) or (int(a[1]) shl 8) or int(a[2])
|
||||
|
|
Loading…
Reference in New Issue