-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement chat example with manual dial (#5)
* feat: implement chat example with manual dial * feat: implement interactive/echo modes * ci: implement release automation * feat: wait for the relayed interfaces before proceeding with the main flow * feat: resolve relayed dial on the first connection
- Loading branch information
Showing
15 changed files
with
1,414 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Build and release chat example | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- feat/chat-example | ||
permissions: write-all | ||
jobs: | ||
metadata: | ||
name: Get release metadata | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version: ${{ steps.get_version.outputs.version }} | ||
release_exists: ${{ steps.check_release.outputs.exists }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Get version | ||
id: get_version | ||
run: echo "version=chat-example-$(cargo read-manifest --manifest-path examples/chat/Cargo.toml | jq -r '.version')" >> $GITHUB_OUTPUT | ||
|
||
- name: Check if release exists | ||
id: check_release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
RELEASE_URL=$(curl --silent "https://api.github.com/repos/calimero-network/relay-server/releases/tags/${{ steps.get_version.outputs.version }}" \ | ||
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||
-H "Accept: application/vnd.github.v3+json" | jq -r '.url') | ||
if [[ "$RELEASE_URL" != "null" ]]; then | ||
echo "exists=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "exists=false" >> $GITHUB_OUTPUT | ||
fi | ||
release: | ||
name: Build and release | ||
runs-on: ubuntu-latest | ||
needs: metadata | ||
if: needs.metadata.outputs.release_exists == 'false' | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup rust toolchain | ||
run: rustup toolchain install stable --profile minimal | ||
|
||
- name: Setup rust cache | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- name: Build for Intel Linux | ||
run: cargo build -p chat-example --release --target=x86_64-unknown-linux-gnu | ||
|
||
- name: Build for Aarch Linux | ||
run: cross build -p chat-example --release --target=aarch64-unknown-linux-gnu | ||
|
||
- name: Create artifacts directory | ||
run: | | ||
mkdir -p artifacts | ||
cp target/x86_64-unknown-linux-gnu/release/chat-example artifacts/chat-example-x86_64-unknown-linux | ||
cp target/aarch64-unknown-linux-gnu/release/chat-example artifacts/chat-example-aarch64-unknown-linux | ||
- name: Create GitHub Release | ||
uses: softprops/action-gh-release@v2 | ||
with: | ||
tag_name: ${{ needs.metadata.outputs.version }} | ||
files: | | ||
examples/chat/README.md | ||
artifacts/* | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[package] | ||
name = "chat-example" | ||
version = "0.1.0" | ||
authors = ["Calimero Limited <info@calimero.network>"] | ||
edition = "2021" | ||
repository = "https://github.com/calimero-network/relay-server" | ||
license = "MIT OR Apache-2.0" | ||
|
||
[dependencies] | ||
clap = { version = "4.5.4", features = ["derive", "env"] } | ||
eyre = "0.6.12" | ||
libp2p = { version = "0.53.2", features = [ | ||
"dcutr", | ||
"dns", | ||
"gossipsub", | ||
"identify", | ||
"macros", | ||
"noise", | ||
"ping", | ||
"quic", | ||
"relay", | ||
"tokio", | ||
"tcp", | ||
"tls", | ||
"yamux", | ||
] } | ||
multiaddr = "0.18.1" | ||
owo-colors = "4.0.0" | ||
serde = "1.0.196" | ||
serde_json = "1.0.113" | ||
tokio = { version = "1.35.1", features = [ | ||
"io-std", | ||
"macros", | ||
"rt", | ||
"rt-multi-thread", | ||
] } | ||
tracing = "0.1.37" | ||
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Chat | ||
This examples show cases how to manually dial (connect to) either local peer or remote peer has a reservation on relay-server. | ||
|
||
## Run local only | ||
This examples shows how to run two sessions locally and connect sessions by manually dialing local peer. | ||
|
||
Run first chat session in echo mode. | ||
``` | ||
cargo run -p chat-example -- --mode echo --port 4002 --secret-key-seed 102 --gossip-topic-names calimero-network/examples/chat/v0.0.1 --relay-address /ip4/3.71.239.80/udp/4001/quic-v1/p2p/12D3KooWAgFah4EZtWnMMGMUddGdJpb5cq2NubNCAD2jA5AZgbXF | ||
``` | ||
|
||
Run second chat session in interactive mode with local peer dial. | ||
``` | ||
cargo run -p chat-example -- --mode interactive --port 4003 --secret-key-seed 103 --gossip-topic-names calimero-network/examples/chat/v0.0.1 --dial-peer-addrs /ip4/127.0.0.1/udp/4002/quic-v1/p2p/12D3KooWMpeKAbMK4BTPsQY3rG7XwtdstseHGcq7kffY8LToYYKK --relay-address /ip4/3.71.239.80/udp/4001/quic-v1/p2p/12D3KooWAgFah4EZtWnMMGMUddGdJpb5cq2NubNCAD2jA5AZgbXF | ||
``` | ||
|
||
In the interactive session publish new message manually: | ||
``` | ||
publish calimero-network/examples/chat/v0.0.1 ola | ||
``` | ||
|
||
## Run locally with remote peer dial in | ||
This examples shows how to run two sessions locally and connect sessions manually by dialing private remote peer from each session. For the gossip message to pass from one local session to second local session it needs to go "the long way" around (local -> remote -> local). | ||
|
||
Additional info: | ||
- Remote instance is running in a private subnet behind NAT. | ||
- Remote instance PeerId: `12D3KooWP285Hw3CSTdr9oU6Ezz4hDoi6XS5vfDjjNeTJ1uFMGvp` | ||
- Remote instance address at the relay server: `ip4/3.71.239.80/udp/4001/quic-v1/p2p/12D3KooWAgFah4EZtWnMMGMUddGdJpb5cq2NubNCAD2jA5AZgbXF/p2p-circuit/p2p/12D3KooWP285Hw3CSTdr9oU6Ezz4hDoi6XS5vfDjjNeTJ1uFMGvp` | ||
Run first chat session in interactive mode with remote peer dial. | ||
``` | ||
cargo run -p chat-example -- --mode interactive --port 4002 --secret-key-seed 102 --gossip-topic-names calimero-network/examples/chat/v0.0.1 --dial-peer-addrs /ip4/3.71.239.80/udp/4001/quic-v1/p2p/12D3KooWAgFah4EZtWnMMGMUddGdJpb5cq2NubNCAD2jA5AZgbXF/p2p-circuit/p2p/12D3KooWP285Hw3CSTdr9oU6Ezz4hDoi6XS5vfDjjNeTJ1uFMGvp --relay-address /ip4/3.71.239.80/udp/4001/quic-v1/p2p/12D3KooWAgFah4EZtWnMMGMUddGdJpb5cq2NubNCAD2jA5AZgbXF | ||
``` | ||
|
||
Run second chat session in interactive mode with remote peer dial. | ||
``` | ||
cargo run -p chat-example -- --mode interactive --port 4003 --secret-key-seed 103 --gossip-topic-names calimero-network/examples/chat/v0.0.1 --dial-peer-addrs /ip4/3.71.239.80/udp/4001/quic-v1/p2p/12D3KooWAgFah4EZtWnMMGMUddGdJpb5cq2NubNCAD2jA5AZgbXF/p2p-circuit/p2p/12D3KooWP285Hw3CSTdr9oU6Ezz4hDoi6XS5vfDjjNeTJ1uFMGvp --relay-address /ip4/3.71.239.80/udp/4001/quic-v1/p2p/12D3KooWAgFah4EZtWnMMGMUddGdJpb5cq2NubNCAD2jA5AZgbXF | ||
``` | ||
|
||
In any interactive session publish new message manually: | ||
``` | ||
publish calimero-network/examples/chat/v0.0.1 ola | ||
``` | ||
|
||
## Debugging and known issues | ||
- If multiple people are running the same example, some will fail to get reservation on relay server because the same PeerId already exists. | ||
- Fix: change `secret-key-seed` to something else | ||
|
Oops, something went wrong.