Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ NIM_PARAMS := $(NIM_PARAMS) -d:disable_libbacktrace
# enable experimental exit is dest feature in libp2p mix
NIM_PARAMS := $(NIM_PARAMS) -d:libp2p_mix_experimental_exit_is_dest

# enable libp2p's QUIC transport
NIM_PARAMS := $(NIM_PARAMS) -d:libp2p_quic_support

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this line in particular should go for QUIC adoption. Not a big deal, though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right; I don't think "libp2p without quic" is a thing that makes much sense, we want it enabled always so I rolled this into the bump.


ifeq ($(POSTGRES), 1)
NIM_PARAMS := $(NIM_PARAMS) -d:postgres -d:nimDebugDlOpen
endif
Expand Down
6 changes: 3 additions & 3 deletions apps/chat2/chat2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,15 @@ proc readInput(wfd: AsyncFD) {.thread, raises: [Defect, CatchableError].} =

{.pop.}
# @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError
proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} =
let
transp = fromPipe(rfd)
conf = Chat2Conf.load()
nodekey =
if conf.nodekey.isSome():
conf.nodekey.get()
else:
PrivateKey.random(Secp256k1, rng[]).tryGet()
PrivateKey.random(Secp256k1, rng).tryGet()

# set log level
if conf.logLevel != LogLevel.NONE:
Expand Down Expand Up @@ -568,7 +568,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =

runForever()

proc main(rng: ref HmacDrbgContext) {.async.} =
proc main(rng: crypto.Rng) {.async.} =
let (rfd, wfd) = createAsyncPipe()
if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe:
raise newException(ValueError, "Could not initialize pipe!")
Expand Down
2 changes: 1 addition & 1 deletion apps/chat2bridge/chat2bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ when isMainModule:
if conf.nodekey.isSome():
conf.nodekey.get()
else:
crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
crypto.PrivateKey.random(Secp256k1, rng).tryGet()

