Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less warnings #813

Merged
merged 41 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a12ffdc
Less warnings
Menduist Nov 30, 2022
c7ad7af
remove unused imports
diegomrsantos Apr 21, 2023
98e24e6
remove unnecessary try/except
diegomrsantos Apr 24, 2023
4068051
remove unused import and use checkedEnumAssign
diegomrsantos Apr 24, 2023
43235df
replace bare except by CatchableError
diegomrsantos Apr 24, 2023
6df2ec3
remove unused import and unnecessary try/except
diegomrsantos Apr 24, 2023
87ae1ef
replace bare except
diegomrsantos Apr 24, 2023
a21be5e
remove unused import and replace Exception by CatchableError
diegomrsantos Apr 24, 2023
14618c7
remove warnings
diegomrsantos Apr 24, 2023
7731584
fix for 1.2
diegomrsantos Apr 24, 2023
24e108f
testing removal of GC_fullCollect()
diegomrsantos Apr 25, 2023
1f41c8c
create tryException
diegomrsantos Apr 25, 2023
c5f577b
remove secio warning
diegomrsantos Apr 25, 2023
46fc4bf
include import in when
diegomrsantos Apr 25, 2023
a406045
update deps
diegomrsantos Apr 25, 2023
2711c48
rename
diegomrsantos Apr 26, 2023
a2075f6
check isErr instead
diegomrsantos Apr 26, 2023
fc66eac
add used in test files
diegomrsantos Apr 26, 2023
0bda0c0
handle defect
diegomrsantos Apr 27, 2023
0423ae6
use stew/ptrops
diegomrsantos Apr 27, 2023
acdaf3e
use safeConvert
diegomrsantos Apr 28, 2023
44eb2cd
fix issue on linux 32
diegomrsantos May 2, 2023
a88380e
rollback
diegomrsantos May 2, 2023
8b5d3bf
'{.deadcodeelim: on.}' is deprecated, now a noop
diegomrsantos May 4, 2023
5f42210
removing [ImplicitDefaultValue] warning
diegomrsantos May 4, 2023
e895d4e
workaround for enum size bug
diegomrsantos May 4, 2023
266ffc7
using an array instead of a set
diegomrsantos May 4, 2023
a87aba4
remove unnecessary import
diegomrsantos May 4, 2023
e5b6318
removing cast sizes warning
diegomrsantos May 4, 2023
6d7784e
replace cast by type conversion
diegomrsantos May 4, 2023
055ac0a
fix issue with incompatible types
diegomrsantos May 4, 2023
7b0eb32
remove unused import
diegomrsantos May 4, 2023
82ccd76
remove casts
diegomrsantos May 5, 2023
ff482e1
improve docs
diegomrsantos May 5, 2023
b426db3
make getLength return int64
diegomrsantos May 5, 2023
f1e7e55
make exceptionToAssert handle void body
diegomrsantos May 8, 2023
4dfe255
fix compilation error
diegomrsantos May 8, 2023
d33b77d
fix compilation error for 1.2
diegomrsantos May 9, 2023
31d4358
remove unused asn1EncodeOid
diegomrsantos May 9, 2023
062de19
changes after code review
diegomrsantos May 12, 2023
72a53f3
safeConvert tests
diegomrsantos May 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .pinned
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
bearssl;https://github.com/status-im/nim-bearssl@#acf9645e328bdcab481cfda1c158e07ecd46bd7b
chronicles;https://github.com/status-im/nim-chronicles@#32ac8679680ea699f7dbc046e8e0131cac97d41a
chronicles;https://github.com/status-im/nim-chronicles@#1e6350870855541b381d77d4659688bc0d2c4227
chronos;https://github.com/status-im/nim-chronos@#ab5a8c2e0f6941fe3debd61dff0293790079d1b0
dnsclient;https://github.com/ba0f3/dnsclient.nim@#fcd7443634b950eaea574e5eaa00a628ae029823
faststreams;https://github.com/status-im/nim-faststreams@#814f8927e1f356f39219f37f069b83066bcc893a
httputils;https://github.com/status-im/nim-http-utils@#a85bd52ae0a956983ca6b3267c72961d2ec0245f
json_serialization;https://github.com/status-im/nim-json-serialization@#a7d815ed92f200f490c95d3cfd722089cc923ce6
metrics;https://github.com/status-im/nim-metrics@#21e99a2e9d9f80e68bef65c80ef781613005fccb
metrics;https://github.com/status-im/nim-metrics@#abf3acc7f06cee9ee2c287d2f31413dc3df4c04e
nimcrypto;https://github.com/cheatfate/nimcrypto@#4014ef939b51e02053c2e16dd3481d47bc9267dd
secp256k1;https://github.com/status-im/nim-secp256k1@#fd173fdff863ce2e211cf64c9a03bc7539fe40b0
serialization;https://github.com/status-im/nim-serialization@#5b7cea55efeb074daa8abd8146a03a34adb4521a
stew;https://github.com/status-im/nim-stew@#407a59883691d362db2fe8eab7f7c3b1f75112ff
stew;https://github.com/status-im/nim-stew@#8caa9771995b266e10b2e7c0de6cbfa698902e68
testutils;https://github.com/status-im/nim-testutils@#dfc4c1b39f9ded9baf6365014de2b4bfb4dafc34
unittest2;https://github.com/status-im/nim-unittest2@#da8398c45cafd5bd7772da1fc96e3924a18d3823
unittest2;https://github.com/status-im/nim-unittest2@#883c7a50ad3b82158e64d074c5578fe33ab3c452
websock;https://github.com/status-im/nim-websock@#fea05cde8b123b38d1a0a8524b77efbc84daa848
zlib;https://github.com/status-im/nim-zlib@#826e2fc013f55b4478802d4f2e39f187c50d520a
zlib;https://github.com/status-im/nim-zlib@#826e2fc013f55b4478802d4f2e39f187c50d520a
3 changes: 0 additions & 3 deletions libp2p.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@ else:
stream/connection,
transports/transport,
transports/tcptransport,
transports/wstransport,
protocols/secure/noise,
protocols/ping,
cid,
multihash,
multibase,
multicodec,
errors,
switch,
Expand Down
3 changes: 2 additions & 1 deletion libp2p/builders.nim
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,10 @@ proc newStandardSwitch*(
peerStoreCapacity = 1000): Switch
{.raises: [Defect, LPError], public.} =
## Helper for common switch configurations.

