mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-02-05 06:23:28 +00:00
Added mix as submodule
This commit is contained in:
parent
8270cb9420
commit
06bfd94aef
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -174,3 +174,7 @@
|
||||
branch = master
|
||||
path = vendor/nph
|
||||
url = https://github.com/arnetheduck/nph.git
|
||||
[submodule "vendor/mix"]
|
||||
path = vendor/mix
|
||||
url = https://github.com/vacp2p/mix.git
|
||||
branch = mix-transport
|
||||
|
||||
104
examples/mix_lightpush_publisher.nim
Normal file
104
examples/mix_lightpush_publisher.nim
Normal file
@ -0,0 +1,104 @@
|
||||
import
|
||||
chronicles, chronos, confutils,
|
||||
eth/[keys, p2p/discoveryv5/enr],
|
||||
libp2p/crypto/crypto,
|
||||
std/[tables, times, sequtils],
|
||||
stew/byteutils,
|
||||
stew/shims/net,
|
||||
results,
|
||||
waku/[
|
||||
common/logging,
|
||||
node/peer_manager,
|
||||
waku_core,
|
||||
waku_node,
|
||||
waku_enr,
|
||||
discovery/waku_discv5,
|
||||
factory/builder,
|
||||
]
|
||||
|
||||
proc now*(): Timestamp =
|
||||
getNanosecondTime(getTime().toUnixFloat())
|
||||
|
||||
# careful if running pub and sub in the same machine
|
||||
const
|
||||
wakuPort = 60000
|
||||
clusterId = 16
|
||||
shardId = @[32'u16]
|
||||
LightpushPeer =
|
||||
"/ip4/143.198.250.233/tcp/30303/p2p/16Uiu2HAmQE7FXQc6iZHdBzYfw3qCSDa9dLc1wsBJKoP4aZvztq2d"
|
||||
|
||||
proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
|
||||
# use notice to filter all waku messaging
|
||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||
|
||||
notice "starting publisher", wakuPort = wakuPort
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get()
|
||||
ip = parseIpAddress("0.0.0.0")
|
||||
flags = CapabilitiesBitfield.init(relay = true)
|
||||
|
||||
let relayShards = RelayShards.init(clusterId, shardId).valueOr:
|
||||
error "Relay shards initialization failed", error = error
|
||||
quit(QuitFailure)
|
||||
|
||||
var enrBuilder = EnrBuilder.init(nodeKey)
|
||||
enrBuilder.withWakuRelaySharding(relayShards).expect(
|
||||
"Building ENR with relay sharding failed"
|
||||
)
|
||||
|
||||
let recordRes = enrBuilder.build()
|
||||
let record =
|
||||
if recordRes.isErr():
|
||||
error "failed to create enr record", error = recordRes.error
|
||||
quit(QuitFailure)
|
||||
else:
|
||||
recordRes.get()
|
||||
|
||||
var builder = WakuNodeBuilder.init()
|
||||
builder.withNodeKey(nodeKey)
|
||||
builder.withRecord(record)
|
||||
builder.withNetworkConfigurationDetails(ip, Port(wakuPort)).tryGet()
|
||||
let node = builder.build().tryGet()
|
||||
|
||||
node.mountMetadata(clusterId).expect("failed to mount waku metadata protocol")
|
||||
node.mountLightPushClient()
|
||||
|
||||
await node.start()
|
||||
node.peerManager.start()
|
||||
|
||||
# Make sure it matches the publisher. Use default value
|
||||
# see spec: https://rfc.vac.dev/spec/23/
|
||||
let pubSubTopic = PubsubTopic("/waku/2/rs/16/32")
|
||||
|
||||
# any content topic can be chosen
|
||||
let contentTopic = ContentTopic("/examples/1/pubsub-example/proto")
|
||||
|
||||
notice "publisher service started"
|
||||
while true:
|
||||
let text = "hi there i'm a publisher"
|
||||
let message = WakuMessage(
|
||||
payload: toBytes(text), # content of the message
|
||||
contentTopic: contentTopic, # content topic to publish to
|
||||
ephemeral: true, # tell store nodes to not store it
|
||||
timestamp: now(),
|
||||
) # current timestamp
|
||||
|
||||
let lightpushPeer = parsePeerInfo(LightpushPeer).get()
|
||||
|
||||
let res = await node.lightpushPublish(some(pubSubTopic), message, lightpushPeer)
|
||||
|
||||
if res.isOk:
|
||||
notice "published message",
|
||||
text = text,
|
||||
timestamp = message.timestamp,
|
||||
psTopic = pubSubTopic,
|
||||
contentTopic = contentTopic
|
||||
else:
|
||||
error "failed to publish message", error = res.error
|
||||
|
||||
await sleepAsync(5000)
|
||||
|
||||
when isMainModule:
|
||||
let rng = crypto.newRng()
|
||||
asyncSpawn setupAndPublish(rng)
|
||||
runForever()
|
||||
1
vendor/mix
vendored
Submodule
1
vendor/mix
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 3f9454e20e6b5d2bea5599676354a7c056799769
|
||||
@ -130,6 +130,8 @@ task example2, "Build Waku examples":
|
||||
buildBinary "subscriber", "examples/"
|
||||
buildBinary "filter_subscriber", "examples/"
|
||||
buildBinary "lightpush_publisher", "examples/"
|
||||
buildBinary "mix_filter_subscriber", "examples/"
|
||||
buildBinary "mix_lightpush_publisher", "examples/"
|
||||
|
||||
task chat2, "Build example Waku chat usage":
|
||||
# NOTE For debugging, set debug level. For chat usage we want minimal log
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user