let bridge = Chat2Matterbridge.new(
mbHostUri = "http://" & $initTAddress(conf.mbHostAddress, Port(conf.mbHostPort)),
Expand Down
6 changes: 3 additions & 3 deletions apps/chat2mix/chat2mix.nim
Original file line number Diff line number Diff line change
Expand Up @@ -388,15 +388,15 @@ proc maintainSubscription(

{.pop.}
# @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError
proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} =
let
transp = fromPipe(rfd)
conf = Chat2Conf.load()
nodekey =
if conf.nodekey.isSome():
conf.nodekey.get()
else:
PrivateKey.random(Secp256k1, rng[]).tryGet()
PrivateKey.random(Secp256k1, rng).tryGet()

# set log level
if conf.logLevel != LogLevel.NONE:
Expand Down Expand Up @@ -660,7 +660,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =

runForever()

proc main(rng: ref HmacDrbgContext) {.async.} =
proc main(rng: crypto.Rng) {.async.} =
let (rfd, wfd) = createAsyncPipe()
if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe:
raise newException(ValueError, "Could not initialize pipe!")
Expand Down
2 changes: 1 addition & 1 deletion apps/networkmonitor/networkmonitor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ proc initAndStartApp(
let
# some hardcoded parameters
rng = keys.newRng()
key = crypto.PrivateKey.random(Secp256k1, rng[])[]
key = crypto.PrivateKey.random(Secp256k1, rng)[]
nodeTcpPort = Port(60000)
nodeUdpPort = Port(9000)
flags = CapabilitiesBitfield.init(
Expand Down
4 changes: 2 additions & 2 deletions apps/wakucanary/wakucanary.nim
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ proc pingNode(
error "Failed to ping the peer", peer = peerInfo, err = msg
return false

proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
proc main(rng: Rng): Future[int] {.async.} =
let conf: WakuCanaryConf = WakuCanaryConf.load()

# create dns resolver
Expand Down Expand Up @@ -192,7 +192,7 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
quit(QuitFailure)

let
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
nodeKey = crypto.PrivateKey.random(Secp256k1, rng)[]
bindIp = parseIpAddress("0.0.0.0")
wsBindPort = Port(conf.nodePort + WebSocketPortOffset)
nodeTcpPort = Port(conf.nodePort)
Expand Down
4 changes: 2 additions & 2 deletions examples/lightpush_mix/lightpush_publisher_mix.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import
confutils,
libp2p/crypto/crypto,
libp2p/crypto/curve25519,
libp2p/protocols/mix,
libp2p/protocols/mix/curve25519,
libp2p_mix,
libp2p_mix/curve25519,
libp2p/multiaddress,
eth/keys,
eth/p2p/discoveryv5/enr,
Expand Down
1 change: 1 addition & 0 deletions library/kernel_api/discovery_api.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import std/json
import chronos, chronicles, results, strutils, libp2p/multiaddress, ffi
import
Expand Down
1 change: 1 addition & 0 deletions library/kernel_api/node_lifecycle_api.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import std/[options, json, strutils, net]
import chronos, chronicles, results, confutils, confutils/std/net, ffi

Expand Down
1 change: 1 addition & 0 deletions library/kernel_api/peer_manager_api.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import std/[sequtils, strutils, tables]
import chronicles, chronos, results, options, json, ffi
import
Expand Down
1 change: 1 addition & 0 deletions library/kernel_api/protocols/filter_api.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import options, std/[strutils, sequtils]
import chronicles, chronos, results, ffi
import
Expand Down
1 change: 1 addition & 0 deletions library/kernel_api/protocols/lightpush_api.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import options, std/[json, strformat]
import chronicles, chronos, results, ffi
import
Expand Down
1 change: 1 addition & 0 deletions library/kernel_api/protocols/relay_api.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import std/[net, sequtils, strutils, json], strformat
import chronicles, chronos, stew/byteutils, results, ffi
import
Expand Down
1 change: 1 addition & 0 deletions library/kernel_api/protocols/store_api.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import std/[json, sugar, strutils, options]
import chronos, chronicles, results, stew/byteutils, ffi
import
Expand Down
1 change: 1 addition & 0 deletions library/liblogosdelivery.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import std/[atomics, options, macros]
import chronicles, chronos, chronos/threadsync, ffi
import
Expand Down
7 changes: 4 additions & 3 deletions logos_delivery.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ requires "nim >= 2.2.4",
"toml_serialization",
"faststreams",
# Networking & P2P
"https://github.com/vacp2p/nim-libp2p.git#ff8d51857b4b79a68468e7bcc27b2026cca02996",
"https://github.com/vacp2p/nim-libp2p.git#v2.0.0",
"eth",
"nat_traversal",
"dnsdisc",
Expand All @@ -40,7 +40,7 @@ requires "nim >= 2.2.4",
"secp256k1",
"bearssl",
# RPC & APIs
"https://github.com/status-im/nim-json-rpc.git#43bbf499143eb45046c83ac9794c9e3280a2b8e7",
"https://github.com/status-im/nim-json-rpc.git#v0.6.1",
"presto",
"web3",
# Database
Expand All @@ -67,8 +67,9 @@ requires "https://github.com/logos-messaging/nim-sds.git#abdd40cc645f1b024c3ee99

requires "https://github.com/NagyZoltanPeter/nim-brokers.git#v3.1.1"

requires "https://github.com/vacp2p/nim-lsquic"
requires "https://github.com/vacp2p/nim-lsquic.git#v0.5.1"
requires "https://github.com/vacp2p/nim-jwt.git#057ec95eb5af0eea9c49bfe9025b3312c95dc5f2"
requires "https://github.com/logos-co/nim-libp2p-mix#380513117d556bf8f70066f5e72a7fd74fe36ba6"

proc getMyCPU(): string =
## Need to set cpu more explicit manner to avoid arch issues between dependencies
Expand Down
3 changes: 2 additions & 1 deletion logos_delivery/channels/reliable_channel.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
## Reliable Channel type.
##
## A `ReliableChannel` orchestrates segmentation, SDS (end-to-end
Expand Down Expand Up @@ -93,7 +94,7 @@ type
channelId: ChannelId
contentTopic: ContentTopic
senderId: SdsParticipantID
rng: ref HmacDrbgContext
rng: libp2p_crypto.Rng
segmentation: SegmentationHandler
sdsHandler: SdsHandler
rateLimit: RateLimitManager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
## This module is in charge of taking care of the messages that this node is expecting to
## receive and is backed by store-v3 requests to get an additional degree of certainty
##
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import std/[options, times], chronos
import brokers/broker_context
import
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import chronicles, chronos, results
import std/options
import brokers/broker_context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import std/options
import chronos, chronicles
import brokers/broker_context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
## This module reinforces the publish operation with regular store-v3 requests.
##

Expand Down
1 change: 1 addition & 0 deletions logos_delivery/waku/api/api.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import std/[net, options]

import chronicles, chronos, libp2p/peerid, results
Expand Down
1 change: 1 addition & 0 deletions logos_delivery/waku/api/api_conf.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import std/[net, options]

import results
Expand Down
4 changes: 3 additions & 1 deletion logos_delivery/waku/api/types.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logos_delivery/waku/compat/option_valueor
import libp2p/crypto/crypto
{.push raises: [].}

import bearssl/rand, std/times, chronos
Expand All @@ -23,7 +25,7 @@ type
PartiallyConnected
Connected

proc new*(T: typedesc[RequestId], rng: ref HmacDrbgContext): T =
proc new*(T: typedesc[RequestId], rng: crypto.Rng): T =
## Generate a new RequestId using the provided RNG.
RequestId(request_utils.generateRequestId(rng))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import
std/[times, strutils, os, sets, strformat, tables],
results,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
# Simple async pool driver for postgress.
# Inspired by: https://github.com/treeform/pg/
{.push raises: [].}
Expand Down
1 change: 1 addition & 0 deletions logos_delivery/waku/common/databases/db_sqlite.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
{.push raises: [].}
# The code in this file is an adaptation of the Sqlite KV Store found in nim-eth.
# https://github.com/status-im/nim-eth/blob/master/eth/db/kvstore_sqlite3.nim
Expand Down
1 change: 1 addition & 0 deletions logos_delivery/waku/common/enr/typed_record.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
{.push raises: [].}

import std/options, results, eth/keys as eth_keys, libp2p/crypto/crypto as libp2p_crypto
Expand Down
1 change: 1 addition & 0 deletions logos_delivery/waku/common/rate_limit/request_limiter.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
## RequestRateLimiter
##
## RequestRateLimiter is a general service protection mechanism.
Expand Down
1 change: 1 addition & 0 deletions logos_delivery/waku/common/utils/parse_size_units.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
import std/[strutils, math], results, regex

proc parseMsgSize*(input: string): Result[uint64, string] =
Expand Down
32 changes: 32 additions & 0 deletions logos_delivery/waku/compat/option_valueor.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Polyfill: `valueOr` / `withValue` templates for `std/options.Option[T]`.
##
## Previously provided transitively by `libp2p/utility`, removed in
## nim-libp2p PR #2162 (commit 8a9943145). logos-delivery uses these

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can avoid having that file by only using Opt instead of Option, similar to how has been done in vacp2p/nim-libp2p#2162.

Opt is defined in nim-results ( we usually get it with import result .)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think swapping Option for Opt everywhere is going to be its own Issue/PR yep

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good idea thanks. #3955

## templates pervasively on `Option[T]`.

{.push raises: [].}

import std/[macros, options]

template valueOr*[T](self: Option[T], body: untyped): untyped =
let temp = (self)
if temp.isSome:
temp.get()
else:
body

template withValue*[T](self: Option[T], value, body: untyped): untyped =
let temp = (self)
if temp.isSome:
let `value` {.inject.} = temp.get()
body

macro withValue*[T](self: Option[T], value, body, elseStmt: untyped): untyped =
let elseBody = elseStmt[0]
quote:
let temp = (`self`)
if temp.isSome:
let `value` {.inject.} = temp.get()
`body`
else:
`elseBody`
3 changes: 2 additions & 1 deletion logos_delivery/waku/discovery/autonat_service.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import libp2p/crypto/crypto
import
chronos,
chronicles,
Expand All @@ -7,7 +8,7 @@ import

const AutonatCheckInterval = Opt.some(chronos.seconds(30))

proc getAutonatService*(rng: ref HmacDrbgContext): AutonatService =
proc getAutonatService*(rng: crypto.Rng): AutonatService =
## AutonatService request other peers to dial us back
## flagging us as Reachable or NotReachable.
## minConfidence is used as threshold to determine the state.
Expand Down
11 changes: 7 additions & 4 deletions logos_delivery/waku/discovery/waku_discv5.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import libp2p/crypto/crypto
import libp2p/crypto/rng
import logos_delivery/waku/compat/option_valueor
{.push raises: [].}

import
Expand Down Expand Up @@ -82,15 +85,15 @@ proc shardingPredicate*(

proc new*(
T: type WakuDiscoveryV5,
rng: ref HmacDrbgContext,
rng: crypto.Rng,
conf: WakuDiscoveryV5Config,
record: Option[waku_enr.Record],
peerManager: Option[PeerManager] = none(PeerManager),
queue: AsyncEventQueue[SubscriptionEvent] =
newAsyncEventQueue[SubscriptionEvent](30),
): T =
let protocol = newProtocol(
rng = rng,
rng = rng.bearSslDrbgRef,
config = conf.discv5Config.get(protocol.defaultDiscoveryConfig),
bindPort = conf.port,
bindIp = conf.address,
Expand Down Expand Up @@ -407,7 +410,7 @@ proc setupDiscoveryV5*(
nodeTopicSubscriptionQueue: AsyncEventQueue[SubscriptionEvent],
conf: Discv5Conf,
dynamicBootstrapNodes: seq[RemotePeerInfo],
rng: ref HmacDrbgContext,
rng: crypto.Rng,
key: crypto.PrivateKey,
p2pListenAddress: IpAddress,
portsShift: uint16,
Expand Down Expand Up @@ -463,7 +466,7 @@ proc setupAndStartDiscv5*(
nodeTopicSubscriptionQueue: AsyncEventQueue[SubscriptionEvent],
conf: Discv5Conf,
dynamicBootstrapNodes: seq[RemotePeerInfo],
rng: ref HmacDrbgContext,
rng: crypto.Rng,
key: crypto.PrivateKey,
p2pListenAddress: IpAddress,
portsShift: uint16,
Expand Down
1 change: 1 addition & 0 deletions logos_delivery/waku/discovery/waku_dnsdisc.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logos_delivery/waku/compat/option_valueor
{.push raises: [].}

## A set of utilities to integrate EIP-1459 DNS-based discovery
Expand Down
Loading
Loading