{.push warning[Deprecated]:off.}
if SecureProtocol.Secio in secureManagers:
quit("Secio is deprecated!") # use of secio is unsafe
{.pop.}

let addrs = when addrs is MultiAddress: @[addrs] else: addrs
var b = SwitchBuilder
Expand Down
37 changes: 4 additions & 33 deletions libp2p/connmanager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,13 @@ proc addConnEventHandler*(c: ConnManager,
kind: ConnEventKind) =
## Add peer event handler - handlers must not raise exceptions!
##

try:
if isNil(handler): return
c.connEvents[kind].incl(handler)
except Exception as exc:
# TODO: there is an Exception being raised
# somewhere in the depths of the std.
# Might be related to https://github.com/nim-lang/Nim/issues/17382

raiseAssert exc.msg
if isNil(handler): return
c.connEvents[kind].incl(handler)

proc removeConnEventHandler*(c: ConnManager,
handler: ConnEventHandler,
kind: ConnEventKind) =
try:
c.connEvents[kind].excl(handler)
except Exception as exc:
# TODO: there is an Exception being raised
# somewhere in the depths of the std.
# Might be related to https://github.com/nim-lang/Nim/issues/17382

raiseAssert exc.msg

proc triggerConnEvent*(c: ConnManager,
peerId: PeerId,
Expand All @@ -169,26 +154,12 @@ proc addPeerEventHandler*(c: ConnManager,
##

if isNil(handler): return
try:
c.peerEvents[kind].incl(handler)
except Exception as exc:
# TODO: there is an Exception being raised
# somewhere in the depths of the std.
# Might be related to https://github.com/nim-lang/Nim/issues/17382

raiseAssert exc.msg
c.peerEvents[kind].incl(handler)

proc removePeerEventHandler*(c: ConnManager,
handler: PeerEventHandler,
kind: PeerEventKind) =
try:
c.peerEvents[kind].excl(handler)
except Exception as exc:
# TODO: there is an Exception being raised
# somewhere in the depths of the std.
# Might be related to https://github.com/nim-lang/Nim/issues/17382

raiseAssert exc.msg
c.peerEvents[kind].excl(handler)

proc triggerPeerEvents*(c: ConnManager,
peerId: PeerId,
Expand Down
2 changes: 1 addition & 1 deletion libp2p/crypto/chacha20poly1305.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ else:

import bearssl/blockx
from stew/assign2 import assign
from stew/ranges/ptr_arith import baseAddr
from stew/ptrops import baseAddr

const
ChaChaPolyKeySize = 32
Expand Down
2 changes: 1 addition & 1 deletion libp2p/crypto/curve25519.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ when (NimMajor, NimMinor) < (1, 4):
else:
{.push raises: [].}

import bearssl/[ec, rand, hash]
import bearssl/[ec, rand]
import stew/results
from stew/assign2 import assign
export results
Expand Down
31 changes: 17 additions & 14 deletions libp2p/crypto/ecnist.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import nimcrypto/utils as ncrutils
import minasn1
export minasn1.Asn1Error
import stew/[results, ctops]

import ../utility

export results

const
Expand Down Expand Up @@ -74,7 +77,7 @@ type
EcResult*[T] = Result[T, EcError]

const
EcSupportedCurvesCint* = {cint(Secp256r1), cint(Secp384r1), cint(Secp521r1)}
EcSupportedCurvesCint* = @[cint(Secp256r1), cint(Secp384r1), cint(Secp521r1)]

proc `-`(x: uint32): uint32 {.inline.} =
result = (0xFFFF_FFFF'u32 - x) + 1'u32
Expand Down Expand Up @@ -243,7 +246,7 @@ proc random*(
var res = new EcPrivateKey
if ecKeygen(addr rng.vtable, ecimp,
addr res.key, addr res.buffer[0],
cast[cint](kind)) == 0:
safeConvert[cint](kind)) == 0:
err(EcKeyGenError)
else:
ok(res)
Expand Down Expand Up @@ -630,11 +633,11 @@ proc init*(key: var EcPrivateKey, data: openArray[byte]): Result[void, Asn1Error
return err(Asn1Error.Incorrect)

if oid == Asn1OidSecp256r1:
curve = cast[cint](Secp256r1)
curve = safeConvert[cint](Secp256r1)
elif oid == Asn1OidSecp384r1:
curve = cast[cint](Secp384r1)
curve = safeConvert[cint](Secp384r1)
elif oid == Asn1OidSecp521r1:
curve = cast[cint](Secp521r1)
curve = safeConvert[cint](Secp521r1)
else:
return err(Asn1Error.Incorrect)

Expand Down Expand Up @@ -684,11 +687,11 @@ proc init*(pubkey: var EcPublicKey, data: openArray[byte]): Result[void, Asn1Err
return err(Asn1Error.Incorrect)

if oid == Asn1OidSecp256r1:
curve = cast[cint](Secp256r1)
curve = safeConvert[cint](Secp256r1)
elif oid == Asn1OidSecp384r1:
curve = cast[cint](Secp384r1)
curve = safeConvert[cint](Secp384r1)
elif oid == Asn1OidSecp521r1:
curve = cast[cint](Secp521r1)
curve = safeConvert[cint](Secp521r1)
else:
return err(Asn1Error.Incorrect)

Expand Down Expand Up @@ -774,13 +777,13 @@ proc initRaw*(key: var EcPrivateKey, data: openArray[byte]): bool =
## Procedure returns ``true`` on success, ``false`` otherwise.
var curve: cint
if len(data) == SecKey256Length:
curve = cast[cint](Secp256r1)
curve = safeConvert[cint](Secp256r1)
result = true
elif len(data) == SecKey384Length:
curve = cast[cint](Secp384r1)
curve = safeConvert[cint](Secp384r1)
result = true
elif len(data) == SecKey521Length:
curve = cast[cint](Secp521r1)
curve = safeConvert[cint](Secp521r1)
result = true
if result:
result = false
Expand All @@ -805,13 +808,13 @@ proc initRaw*(pubkey: var EcPublicKey, data: openArray[byte]): bool =
if len(data) > 0:
if data[0] == 0x04'u8:
if len(data) == PubKey256Length:
curve = cast[cint](Secp256r1)
curve = safeConvert[cint](Secp256r1)
result = true
elif len(data) == PubKey384Length:
curve = cast[cint](Secp384r1)
curve = safeConvert[cint](Secp384r1)
result = true
elif len(data) == PubKey521Length:
curve = cast[cint](Secp521r1)
curve = safeConvert[cint](Secp521r1)
result = true
if result:
result = false
Expand Down
Loading