diff --git a/config.nims b/config.nims index da72649d4..93ecec949 100644 --- a/config.nims +++ b/config.nims @@ -5,6 +5,7 @@ if dirExists("nimbledeps/pkgs"): switch("warning", "CaseTransition:off") switch("warning", "ObservableStores:off") switch("warning", "LockLevel:off") +switch("warningAsError", "UseBase:on") --define:chronosStrictException --styleCheck:usages if (NimMajor, NimMinor) < (1, 6): diff --git a/libp2p/muxers/mplex/coder.nim b/libp2p/muxers/mplex/coder.nim index f2cce3fce..619e7f400 100644 --- a/libp2p/muxers/mplex/coder.nim +++ b/libp2p/muxers/mplex/coder.nim @@ -61,7 +61,7 @@ proc readMsg*(conn: Connection): Future[Msg] {.async, gcsafe.} = proc writeMsg*(conn: Connection, id: uint64, msgType: MessageType, - data: seq[byte] = @[]): Future[void] = + data: sink seq[byte] = @[]): Future[void] = var left = data.len offset = 0 diff --git a/libp2p/muxers/mplex/lpchannel.nim b/libp2p/muxers/mplex/lpchannel.nim index 5f6faa809..c701c2158 100644 --- a/libp2p/muxers/mplex/lpchannel.nim +++ b/libp2p/muxers/mplex/lpchannel.nim @@ -197,7 +197,7 @@ method readOnce*(s: LPChannel, await s.reset() raise newLPStreamConnDownError(exc) -proc prepareWrite(s: LPChannel, msg: seq[byte]): Future[void] {.async.} = +proc prepareWrite(s: LPChannel, msg: sink seq[byte]): Future[void] {.async.} = # prepareWrite is the slow path of writing a message - see conditions in # write if s.remoteReset: @@ -254,7 +254,7 @@ proc completeWrite( finally: s.writes -= 1 -method write*(s: LPChannel, msg: seq[byte]): Future[void] = +method write*(s: LPChannel, msg: sink seq[byte]): Future[void] = ## Write to mplex channel - there may be up to MaxWrite concurrent writes ## pending after which the peer is disconnected diff --git a/libp2p/muxers/yamux/yamux.nim b/libp2p/muxers/yamux/yamux.nim index a5273794d..ca1587cfc 100644 --- a/libp2p/muxers/yamux/yamux.nim +++ b/libp2p/muxers/yamux/yamux.nim @@ -265,7 +265,7 @@ method readOnce*( channel.activity = true return toRead -proc gotDataFromRemote(channel: YamuxChannel, b: seq[byte]) {.async.} = +proc gotDataFromRemote(channel: YamuxChannel, b: sink seq[byte]) {.async.} = channel.recvWindow -= b.len channel.recvQueue = channel.recvQueue.concat(b) channel.receivedData.fire() @@ -333,7 +333,7 @@ proc trySend(channel: YamuxChannel) {.async.} = fut.complete() channel.activity = true -method write*(channel: YamuxChannel, msg: seq[byte]): Future[void] = +method write*(channel: YamuxChannel, msg: sink seq[byte]): Future[void] = result = newFuture[void]("Yamux Send") if channel.remoteReset: result.fail(newLPStreamResetError()) diff --git a/libp2p/protocols/connectivity/relay/rconn.nim b/libp2p/protocols/connectivity/relay/rconn.nim index f355fd8a9..1006edfd6 100644 --- a/libp2p/protocols/connectivity/relay/rconn.nim +++ b/libp2p/protocols/connectivity/relay/rconn.nim @@ -30,7 +30,7 @@ method readOnce*( self.activity = true return await self.conn.readOnce(pbytes, nbytes) -method write*(self: RelayConnection, msg: seq[byte]): Future[void] {.async.} = +method write*(self: RelayConnection, msg: sink seq[byte]): Future[void] {.async.} = self.dataSent.inc(msg.len) if self.limitData != 0 and self.dataSent > self.limitData: await self.close() diff --git a/libp2p/protocols/identify.nim b/libp2p/protocols/identify.nim index ae7d26c48..bf8d60c6b 100644 --- a/libp2p/protocols/identify.nim +++ b/libp2p/protocols/identify.nim @@ -111,7 +111,7 @@ proc encodeMsg(peerInfo: PeerInfo, observedAddr: Opt[MultiAddress], sendSpr: boo result.finish() -proc decodeMsg*(buf: seq[byte]): Option[IdentifyInfo] = +proc decodeMsg*(buf: sink seq[byte]): Option[IdentifyInfo] = var iinfo: IdentifyInfo pubkey: PublicKey diff --git a/libp2p/protocols/pubsub/floodsub.nim b/libp2p/protocols/pubsub/floodsub.nim index 0bbf09399..1049773fb 100644 --- a/libp2p/protocols/pubsub/floodsub.nim +++ b/libp2p/protocols/pubsub/floodsub.nim @@ -176,7 +176,7 @@ method init*(f: FloodSub) = method publish*(f: FloodSub, topic: string, - data: seq[byte]): Future[int] {.async.} = + data: sink seq[byte]): Future[int] {.async.} = # base returns always 0 discard await procCall PubSub(f).publish(topic, data) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index 92d352655..dccc9aa8c 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -477,7 +477,7 @@ method onTopicSubscription*(g: GossipSub, topic: string, subscribed: bool) = method publish*(g: GossipSub, topic: string, - data: seq[byte]): Future[int] {.async.} = + data: sink seq[byte]): Future[int] {.async.} = # base returns always 0 discard await procCall PubSub(g).publish(topic, data) diff --git a/libp2p/protocols/pubsub/pubsub.nim b/libp2p/protocols/pubsub/pubsub.nim index a7d7fc210..f96832226 100644 --- a/libp2p/protocols/pubsub/pubsub.nim +++ b/libp2p/protocols/pubsub/pubsub.nim @@ -84,6 +84,7 @@ declarePublicCounter(libp2p_pubsub_received_prune, "pubsub broadcast prune", lab type InitializationError* = object of LPError + #TODO sink? TopicHandler* {.public.} = proc(topic: string, data: seq[byte]): Future[void] {.gcsafe, raises: [Defect].} @@ -311,7 +312,7 @@ proc getOrCreatePeer*( return pubSubPeer -proc handleData*(p: PubSub, topic: string, data: seq[byte]): Future[void] = +proc handleData*(p: PubSub, topic: string, data: sink seq[byte]): Future[void] = # Start work on all data handlers without copying data into closure like # happens on {.async.} transformation p.topics.withValue(topic, handlers) do: @@ -474,7 +475,7 @@ proc subscribe*(p: PubSub, method publish*(p: PubSub, topic: string, - data: seq[byte]): Future[int] {.base, async, public.} = + data: sink seq[byte]): Future[int] {.base, async, public.} = ## publish to a ``topic`` ## ## The return value is the number of neighbours that we attempted to send the diff --git a/libp2p/protocols/pubsub/pubsubpeer.nim b/libp2p/protocols/pubsub/pubsubpeer.nim index 5a1afedbd..fe85e2477 100644 --- a/libp2p/protocols/pubsub/pubsubpeer.nim +++ b/libp2p/protocols/pubsub/pubsubpeer.nim @@ -210,7 +210,7 @@ proc connectImpl(p: PubSubPeer) {.async.} = proc connect*(p: PubSubPeer) = asyncSpawn connectImpl(p) -proc sendImpl(conn: Connection, encoded: seq[byte]): Future[void] {.raises: [Defect].} = +proc sendImpl(conn: Connection, encoded: sink seq[byte]): Future[void] {.raises: [Defect].} = trace "sending encoded msgs to peer", conn, encoded = shortLog(encoded) let fut = conn.writeLp(encoded) # Avoid copying `encoded` into future @@ -237,7 +237,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].} = +proc sendEncoded*(p: PubSubPeer, msg: sink seq[byte]) {.raises: [Defect].} = doAssert(not isNil(p), "pubsubpeer nil!") if msg.len <= 0: diff --git a/libp2p/protocols/pubsub/rpc/protobuf.nim b/libp2p/protocols/pubsub/rpc/protobuf.nim index 1b4cd2268..48ffbc6d9 100644 --- a/libp2p/protocols/pubsub/rpc/protobuf.nim +++ b/libp2p/protocols/pubsub/rpc/protobuf.nim @@ -322,7 +322,7 @@ proc encodeRpcMsg*(msg: RPCMsg, anonymize: bool): seq[byte] = pb.finish() pb.buffer -proc decodeRpcMsg*(msg: seq[byte]): ProtoResult[RPCMsg] {.inline.} = +proc decodeRpcMsg*(msg: sink seq[byte]): ProtoResult[RPCMsg] {.inline.} = trace "decodeRpcMsg: decoding message", msg = msg.shortLog() var pb = initProtoBuffer(msg) var rpcMsg = ok(RPCMsg()) diff --git a/libp2p/protocols/secure/noise.nim b/libp2p/protocols/secure/noise.nim index 66a8dcd22..5a119cff7 100644 --- a/libp2p/protocols/secure/noise.nim +++ b/libp2p/protocols/secure/noise.nim @@ -333,7 +333,7 @@ proc sendHSMessage(sconn: Connection, buf: openArray[byte]): Future[void] = proc handshakeXXOutbound( p: Noise, conn: Connection, - p2pSecret: seq[byte]): Future[HandshakeResult] {.async.} = + p2pSecret: sink seq[byte]): Future[HandshakeResult] {.async.} = const initiator = true var hs = HandshakeState.init() @@ -381,7 +381,7 @@ proc handshakeXXOutbound( proc handshakeXXInbound( p: Noise, conn: Connection, - p2pSecret: seq[byte]): Future[HandshakeResult] {.async.} = + p2pSecret: sink seq[byte]): Future[HandshakeResult] {.async.} = const initiator = false var @@ -461,7 +461,7 @@ proc encryptFrame( cipherFrame[2 + src.len()..