add config for lpmix example

This commit is contained in:
Prem Chaitanya Prathi 2025-03-29 05:56:45 +05:30
parent e0462fc7b9
commit f70ab28e42
2 changed files with 39 additions and 19 deletions

View File

@ -24,29 +24,26 @@ import
waku_enr, waku_enr,
discovery/waku_discv5, discovery/waku_discv5,
factory/builder, factory/builder,
waku_lightpush/client, waku_lightpush/client
] ],
./lightpush_publisher_mix_config
proc now*(): Timestamp = proc now*(): Timestamp =
getNanosecondTime(getTime().toUnixFloat()) getNanosecondTime(getTime().toUnixFloat())
# careful if running pub and sub in the same machine const clusterId = 66
const wakuPort = 60000
const clusterId = 2
const shardId = @[0'u16] const shardId = @[0'u16]
const const
LightpushPeer = LightpushPubsubTopic = PubsubTopic("/waku/2/rs/66/0")
"/ip4/127.0.0.1/tcp/60001/p2p/16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o"
LightpushPubsubTopic = PubsubTopic("/waku/2/rs/2/0")
LightpushContentTopic = ContentTopic("/examples/1/light-pubsub-mix-example/proto") LightpushContentTopic = ContentTopic("/examples/1/light-pubsub-mix-example/proto")
proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} = proc setupAndPublish(rng: ref HmacDrbgContext, conf: LPMixConf) {.async.} =
# use notice to filter all waku messaging # use notice to filter all waku messaging
setupLog(logging.LogLevel.DEBUG, logging.LogFormat.TEXT) setupLog(logging.LogLevel.DEBUG, logging.LogFormat.TEXT)
notice "starting publisher", wakuPort = wakuPort notice "starting publisher", wakuPort = conf.port
let let
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get() nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get()
@ -73,7 +70,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
var builder = WakuNodeBuilder.init() var builder = WakuNodeBuilder.init()
builder.withNodeKey(nodeKey) builder.withNodeKey(nodeKey)
builder.withRecord(record) builder.withRecord(record)
builder.withNetworkConfigurationDetails(ip, Port(wakuPort)).tryGet() builder.withNetworkConfigurationDetails(ip, Port(conf.port)).tryGet()
let node = builder.build().tryGet() let node = builder.build().tryGet()
@ -87,16 +84,16 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
return return
let pxPeerInfo = RemotePeerInfo.init( let pxPeerInfo = RemotePeerInfo.init(
"16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o", conf.destPeerId,
@[MultiAddress.init("/ip4/127.0.0.1/tcp/60001").get()], @[MultiAddress.init(conf.destPeerAddr).get()],
) )
node.peerManager.addServicePeer(pxPeerInfo, WakuPeerExchangeCodec) node.peerManager.addServicePeer(pxPeerInfo, WakuPeerExchangeCodec)
let pxPeerInfo2 = RemotePeerInfo.init( #[ let pxPeerInfo2 = RemotePeerInfo.init(
"16Uiu2HAmRhxmCHBYdXt1RibXrjAUNJbduAhzaTHwFCZT4qWnqZAu", "16Uiu2HAmRhxmCHBYdXt1RibXrjAUNJbduAhzaTHwFCZT4qWnqZAu",
@[MultiAddress.init("/ip4/127.0.0.1/tcp/60005").get()], @[MultiAddress.init("/ip4/127.0.0.1/tcp/60005").get()],
) )
node.peerManager.addServicePeer(pxPeerInfo2, WakuPeerExchangeCodec) node.peerManager.addServicePeer(pxPeerInfo2, WakuPeerExchangeCodec)
]#
( (
await node.mountMix( await node.mountMix(
intoCurve25519Key( intoCurve25519Key(
@ -110,12 +107,12 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
return return
#discard node.setMixBootStrapNodes() #discard node.setMixBootStrapNodes()
let destPeerId = PeerId.init("16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o").valueOr: let destPeerId = PeerId.init(conf.destPeerId).valueOr:
error "Failed to initialize PeerId", err = error error "Failed to initialize PeerId", err = error
return return
let conn = MixEntryConnection.newConn( let conn = MixEntryConnection.newConn(
"/ip4/127.0.0.1/tcp/60001", conf.destPeerAddr,
destPeerId, destPeerId,
ProtocolType.fromString(WakuLightPushCodec), ProtocolType.fromString(WakuLightPushCodec),
node.mix, node.mix,
@ -162,6 +159,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
await sleepAsync(1000) await sleepAsync(1000)
when isMainModule: when isMainModule:
let conf = LPMixConf.load()
let rng = crypto.newRng() let rng = crypto.newRng()
asyncSpawn setupAndPublish(rng) asyncSpawn setupAndPublish(rng, conf)
runForever() runForever()

View File

@ -0,0 +1,22 @@
import
confutils/defs
type
LPMixConf* = object
destPeerAddr* {.
desc: "Destination peer address.",
name: "dp-addr",
}: string
destPeerId* {.
desc: "Destination peer ID.",
name: "dp-id",
}: string
port* {.
desc: "Port to listen on.",
defaultValue: 50000,
name: "port",
}: int