Skip to content

Commit cfde7ee

Browse files
chore: Circuit relay (#3112)
* undo apt install libpcre (not circuit-relay related.) * nat.nim: protect against possible exceptions when calling getExternalIP * new external CLI argument, isRelayClient * waku factory change to mount circuit hop proto by default * waku_node: move autonat_service to a separate module
1 parent 268e7e6 commit cfde7ee

File tree

22 files changed

+304
-117
lines changed

22 files changed

+304
-117
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ jobs:
111111
run: |
112112
postgres_enabled=0
113113
if [ ${{ runner.os }} == "Linux" ]; then
114-
sudo apt-get update
115-
sudo apt-get install -y libpcre3 libpcre3-dev
116-
117114
sudo docker run --rm -d -e POSTGRES_PASSWORD=test123 -p 5432:5432 postgres:15.4-alpine3.18
118115
postgres_enabled=1
119116
fi

apps/liteprotocoltester/liteprotocoltester.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ when isMainModule:
132132
error "Starting esential REST server failed.", error = $error
133133
quit(QuitFailure)
134134

135-
var wakuApp = Waku.init(wakuConf).valueOr:
135+
var wakuApp = Waku.new(wakuConf).valueOr:
136136
error "Waku initialization failed", error = error
137137
quit(QuitFailure)
138138

apps/wakunode2/wakunode2.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ when isMainModule:
4242
error "failure while loading the configuration", error = error
4343
quit(QuitFailure)
4444

45-
## Also called within Waku.init. The call to startRestServerEsentials needs the following line
45+
## Also called within Waku.new. The call to startRestServerEsentials needs the following line
4646
logging.setupLog(conf.logLevel, conf.logFormat)
4747

4848
case conf.cmd
@@ -66,7 +66,7 @@ when isMainModule:
6666
error "Starting esential REST server failed.", error = $error
6767
quit(QuitFailure)
6868

69-
var waku = Waku.init(confCopy).valueOr:
69+
var waku = Waku.new(confCopy).valueOr:
7070
error "Waku initialization failed", error = error
7171
quit(QuitFailure)
7272

examples/wakustealthcommitments/node_spec.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ proc setup*(): Waku =
4848
conf.rlnRelay = twnClusterConf.rlnRelay
4949

5050
debug "Starting node"
51-
var waku = Waku.init(conf).valueOr:
51+
var waku = Waku.new(conf).valueOr:
5252
error "Waku initialization failed", error = error
5353
quit(QuitFailure)
5454

library/waku_thread/inter_thread_communication/requests/node_lifecycle_request.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ proc createWaku(configJson: cstring): Future[Result[Waku, string]] {.async.} =
5959
formattedString & ". expected type: " & $typeof(confValue)
6060
)
6161

62-
let wakuRes = Waku.init(conf).valueOr:
62+
let wakuRes = Waku.new(conf).valueOr:
6363
error "waku initialization failed", error = error
6464
return err("Failed setting up Waku: " & $error)
6565

tests/factory/test_node_factory.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{.used.}
22

3-
import testutils/unittests, chronos
3+
import testutils/unittests, chronos, libp2p/protocols/connectivity/relay/relay
44

55
import ../testlib/wakunode, waku/factory/node_factory, waku/waku_node
66

77
suite "Node Factory":
88
test "Set up a node based on default configurations":
99
let conf = defaultTestWakuNodeConf()
1010

11-
let node = setupNode(conf).valueOr:
11+
let node = setupNode(conf, relay = Relay.new()).valueOr:
1212
raiseAssert error
1313

1414
check:
@@ -23,7 +23,7 @@ suite "Node Factory":
2323
var conf = defaultTestWakuNodeConf()
2424
conf.store = true
2525

26-
let node = setupNode(conf).valueOr:
26+
let node = setupNode(conf, relay = Relay.new()).valueOr:
2727
raiseAssert error
2828

2929
check:
@@ -35,7 +35,7 @@ test "Set up a node with Filter enabled":
3535
var conf = defaultTestWakuNodeConf()
3636
conf.filter = true
3737

38-
let node = setupNode(conf).valueOr:
38+
let node = setupNode(conf, relay = Relay.new()).valueOr:
3939
raiseAssert error
4040

4141
check:
@@ -45,7 +45,7 @@ test "Set up a node with Filter enabled":
4545
test "Start a node based on default configurations":
4646
let conf = defaultTestWakuNodeConf()
4747

48-
let node = setupNode(conf).valueOr:
48+
let node = setupNode(conf, relay = Relay.new()).valueOr:
4949
raiseAssert error
5050

5151
assert not node.isNil(), "Node can't be nil"

tests/test_peer_manager.nim

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{.used.}
22

