diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5a72b8fd..eb48f2e42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: cpu: amd64 #- os: windows #cpu: i386 - branch: [version-1-2, version-1-6] + branch: [version-1-6] include: - target: os: linux diff --git a/.github/workflows/multi_nim.yml b/.github/workflows/multi_nim.yml index 1334983ec..61d1d827b 100644 --- a/.github/workflows/multi_nim.yml +++ b/.github/workflows/multi_nim.yml @@ -27,7 +27,7 @@ jobs: cpu: amd64 #- os: windows #cpu: i386 - branch: [version-1-2, version-1-6, devel] + branch: [version-1-6, version-2-0, devel] include: - target: os: linux @@ -48,7 +48,7 @@ jobs: name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (Nim ${{ matrix.branch }})' runs-on: ${{ matrix.builder }} - continue-on-error: ${{ matrix.branch == 'devel' }} + continue-on-error: ${{ matrix.branch == 'devel' || matrix.branch == 'version-2-0' }} steps: - name: Checkout uses: actions/checkout@v2 diff --git a/README.md b/README.md index f91a730a2..5d3b4771f 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ The versioning follows [semver](https://semver.org/), with some additions: - Some of libp2p procedures are marked as `.public.`, they will remain compatible during each `MAJOR` version - The rest of the procedures are considered internal, and can change at any `MINOR` version (but remain compatible for each new `PATCH`) -We aim to be compatible at all time with at least 2 Nim `MINOR` versions, currently `1.2 & 1.6` +We aim to be compatible at all time with at least 2 Nim `MINOR` versions, currently `1.6 & 2.0` ## Development Clone and Install dependencies: diff --git a/config.nims b/config.nims index 5d3e88d2a..69f9485d4 100644 --- a/config.nims +++ b/config.nims @@ -9,11 +9,8 @@ switch("warning", "ObservableStores:off") switch("warning", "LockLevel:off") --define:chronosStrictException --styleCheck:usages -if (NimMajor, NimMinor) < (1, 6): - --styleCheck:hint -else: - switch("warningAsError", "UseBase:on") - --styleCheck:error +switch("warningAsError", "UseBase:on") +--styleCheck:error # Avoid some rare stack corruption while using exceptions with a SEH-enabled # toolchain: https://github.com/status-im/nimbus-eth2/issues/3121 diff --git a/libp2p.nimble b/libp2p.nimble index 5f82b3742..b9b89f411 100644 --- a/libp2p.nimble +++ b/libp2p.nimble @@ -7,7 +7,7 @@ description = "LibP2P implementation" license = "MIT" skipDirs = @["tests", "examples", "Nim", "tools", "scripts", "docs"] -requires "nim >= 1.2.0", +requires "nim >= 1.6.0", "nimcrypto >= 0.4.1", "dnsclient >= 0.3.0 & < 0.4.0", "bearssl >= 0.1.4", @@ -104,15 +104,12 @@ task examples_build, "Build the samples": buildSample("circuitrelay", true) buildSample("tutorial_1_connect", true) buildSample("tutorial_2_customproto", true) - if (NimMajor, NimMinor) > (1, 2): - # These tutorials relies on post 1.4 exception tracking - buildSample("tutorial_3_protobuf", true) - buildSample("tutorial_4_gossipsub", true) - buildSample("tutorial_5_discovery", true) - # Nico doesn't work in 1.2 - exec "nimble install -y nimpng@#HEAD" # this is to fix broken build on 1.7.3, remove it when nimpng version 0.3.2 or later is released - exec "nimble install -y nico" - buildSample("tutorial_6_game", false, "--styleCheck:off") + buildSample("tutorial_3_protobuf", true) + buildSample("tutorial_4_gossipsub", true) + buildSample("tutorial_5_discovery", true) + exec "nimble install -y nimpng@#HEAD" # this is to fix broken build on 1.7.3, remove it when nimpng version 0.3.2 or later is released + exec "nimble install -y nico" + buildSample("tutorial_6_game", false, "--styleCheck:off") # pin system # while nimble lockfile diff --git a/libp2p/builders.nim b/libp2p/builders.nim index a0d91261c..d8e7d5117 100644 --- a/libp2p/builders.nim +++ b/libp2p/builders.nim @@ -16,10 +16,7 @@ runnableExamples: # etc .build() -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import options, tables, chronos, chronicles, sequtils, @@ -36,7 +33,7 @@ export switch, peerid, peerinfo, connection, multiaddress, crypto, errors type - TransportProvider* {.public.} = proc(upgr: Upgrade): Transport {.gcsafe, raises: [Defect].} + TransportProvider* {.public.} = proc(upgr: Upgrade): Transport {.gcsafe, raises: [].} SecureProtocol* {.pure.} = enum Noise, @@ -205,7 +202,7 @@ proc withServices*(b: SwitchBuilder, services: seq[Service]): SwitchBuilder = b proc build*(b: SwitchBuilder): Switch - {.raises: [Defect, LPError], public.} = + {.raises: [LPError], public.} = if b.rng == nil: # newRng could fail raise newException(Defect, "Cannot initialize RNG") @@ -296,7 +293,7 @@ proc newStandardSwitch*( nameResolver: NameResolver = nil, sendSignedPeerRecord = false, peerStoreCapacity = 1000): Switch - {.raises: [Defect, LPError], public.} = + {.raises: [LPError], public.} = ## Helper for common switch configurations. {.push warning[Deprecated]:off.} if SecureProtocol.Secio in secureManagers: diff --git a/libp2p/cid.nim b/libp2p/cid.nim index 846cc71fd..195c1b607 100644 --- a/libp2p/cid.nim +++ b/libp2p/cid.nim @@ -9,10 +9,7 @@ ## This module implementes CID (Content IDentifier). -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import tables, hashes import multibase, multicodec, multihash, vbuffer, varint diff --git a/libp2p/connmanager.nim b/libp2p/connmanager.nim index 48d3ead46..619c5b2c0 100644 --- a/libp2p/connmanager.nim +++ b/libp2p/connmanager.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[options, tables, sequtils, sets] import pkg/[chronos, chronicles, metrics] @@ -51,7 +48,7 @@ type ConnEventHandler* = proc(peerId: PeerId, event: ConnEvent): Future[void] - {.gcsafe, raises: [Defect].} + {.gcsafe, raises: [].} PeerEventKind* {.pure.} = enum Left, @@ -65,7 +62,7 @@ type discard PeerEventHandler* = - proc(peerId: PeerId, event: PeerEvent): Future[void] {.gcsafe, raises: [Defect].} + proc(peerId: PeerId, event: PeerEvent): Future[void] {.gcsafe, raises: [].} ConnManager* = ref object of RootObj maxConnsPerPeer: int @@ -285,7 +282,7 @@ proc selectMuxer*(c: ConnManager, peerId: PeerId): Muxer = proc storeMuxer*(c: ConnManager, muxer: Muxer) - {.raises: [Defect, CatchableError].} = + {.raises: [CatchableError].} = ## store the connection and muxer ## @@ -338,7 +335,7 @@ proc getIncomingSlot*(c: ConnManager): Future[ConnectionSlot] {.async.} = await c.inSema.acquire() return ConnectionSlot(connManager: c, direction: In) -proc getOutgoingSlot*(c: ConnManager, forceDial = false): ConnectionSlot {.raises: [Defect, TooManyConnectionsError].} = +proc getOutgoingSlot*(c: ConnManager, forceDial = false): ConnectionSlot {.raises: [TooManyConnectionsError].} = if forceDial: c.outSema.forceAcquire() elif not c.outSema.tryAcquire(): diff --git a/libp2p/crypto/chacha20poly1305.nim b/libp2p/crypto/chacha20poly1305.nim index d26f31ce9..bddbed81c 100644 --- a/libp2p/crypto/chacha20poly1305.nim +++ b/libp2p/crypto/chacha20poly1305.nim @@ -15,10 +15,7 @@ # RFC @ https://tools.ietf.org/html/rfc7539 -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import bearssl/blockx from stew/assign2 import assign diff --git a/libp2p/crypto/crypto.nim b/libp2p/crypto/crypto.nim index 27df105d4..1c8e5c2a9 100644 --- a/libp2p/crypto/crypto.nim +++ b/libp2p/crypto/crypto.nim @@ -8,10 +8,7 @@ # those terms. ## This module implements Public Key and Private Key interface for libp2p. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} from strutils import split, strip, cmpIgnoreCase @@ -1003,27 +1000,27 @@ proc decodeExchange*(message: seq[byte], ## Serialization/Deserialization helpers proc write*(vb: var VBuffer, pubkey: PublicKey) {. - inline, raises: [Defect, ResultError[CryptoError]].} = + inline, raises: [ResultError[CryptoError]].} = ## Write PublicKey value ``pubkey`` to buffer ``vb``. vb.writeSeq(pubkey.getBytes().tryGet()) proc write*(vb: var VBuffer, seckey: PrivateKey) {. - inline, raises: [Defect, ResultError[CryptoError]].} = + inline, raises: [ResultError[CryptoError]].} = ## Write PrivateKey value ``seckey`` to buffer ``vb``. vb.writeSeq(seckey.getBytes().tryGet()) proc write*(vb: var VBuffer, sig: PrivateKey) {. - inline, raises: [Defect, ResultError[CryptoError]].} = + inline, raises: [ResultError[CryptoError]].} = ## Write Signature value ``sig`` to buffer ``vb``. vb.writeSeq(sig.getBytes().tryGet()) proc write*[T: PublicKey|PrivateKey](pb: var ProtoBuffer, field: int, key: T) {. - inline, raises: [Defect, ResultError[CryptoError]].} = + inline, raises: [ResultError[CryptoError]].} = write(pb, field, key.getBytes().tryGet()) proc write*(pb: var ProtoBuffer, field: int, sig: Signature) {. - inline, raises: [Defect].} = + inline, raises: [].} = write(pb, field, sig.getBytes()) proc getField*[T: PublicKey|PrivateKey](pb: ProtoBuffer, field: int, diff --git a/libp2p/crypto/curve25519.nim b/libp2p/crypto/curve25519.nim index 94255ac37..b9d641088 100644 --- a/libp2p/crypto/curve25519.nim +++ b/libp2p/crypto/curve25519.nim @@ -15,10 +15,7 @@ # RFC @ https://tools.ietf.org/html/rfc7748 -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import bearssl/[ec, rand] import stew/results diff --git a/libp2p/crypto/ecnist.nim b/libp2p/crypto/ecnist.nim index cbc30e6f9..644e91d69 100644 --- a/libp2p/crypto/ecnist.nim +++ b/libp2p/crypto/ecnist.nim @@ -14,10 +14,7 @@ ## BearSSL library ## Copyright(C) 2018 Thomas Pornin . -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import bearssl/[ec, rand, hash] # We use `ncrutils` for constant-time hexadecimal encoding/decoding procedures. diff --git a/libp2p/crypto/ed25519/ed25519.nim b/libp2p/crypto/ed25519/ed25519.nim index 003341705..dc49d4713 100644 --- a/libp2p/crypto/ed25519/ed25519.nim +++ b/libp2p/crypto/ed25519/ed25519.nim @@ -11,10 +11,7 @@ ## This code is a port of the public domain, "ref10" implementation of ed25519 ## from SUPERCOP. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import bearssl/rand import constants diff --git a/libp2p/crypto/hkdf.nim b/libp2p/crypto/hkdf.nim index f29d34b66..4808120dc 100644 --- a/libp2p/crypto/hkdf.nim +++ b/libp2p/crypto/hkdf.nim @@ -9,10 +9,7 @@ # https://tools.ietf.org/html/rfc5869 -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import nimcrypto import bearssl/[kdf, hash] diff --git a/libp2p/crypto/minasn1.nim b/libp2p/crypto/minasn1.nim index 8185a0f73..2c06d3db3 100644 --- a/libp2p/crypto/minasn1.nim +++ b/libp2p/crypto/minasn1.nim @@ -9,10 +9,7 @@ ## This module implements minimal ASN.1 encoding/decoding primitives. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import stew/[endians2, results, ctops] export results diff --git a/libp2p/crypto/rsa.nim b/libp2p/crypto/rsa.nim index 5c5890a3c..53f0985b1 100644 --- a/libp2p/crypto/rsa.nim +++ b/libp2p/crypto/rsa.nim @@ -13,10 +13,7 @@ ## BearSSL library ## Copyright(C) 2018 Thomas Pornin . -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import bearssl/[rsa, rand, hash] import minasn1 diff --git a/libp2p/crypto/secp.nim b/libp2p/crypto/secp.nim index e7be08667..caf17c2ee 100644 --- a/libp2p/crypto/secp.nim +++ b/libp2p/crypto/secp.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import bearssl/rand import diff --git a/libp2p/daemon/daemonapi.nim b/libp2p/daemon/daemonapi.nim index bced3eb05..27bafa7be 100644 --- a/libp2p/daemon/daemonapi.nim +++ b/libp2p/daemon/daemonapi.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} ## This module implementes API for `go-libp2p-daemon`. import std/[os, osproc, strutils, tables, strtabs, sequtils] @@ -153,10 +150,10 @@ type key*: PublicKey P2PStreamCallback* = proc(api: DaemonAPI, - stream: P2PStream): Future[void] {.gcsafe, raises: [Defect, CatchableError].} + stream: P2PStream): Future[void] {.gcsafe, raises: [CatchableError].} P2PPubSubCallback* = proc(api: DaemonAPI, ticket: PubsubTicket, - message: PubSubMessage): Future[bool] {.gcsafe, raises: [Defect, CatchableError].} + message: PubSubMessage): Future[bool] {.gcsafe, raises: [CatchableError].} DaemonError* = object of LPError DaemonRemoteError* = object of DaemonError @@ -474,7 +471,7 @@ proc checkResponse(pb: ProtoBuffer): ResponseKind {.inline.} = else: result = ResponseKind.Error -proc getErrorMessage(pb: ProtoBuffer): string {.inline, raises: [Defect, DaemonLocalError].} = +proc getErrorMessage(pb: ProtoBuffer): string {.inline, raises: [DaemonLocalError].} = var error: seq[byte] if pb.getRequiredField(ResponseType.ERROR.int, error).isOk(): if initProtoBuffer(error).getRequiredField(1, result).isErr(): @@ -504,7 +501,7 @@ proc recvMessage(conn: StreamTransport): Future[seq[byte]] {.async.} = result = buffer proc newConnection*(api: DaemonAPI): Future[StreamTransport] - {.raises: [Defect, LPError].} = + {.raises: [LPError].} = result = connect(api.address) proc closeConnection*(api: DaemonAPI, transp: StreamTransport): Future[void] = @@ -515,7 +512,7 @@ proc socketExists(address: MultiAddress): Future[bool] {.async.} = var transp = await connect(address) await transp.closeWait() result = true - except CatchableError, Defect: + except CatchableError: result = false when defined(windows): @@ -837,7 +834,7 @@ proc transactMessage(transp: StreamTransport, result = initProtoBuffer(message) proc getPeerInfo(pb: ProtoBuffer): PeerInfo - {.raises: [Defect, DaemonLocalError].} = + {.raises: [DaemonLocalError].} = ## Get PeerInfo object from ``pb``. result.addresses = newSeq[MultiAddress]() if pb.getRequiredField(1, result.peer).isErr(): @@ -868,7 +865,7 @@ proc connect*(api: DaemonAPI, peer: PeerId, timeout)) pb.withMessage() do: discard - except CatchableError, Defect: + except CatchableError: await api.closeConnection(transp) proc disconnect*(api: DaemonAPI, peer: PeerId) {.async.} = @@ -928,7 +925,7 @@ proc streamHandler(server: StreamServer, transp: StreamTransport) {.async.} = asyncSpawn handler(api, stream) proc addHandler*(api: DaemonAPI, protocols: seq[string], - handler: P2PStreamCallback) {.async, raises: [Defect, LPError].} = + handler: P2PStreamCallback) {.async, raises: [LPError].} = ## Add stream handler ``handler`` for set of protocols ``protocols``. var transp = await api.newConnection() let maddress = await getSocket(api.pattern, addr api.ucounter) @@ -998,7 +995,7 @@ proc cmTrimPeers*(api: DaemonAPI) {.async.} = await api.closeConnection(transp) proc dhtGetSinglePeerInfo(pb: ProtoBuffer): PeerInfo - {.raises: [Defect, DaemonLocalError].} = + {.raises: [DaemonLocalError].} = var res: seq[byte] if pb.getRequiredField(2, res).isOk(): result = initProtoBuffer(res).getPeerInfo() @@ -1006,23 +1003,23 @@ proc dhtGetSinglePeerInfo(pb: ProtoBuffer): PeerInfo raise newException(DaemonLocalError, "Missing required field `peer`!") proc dhtGetSingleValue(pb: ProtoBuffer): seq[byte] - {.raises: [Defect, DaemonLocalError].} = + {.raises: [DaemonLocalError].} = result = newSeq[byte]() if pb.getRequiredField(3, result).isErr(): raise newException(DaemonLocalError, "Missing field `value`!") proc dhtGetSinglePublicKey(pb: ProtoBuffer): PublicKey - {.raises: [Defect, DaemonLocalError].} = + {.raises: [DaemonLocalError].} = if pb.getRequiredField(3, result).isErr(): raise newException(DaemonLocalError, "Missing field `value`!") proc dhtGetSinglePeerId(pb: ProtoBuffer): PeerId - {.raises: [Defect, DaemonLocalError].} = + {.raises: [DaemonLocalError].} = if pb.getRequiredField(3, result).isErr(): raise newException(DaemonLocalError, "Missing field `value`!") proc enterDhtMessage(pb: ProtoBuffer, rt: DHTResponseType): ProtoBuffer - {.inline, raises: [Defect, DaemonLocalError].} = + {.inline, raises: [DaemonLocalError].} = var dhtResponse: seq[byte] if pb.getRequiredField(ResponseType.DHT.int, dhtResponse).isOk(): var pbDhtResponse = initProtoBuffer(dhtResponse) @@ -1041,7 +1038,7 @@ proc enterDhtMessage(pb: ProtoBuffer, rt: DHTResponseType): ProtoBuffer raise newException(DaemonLocalError, "Wrong message type!") proc enterPsMessage(pb: ProtoBuffer): ProtoBuffer - {.inline, raises: [Defect, DaemonLocalError].} = + {.inline, raises: [DaemonLocalError].} = var res: seq[byte] if pb.getRequiredField(ResponseType.PUBSUB.int, res).isErr(): raise newException(DaemonLocalError, "Wrong message type!") @@ -1049,7 +1046,7 @@ proc enterPsMessage(pb: ProtoBuffer): ProtoBuffer initProtoBuffer(res) proc getDhtMessageType(pb: ProtoBuffer): DHTResponseType - {.inline, raises: [Defect, DaemonLocalError].} = + {.inline, raises: [DaemonLocalError].} = var dtype: uint if pb.getRequiredField(1, dtype).isErr(): raise newException(DaemonLocalError, "Missing required DHT field `type`!") diff --git a/libp2p/daemon/transpool.nim b/libp2p/daemon/transpool.nim index ce0061761..ae1090b9c 100644 --- a/libp2p/daemon/transpool.nim +++ b/libp2p/daemon/transpool.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} ## This module implements Pool of StreamTransport. import chronos diff --git a/libp2p/dial.nim b/libp2p/dial.nim index 089ebdb69..422af7018 100644 --- a/libp2p/dial.nim +++ b/libp2p/dial.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos import stew/results diff --git a/libp2p/discovery/discoverymngr.nim b/libp2p/discovery/discoverymngr.nim index 55f71820c..8da369e7a 100644 --- a/libp2p/discovery/discoverymngr.nim +++ b/libp2p/discovery/discoverymngr.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/sequtils import chronos, chronicles, stew/results @@ -18,7 +15,7 @@ import ../errors type BaseAttr = ref object of RootObj - comparator: proc(f, c: BaseAttr): bool {.gcsafe, raises: [Defect].} + comparator: proc(f, c: BaseAttr): bool {.gcsafe, raises: [].} Attribute[T] = ref object of BaseAttr value: T @@ -60,7 +57,7 @@ proc `{}`*[T](pa: PeerAttributes, t: typedesc[T]): Opt[T] = return Opt.some(f.to(T)) Opt.none(T) -proc `[]`*[T](pa: PeerAttributes, t: typedesc[T]): T {.raises: [Defect, KeyError].} = +proc `[]`*[T](pa: PeerAttributes, t: typedesc[T]): T {.raises: [KeyError].} = pa{T}.valueOr: raise newException(KeyError, "Attritute not found") proc match*(pa, candidate: PeerAttributes): bool = @@ -73,7 +70,7 @@ proc match*(pa, candidate: PeerAttributes): bool = return true type - PeerFoundCallback* = proc(pa: PeerAttributes) {.raises: [Defect], gcsafe.} + PeerFoundCallback* = proc(pa: PeerAttributes) {.raises: [], gcsafe.} DiscoveryInterface* = ref object of RootObj onPeerFound*: PeerFoundCallback diff --git a/libp2p/discovery/rendezvousinterface.nim b/libp2p/discovery/rendezvousinterface.nim index c903244a2..b95410b93 100644 --- a/libp2p/discovery/rendezvousinterface.nim +++ b/libp2p/discovery/rendezvousinterface.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos import ./discoverymngr, diff --git a/libp2p/multiaddress.nim b/libp2p/multiaddress.nim index 2c5d09995..75c118d19 100644 --- a/libp2p/multiaddress.nim +++ b/libp2p/multiaddress.nim @@ -9,10 +9,7 @@ ## This module implements MultiAddress. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} {.push public.} import pkg/chronos, chronicles @@ -775,7 +772,7 @@ proc toString*(value: MultiAddress): MaResult[string] = res = "/" & parts.join("/") ok(res) -proc `$`*(value: MultiAddress): string {.raises: [Defect].} = +proc `$`*(value: MultiAddress): string = ## Return string representation of MultiAddress ``value``. let s = value.toString() if s.isErr: s.error @@ -1025,7 +1022,7 @@ proc append*(m1: var MultiAddress, m2: MultiAddress): MaResult[void] = ok() proc `&`*(m1, m2: MultiAddress): MultiAddress {. - raises: [Defect, LPError].} = + raises: [LPError].} = ## Concatenates two addresses ``m1`` and ``m2``, and returns result. ## ## This procedure performs validation of concatenated result and can raise @@ -1035,7 +1032,7 @@ proc `&`*(m1, m2: MultiAddress): MultiAddress {. concat(m1, m2).tryGet() proc `&=`*(m1: var MultiAddress, m2: MultiAddress) {. - raises: [Defect, LPError].} = + raises: [LPError].} = ## Concatenates two addresses ``m1`` and ``m2``. ## ## This procedure performs validation of concatenated result and can raise diff --git a/libp2p/multibase.nim b/libp2p/multibase.nim index 49bdd5fe9..2fad33be2 100644 --- a/libp2p/multibase.nim +++ b/libp2p/multibase.nim @@ -13,10 +13,7 @@ ## 1. base32z ## -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import tables import stew/[base32, base58, base64, results] @@ -27,17 +24,17 @@ type MultiBase* = object - MBCodeSize = proc(length: int): int {.nimcall, gcsafe, noSideEffect, raises: [Defect].} + MBCodeSize = proc(length: int): int {.nimcall, gcsafe, noSideEffect, raises: [].} MBCodec = object code: char name: string encr: proc(inbytes: openArray[byte], outbytes: var openArray[char], - outlen: var int): MultiBaseStatus {.nimcall, gcsafe, noSideEffect, raises: [Defect].} + outlen: var int): MultiBaseStatus {.nimcall, gcsafe, noSideEffect, raises: [].} decr: proc(inbytes: openArray[char], outbytes: var openArray[byte], - outlen: var int): MultiBaseStatus {.nimcall, gcsafe, noSideEffect, raises: [Defect].} + outlen: var int): MultiBaseStatus {.nimcall, gcsafe, noSideEffect, raises: [].} encl: MBCodeSize decl: MBCodeSize diff --git a/libp2p/multicodec.nim b/libp2p/multicodec.nim index a40676360..538e52ce8 100644 --- a/libp2p/multicodec.nim +++ b/libp2p/multicodec.nim @@ -9,10 +9,7 @@ ## This module implements MultiCodec. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import tables, hashes import varint, vbuffer diff --git a/libp2p/multihash.nim b/libp2p/multihash.nim index 32fddf7b9..4d890d154 100644 --- a/libp2p/multihash.nim +++ b/libp2p/multihash.nim @@ -21,10 +21,7 @@ ## 1. SKEIN ## 2. MURMUR -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import tables import nimcrypto/[sha, sha2, keccak, blake2, hash, utils] @@ -45,7 +42,7 @@ const type MHashCoderProc* = proc(data: openArray[byte], - output: var openArray[byte]) {.nimcall, gcsafe, noSideEffect, raises: [Defect].} + output: var openArray[byte]) {.nimcall, gcsafe, noSideEffect, raises: [].} MHash* = object mcodec*: MultiCodec size*: int diff --git a/libp2p/multistream.nim b/libp2p/multistream.nim index 9f9e75f1b..9c5444264 100644 --- a/libp2p/multistream.nim +++ b/libp2p/multistream.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[strutils, sequtils, tables] import chronos, chronicles, stew/byteutils @@ -28,7 +25,7 @@ const Ls = "ls\n" type - Matcher* = proc (proto: string): bool {.gcsafe, raises: [Defect].} + Matcher* = proc (proto: string): bool {.gcsafe, raises: [].} MultiStreamError* = object of LPError diff --git a/libp2p/muxers/mplex/coder.nim b/libp2p/muxers/mplex/coder.nim index 8a05b20ef..d1068e367 100644 --- a/libp2p/muxers/mplex/coder.nim +++ b/libp2p/muxers/mplex/coder.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import pkg/[chronos, chronicles, stew/byteutils] import ../../stream/connection, diff --git a/libp2p/muxers/mplex/lpchannel.nim b/libp2p/muxers/mplex/lpchannel.nim index bbd10d664..d5c604c30 100644 --- a/libp2p/muxers/mplex/lpchannel.nim +++ b/libp2p/muxers/mplex/lpchannel.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[oids, strformat] import pkg/[chronos, chronicles, metrics] diff --git a/libp2p/muxers/mplex/mplex.nim b/libp2p/muxers/mplex/mplex.nim index fed8e678e..b8d287ec3 100644 --- a/libp2p/muxers/mplex/mplex.nim +++ b/libp2p/muxers/mplex/mplex.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import tables, sequtils, oids import chronos, chronicles, stew/byteutils, metrics @@ -79,7 +76,7 @@ proc newStreamInternal*(m: Mplex, chanId: uint64 = 0, name: string = "", timeout: Duration): LPChannel - {.gcsafe, raises: [Defect, InvalidChannelIdError].} = + {.gcsafe, raises: [InvalidChannelIdError].} = ## create new channel/stream ## let id = if initiator: diff --git a/libp2p/muxers/muxer.nim b/libp2p/muxers/muxer.nim index 5b93c5745..6c59fc463 100644 --- a/libp2p/muxers/muxer.nim +++ b/libp2p/muxers/muxer.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos, chronicles import ../stream/connection, @@ -26,8 +23,8 @@ type MuxerError* = object of LPError TooManyChannels* = object of MuxerError - StreamHandler* = proc(conn: Connection): Future[void] {.gcsafe, raises: [Defect].} - MuxerHandler* = proc(muxer: Muxer): Future[void] {.gcsafe, raises: [Defect].} + StreamHandler* = proc(conn: Connection): Future[void] {.gcsafe, raises: [].} + MuxerHandler* = proc(muxer: Muxer): Future[void] {.gcsafe, raises: [].} Muxer* = ref object of RootObj streamHandler*: StreamHandler @@ -35,7 +32,7 @@ type connection*: Connection # user provider proc that returns a constructed Muxer - MuxerConstructor* = proc(conn: Connection): Muxer {.gcsafe, closure, raises: [Defect].} + MuxerConstructor* = proc(conn: Connection): Muxer {.gcsafe, closure, raises: [].} # this wraps a creator proc that knows how to make muxers MuxerProvider* = object diff --git a/libp2p/muxers/yamux/yamux.nim b/libp2p/muxers/yamux/yamux.nim index 9e15844c4..e71772da1 100644 --- a/libp2p/muxers/yamux/yamux.nim +++ b/libp2p/muxers/yamux/yamux.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import sequtils, std/[tables] import chronos, chronicles, metrics, stew/[endians2, byteutils, objects] diff --git a/libp2p/nameresolving/dnsresolver.nim b/libp2p/nameresolving/dnsresolver.nim index 92313b158..58bfdf208 100644 --- a/libp2p/nameresolving/dnsresolver.nim +++ b/libp2p/nameresolving/dnsresolver.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[streams, strutils, sets, sequtils], diff --git a/libp2p/nameresolving/mockresolver.nim b/libp2p/nameresolving/mockresolver.nim index 266933b35..492dc1c42 100644 --- a/libp2p/nameresolving/mockresolver.nim +++ b/libp2p/nameresolving/mockresolver.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/tables, diff --git a/libp2p/nameresolving/nameresolver.nim b/libp2p/nameresolving/nameresolver.nim index 81ecef6d0..cb58ffadc 100644 --- a/libp2p/nameresolving/nameresolver.nim +++ b/libp2p/nameresolving/nameresolver.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[sugar, sets, sequtils, strutils] import @@ -55,7 +52,7 @@ proc resolveOneAddress( ma: MultiAddress, domain: Domain = Domain.AF_UNSPEC, prefix = ""): Future[seq[MultiAddress]] - {.async, raises: [Defect, MaError, TransportAddressError].} = + {.async, raises: [MaError, TransportAddressError].} = #Resolve a single address var pbuf: array[2, byte] diff --git a/libp2p/observedaddrmanager.nim b/libp2p/observedaddrmanager.nim index 882e16ea7..b84e905e2 100644 --- a/libp2p/observedaddrmanager.nim +++ b/libp2p/observedaddrmanager.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[sequtils, tables], diff --git a/libp2p/peerid.nim b/libp2p/peerid.nim index a26605181..c705d2e97 100644 --- a/libp2p/peerid.nim +++ b/libp2p/peerid.nim @@ -9,10 +9,7 @@ ## This module implementes API for libp2p peer. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} {.push public.} import @@ -44,10 +41,7 @@ func shortLog*(pid: PeerId): string = if len(spid) > 10: spid[3] = '*' - when (NimMajor, NimMinor) > (1, 4): - spid.delete(4 .. spid.high - 6) - else: - spid.delete(4, spid.high - 6) + spid.delete(4 .. spid.high - 6) spid diff --git a/libp2p/peerinfo.nim b/libp2p/peerinfo.nim index a96a347e4..e017bbb63 100644 --- a/libp2p/peerinfo.nim +++ b/libp2p/peerinfo.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} {.push public.} import std/[options, sequtils] @@ -26,7 +23,7 @@ type AddressMapper* = proc(listenAddrs: seq[MultiAddress]): Future[seq[MultiAddress]] - {.gcsafe, raises: [Defect].} + {.gcsafe, raises: [].} PeerInfo* {.public.} = ref object peerId*: PeerId @@ -99,7 +96,7 @@ proc new*( agentVersion: string = "", addressMappers = newSeq[AddressMapper](), ): PeerInfo - {.raises: [Defect, LPError].} = + {.raises: [LPError].} = let pubkey = try: key.getPublicKey().tryGet() diff --git a/libp2p/peerstore.nim b/libp2p/peerstore.nim index 67f71d1d2..5c4a212f2 100644 --- a/libp2p/peerstore.nim +++ b/libp2p/peerstore.nim @@ -21,10 +21,7 @@ runnableExamples: peerStore[MoodBook][somePeerId] = "Happy" doAssert peerStore[MoodBook][somePeerId] == "Happy" -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[tables, sets, options, macros], @@ -45,7 +42,7 @@ type # Handler types # ################# - PeerBookChangeHandler* = proc(peerId: PeerId) {.gcsafe, raises: [Defect].} + PeerBookChangeHandler* = proc(peerId: PeerId) {.gcsafe, raises: [].} ######### # Books # diff --git a/libp2p/protobuf/minprotobuf.nim b/libp2p/protobuf/minprotobuf.nim index 5d28cd5ff..fa96175d0 100644 --- a/libp2p/protobuf/minprotobuf.nim +++ b/libp2p/protobuf/minprotobuf.nim @@ -9,10 +9,7 @@ ## This module implements minimal Google's ProtoBuf primitives. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import ../varint, ../utility, stew/[endians2, results] export results, utility diff --git a/libp2p/protocols/connectivity/autonat/client.nim b/libp2p/protocols/connectivity/autonat/client.nim index e6ec928ff..cdc8b9917 100644 --- a/libp2p/protocols/connectivity/autonat/client.nim +++ b/libp2p/protocols/connectivity/autonat/client.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/options import stew/results @@ -36,7 +33,7 @@ proc sendDial(conn: Connection, pid: PeerId, addrs: seq[MultiAddress]) {.async.} method dialMe*(self: AutonatClient, switch: Switch, pid: PeerId, addrs: seq[MultiAddress] = newSeq[MultiAddress]()): Future[MultiAddress] {.base, async.} = - proc getResponseOrRaise(autonatMsg: Option[AutonatMsg]): AutonatDialResponse {.raises: [Defect, AutonatError].} = + proc getResponseOrRaise(autonatMsg: Option[AutonatMsg]): AutonatDialResponse {.raises: [AutonatError].} = if autonatMsg.isNone() or autonatMsg.get().msgType != DialResponse or autonatMsg.get().response.isNone() or diff --git a/libp2p/protocols/connectivity/autonat/core.nim b/libp2p/protocols/connectivity/autonat/core.nim index c3d1a22e7..e97bc0af3 100644 --- a/libp2p/protocols/connectivity/autonat/core.nim +++ b/libp2p/protocols/connectivity/autonat/core.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[options] import stew/[results, objects] @@ -152,4 +149,4 @@ proc decode*(_: typedesc[AutonatMsg], buf: seq[byte]): Option[AutonatMsg] = if r6.get(): response.ma = some(ma) msg.response = some(response) - return some(msg) \ No newline at end of file + return some(msg) diff --git a/libp2p/protocols/connectivity/autonat/server.nim b/libp2p/protocols/connectivity/autonat/server.nim index 0927369fd..82641ea26 100644 --- a/libp2p/protocols/connectivity/autonat/server.nim +++ b/libp2p/protocols/connectivity/autonat/server.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[options, sets, sequtils] import stew/results diff --git a/libp2p/protocols/connectivity/autonat/service.nim b/libp2p/protocols/connectivity/autonat/service.nim index 50edae185..327ec412b 100644 --- a/libp2p/protocols/connectivity/autonat/service.nim +++ b/libp2p/protocols/connectivity/autonat/service.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[options, deques, sequtils] import chronos, metrics @@ -47,7 +44,7 @@ type dialTimeout: Duration enableAddressMapper: bool - StatusAndConfidenceHandler* = proc (networkReachability: NetworkReachability, confidence: Option[float]): Future[void] {.gcsafe, raises: [Defect].} + StatusAndConfidenceHandler* = proc (networkReachability: NetworkReachability, confidence: Option[float]): Future[void] {.gcsafe, raises: [].} proc new*( T: typedesc[AutonatService], diff --git a/libp2p/protocols/connectivity/dcutr/client.nim b/libp2p/protocols/connectivity/dcutr/client.nim index 1aafeb160..a604a4829 100644 --- a/libp2p/protocols/connectivity/dcutr/client.nim +++ b/libp2p/protocols/connectivity/dcutr/client.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/sequtils diff --git a/libp2p/protocols/connectivity/dcutr/core.nim b/libp2p/protocols/connectivity/dcutr/core.nim index 07585dc51..d0744c80d 100644 --- a/libp2p/protocols/connectivity/dcutr/core.nim +++ b/libp2p/protocols/connectivity/dcutr/core.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/sequtils @@ -44,7 +41,7 @@ proc encode*(msg: DcutrMsg): ProtoBuffer = result.write(2, addr) result.finish() -proc decode*(_: typedesc[DcutrMsg], buf: seq[byte]): DcutrMsg {.raises: [Defect, DcutrError].} = +proc decode*(_: typedesc[DcutrMsg], buf: seq[byte]): DcutrMsg {.raises: [DcutrError].} = var msgTypeOrd: uint32 dcutrMsg: DcutrMsg diff --git a/libp2p/protocols/connectivity/dcutr/server.nim b/libp2p/protocols/connectivity/dcutr/server.nim index c9f4fcb4b..1a9bd92ae 100644 --- a/libp2p/protocols/connectivity/dcutr/server.nim +++ b/libp2p/protocols/connectivity/dcutr/server.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[options, sets, sequtils] diff --git a/libp2p/protocols/connectivity/relay/client.nim b/libp2p/protocols/connectivity/relay/client.nim index e8573e078..94d794eb5 100644 --- a/libp2p/protocols/connectivity/relay/client.nim +++ b/libp2p/protocols/connectivity/relay/client.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import times, options @@ -39,7 +36,7 @@ type RelayV2DialError* = object of RelayClientError RelayClientAddConn* = proc(conn: Connection, duration: uint32, - data: uint64): Future[void] {.gcsafe, raises: [Defect].} + data: uint64): Future[void] {.gcsafe, raises: [].} RelayClient* = ref object of Relay onNewConnection*: RelayClientAddConn canHop: bool diff --git a/libp2p/protocols/connectivity/relay/messages.nim b/libp2p/protocols/connectivity/relay/messages.nim index 4b4a0fb3a..6c8e4583c 100644 --- a/libp2p/protocols/connectivity/relay/messages.nim +++ b/libp2p/protocols/connectivity/relay/messages.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import options, macros import stew/objects diff --git a/libp2p/protocols/connectivity/relay/rconn.nim b/libp2p/protocols/connectivity/relay/rconn.nim index c46b8cc70..1856afe70 100644 --- a/libp2p/protocols/connectivity/relay/rconn.nim +++ b/libp2p/protocols/connectivity/relay/rconn.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos diff --git a/libp2p/protocols/connectivity/relay/relay.nim b/libp2p/protocols/connectivity/relay/relay.nim index d9b1bd928..638115901 100644 --- a/libp2p/protocols/connectivity/relay/relay.nim +++ b/libp2p/protocols/connectivity/relay/relay.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import options, sequtils, tables diff --git a/libp2p/protocols/connectivity/relay/rtransport.nim b/libp2p/protocols/connectivity/relay/rtransport.nim index 83ab7ba9d..123a1e936 100644 --- a/libp2p/protocols/connectivity/relay/rtransport.nim +++ b/libp2p/protocols/connectivity/relay/rtransport.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import sequtils, strutils @@ -40,7 +37,7 @@ method start*(self: RelayTransport, ma: seq[MultiAddress]) {.async.} = self.client.onNewConnection = proc( conn: Connection, duration: uint32 = 0, - data: uint64 = 0) {.async, gcsafe, raises: [Defect].} = + data: uint64 = 0) {.async, gcsafe, raises: [].} = await self.queue.addLast(RelayConnection.new(conn, duration, data)) await conn.join() self.selfRunning = true diff --git a/libp2p/protocols/connectivity/relay/utils.nim b/libp2p/protocols/connectivity/relay/utils.nim index 65eb4f4e3..50fd6a062 100644 --- a/libp2p/protocols/connectivity/relay/utils.nim +++ b/libp2p/protocols/connectivity/relay/utils.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import options diff --git a/libp2p/protocols/identify.nim b/libp2p/protocols/identify.nim index 85202d596..96f7ff694 100644 --- a/libp2p/protocols/identify.nim +++ b/libp2p/protocols/identify.nim @@ -10,10 +10,7 @@ ## `Identify `_ and ## `Push Identify `_ implementation -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[sequtils, options, strutils, sugar] import stew/results @@ -65,7 +62,7 @@ type peer: PeerId, newInfo: IdentifyInfo): Future[void] - {.gcsafe, raises: [Defect], public.} + {.gcsafe, raises: [], public.} IdentifyPush* = ref object of LPProtocol identifyHandler: IdentifyPushHandler @@ -86,7 +83,7 @@ chronicles.expandIt(IdentifyInfo): else: "None" proc encodeMsg(peerInfo: PeerInfo, observedAddr: Opt[MultiAddress], sendSpr: bool): ProtoBuffer - {.raises: [Defect].} = + {.raises: [].} = result = initProtoBuffer() let pkey = peerInfo.publicKey diff --git a/libp2p/protocols/ping.nim b/libp2p/protocols/ping.nim index cfa6c59bd..7e385db6e 100644 --- a/libp2p/protocols/ping.nim +++ b/libp2p/protocols/ping.nim @@ -9,10 +9,7 @@ ## `Ping `_ protocol implementation -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos, chronicles import bearssl/rand @@ -42,7 +39,7 @@ type PingHandler* {.public.} = proc ( peer: PeerId): Future[void] - {.gcsafe, raises: [Defect].} + {.gcsafe, raises: [].} Ping* = ref object of LPProtocol pingHandler*: PingHandler diff --git a/libp2p/protocols/protocol.nim b/libp2p/protocols/protocol.nim index 88d96f623..cb328849d 100644 --- a/libp2p/protocols/protocol.nim +++ b/libp2p/protocols/protocol.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos, stew/results import ../stream/connection @@ -25,7 +22,7 @@ type conn: Connection, proto: string): Future[void] - {.gcsafe, raises: [Defect].} + {.gcsafe, raises: [].} LPProtocol* = ref object of RootObj codecs*: seq[string] @@ -55,8 +52,8 @@ func `codec=`*(p: LPProtocol, codec: string) = proc new*( T: type LPProtocol, codecs: seq[string], - handler: LPProtoHandler, # default(Opt[int]) or Opt.none(int) don't work on 1.2 - maxIncomingStreams: Opt[int] | int = Opt[int]()): T = + handler: LPProtoHandler, + maxIncomingStreams: Opt[int] | int = Opt.none(int)): T = T( codecs: codecs, handler: handler, diff --git a/libp2p/protocols/pubsub/floodsub.nim b/libp2p/protocols/pubsub/floodsub.nim index c68aca8ea..baea4d264 100644 --- a/libp2p/protocols/pubsub/floodsub.nim +++ b/libp2p/protocols/pubsub/floodsub.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[sets, hashes, tables] import chronos, chronicles, metrics @@ -223,7 +220,7 @@ method publish*(f: FloodSub, return peers.len method initPubSub*(f: FloodSub) - {.raises: [Defect, InitializationError].} = + {.raises: [InitializationError].} = procCall PubSub(f).initPubSub() f.seen = TimedCache[MessageId].init(2.minutes) f.seenSalt = newSeqUninitialized[byte](sizeof(Hash)) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index d707bf285..75fc48d9a 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -9,10 +9,7 @@ ## Gossip based publishing -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[sets, sequtils] import chronos, chronicles, metrics @@ -622,7 +619,7 @@ method stop*(g: GossipSub) {.async.} = g.heartbeatFut = nil method initPubSub*(g: GossipSub) - {.raises: [Defect, InitializationError].} = + {.raises: [InitializationError].} = procCall FloodSub(g).initPubSub() if not g.parameters.explicit: diff --git a/libp2p/protocols/pubsub/gossipsub/behavior.nim b/libp2p/protocols/pubsub/gossipsub/behavior.nim index 13a041245..f424937ef 100644 --- a/libp2p/protocols/pubsub/gossipsub/behavior.nim +++ b/libp2p/protocols/pubsub/gossipsub/behavior.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[tables, sequtils, sets, algorithm, deques] import chronos, chronicles, metrics @@ -33,7 +30,7 @@ declareGauge(libp2p_gossipsub_healthy_peers_topics, "number of topics in mesh wi declareCounter(libp2p_gossipsub_above_dhigh_condition, "number of above dhigh pruning branches ran", labels = ["topic"]) declareGauge(libp2p_gossipsub_received_iwants, "received iwants", labels = ["kind"]) -proc grafted*(g: GossipSub, p: PubSubPeer, topic: string) {.raises: [Defect].} = +proc grafted*(g: GossipSub, p: PubSubPeer, topic: string) {.raises: [].} = g.withPeerStats(p.peerId) do (stats: var PeerStats): var info = stats.topicInfos.getOrDefault(topic) info.graftTime = Moment.now() @@ -49,7 +46,7 @@ proc pruned*(g: GossipSub, p: PubSubPeer, topic: string, setBackoff: bool = true, - backoff = none(Duration)) {.raises: [Defect].} = + backoff = none(Duration)) {.raises: [].} = if setBackoff: let backoffDuration = @@ -75,7 +72,7 @@ proc pruned*(g: GossipSub, trace "pruned", peer=p, topic -proc handleBackingOff*(t: var BackoffTable, topic: string) {.raises: [Defect].} = +proc handleBackingOff*(t: var BackoffTable, topic: string) {.raises: [].} = let now = Moment.now() var expired = toSeq(t.getOrDefault(topic).pairs()) expired.keepIf do (pair: tuple[peer: PeerId, expire: Moment]) -> bool: @@ -84,7 +81,7 @@ proc handleBackingOff*(t: var BackoffTable, topic: string) {.raises: [Defect].} t.withValue(topic, v): v[].del(peer) -proc peerExchangeList*(g: GossipSub, topic: string): seq[PeerInfoMsg] {.raises: [Defect].} = +proc peerExchangeList*(g: GossipSub, topic: string): seq[PeerInfoMsg] {.raises: [].} = if not g.parameters.enablePX: return @[] var peers = g.gossipsub.getOrDefault(topic, initHashSet[PubSubPeer]()).toSeq() @@ -214,7 +211,7 @@ proc getPeers(prune: ControlPrune, peer: PubSubPeer): seq[(PeerId, Option[PeerRe routingRecords -proc handlePrune*(g: GossipSub, peer: PubSubPeer, prunes: seq[ControlPrune]) {.raises: [Defect].} = +proc handlePrune*(g: GossipSub, peer: PubSubPeer, prunes: seq[ControlPrune]) {.raises: [].} = for prune in prunes: let topic = prune.topicId @@ -248,7 +245,7 @@ proc handlePrune*(g: GossipSub, peer: PubSubPeer, prunes: seq[ControlPrune]) {.r proc handleIHave*(g: GossipSub, peer: PubSubPeer, - ihaves: seq[ControlIHave]): ControlIWant {.raises: [Defect].} = + ihaves: seq[ControlIHave]): ControlIWant {.raises: [].} = var res: ControlIWant if peer.score < g.parameters.gossipThreshold: trace "ihave: ignoring low score peer", peer, score = peer.score @@ -280,7 +277,7 @@ proc handleIHave*(g: GossipSub, proc handleIWant*(g: GossipSub, peer: PubSubPeer, - iwants: seq[ControlIWant]): seq[Message] {.raises: [Defect].} = + iwants: seq[ControlIWant]): seq[Message] {.raises: [].} = var messages: seq[Message] invalidRequests = 0 @@ -307,7 +304,7 @@ proc handleIWant*(g: GossipSub, libp2p_gossipsub_received_iwants.inc(1, labelValues=["unknown"]) return messages -proc commitMetrics(metrics: var MeshMetrics) {.raises: [Defect].} = +proc commitMetrics(metrics: var MeshMetrics) {.raises: [].} = libp2p_gossipsub_low_peers_topics.set(metrics.lowPeersTopics) libp2p_gossipsub_no_peers_topics.set(metrics.noPeersTopics) libp2p_gossipsub_under_dout_topics.set(metrics.underDoutTopics) @@ -316,7 +313,7 @@ proc commitMetrics(metrics: var MeshMetrics) {.raises: [Defect].} = libp2p_gossipsub_peers_per_topic_fanout.set(metrics.otherPeersPerTopicFanout, labelValues = ["other"]) libp2p_gossipsub_peers_per_topic_mesh.set(metrics.otherPeersPerTopicMesh, labelValues = ["other"]) -proc rebalanceMesh*(g: GossipSub, topic: string, metrics: ptr MeshMetrics = nil) {.raises: [Defect].} = +proc rebalanceMesh*(g: GossipSub, topic: string, metrics: ptr MeshMetrics = nil) {.raises: [].} = logScope: topic mesh = g.mesh.peers(topic) @@ -546,7 +543,7 @@ proc rebalanceMesh*(g: GossipSub, topic: string, metrics: ptr MeshMetrics = nil) backoff: g.parameters.pruneBackoff.seconds.uint64)]))) g.broadcast(prunes, prune) -proc dropFanoutPeers*(g: GossipSub) {.raises: [Defect].} = +proc dropFanoutPeers*(g: GossipSub) {.raises: [].} = # drop peers that we haven't published to in # GossipSubFanoutTTL seconds let now = Moment.now() @@ -559,7 +556,7 @@ proc dropFanoutPeers*(g: GossipSub) {.raises: [Defect].} = for topic in drops: g.lastFanoutPubSub.del topic -proc replenishFanout*(g: GossipSub, topic: string) {.raises: [Defect].} = +proc replenishFanout*(g: GossipSub, topic: string) {.raises: [].} = ## get fanout peers for a topic logScope: topic trace "about to replenish fanout" @@ -575,7 +572,7 @@ proc replenishFanout*(g: GossipSub, topic: string) {.raises: [Defect].} = trace "fanout replenished with peers", peers = g.fanout.peers(topic) -proc getGossipPeers*(g: GossipSub): Table[PubSubPeer, ControlMessage] {.raises: [Defect].} = +proc getGossipPeers*(g: GossipSub): Table[PubSubPeer, ControlMessage] {.raises: [].} = ## gossip iHave messages to peers ## @@ -638,7 +635,7 @@ proc getGossipPeers*(g: GossipSub): Table[PubSubPeer, ControlMessage] {.raises: return control -proc onHeartbeat(g: GossipSub) {.raises: [Defect].} = +proc onHeartbeat(g: GossipSub) {.raises: [].} = # reset IWANT budget # reset IHAVE cap block: @@ -698,7 +695,7 @@ proc onHeartbeat(g: GossipSub) {.raises: [Defect].} = g.mcache.shift() # shift the cache -# {.pop.} # raises [Defect] +# {.pop.} # raises [] proc heartbeat*(g: GossipSub) {.async.} = heartbeat "GossipSub", g.parameters.heartbeatInterval: diff --git a/libp2p/protocols/pubsub/gossipsub/scoring.nim b/libp2p/protocols/pubsub/gossipsub/scoring.nim index 3606059db..bebd1250d 100644 --- a/libp2p/protocols/pubsub/gossipsub/scoring.nim +++ b/libp2p/protocols/pubsub/gossipsub/scoring.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[tables, sets, options] import chronos, chronicles, metrics @@ -55,7 +52,7 @@ proc init*(_: type[TopicParams]): TopicParams = proc withPeerStats*( g: GossipSub, peerId: PeerId, - action: proc (stats: var PeerStats) {.gcsafe, raises: [Defect].}) = + action: proc (stats: var PeerStats) {.gcsafe, raises: [].}) = ## Add or update peer statistics for a particular peer id - the statistics ## are retained across multiple connections until they expire g.peerStats.withValue(peerId, stats) do: diff --git a/libp2p/protocols/pubsub/gossipsub/types.nim b/libp2p/protocols/pubsub/gossipsub/types.nim index e82b85af8..6827460cd 100644 --- a/libp2p/protocols/pubsub/gossipsub/types.nim +++ b/libp2p/protocols/pubsub/gossipsub/types.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos import std/[options, tables, sets] @@ -152,7 +149,7 @@ type proc(peer: PeerId, tag: string, # For gossipsub, the topic peers: seq[RoutingRecordsPair]) - {.gcsafe, raises: [Defect].} + {.gcsafe, raises: [].} GossipSub* = ref object of FloodSub mesh*: PeerTable # peers that we send messages to when we are subscribed to the topic diff --git a/libp2p/protocols/pubsub/mcache.nim b/libp2p/protocols/pubsub/mcache.nim index 14aa9a0ee..d6ea6871a 100644 --- a/libp2p/protocols/pubsub/mcache.nim +++ b/libp2p/protocols/pubsub/mcache.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[sets, tables, options] import rpc/[messages] diff --git a/libp2p/protocols/pubsub/peertable.nim b/libp2p/protocols/pubsub/peertable.nim index 2f19befaf..78eadc464 100644 --- a/libp2p/protocols/pubsub/peertable.nim +++ b/libp2p/protocols/pubsub/peertable.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[tables, sets, sequtils] import ./pubsubpeer, ../../peerid diff --git a/libp2p/protocols/pubsub/pubsub.nim b/libp2p/protocols/pubsub/pubsub.nim index fb7aea13b..d5d71e5ab 100644 --- a/libp2p/protocols/pubsub/pubsub.nim +++ b/libp2p/protocols/pubsub/pubsub.nim @@ -13,10 +13,7 @@ ## `publish<#publish.e%2CPubSub%2Cstring%2Cseq%5Bbyte%5D>`_ something on it, ## and eventually `unsubscribe<#unsubscribe%2CPubSub%2Cstring%2CTopicHandler>`_ from it. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[tables, sequtils, sets, strutils] import chronos, chronicles, metrics @@ -86,18 +83,18 @@ type InitializationError* = object of LPError TopicHandler* {.public.} = proc(topic: string, - data: seq[byte]): Future[void] {.gcsafe, raises: [Defect].} + data: seq[byte]): Future[void] {.gcsafe, raises: [].} ValidatorHandler* {.public.} = proc(topic: string, - message: Message): Future[ValidationResult] {.gcsafe, raises: [Defect].} + message: Message): Future[ValidationResult] {.gcsafe, raises: [].} TopicPair* = tuple[topic: string, handler: TopicHandler] MsgIdProvider* {.public.} = - proc(m: Message): Result[MessageId, ValidationResult] {.noSideEffect, raises: [Defect], gcsafe.} + proc(m: Message): Result[MessageId, ValidationResult] {.noSideEffect, raises: [], gcsafe.} SubscriptionValidator* {.public.} = - proc(topic: string): bool {.raises: [Defect], gcsafe.} + proc(topic: string): bool {.raises: [], gcsafe.} ## Every time a peer send us a subscription (even to an unknown topic), ## we have to store it, which may be an attack vector. ## This callback can be used to reject topic we're not interested in @@ -140,7 +137,7 @@ method unsubscribePeer*(p: PubSub, peerId: PeerId) {.base, gcsafe.} = libp2p_pubsub_peers.set(p.peers.len.int64) -proc send*(p: PubSub, peer: PubSubPeer, msg: RPCMsg) {.raises: [Defect].} = +proc send*(p: PubSub, peer: PubSubPeer, msg: RPCMsg) {.raises: [].} = ## Attempt to send `msg` to remote peer ## @@ -150,7 +147,7 @@ proc send*(p: PubSub, peer: PubSubPeer, msg: RPCMsg) {.raises: [Defect].} = proc broadcast*( p: PubSub, sendPeers: auto, # Iteratble[PubSubPeer] - msg: RPCMsg) {.raises: [Defect].} = + msg: RPCMsg) {.raises: [].} = ## Attempt to send `msg` to the given peers let npeers = sendPeers.len.int64 @@ -491,7 +488,7 @@ method publish*(p: PubSub, return 0 method initPubSub*(p: PubSub) - {.base, raises: [Defect, InitializationError].} = + {.base, raises: [InitializationError].} = ## perform pubsub initialization p.observers = new(seq[PubSubObserver]) if p.msgIdProvider == nil: @@ -559,7 +556,7 @@ proc init*[PubParams: object | bool]( maxMessageSize: int = 1024 * 1024, rng: ref HmacDrbgContext = newRng(), parameters: PubParams = false): P - {.raises: [Defect, InitializationError], public.} = + {.raises: [InitializationError], public.} = let pubsub = when PubParams is bool: P(switch: switch, diff --git a/libp2p/protocols/pubsub/pubsubpeer.nim b/libp2p/protocols/pubsub/pubsubpeer.nim index 31fbbe7a6..6241a30b9 100644 --- a/libp2p/protocols/pubsub/pubsubpeer.nim +++ b/libp2p/protocols/pubsub/pubsubpeer.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[sequtils, strutils, tables, hashes, options, sets, deques] import stew/results @@ -36,8 +33,8 @@ when defined(libp2p_expensive_metrics): type PubSubObserver* = ref object - onRecv*: proc(peer: PubSubPeer; msgs: var RPCMsg) {.gcsafe, raises: [Defect].} - onSend*: proc(peer: PubSubPeer; msgs: var RPCMsg) {.gcsafe, raises: [Defect].} + onRecv*: proc(peer: PubSubPeer; msgs: var RPCMsg) {.gcsafe, raises: [].} + onSend*: proc(peer: PubSubPeer; msgs: var RPCMsg) {.gcsafe, raises: [].} PubSubPeerEventKind* {.pure.} = enum Connected @@ -46,9 +43,9 @@ type PubSubPeerEvent* = object kind*: PubSubPeerEventKind - GetConn* = proc(): Future[Connection] {.gcsafe, raises: [Defect].} - DropConn* = proc(peer: PubSubPeer) {.gcsafe, raises: [Defect].} # have to pass peer as it's unknown during init - OnEvent* = proc(peer: PubSubPeer, event: PubSubPeerEvent) {.gcsafe, raises: [Defect].} + GetConn* = proc(): Future[Connection] {.gcsafe, raises: [].} + DropConn* = proc(peer: PubSubPeer) {.gcsafe, raises: [].} # have to pass peer as it's unknown during init + OnEvent* = proc(peer: PubSubPeer, event: PubSubPeerEvent) {.gcsafe, raises: [].} PubSubPeer* = ref object of RootObj getConn*: GetConn # callback to establish a new send connection @@ -69,7 +66,7 @@ type behaviourPenalty*: float64 # the eventual penalty score RPCHandler* = proc(peer: PubSubPeer, msg: RPCMsg): Future[void] - {.gcsafe, raises: [Defect].} + {.gcsafe, raises: [].} when defined(libp2p_agents_metrics): func shortAgent*(p: PubSubPeer): string = @@ -237,7 +234,7 @@ template sendMetrics(msg: RPCMsg): untyped = # metrics libp2p_pubsub_sent_messages.inc(labelValues = [$p.peerId, t]) -proc sendEncoded*(p: PubSubPeer, msg: seq[byte]) {.raises: [Defect], async.} = +proc sendEncoded*(p: PubSubPeer, msg: seq[byte]) {.raises: [], async.} = doAssert(not isNil(p), "pubsubpeer nil!") if msg.len <= 0: @@ -270,7 +267,7 @@ proc sendEncoded*(p: PubSubPeer, msg: seq[byte]) {.raises: [Defect], async.} = await conn.close() # This will clean up the send connection -proc send*(p: PubSubPeer, msg: RPCMsg, anonymize: bool) {.raises: [Defect].} = +proc send*(p: PubSubPeer, msg: RPCMsg, anonymize: bool) {.raises: [].} = trace "sending msg to peer", peer = p, rpcMsg = shortLog(msg) # When sending messages, we take care to re-encode them with the right diff --git a/libp2p/protocols/pubsub/rpc/message.nim b/libp2p/protocols/pubsub/rpc/message.nim index a37cc7380..d84ef4f74 100644 --- a/libp2p/protocols/pubsub/rpc/message.nim +++ b/libp2p/protocols/pubsub/rpc/message.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronicles, metrics, stew/[byteutils, endians2] import ./messages, @@ -65,7 +62,7 @@ proc init*( topic: string, seqno: Option[uint64], sign: bool = true): Message - {.gcsafe, raises: [Defect, LPError].} = + {.gcsafe, raises: [LPError].} = var msg = Message(data: data, topicIDs: @[topic]) # order matters, we want to include seqno in the signature @@ -90,7 +87,7 @@ proc init*( data: seq[byte], topic: string, seqno: Option[uint64]): Message - {.gcsafe, raises: [Defect, LPError].} = + {.gcsafe, raises: [LPError].} = var msg = Message(data: data, topicIDs: @[topic]) msg.fromPeer = peerId diff --git a/libp2p/protocols/pubsub/rpc/messages.nim b/libp2p/protocols/pubsub/rpc/messages.nim index 541782a8b..6192be920 100644 --- a/libp2p/protocols/pubsub/rpc/messages.nim +++ b/libp2p/protocols/pubsub/rpc/messages.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import options, sequtils import "../../.."/[ diff --git a/libp2p/protocols/pubsub/rpc/protobuf.nim b/libp2p/protocols/pubsub/rpc/protobuf.nim index d87a6b928..03f710e27 100644 --- a/libp2p/protocols/pubsub/rpc/protobuf.nim +++ b/libp2p/protocols/pubsub/rpc/protobuf.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import options import stew/assign2 diff --git a/libp2p/protocols/pubsub/timedcache.nim b/libp2p/protocols/pubsub/timedcache.nim index 9bcfed1fc..868099d74 100644 --- a/libp2p/protocols/pubsub/timedcache.nim +++ b/libp2p/protocols/pubsub/timedcache.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[tables] diff --git a/libp2p/protocols/rendezvous.nim b/libp2p/protocols/rendezvous.nim index 3a994456d..ee9bd036a 100644 --- a/libp2p/protocols/rendezvous.nim +++ b/libp2p/protocols/rendezvous.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import tables, sequtils, sugar, sets, options import chronos, diff --git a/libp2p/protocols/secure/noise.nim b/libp2p/protocols/secure/noise.nim index 41a8ed02d..b5c30abee 100644 --- a/libp2p/protocols/secure/noise.nim +++ b/libp2p/protocols/secure/noise.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/strformat import chronos @@ -136,7 +133,7 @@ proc encrypt( state: var CipherState, data: var openArray[byte], ad: openArray[byte]): ChaChaPolyTag - {.noinit, raises: [Defect, NoiseNonceMaxError].} = + {.noinit, raises: [NoiseNonceMaxError].} = var nonce: ChaChaPolyNonce nonce[4..<12] = toBytesLE(state.n) @@ -148,7 +145,7 @@ proc encrypt( raise newException(NoiseNonceMaxError, "Noise max nonce value reached") proc encryptWithAd(state: var CipherState, ad, data: openArray[byte]): seq[byte] - {.raises: [Defect, NoiseNonceMaxError].} = + {.raises: [NoiseNonceMaxError].} = result = newSeqOfCap[byte](data.len + sizeof(ChaChaPolyTag)) result.add(data) @@ -160,7 +157,7 @@ proc encryptWithAd(state: var CipherState, ad, data: openArray[byte]): seq[byte] tag = byteutils.toHex(tag), data = result.shortLog, nonce = state.n - 1 proc decryptWithAd(state: var CipherState, ad, data: openArray[byte]): seq[byte] - {.raises: [Defect, NoiseDecryptTagError, NoiseNonceMaxError].} = + {.raises: [NoiseDecryptTagError, NoiseNonceMaxError].} = var tagIn = data.toOpenArray(data.len - ChaChaPolyTag.len, data.high).intoChaChaPolyTag tagOut: ChaChaPolyTag @@ -209,7 +206,7 @@ proc mixKeyAndHash(ss: var SymmetricState, ikm: openArray[byte]) {.used.} = ss.cs = CipherState(k: temp_keys[2]) proc encryptAndHash(ss: var SymmetricState, data: openArray[byte]): seq[byte] - {.raises: [Defect, NoiseNonceMaxError].} = + {.raises: [NoiseNonceMaxError].} = # according to spec if key is empty leave plaintext if ss.cs.hasKey: result = ss.cs.encryptWithAd(ss.h.data, data) @@ -218,7 +215,7 @@ proc encryptAndHash(ss: var SymmetricState, data: openArray[byte]): seq[byte] ss.mixHash(result) proc decryptAndHash(ss: var SymmetricState, data: openArray[byte]): seq[byte] - {.raises: [Defect, NoiseDecryptTagError, NoiseNonceMaxError].} = + {.raises: [NoiseDecryptTagError, NoiseNonceMaxError].} = # according to spec if key is empty leave plaintext if ss.cs.hasKey and data.len > ChaChaPolyTag.len: result = ss.cs.decryptWithAd(ss.h.data, data) @@ -448,7 +445,7 @@ proc encryptFrame( sconn: NoiseConnection, cipherFrame: var openArray[byte], src: openArray[byte]) - {.raises: [Defect, NoiseNonceMaxError].} = + {.raises: [NoiseNonceMaxError].} = # Frame consists of length + cipher data + tag doAssert src.len <= MaxPlainSize doAssert cipherFrame.len == 2 + src.len + sizeof(ChaChaPolyTag) diff --git a/libp2p/protocols/secure/plaintext.nim b/libp2p/protocols/secure/plaintext.nim index 04d08fe5c..48ada7631 100644 --- a/libp2p/protocols/secure/plaintext.nim +++ b/libp2p/protocols/secure/plaintext.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos import secure, ../../stream/connection diff --git a/libp2p/protocols/secure/secio.nim b/libp2p/protocols/secure/secio.nim index 0674b54e2..77e498350 100644 --- a/libp2p/protocols/secure/secio.nim +++ b/libp2p/protocols/secure/secio.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[oids, strformat] import bearssl/rand @@ -262,7 +259,7 @@ proc newSecioConn(conn: Connection, secrets: Secret, order: int, remotePubKey: PublicKey): SecioConn - {.raises: [Defect, LPError].} = + {.raises: [LPError].} = ## Create new secure stream/lpstream, using specified hash algorithm ``hash``, ## cipher algorithm ``cipher``, stretched keys ``secrets`` and order ## ``order``. diff --git a/libp2p/protocols/secure/secure.nim b/libp2p/protocols/secure/secure.nim index e915934c9..96526714d 100644 --- a/libp2p/protocols/secure/secure.nim +++ b/libp2p/protocols/secure/secure.nim @@ -8,10 +8,7 @@ # those terms. {.push gcsafe.} -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[strformat] import stew/results diff --git a/libp2p/routing_record.nim b/libp2p/routing_record.nim index de39891ef..655c87c8c 100644 --- a/libp2p/routing_record.nim +++ b/libp2p/routing_record.nim @@ -9,10 +9,7 @@ ## This module implements Routing Records. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[sequtils, times] import pkg/stew/results diff --git a/libp2p/services/autorelayservice.nim b/libp2p/services/autorelayservice.nim index 5dd71faa2..c1b2c528b 100644 --- a/libp2p/services/autorelayservice.nim +++ b/libp2p/services/autorelayservice.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos, chronicles, times, tables, sequtils import ../switch, @@ -20,7 +17,7 @@ logScope: topics = "libp2p autorelay" type - OnReservationHandler = proc (addresses: seq[MultiAddress]) {.gcsafe, raises: [Defect].} + OnReservationHandler = proc (addresses: seq[MultiAddress]) {.gcsafe, raises: [].} AutoRelayService* = ref object of Service running: bool diff --git a/libp2p/services/hpservice.nim b/libp2p/services/hpservice.nim index bc39c1b1c..c88c865ca 100644 --- a/libp2p/services/hpservice.nim +++ b/libp2p/services/hpservice.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[tables, sequtils] @@ -35,7 +32,7 @@ type autonatService: AutonatService isPublicIPAddrProc: IsPublicIPAddrProc - IsPublicIPAddrProc* = proc(ta: TransportAddress): bool {.gcsafe, raises: [Defect].} + IsPublicIPAddrProc* = proc(ta: TransportAddress): bool {.gcsafe, raises: [].} proc new*(T: typedesc[HPService], autonatService: AutonatService, autoRelayService: AutoRelayService, isPublicIPAddrProc: IsPublicIPAddrProc = isGlobal): T = diff --git a/libp2p/signed_envelope.nim b/libp2p/signed_envelope.nim index 8e7c1d8ce..c2add96d5 100644 --- a/libp2p/signed_envelope.nim +++ b/libp2p/signed_envelope.nim @@ -9,10 +9,7 @@ ## This module implements Signed Envelope. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/sugar import pkg/stew/[results, byteutils] diff --git a/libp2p/stream/bufferstream.nim b/libp2p/stream/bufferstream.nim index 3dcfbdb0c..558cf2df4 100644 --- a/libp2p/stream/bufferstream.nim +++ b/libp2p/stream/bufferstream.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/strformat import stew/byteutils diff --git a/libp2p/stream/chronosstream.nim b/libp2p/stream/chronosstream.nim index f842886e4..b5f365875 100644 --- a/libp2p/stream/chronosstream.nim +++ b/libp2p/stream/chronosstream.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[strformat] import stew/results diff --git a/libp2p/stream/connection.nim b/libp2p/stream/connection.nim index 86539a058..faa595d45 100644 --- a/libp2p/stream/connection.nim +++ b/libp2p/stream/connection.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[hashes, oids, strformat] import stew/results @@ -30,7 +27,7 @@ const DefaultConnectionTimeout* = 5.minutes type - TimeoutHandler* = proc(): Future[void] {.gcsafe, raises: [Defect].} + TimeoutHandler* = proc(): Future[void] {.gcsafe, raises: [].} Connection* = ref object of LPStream activity*: bool # reset every time data is sent or received diff --git a/libp2p/stream/lpstream.nim b/libp2p/stream/lpstream.nim index 6dfe501c4..1a56c8471 100644 --- a/libp2p/stream/lpstream.nim +++ b/libp2p/stream/lpstream.nim @@ -10,10 +10,7 @@ ## Length Prefixed stream implementation {.push gcsafe.} -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/oids import stew/byteutils diff --git a/libp2p/stream/streamseq.nim b/libp2p/stream/streamseq.nim index f91b9bdf7..881e505cd 100644 --- a/libp2p/stream/streamseq.nim +++ b/libp2p/stream/streamseq.nim @@ -1,7 +1,13 @@ -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +# Nim-LibP2P +# Copyright (c) 2023 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +# * MIT license ([LICENSE-MIT](LICENSE-MIT)) +# at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + +{.push raises: [].} import stew/bitops2 diff --git a/libp2p/switch.nim b/libp2p/switch.nim index 231857899..8e98c42cf 100644 --- a/libp2p/switch.nim +++ b/libp2p/switch.nim @@ -11,10 +11,7 @@ ## transports, the connection manager, the upgrader and other ## parts to allow programs to use libp2p -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[tables, options, @@ -198,7 +195,7 @@ proc dial*( dial(s, peerId, addrs, @[proto]) proc mount*[T: LPProtocol](s: Switch, proto: T, matcher: Matcher = nil) - {.gcsafe, raises: [Defect, LPError], public.} = + {.gcsafe, raises: [LPError], public.} = ## mount a protocol to the switch if isNil(proto.handler): @@ -380,7 +377,7 @@ proc newSwitch*(peerInfo: PeerInfo, peerStore: PeerStore, nameResolver: NameResolver = nil, services = newSeq[Service]()): Switch - {.raises: [Defect, LPError].} = + {.raises: [LPError].} = if secureManagers.len == 0: raise newException(LPError, "Provide at least one secure manager") diff --git a/libp2p/transcoder.nim b/libp2p/transcoder.nim index 2acea8ab1..7f00fe650 100644 --- a/libp2p/transcoder.nim +++ b/libp2p/transcoder.nim @@ -13,7 +13,7 @@ import vbuffer type Transcoder* = object stringToBuffer*: proc(s: string, - vb: var VBuffer): bool {.nimcall, gcsafe, noSideEffect, raises: [Defect].} + vb: var VBuffer): bool {.nimcall, gcsafe, noSideEffect, raises: [].} bufferToString*: proc(vb: var VBuffer, - s: var string): bool {.nimcall, gcsafe, noSideEffect, raises: [Defect].} - validateBuffer*: proc(vb: var VBuffer): bool {.nimcall, gcsafe, noSideEffect, raises: [Defect].} + s: var string): bool {.nimcall, gcsafe, noSideEffect, raises: [].} + validateBuffer*: proc(vb: var VBuffer): bool {.nimcall, gcsafe, noSideEffect, raises: [].} diff --git a/libp2p/transports/tcptransport.nim b/libp2p/transports/tcptransport.nim index 6407557db..34fb5d2b9 100644 --- a/libp2p/transports/tcptransport.nim +++ b/libp2p/transports/tcptransport.nim @@ -9,10 +9,7 @@ ## TCP transport implementation -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[sequtils] import stew/results @@ -50,7 +47,7 @@ type TcpTransportError* = object of transport.TransportError -proc setupTcpTransportTracker(): TcpTransportTracker {.gcsafe, raises: [Defect].} +proc setupTcpTransportTracker(): TcpTransportTracker {.gcsafe, raises: [].} proc getTcpTransportTracker(): TcpTransportTracker {.gcsafe.} = result = cast[TcpTransportTracker](getTracker(TcpTransportTrackerName)) diff --git a/libp2p/transports/tortransport.nim b/libp2p/transports/tortransport.nim index 371cc616e..8543f7113 100644 --- a/libp2p/transports/tortransport.nim +++ b/libp2p/transports/tortransport.nim @@ -9,10 +9,7 @@ ## Tor transport implementation -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/strformat import chronos, chronicles, strutils @@ -133,7 +130,7 @@ proc readServerReply(transp: StreamTransport) {.async, gcsafe.} = else: raise newException(LPError, "Address not supported") -proc parseOnion3(address: MultiAddress): (byte, seq[byte], seq[byte]) {.raises: [Defect, LPError, ValueError].} = +proc parseOnion3(address: MultiAddress): (byte, seq[byte], seq[byte]) {.raises: [LPError, ValueError].} = var addressArray = ($address).split('/') if addressArray.len < 2: raise newException(LPError, fmt"Onion address not supported {address}") addressArray = addressArray[2].split(':') @@ -144,7 +141,7 @@ proc parseOnion3(address: MultiAddress): (byte, seq[byte], seq[byte]) {.raises: dstPort = address.data.buffer[37..38] return (Socks5AddressType.FQDN.byte, dstAddr, dstPort) -proc parseIpTcp(address: MultiAddress): (byte, seq[byte], seq[byte]) {.raises: [Defect, LPError, ValueError].} = +proc parseIpTcp(address: MultiAddress): (byte, seq[byte], seq[byte]) {.raises: [LPError, ValueError].} = let (codec, atyp) = if IPv4Tcp.match(address): (multiCodec("ip4"), Socks5AddressType.IPv4.byte) @@ -254,7 +251,7 @@ proc new*( rng: ref HmacDrbgContext, addresses: seq[MultiAddress] = @[], flags: set[ServerFlags] = {}): TorSwitch - {.raises: [LPError, Defect], public.} = + {.raises: [LPError], public.} = var builder = SwitchBuilder.new() .withRng(rng) .withTransport(proc(upgr: Upgrade): Transport = TorTransport.new(torServer, flags, upgr)) diff --git a/libp2p/transports/transport.nim b/libp2p/transports/transport.nim index 7e00fc2fc..86c31a669 100644 --- a/libp2p/transports/transport.nim +++ b/libp2p/transports/transport.nim @@ -8,10 +8,7 @@ # those terms. ## -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import sequtils import chronos, chronicles diff --git a/libp2p/transports/wstransport.nim b/libp2p/transports/wstransport.nim index 1bb86c4af..d77a532aa 100644 --- a/libp2p/transports/wstransport.nim +++ b/libp2p/transports/wstransport.nim @@ -9,10 +9,7 @@ ## WebSocket & WebSocket Secure transport implementation -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[sequtils] import stew/results diff --git a/libp2p/upgrademngrs/muxedupgrade.nim b/libp2p/upgrademngrs/muxedupgrade.nim index bde7e3f58..eb428ecb1 100644 --- a/libp2p/upgrademngrs/muxedupgrade.nim +++ b/libp2p/upgrademngrs/muxedupgrade.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/sequtils import pkg/[chronos, chronicles, metrics] @@ -104,7 +101,7 @@ proc new*( ms: ms) upgrader.streamHandler = proc(conn: Connection) - {.async, gcsafe, raises: [Defect].} = + {.async, gcsafe, raises: [].} = trace "Starting stream handler", conn try: await upgrader.ms.handle(conn) # handle incoming connection diff --git a/libp2p/upgrademngrs/upgrade.nim b/libp2p/upgrademngrs/upgrade.nim index 8a191dea3..005a2a97f 100644 --- a/libp2p/upgrademngrs/upgrade.nim +++ b/libp2p/upgrademngrs/upgrade.nim @@ -8,10 +8,7 @@ # those terms. {.push gcsafe.} -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/[sequtils, strutils] import pkg/[chronos, chronicles, metrics] diff --git a/libp2p/utility.nim b/libp2p/utility.nim index b22887dcc..09c1fac15 100644 --- a/libp2p/utility.nim +++ b/libp2p/utility.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import stew/byteutils diff --git a/libp2p/utils/future.nim b/libp2p/utils/future.nim index 6c18af85c..e15bf40b0 100644 --- a/libp2p/utils/future.nim +++ b/libp2p/utils/future.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos diff --git a/libp2p/utils/heartbeat.nim b/libp2p/utils/heartbeat.nim index 6f99008ff..0db43a54d 100644 --- a/libp2p/utils/heartbeat.nim +++ b/libp2p/utils/heartbeat.nim @@ -7,10 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos, chronicles diff --git a/libp2p/utils/offsettedseq.nim b/libp2p/utils/offsettedseq.nim index 40539f85e..4e28c5ff2 100644 --- a/libp2p/utils/offsettedseq.nim +++ b/libp2p/utils/offsettedseq.nim @@ -50,10 +50,7 @@ template flushIfIt*(o, pred: untyped) = if not pred: break i.inc() if i > 0: - when (NimMajor, NimMinor) < (1, 4): - o.s.delete(0, i - 1) - else: - o.s.delete(0.. (start + chronos.seconds(5)): @@ -140,4 +137,4 @@ proc unorderedCompare*[T](a, b: seq[T]): bool = if aSorted == bSorted: return true - return false \ No newline at end of file + return false diff --git a/tests/stubs/autonatclientstub.nim b/tests/stubs/autonatclientstub.nim index 935024425..d904da86e 100644 --- a/tests/stubs/autonatclientstub.nim +++ b/tests/stubs/autonatclientstub.nim @@ -9,10 +9,7 @@ {.used.} -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos import ../../libp2p/[protocols/connectivity/autonat/client, diff --git a/tests/stubs/switchstub.nim b/tests/stubs/switchstub.nim index 38c99739f..2accd2cd8 100644 --- a/tests/stubs/switchstub.nim +++ b/tests/stubs/switchstub.nim @@ -9,10 +9,7 @@ {.used.} -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos import ../../libp2p/[peerid, multiaddress, switch] diff --git a/tests/stubs/torstub.nim b/tests/stubs/torstub.nim index 2b96bbfb3..8149b2739 100644 --- a/tests/stubs/torstub.nim +++ b/tests/stubs/torstub.nim @@ -9,10 +9,7 @@ {.used.} -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import tables import chronos, stew/[byteutils, endians2, shims/net] diff --git a/tests/testbufferstream.nim b/tests/testbufferstream.nim index a0f83f32d..905459de8 100644 --- a/tests/testbufferstream.nim +++ b/tests/testbufferstream.nim @@ -237,8 +237,6 @@ suite "BufferStream": await stream.pushData("123".toBytes()) let push = stream.pushData("123".toBytes()) - when (NimMajor, NimMinor) < (1, 4): - type AssertionDefect = AssertionError expect AssertionDefect: await stream.pushData("123".toBytes()) diff --git a/tests/testhpservice.nim b/tests/testhpservice.nim index 8ff6efcf2..2afe73994 100644 --- a/tests/testhpservice.nim +++ b/tests/testhpservice.nim @@ -9,10 +9,7 @@ {.used.} -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import chronos @@ -33,7 +30,7 @@ import stubs/autonatclientstub proc isPublicAddrIPAddrMock(ta: TransportAddress): bool = return true -proc createSwitch(r: Relay = nil, hpService: Service = nil, nameResolver: NameResolver = nil): Switch {.raises: [LPError, Defect].} = +proc createSwitch(r: Relay = nil, hpService: Service = nil, nameResolver: NameResolver = nil): Switch {.raises: [LPError].} = var builder = SwitchBuilder.new() .withRng(newRng()) .withAddresses(@[ MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() ]) diff --git a/tests/testinterop.nim b/tests/testinterop.nim index b53b5afdd..b2b0e2e8d 100644 --- a/tests/testinterop.nim +++ b/tests/testinterop.nim @@ -6,7 +6,7 @@ proc switchMplexCreator( ma: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(), prov: TransportProvider = proc(upgr: Upgrade): Transport = TcpTransport.new({}, upgr), relay: Relay = Relay.new(circuitRelayV1 = true)): - Switch {.raises: [Defect, LPError].} = + Switch {.raises: [LPError].} = SwitchBuilder.new() .withSignedPeerRecord(false) @@ -28,7 +28,7 @@ proc switchYamuxCreator( ma: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(), prov: TransportProvider = proc(upgr: Upgrade): Transport = TcpTransport.new({}, upgr), relay: Relay = Relay.new(circuitRelayV1 = true)): - Switch {.raises: [Defect, LPError].} = + Switch {.raises: [LPError].} = SwitchBuilder.new() .withSignedPeerRecord(false) diff --git a/tests/testmultiaddress.nim b/tests/testmultiaddress.nim index b7bcebc6d..1f98126c9 100644 --- a/tests/testmultiaddress.nim +++ b/tests/testmultiaddress.nim @@ -9,10 +9,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import std/sequtils diff --git a/tests/testmultistream.nim b/tests/testmultistream.nim index f9913e585..c029a237c 100644 --- a/tests/testmultistream.nim +++ b/tests/testmultistream.nim @@ -21,10 +21,7 @@ import ../libp2p/multistream, ../libp2p/upgrademngrs/upgrade -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import ./helpers @@ -79,7 +76,7 @@ proc newTestSelectStream(): TestSelectStream = ## Mock stream for handles `ls` test type - LsHandler = proc(procs: seq[byte]): Future[void] {.gcsafe, raises: [Defect].} + LsHandler = proc(procs: seq[byte]): Future[void] {.gcsafe, raises: [].} TestLsStream = ref object of Connection step*: int @@ -131,7 +128,7 @@ proc newTestLsStream(ls: LsHandler): TestLsStream {.gcsafe.} = ## Mock stream for handles `na` test type - NaHandler = proc(procs: string): Future[void] {.gcsafe, raises: [Defect].} + NaHandler = proc(procs: string): Future[void] {.gcsafe, raises: [].} TestNaStream = ref object of Connection step*: int diff --git a/tests/testnoise.nim b/tests/testnoise.nim index 074d85044..d873ecb07 100644 --- a/tests/testnoise.nim +++ b/tests/testnoise.nim @@ -38,10 +38,7 @@ const type TestProto = ref object of LPProtocol -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} method init(p: TestProto) {.gcsafe.} = proc handle(conn: Connection, proto: string) {.async, gcsafe.} = diff --git a/tests/testtortransport.nim b/tests/testtortransport.nim index 213606479..5c2cfe8bd 100644 --- a/tests/testtortransport.nim +++ b/tests/testtortransport.nim @@ -9,10 +9,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} import tables import chronos, stew/[byteutils] @@ -135,9 +132,6 @@ suite "Tor transport": await serverSwitch.stop() test "It's not possible to add another transport in TorSwitch": - when (NimMajor, NimMinor, NimPatch) < (1, 4, 0): - type AssertionDefect = AssertionError - let torSwitch = TorSwitch.new(torServer = torServer, rng= rng, flags = {ReuseAddr}) expect(AssertionDefect): torSwitch.addTransport(TcpTransport.new(upgrade = Upgrade()))