pub struct HightowerConnection { /* private fields */ }Expand description
Main connection to Hightower gateway with integrated WireGuard transport
Implementations§
Source§impl HightowerConnection
impl HightowerConnection
Sourcepub async fn connect(
gateway_url: impl Into<String>,
auth_token: impl Into<String>,
) -> Result<Self, ClientError>
pub async fn connect( gateway_url: impl Into<String>, auth_token: impl Into<String>, ) -> Result<Self, ClientError>
Connect to a Hightower gateway
This method handles everything:
- Checks for existing stored connection and restores if available
- Otherwise: Generates WireGuard keypair, registers with gateway
- Creates transport server on 0.0.0.0:0
- Discovers network info via STUN using actual bound port
- Adds gateway as peer
- Persists connection info to storage (default: ~/.hightower-client/data)
Returns a ready-to-use connection with working transport
Sourcepub async fn connect_ephemeral(
gateway_url: impl Into<String>,
auth_token: impl Into<String>,
) -> Result<Self, ClientError>
pub async fn connect_ephemeral( gateway_url: impl Into<String>, auth_token: impl Into<String>, ) -> Result<Self, ClientError>
Connect without using persistent storage
Sourcepub async fn connect_with_storage(
gateway_url: impl Into<String>,
auth_token: impl Into<String>,
storage_dir: impl Into<PathBuf>,
) -> Result<Self, ClientError>
pub async fn connect_with_storage( gateway_url: impl Into<String>, auth_token: impl Into<String>, storage_dir: impl Into<PathBuf>, ) -> Result<Self, ClientError>
Connect with custom storage directory
Sourcepub async fn connect_fresh(
gateway_url: impl Into<String>,
auth_token: impl Into<String>,
) -> Result<Self, ClientError>
pub async fn connect_fresh( gateway_url: impl Into<String>, auth_token: impl Into<String>, ) -> Result<Self, ClientError>
Force a fresh registration even if stored connection exists
Sourcepub async fn connect_with_auth_token(
auth_token: impl Into<String>,
) -> Result<Self, ClientError>
pub async fn connect_with_auth_token( auth_token: impl Into<String>, ) -> Result<Self, ClientError>
Connect using default gateway (http://127.0.0.1:8008)
Sourcepub fn assigned_ip(&self) -> &str
pub fn assigned_ip(&self) -> &str
Get the IP address assigned by the gateway
Sourcepub fn transport(&self) -> &TransportServer
pub fn transport(&self) -> &TransportServer
Get the transport for sending/receiving data
Sourcepub async fn ping_gateway(&self) -> Result<(), ClientError>
pub async fn ping_gateway(&self) -> Result<(), ClientError>
Ping the gateway over WireGuard to verify connectivity
Sourcepub async fn get_peer_info(
&self,
node_id_or_ip: &str,
) -> Result<PeerInfo, ClientError>
pub async fn get_peer_info( &self, node_id_or_ip: &str, ) -> Result<PeerInfo, ClientError>
Get peer information from the gateway
Accepts either a node_id (e.g., “ht-festive-penguin-abc123”) or an assigned IP (e.g., “100.64.0.5”)
Sourcepub async fn dial(&self, peer: &str, port: u16) -> Result<Stream, ClientError>
pub async fn dial(&self, peer: &str, port: u16) -> Result<Stream, ClientError>
Dial a peer by node ID or assigned IP
This method:
- Fetches peer info from gateway (public key, endpoint, etc.)
- Adds peer to WireGuard if not already present
- Dials the peer over the WireGuard network
§Arguments
peer- Node ID (e.g., “ht-festive-penguin”) or assigned IP (e.g., “100.64.0.5”)port- Port to connect to on the peer
§Example
let connection = conn.dial("ht-festive-penguin-abc123", 8080).await?;
connection.send(b"Hello, peer!").await?;Sourcepub async fn disconnect(self) -> Result<(), ClientError>
pub async fn disconnect(self) -> Result<(), ClientError>
Disconnect from the gateway and deregister
Auto Trait Implementations§
impl Freeze for HightowerConnection
impl !RefUnwindSafe for HightowerConnection
impl Send for HightowerConnection
impl Sync for HightowerConnection
impl Unpin for HightowerConnection
impl !UnwindSafe for HightowerConnection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more