add relay server to development network
This commit is contained in:
38
Cargo.lock
generated
38
Cargo.lock
generated
@@ -2,6 +2,20 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "acto"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a026259da4f1a13b4af60cda453c392de64c58c12d239c560923e0382f42f2b9"
|
||||
dependencies = [
|
||||
"parking_lot",
|
||||
"pin-project-lite",
|
||||
"rustc_version",
|
||||
"smol_str",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.24.2"
|
||||
@@ -1590,6 +1604,7 @@ dependencies = [
|
||||
"futures",
|
||||
"iroh",
|
||||
"iroh-blobs",
|
||||
"iroh-relay",
|
||||
"libp2p",
|
||||
"rmpv",
|
||||
"serde",
|
||||
@@ -1600,6 +1615,7 @@ dependencies = [
|
||||
"tower-http",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"url",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
@@ -2338,6 +2354,7 @@ dependencies = [
|
||||
"strum",
|
||||
"stun-rs",
|
||||
"surge-ping",
|
||||
"swarm-discovery",
|
||||
"thiserror 2.0.12",
|
||||
"time",
|
||||
"tokio",
|
||||
@@ -5235,6 +5252,12 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smol_str"
|
||||
version = "0.1.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fad6c857cbab2627dcf01ec85a623ca4e7dcb5691cbaa3d7fb7653671f0d09c9"
|
||||
|
||||
[[package]]
|
||||
name = "snafu"
|
||||
version = "0.8.6"
|
||||
@@ -5483,6 +5506,21 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "swarm-discovery"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3a95032b94c1dc318f55e0b130e3d2176cda022310a65c3df0092764ea69562"
|
||||
dependencies = [
|
||||
"acto",
|
||||
"anyhow",
|
||||
"hickory-proto 0.25.2",
|
||||
"rand 0.8.5",
|
||||
"socket2",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
|
@@ -22,5 +22,7 @@ serde_json = "1.0"
|
||||
uuid = { version = "1.7.0", features = ["v4", "serde"] }
|
||||
chrono = { version = "0.4.35", features = ["serde"] }
|
||||
sha2 = "0.10.8"
|
||||
iroh = { version = "0.35.0", features = ["discovery-pkarr-dht"] }
|
||||
iroh = { version = "0.35.0", features = ["discovery-pkarr-dht", "discovery-local-network"] }
|
||||
iroh-blobs = { version = "0.35.0", features = ["rpc"] }
|
||||
url = "2.5.4"
|
||||
iroh-relay = "0.35.0"
|
@@ -6,7 +6,7 @@
|
||||
// - Each node is an autonomous sync unit
|
||||
|
||||
use axum::{routing::get, Router};
|
||||
use iroh::{protocol::Router as IrohRouter, Endpoint};
|
||||
use iroh::{protocol::Router as IrohRouter, Endpoint, RelayMap, RelayMode, RelayUrl};
|
||||
use iroh_blobs::{
|
||||
net_protocol::Blobs,
|
||||
rpc::client::blobs::MemClient,
|
||||
@@ -30,6 +30,9 @@ mod p2p;
|
||||
|
||||
use ledger::{LedgerEntry, SharedLedger};
|
||||
use p2p::P2PManager;
|
||||
use url::Url;
|
||||
|
||||
// assuming 'localhost' resolves to 127.0.0.1
|
||||
|
||||
/// ========== Socket.io namespace helpers ==========
|
||||
fn register_root_namespace(io: &SocketIo, p2p: Arc<P2PManager>) {
|
||||
@@ -355,8 +358,23 @@ async fn handle_blob_available(socket: SocketRef, p2p: Arc<P2PManager>, data: &J
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tracing::subscriber::set_global_default(FmtSubscriber::default())?;
|
||||
|
||||
|
||||
let relay_address = std::env::var("RELAY_ADDRESS").expect("RELAY_ADDRESS must be set");
|
||||
|
||||
|
||||
let relay_url = RelayUrl::from_str(&*relay_address).unwrap();
|
||||
|
||||
|
||||
let relays = RelayMap::from(relay_url);
|
||||
|
||||
|
||||
|
||||
// --- IROH SETUP --------------------------------------------------------
|
||||
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
|
||||
let endpoint = Endpoint::builder().discovery_n0()
|
||||
.relay_conn_protocol(iroh_relay::http::Protocol::Websocket)
|
||||
.discovery_local_network()
|
||||
.discovery_dht()
|
||||
.relay_mode(RelayMode::Custom(relays)).bind().await?;
|
||||
// Concrete store type inferred from the builder
|
||||
let blobs = Arc::new(Blobs::memory().build(&endpoint));
|
||||
let router = IrohRouter::builder(endpoint.clone())
|
||||
|
33
crates/gsio-relay/Dockerfile
Normal file
33
crates/gsio-relay/Dockerfile
Normal file
@@ -0,0 +1,33 @@
|
||||
################################################################
|
||||
# Stage 1 – build rustls-cert-gen and generate the certs
|
||||
################################################################
|
||||
FROM rust:bookworm AS ssl-step
|
||||
|
||||
# ↓ Allow override of SAN / output directory at build time
|
||||
ARG CERT_DOMAIN=relay.local
|
||||
ARG OUT_DIR=/app/ssl
|
||||
|
||||
# ── deps we need only for the build ───────────────────────────
|
||||
RUN apt-get update -qq && \
|
||||
apt-get install -y --no-install-recommends git ca-certificates && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# ── fetch the rcgen repo (contains the CLI) and build once ────
|
||||
WORKDIR /src
|
||||
RUN git clone --depth 1 https://github.com/rustls/rcgen.git
|
||||
WORKDIR /src/rcgen
|
||||
RUN cargo run -- -o /app/ssl
|
||||
|
||||
################################################################
|
||||
# Stage 2 – minimal runtime with the iroh relay
|
||||
################################################################
|
||||
FROM n0computer/iroh-relay:v0.28.2
|
||||
|
||||
# copy the certs produced in stage 1
|
||||
COPY --from=ssl-step /app/ssl /app/ssl
|
||||
|
||||
# your relay configuration
|
||||
COPY ./relay-config.toml /app/
|
||||
|
||||
# hand off control to the relay
|
||||
CMD ["--dev"]
|
1
crates/gsio-relay/relay-config.toml
Normal file
1
crates/gsio-relay/relay-config.toml
Normal file
@@ -0,0 +1 @@
|
||||
stun_only = false
|
@@ -1,25 +1,25 @@
|
||||
version: '3.8'
|
||||
# GSIO-Net Docker Compose Configuration
|
||||
#
|
||||
# This file defines a network of GSIO-Net nodes that can communicate with each other.
|
||||
# It creates three nodes, each exposing the API on a different host port:
|
||||
# - node1: http://localhost:3001
|
||||
# - node2: http://localhost:3002
|
||||
# - node3: http://localhost:3003
|
||||
#
|
||||
# Usage:
|
||||
# - Start the network: docker-compose up -d
|
||||
# - View logs: docker-compose logs -f
|
||||
# - Stop the network: docker-compose down
|
||||
# - Stop and remove volumes: docker-compose down -v
|
||||
|
||||
services:
|
||||
relay:
|
||||
container_name: gsio-relay
|
||||
build:
|
||||
context: ./crates/gsio-relay
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
CERT_DOMAIN: "gsio-relay."
|
||||
networks:
|
||||
- gsio-network
|
||||
ports:
|
||||
- "3340:3340"
|
||||
- "7824:7824"
|
||||
|
||||
# Node 1
|
||||
node1:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: gsio-node1
|
||||
environment:
|
||||
RELAY_ADDRESS: "ws://gsio-relay:3340"
|
||||
ports:
|
||||
- "3001:3000" # Map to different host ports to avoid conflicts
|
||||
volumes:
|
||||
@@ -40,6 +40,8 @@ services:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: gsio-node2
|
||||
environment:
|
||||
RELAY_ADDRESS: "ws://gsio-relay:3340"
|
||||
ports:
|
||||
- "3002:3000"
|
||||
volumes:
|
||||
@@ -60,6 +62,8 @@ services:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: gsio-node3
|
||||
environment:
|
||||
RELAY_ADDRESS: "ws://gsio-relay:3340"
|
||||
ports:
|
||||
- "3003:3000"
|
||||
volumes:
|
||||
|
Reference in New Issue
Block a user