Skip to content

Commit

Permalink
specify mix key to be used and mount mix
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyaprem committed Feb 7, 2025
1 parent be09e73 commit f5cecd0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
10 changes: 10 additions & 0 deletions waku/factory/external_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,16 @@ with the drawback of consuming some more bandwidth.""",
name: "rendezvous"
.}: bool

#Mix config
mixkey* {.desc: "ED25519 private key as 64 char hex string.", name: "mixkey".}:
Option[string]
#TODO: Temp config for simulations.Ideally need to get this info from bootstrap ENRs
#[ mixBootstrapNodes* {.
desc:
"Text-encoded data for mix bootstrap node. Encoded in the format Multiaddress:libp2pPubKey:MixPubKey. Argument may be repeated.",
name: "mix-bootstrap-node"
.}: seq[string] ]#

## websocket config
websocketSupport* {.
desc: "Enable websocket: true|false",
Expand Down
11 changes: 11 additions & 0 deletions waku/factory/node_factory.nim
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,17 @@ proc setupProtocols(
return
err("failed to set node waku peer-exchange peer: " & peerExchangeNode.error)

#mount mix
let mixPrivKey:string =
if conf.mixkey.isSome():
conf.mixkey.get()
else:
error "missing mix key"
return err("missing mix key")
(
await node.mountMix(mixPrivKey)
).isOkOr:
return err("failed to mount waku mix protocol: " & $error)
return ok()

## Start node
Expand Down
18 changes: 8 additions & 10 deletions waku/node/waku_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import
bearssl/rand,
eth/p2p/discoveryv5/enr,
libp2p/crypto/crypto,
libp2p/crypto/curve25519,
libp2p/protocols/ping,
libp2p/protocols/pubsub/gossipsub,
libp2p/protocols/pubsub/rpc/messages,
Expand Down Expand Up @@ -126,6 +127,7 @@ type
contentTopicHandlers: Table[ContentTopic, TopicHandler]
rateLimitSettings*: ProtocolRateLimitSettings
mix*: MixProtocol
mixbootNodes*: Table[PeerId, MixPubInfo]

proc new*(
T: type WakuNode,
Expand Down Expand Up @@ -212,24 +214,20 @@ proc mountSharding*(
return ok()

# Mix Protocol
proc mountMix*(node: WakuNode): Result[void, string] =
proc mountMix*(node: WakuNode, mixPrivKey: string): Future[Result[void, string]] {.async.} =
info "mounting mix protocol" #TODO log the config used

var mixNodes = initTable[PeerId, MixPubInfo]()
# TODO: pass bootstrap node info here as mixNodes

let keyPairResult = generateKeyPair()
if keyPairResult.isErr:
return err("Generate key pair error: " & $keyPairResult.error)
let (mixPrivKey, mixPubKey) = keyPairResult.get()
let mixKey = nimcrypto.fromHex(mixPrivKey).intoCurve25519Key()
let mixPubKey = public(mixKey)

let localaddrStr = node.announcedAddresses[0].toString().valueOr:
return err("Failed to convert multiaddress to string.")

let localMixNodeInfo = initMixNodeInfo(
localaddrStr, mixPubKey, mixPrivKey, node.switch.peerInfo.publicKey.skkey,
localaddrStr, mixPubKey, mixKey, node.switch.peerInfo.publicKey.skkey,
node.switch.peerInfo.privateKey.skkey,
)
let mixNodes = initTable[PeerId, MixPubInfo]()
#mixNodes[""]=

let protoRes = MixProtocol.initMix(localMixNodeInfo, node.switch, mixNodes)
if protoRes.isErr:
Expand Down

0 comments on commit f5cecd0

Please sign in to comment.