| Crates.io | hightower-client |
| lib.rs | hightower-client |
| version | 0.1.5 |
| created_at | 2025-10-08 16:56:06.021353+00 |
| updated_at | 2025-10-13 14:04:43.111034+00 |
| description | Hightower client library |
| homepage | https://github.com/chrishayen/hightower-client |
| repository | https://github.com/chrishayen/hightower-client |
| max_upload_size | |
| id | 1874215 |
| size | 117,006 |
A Rust library for building applications that connect to Hightower gateways with integrated WireGuard transport.
This library provides a complete solution for connecting to Hightower gateways. It handles everything internally:
You only provide: gateway URL and auth token You get: a working transport, node ID, and assigned IP
Everything else is handled automatically!
By default, connections are automatically persisted to ~/.hightower/gateway/<gateway>/. When you reconnect to the same gateway:
disconnect() removes the stored connectionThis makes your application's network identity stable across restarts!
Add this to your Cargo.toml:
[dependencies]
hightower-client = "0.1.4"
use hightower_client::HightowerConnection;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect with default gateway (http://127.0.0.1:8008)
let connection = HightowerConnection::connect_with_auth_token("your-auth-token").await?;
// Access what you need
println!("Node ID: {}", connection.node_id());
println!("Assigned IP: {}", connection.assigned_ip());
// Get transport for communication
let transport = connection.transport();
// Use the underlying server for send/receive operations
// See hightower-wireguard documentation for full API
// let server = transport.server();
// Disconnect (automatically deregisters)
connection.disconnect().await?;
Ok(())
}
use hightower_client::HightowerConnection;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Must specify http:// or https://
let connection = HightowerConnection::connect(
"https://gateway.example.com:8443",
"your-auth-token"
).await?;
println!("Connected to {}", connection.node_id());
connection.disconnect().await?;
Ok(())
}
The library includes several examples:
export HT_AUTH_TOKEN="your-token"
cargo run --example simple_register
export HT_AUTH_TOKEN="your-token"
export HT_GATEWAY_URL="http://127.0.0.1:8008" # optional
cargo run --example connection_persistence
Demonstrates how connections are automatically restored across application restarts.
export HT_AUTH_TOKEN="your-token"
export HT_GATEWAY_URL="http://127.0.0.1:8008" # optional
cargo run --example storage_modes
Shows all available storage modes: default persistence, ephemeral, custom directory, and forced fresh registration.
export HT_AUTH_TOKEN="your-token"
export HT_GATEWAY_URL="https://gateway.example.com:8443"
cargo run --example custom_endpoint
export HT_AUTH_TOKEN="your-token"
cargo run --example https_gateway
export HT_AUTH_TOKEN="your-token"
cargo run --example simple_deregister
HightowerConnectionThe main connection struct with integrated WireGuard transport.
async fn connect(gateway_url: impl Into<String>, auth_token: impl Into<String>) -> Result<Self, ClientError>
Connects to a Hightower gateway with a custom URL. The URL must include the scheme (http:// or https://).
With persistence (default):
~/.hightower/gateway/<gateway>/Handles everything internally:
Returns a ready-to-use connection with working transport.
async fn connect_with_auth_token(auth_token: impl Into<String>) -> Result<Self, ClientError>
Connects using the default gateway (http://127.0.0.1:8008). Includes automatic persistence.
async fn connect_ephemeral(gateway_url: impl Into<String>, auth_token: impl Into<String>) -> Result<Self, ClientError>
Connects without persistence. Always creates fresh registration, nothing stored to disk.
async fn connect_with_storage(gateway_url: impl Into<String>, auth_token: impl Into<String>, storage_dir: impl Into<PathBuf>) -> Result<Self, ClientError>
Connects using a custom storage directory instead of the default location.
async fn connect_fresh(gateway_url: impl Into<String>, auth_token: impl Into<String>) -> Result<Self, ClientError>
Forces a fresh registration even if a stored connection exists. Deletes any existing stored connection for this gateway.
fn node_id(&self) -> &str
Returns the node ID assigned by the gateway.
fn assigned_ip(&self) -> &str
Returns the IP address assigned by the gateway.
fn transport(&self) -> &TransportServer
Returns the transport for sending/receiving data.
async fn disconnect(self) -> Result<(), ClientError>
Disconnects from the gateway and automatically deregisters using the internal token.
TransportServerWrapper around the WireGuard transport.
fn server(&self) -> &Server
Get a reference to the underlying hightower-wireguard Server.
Use this to access the full transport API for sending/receiving data.
ClientErrorError types returned by the library.
Variants:
Configuration(String) - Invalid configuration (e.g., empty endpoint, invalid URL)Request(reqwest::Error) - HTTP request failedGatewayError { status: u16, message: String } - Gateway returned errorInvalidResponse(String) - Unexpected response formatNetworkDiscovery(String) - Failed to discover network info via STUNTransport(String) - Transport creation or operation failedStorage(String) - Storage operation failed (persistence)Run the test suite:
cargo test
MIT