33
import
4-
std/[options, sequtils, times, sugar],
4+
std/[options, sequtils, times, sugar, net],
55
stew/shims/net as stewNet,
66
testutils/unittests,
77
chronos,
@@ -269,14 +269,9 @@ procSuite "Peer Manager":
269269
database = SqliteDatabase.new(":memory:")[]
270270
storage = WakuPeerStorage.new(database)[]
271271
node1 = newTestWakuNode(
272-
generateSecp256k1Key(),
273-
ValidIpAddress.init("127.0.0.1"),
274-
Port(44048),
275-
peerStorage = storage,
276-
)
277-
node2 = newTestWakuNode(
278-
generateSecp256k1Key(), ValidIpAddress.init("127.0.0.1"), Port(34023)
272+
generateSecp256k1Key(), getPrimaryIPAddr(), Port(44048), peerStorage = storage
279273
)
274+
node2 = newTestWakuNode(generateSecp256k1Key(), getPrimaryIPAddr(), Port(34023))
280275

281276
node1.mountMetadata(0).expect("Mounted Waku Metadata")
282277
node2.mountMetadata(0).expect("Mounted Waku Metadata")
@@ -344,14 +339,9 @@ procSuite "Peer Manager":
344339
database = SqliteDatabase.new(":memory:")[]
345340
storage = WakuPeerStorage.new(database)[]
346341
node1 = newTestWakuNode(
347-
generateSecp256k1Key(),
348-
ValidIpAddress.init("127.0.0.1"),
349-
Port(44048),
350-
peerStorage = storage,
351-
)
352-
node2 = newTestWakuNode(
353-
generateSecp256k1Key(), ValidIpAddress.init("127.0.0.1"), Port(34023)
342+
generateSecp256k1Key(), getPrimaryIPAddr(), Port(44048), peerStorage = storage
354343
)
344+
node2 = newTestWakuNode(generateSecp256k1Key(), getPrimaryIPAddr(), Port(34023))
355345

356346
node1.mountMetadata(0).expect("Mounted Waku Metadata")
357347
node2.mountMetadata(0).expect("Mounted Waku Metadata")

tests/test_waku_switch.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ suite "Waku Switch":
2626
## Given
2727
let
2828
sourceSwitch = newTestSwitch()
29-
wakuSwitch = newWakuSwitch(rng = rng())
29+
wakuSwitch = newWakuSwitch(rng = rng(), circuitRelay = Relay.new())
3030
await sourceSwitch.start()
3131
await wakuSwitch.start()
3232

@@ -46,7 +46,7 @@ suite "Waku Switch":
4646
asyncTest "Waku Switch acts as circuit relayer":
4747
## Setup
4848
let
49-
wakuSwitch = newWakuSwitch(rng = rng())
49+
wakuSwitch = newWakuSwitch(rng = rng(), circuitRelay = Relay.new())
5050
sourceClient = RelayClient.new()
5151
destClient = RelayClient.new()
5252
sourceSwitch = newCircuitRelayClientSwitch(sourceClient)

tests/test_wakunode.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{.used.}
22

33
import
4-
std/[sequtils, strutils],
4+
std/[sequtils, strutils, net],
55
stew/byteutils,
66
stew/shims/net as stewNet,
77
testutils/unittests,
@@ -169,7 +169,7 @@ suite "WakuNode":
169169
nodeKey = generateSecp256k1Key()
170170
bindIp = parseIpAddress("0.0.0.0")
171171
bindPort = Port(61006)
172-
extIp = some(parseIpAddress("127.0.0.1"))
172+
extIp = some(getPrimaryIPAddr())
173173
extPort = some(Port(61008))
174174
node = newTestWakuNode(nodeKey, bindIp, bindPort, extIp, extPort)
175175

@@ -205,7 +205,7 @@ suite "WakuNode":
205205
nodeKey = generateSecp256k1Key()
206206
bindIp = parseIpAddress("0.0.0.0")
207207
bindPort = Port(61010)
208-
extIp = some(parseIpAddress("127.0.0.1"))
208+
extIp = some(getPrimaryIPAddr())
209209
extPort = some(Port(61012))
210210
domainName = "example.com"
211211
expectedDns4Addr =

tests/wakunode2/test_app.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ suite "Wakunode2 - Waku":
1919
## Given
2020
var conf = defaultTestWakuNodeConf()
2121

22-
let waku = Waku.init(conf).valueOr:
22+
let waku = Waku.new(conf).valueOr:
2323
raiseAssert error
2424

2525
## When
@@ -35,7 +35,7 @@ suite "Wakunode2 - Waku initialization":
3535
var conf = defaultTestWakuNodeConf()
3636
conf.peerPersistence = true
3737

38-
let waku = Waku.init(conf).valueOr:
38+
let waku = Waku.new(conf).valueOr:
3939
raiseAssert error
4040

4141
check:
@@ -46,7 +46,7 @@ suite "Wakunode2 - Waku initialization":
4646
var conf = defaultTestWakuNodeConf()
4747

4848
## When
49-
var waku = Waku.init(conf).valueOr:
49+
var waku = Waku.new(conf).valueOr:
5050
raiseAssert error
5151

5252
(waitFor startWaku(addr waku)).isOkOr:
@@ -73,7 +73,7 @@ suite "Wakunode2 - Waku initialization":
7373
conf.tcpPort = Port(0)
7474

7575
## When
76-
var waku = Waku.init(conf).valueOr:
76+
var waku = Waku.new(conf).valueOr:
7777
raiseAssert error
7878

7979
(waitFor startWaku(addr waku)).isOkOr:

0 commit comments

Comments
 (0)