9
9
stew/ byteutils,
10
10
eth/ keys,
11
11
nimcrypto,
12
+ nimcrypto/ utils as ncrutils,
12
13
bearssl/ rand,
13
14
eth/ p2p/ discoveryv5/ enr,
14
15
libp2p/ crypto/ crypto,
16
+ libp2p/ crypto/ curve25519,
15
17
libp2p/ protocols/ ping,
16
18
libp2p/ protocols/ pubsub/ gossipsub,
17
19
libp2p/ protocols/ pubsub/ rpc/ messages,
@@ -20,7 +22,13 @@ import
20
22
libp2p/ builders,
21
23
libp2p/ transports/ transport,
22
24
libp2p/ transports/ tcptransport,
23
- libp2p/ transports/ wstransport
25
+ libp2p/ transports/ wstransport,
26
+ ../../ vendor/ mix/ src/ mix_node,
27
+ ../../ vendor/ mix/ src/ mix_protocol,
28
+ ../../ vendor/ mix/ src/ curve25519,
29
+ ../../ vendor/ mix/ src/ protocol
30
+
31
+
24
32
import
25
33
../ waku_core,
26
34
../ waku_core/ topics/ sharding,
119
127
topicSubscriptionQueue* : AsyncEventQueue [SubscriptionEvent ]
120
128
contentTopicHandlers: Table [ContentTopic , TopicHandler ]
121
129
rateLimitSettings* : ProtocolRateLimitSettings
130
+ mix* : MixProtocol
131
+ mixbootNodes* : Table [PeerId , MixPubInfo ]
122
132
123
133
proc new * (
124
134
T: type WakuNode ,
@@ -204,6 +214,65 @@ proc mountSharding*(
204
214
node.wakuSharding = Sharding (clusterId: clusterId, shardCountGenZero: shardCount)
205
215
return ok ()
206
216
217
+ proc getBootStrapMixNodes (node: WakuNode , exceptPeerID: PeerId ): Table [PeerId , MixPubInfo ] =
218
+ var mixNodes = initTable [PeerId , MixPubInfo ]()
219
+ # MixNode Multiaddrs and PublicKeys:
220
+ let bootNodesMultiaddrs = [" /ip4/127.0.0.1/tcp/60001/p2p/16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o" ,
221
+ " /ip4/127.0.0.1/tcp/60002/p2p/16Uiu2HAmLtKaFaSWDohToWhWUZFLtqzYZGPFuXwKrojFVF6az5UF" ,
222
+ " /ip4/127.0.0.1/tcp/60003/p2p/16Uiu2HAmTEDHwAziWUSz6ZE23h5vxG2o4Nn7GazhMor4bVuMXTrA" ,
223
+ " /ip4/127.0.0.1/tcp/60004/p2p/16Uiu2HAmPwRKZajXtfb1Qsv45VVfRZgK3ENdfmnqzSrVm3BczF6f" ,
224
+ " /ip4/127.0.0.1/tcp/60005/p2p/16Uiu2HAmRhxmCHBYdXt1RibXrjAUNJbduAhzaTHwFCZT4qWnqZAu" ,
225
+ ]
226
+ let bootNodesMixPubKeys = [" 9d09ce624f76e8f606265edb9cca2b7de9b41772a6d784bddaf92ffa8fba7d2c" ,
227
+ " 9231e86da6432502900a84f867004ce78632ab52cd8e30b1ec322cd795710c2a" ,
228
+ " 275cd6889e1f29ca48e5b9edb800d1a94f49f13d393a0ecf1a07af753506de6c" ,
229
+ " e0ed594a8d506681be075e8e23723478388fb182477f7a469309a25e7076fc18" ,
230
+ " 8fd7a1a7c19b403d231452a9b1ea40eb1cc76f455d918ef8980e7685f9eeeb1f"
231
+ ]
232
+ for index, mixNodeMultiaddr in bootNodesMultiaddrs:
233
+ let peerIdRes = getPeerIdFromMultiAddr (mixNodeMultiaddr)
234
+ if peerIdRes.isErr:
235
+ error " Failed to get peer id from multiaddress: " , error = peerIdRes.error
236
+ let peerId = peerIdRes.get ()
237
+ if peerID == exceptPeerID:
238
+ continue
239
+ let mixNodePubInfo = createMixPubInfo (mixNodeMultiaddr, intoCurve25519Key (ncrutils.fromHex (bootNodesMixPubKeys[index])))
240
+
241
+ mixNodes[peerId] = mixNodePubInfo
242
+ info " using mix bootstrap nodes " , bootNodes = mixNodes
243
+ return mixNodes
244
+
245
+
246
+ # Mix Protocol
247
+ proc mountMix * (node: WakuNode , mixPrivKey: string ): Future [Result [void , string ]] {.async .} =
248
+ info " mounting mix protocol" , nodeId = node.info # TODO log the config used
249
+ info " mixPrivKey" , mixPrivKey = mixPrivKey
250
+
251
+ let mixKey = intoCurve25519Key (ncrutils.fromHex (mixPrivKey))
252
+ let mixPubKey = public (mixKey)
253
+
254
+ let localaddrStr = node.announcedAddresses[0 ].toString ().valueOr:
255
+ return err (" Failed to convert multiaddress to string." )
256
+ info " local addr" , localaddr = localaddrStr
257
+
258
+ let localMixNodeInfo = initMixNodeInfo (
259
+ localaddrStr & " /p2p/" & $ node.peerId, mixPubKey, mixKey, node.switch.peerInfo.publicKey.skkey,
260
+ node.switch.peerInfo.privateKey.skkey,
261
+ )
262
+
263
+ let protoRes = MixProtocol .initMix (localMixNodeInfo, node.switch, node.getBootStrapMixNodes (node.peerId))
264
+ if protoRes.isErr:
265
+ error " Mix protocol initialization failed" , err = protoRes.error
266
+ return
267
+ node.mix = protoRes.value
268
+
269
+ let catchRes = catch:
270
+ node.switch.mount (node.mix)
271
+ if catchRes.isErr ():
272
+ return err (catchRes.error.msg)
273
+
274
+ return ok ()
275
+
207
276
# # Waku Sync
208
277
209
278
proc mountStoreSync * (
0 commit comments