Created
October 22, 2025 09:09
-
-
Save arnetheduck/49a2cda5a8f9e0a5ae179b048eddcd3b to your computer and use it in GitHub Desktop.
v0 sniffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import | |
| chronos, | |
| libp2p, | |
| libp2p/protocols/pubsub/rpc/messages, | |
| libp2p/crypto/crypto, | |
| libp2p/crypto/ed25519/ed25519 | |
| proc main() {.async.} = | |
| let | |
| rng = newRng() | |
| privKey = PrivateKey.random(PKScheme.Ed25519, rng[]).expect("a key") | |
| local = @[MultiAddress.init("/ip4/0.0.0.0/udp/0/quic-v1").expect("valid addr")] | |
| switch = SwitchBuilder | |
| .new() | |
| .withRng(rng) | |
| .withPrivateKey(privKey) | |
| .withQuicTransport() | |
| .withAddresses(local) | |
| .build() | |
| gossip = GossipSub.init(switch = switch, triggerSelf = true) | |
| proc printer(topic: string, message: Message): Future[ValidationResult] {.async.} = | |
| echo topic, ": ", message | |
| ValidationResult.Accept | |
| gossip.addValidator(["/cryptarchia/proto", "mantle", "da"], printer) | |
| gossip.subscribe("/cryptarchia/proto", nil) | |
| gossip.subscribe("mantle", nil) | |
| gossip.subscribe("da", nil) | |
| switch.mount(gossip) | |
| await switch.start() | |
| let | |
| remote = MultiAddress.init("/ip4/0.0.0.0/udp/3000/quic-v1").expect("valid id") | |
| remoteId = await switch.connect(remote, allowUnknownPeerId = true) | |
| echo "Connected to ", remoteId | |
| await waitSignal(SIGINT) or waitSignal(SIGTERM) | |
| waitFor(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment