pub struct SocialWebNet { /* private fields */ }Expand description
The node’s managed WireGuard mesh: a set of peer tunnels sharing this node’s static keypair.
Implementations§
Source§impl SocialWebNet
impl SocialWebNet
Sourcepub fn new(
keys: WgKeypair,
bind_ip: IpAddr,
read_timeout: Option<Duration>,
) -> SocialWebNet
pub fn new( keys: WgKeypair, bind_ip: IpAddr, read_timeout: Option<Duration>, ) -> SocialWebNet
Create an empty mesh for this node. bind_ip is where per-peer sockets bind (e.g.
0.0.0.0 / :: in production, 127.0.0.1 in tests); read_timeout bounds each
pump so a quiet peer does not stall the loop.
Sourcepub fn public_key_hex(&self) -> String
pub fn public_key_hex(&self) -> String
This node’s WireGuard public key as lowercase hex — what peers need to address it.
Sourcepub fn add_peer(
&mut self,
peer_id: &str,
peer_pubkey_hex: &str,
endpoint: Option<SocketAddr>,
) -> Result<SocketAddr, String>
pub fn add_peer( &mut self, peer_id: &str, peer_pubkey_hex: &str, endpoint: Option<SocketAddr>, ) -> Result<SocketAddr, String>
Add a peer to the mesh: bind a fresh socket and build its tunnel.
peer_pubkey_hex is the peer’s WireGuard public key (64 hex chars — as stored on a
SocialPeer / carried in a ConnectionIdentifier). endpoint is where to send to if
already known (else None, and it is learned by roaming from the first authenticated
packet). Returns the local socket address bound for this peer, so the caller can advertise
it back through the coordination plane. Idempotent-ish: adding an existing peer id replaces
its tunnel (a fresh socket + handshake state).
Sourcepub fn remove_peer(&mut self, peer_id: &str) -> bool
pub fn remove_peer(&mut self, peer_id: &str) -> bool
Remove a peer and drop its tunnel/socket. Returns whether the peer was present.
Sourcepub fn local_addr(&self, peer_id: &str) -> Option<SocketAddr>
pub fn local_addr(&self, peer_id: &str) -> Option<SocketAddr>
The local socket address bound for a peer, if present.
Sourcepub fn set_peer_endpoint(
&mut self,
peer_id: &str,
addr: SocketAddr,
) -> Result<(), String>
pub fn set_peer_endpoint( &mut self, peer_id: &str, addr: SocketAddr, ) -> Result<(), String>
Point a peer’s tunnel at addr (e.g. once its endpoint is learned from the coordination plane).
Sourcepub fn has_session(&self, peer_id: &str) -> bool
pub fn has_session(&self, peer_id: &str) -> bool
Whether a live WireGuard session exists with a peer.
Sourcepub fn initiate_handshake(&mut self, peer_id: &str) -> Result<(), String>
pub fn initiate_handshake(&mut self, peer_id: &str) -> Result<(), String>
Start the handshake with a peer (initiator side). Requires the peer’s endpoint to be set.
Sourcepub fn send_to(&mut self, peer_id: &str, inner: &[u8]) -> Result<bool, String>
pub fn send_to(&mut self, peer_id: &str, inner: &[u8]) -> Result<bool, String>
Encrypt and send one inner IPv6 packet to a peer. See WgTunnel::send_packet for the
pre-session behaviour (a handshake init is sent and the caller retries once established).
Sourcepub fn send_datagram(
&mut self,
peer_id: &str,
src_port: u16,
dst_port: u16,
payload: &[u8],
) -> Result<bool, String>
pub fn send_datagram( &mut self, peer_id: &str, src_port: u16, dst_port: u16, payload: &[u8], ) -> Result<bool, String>
Frame payload as an overlay IPv6/UDP datagram addressed to dst_port (from src_port) and
send it to a peer. This is the application-message path over the mesh: the receiver recovers
(src_port, dst_port, payload) with
mesh_datagram::decode_datagram on the
MeshPacket::inner it pumps. See super::mesh_datagram::ports for well-known ports.
Sourcepub fn pump(&mut self, peer_id: &str) -> Result<TunnelEvent, String>
pub fn pump(&mut self, peer_id: &str) -> Result<TunnelEvent, String>
Pump one datagram for a single peer. See WgTunnel::pump.
Auto Trait Implementations§
impl Freeze for SocialWebNet
impl !RefUnwindSafe for SocialWebNet
impl Send for SocialWebNet
impl Sync for SocialWebNet
impl Unpin for SocialWebNet
impl UnsafeUnpin for SocialWebNet
impl !UnwindSafe for SocialWebNet
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more