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