Skip to content

Commit d03f201

Browse files
committed
working node discovery example using the iroh-gossip-discovery crate
1 parent 4511de4 commit d03f201

File tree

11 files changed

+9946
-0
lines changed

11 files changed

+9946
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ target/
22
*iroh-data
33
*/.sendme*
44
/deploy-out
5+
.envrc
6+
.direnv

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ Use iroh through [extism]
2828

2929
Experiment with [FROST] threshold signatures for iroh.
3030

31+
### [gossip-node-discover](gossip-node-discover)
32+
33+
Discover nodes via [iroh-gossip-discovery](https://crates.io/crates/iroh-gossip-discovery).
34+
3135
### [iroh-automerge](iroh-automerge)
3236

3337
Iroh integration with [automerge]

flake.lock

Lines changed: 96 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
description = "A devShell example";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
rust-overlay.url = "github:oxalica/rust-overlay";
7+
flake-utils.url = "github:numtide/flake-utils";
8+
};
9+
10+
outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
11+
flake-utils.lib.eachDefaultSystem (system:
12+
let
13+
overlays = [ (import rust-overlay) ];
14+
pkgs = import nixpkgs {
15+
inherit system overlays;
16+
};
17+
in
18+
with pkgs;
19+
{
20+
devShells.default = mkShell {
21+
nativeBuildInputs = [
22+
openssl
23+
pkg-config
24+
rust-bin.nightly.latest.default
25+
rust-analyzer
26+
];
27+
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
28+
};
29+
}
30+
);
31+
}

gossip-node-discover/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# gossip-node-discovery
2+
3+
Discover nodes via [iroh-gossip-discovery](https://crates.io/crates/iroh-gossip-discovery).
4+
5+
## node
6+
7+
This binary will start an iroh endpoint and listen for NodeIds on the
8+
mDNS local discovery stream and also make an http request to a known
9+
server for it's NodeId. Once it gets one of these NodeId's it will
10+
subscribe to the [0u8; 32] topic Id and begin to send it's NodeId
11+
every 2 seconds. It also has a task that will listen for NodeId's that
12+
come on the gossip receiver stream and update a hashtable of known
13+
nodes.
14+
15+
## whoami
16+
17+
This is a simple http server that also subscribed to the gossip
18+
topic. `node` can hit this server if it can't find any seed NodeIds
19+
via mDNS.
20+
21+
## Running the Demo
22+
23+
If you are running locally and want to test via mDNS then just do:
24+
```
25+
cd node
26+
cargo run -- <name-of-node>
27+
```
28+
29+
If you also want to test discovery using the `whoami` server do:
30+
```
31+
cd whoami
32+
cargo run
33+
```
34+
in another terminal
35+
```
36+
cd node
37+
cargo run -- <name-of-node>
38+
```

0 commit comments

Comments
 (0)