@@ -24,29 +24,26 @@ import
24
24
waku_enr,
25
25
discovery/ waku_discv5,
26
26
factory/ builder,
27
- waku_lightpush/ client,
28
- ]
27
+ waku_lightpush/ client
28
+ ],
29
+ ./ lightpush_publisher_mix_config
30
+
29
31
30
32
proc now* (): Timestamp =
31
33
getNanosecondTime(getTime().toUnixFloat())
32
34
33
- # careful if running pub and sub in the same machine
34
- const wakuPort = 60000
35
-
36
35
const clusterId = 2
37
36
const shardId = @ [0 'u16]
38
37
39
38
const
40
- LightpushPeer =
41
- " /ip4/127.0.0.1/tcp/60001/p2p/16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o"
42
39
LightpushPubsubTopic = PubsubTopic(" /waku/2/rs/2/0" )
43
40
LightpushContentTopic = ContentTopic(" /examples/1/light-pubsub-mix-example/proto" )
44
41
45
- proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
42
+ proc setupAndPublish(rng: ref HmacDrbgContext, conf: LPMixConf ) {.async.} =
46
43
# use notice to filter all waku messaging
47
44
setupLog(logging.LogLevel.DEBUG, logging.LogFormat.TEXT)
48
45
49
- notice " starting publisher" , wakuPort = wakuPort
46
+ notice " starting publisher" , wakuPort = conf.port
50
47
51
48
let
52
49
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get()
@@ -73,7 +70,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
73
70
var builder = WakuNodeBuilder.init()
74
71
builder.withNodeKey(nodeKey)
75
72
builder.withRecord(record)
76
- builder.withNetworkConfigurationDetails(ip, Port(wakuPort )).tryGet()
73
+ builder.withNetworkConfigurationDetails(ip, Port(conf.port )).tryGet()
77
74
78
75
let node = builder.build().tryGet()
79
76
@@ -87,16 +84,16 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
87
84
return
88
85
89
86
let pxPeerInfo = RemotePeerInfo.init(
90
- " 16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o " ,
91
- @ [MultiAddress.init(" /ip4/127.0.0.1/tcp/60001 " ).get()],
87
+ conf.destPeerId ,
88
+ @ [MultiAddress.init(conf.destPeerAddr ).get()],
92
89
)
93
90
node.peerManager.addServicePeer(pxPeerInfo, WakuPeerExchangeCodec)
94
- let pxPeerInfo2 = RemotePeerInfo.init(
91
+ #[ let pxPeerInfo2 = RemotePeerInfo.init(
95
92
"16Uiu2HAmRhxmCHBYdXt1RibXrjAUNJbduAhzaTHwFCZT4qWnqZAu",
96
93
@[MultiAddress.init("/ip4/127.0.0.1/tcp/60005").get()],
97
94
)
98
95
node.peerManager.addServicePeer(pxPeerInfo2, WakuPeerExchangeCodec)
99
-
96
+ ]#
100
97
(
101
98
await node.mountMix(
102
99
intoCurve25519Key(
@@ -110,12 +107,12 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
110
107
return
111
108
# discard node.setMixBootStrapNodes()
112
109
113
- let destPeerId = PeerId.init(" 16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o " ).valueOr:
110
+ let destPeerId = PeerId.init(conf.destPeerId ).valueOr:
114
111
error " Failed to initialize PeerId" , err = error
115
112
return
116
113
117
114
let conn = MixEntryConnection.newConn(
118
- " /ip4/127.0.0.1/tcp/60001 " ,
115
+ conf.destPeerAddr ,
119
116
destPeerId,
120
117
ProtocolType.fromString(WakuLightPushCodec),
121
118
node.mix,
@@ -162,6 +159,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
162
159
await sleepAsync(1000 )
163
160
164
161
when isMainModule :
162
+ let conf = LPMixConf.load()
165
163
let rng = crypto.newRng()
166
- asyncSpawn setupAndPublish(rng)
164
+ asyncSpawn setupAndPublish(rng, conf )
167
165
runForever()
0 commit comments