add relay server to development network

This commit is contained in:
geoffsee
2025-06-15 20:07:40 -04:00
parent 02bb53b12d
commit 6fdcb220cd
6 changed files with 114 additions and 18 deletions

View File

@@ -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"

View File

@@ -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())

View 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"]

View File

@@ -0,0 +1 @@
stun_only = false