Skip to main content

Crate nym_bridges

Crate nym_bridges 

Source
Expand description

Nym Transport Bridges library.

This crate provides the transport and configuration primitives used by Nym bridge runners and tooling.

The primary responsibilities are:

  • server-side transport configuration for QUIC and TLS listeners,
  • client-side transport parameters derived from server configuration,
  • forwarding/session/connection building blocks for bridge implementations.

The repository binaries (for example, nym-bridge and bridge-cfg) use this crate as their shared core.

§Shared Types Crate

This crate re-exports nym-bridges-types as types.

These shared types can be consumed directly when integrating across crates or language bindings.

§Example: Simple Client Connection Establishment

use anyhow::anyhow;
use nym_bridges::connection::{BridgeConn, SOCKET_OPEN_NOP};
use nym_bridges::config::parse_persisted_config_json;
use nym_bridges::forward::UdpForwarder;
use tokio_util::sync::CancellationToken;

let client_config_str = r#"{"version":"0","transports":[{"transport_type":"quic_plain","args":{"addresses":["139.162.33.226:4443","[2400:8901::2000:faff:fea6:87f2]:4443"],"host":"netdna.bootstrapcdn.com","id_pubkey":"9JC91ZiszhIn3n4FG+MDYE/lYwhGdpHGWQTKUqGl+sE="}}]}"#;
let shutdown_token = CancellationToken::new();
let entry_bridge_params = parse_persisted_config_json(client_config_str)?;
let transport_params = entry_bridge_params
    .transports
    .first()
    .ok_or(anyhow!("no config provided"))?;

let bridge_conn = BridgeConn::try_connect(
    transport_params.clone(),
    shutdown_token.clone(),
    #[cfg(any(target_os = "linux", target_os = "android"))]
    SOCKET_OPEN_NOP,
)
.await?;

let remote_addr = bridge_conn.endpoint();
let (listen_addr, join_handle) = UdpForwarder::launch_initiator(
    bridge_conn,
    None,
    None,
    shutdown_token.clone(),
)
.await?;

§Example: Parse and Convert Configuration

use nym_bridges::config::PersistedServerConfig;
use nym_bridges::types::PersistedClientConfig;

let server_toml = r#"
public_ips = ["192.168.0.1", "fe80::1"]

[forward]
address = "[::1]:51822"

[[transports]]
transport_type = "quic_plain"

[transports.args]
stateless_retry = false
listen = "[::]:4443"
identity_key = "fditK5JfNM/88mLWd3ccbLasSrHA5dw1wj+/+1bfGWk="
"#;

let server_cfg = PersistedServerConfig::parse(server_toml)?;
let client_cfg = PersistedClientConfig::try_from(&server_cfg)?;
assert_eq!(client_cfg.version, "0");

Re-exports§

pub use nym_bridges_types as types;

Modules§

config
Persisted server/client configuration types and conversion from server transport config to client connection parameters.
connection
Runtime components for creating connections over configured transports.
error
Crate-specific error types.
forward
Runtime components for forwarding client traffic over established transport connections. UDP forwarding between a local application socket and a bridge transport connection.
session
Stored state and config for established connection.
transport
Protocol-specific transport implementations.