pub struct SamSession { /* private fields */ }Expand description
A SAM session connected to the I2P router.
Owns the control socket and the session’s ephemeral destination. Creating a session requires a HELLO handshake followed by SESSION CREATE.
The control socket must stay open for the session’s lifetime. If it is dropped, the I2P router destroys the session and all associated tunnels.
Implementations§
Source§impl SamSession
impl SamSession
Sourcepub async fn create(
host: &str,
port: u16,
session_id: &str,
tunnel_config: SamTunnelConfig,
) -> Result<Self, SamError>
pub async fn create( host: &str, port: u16, session_id: &str, tunnel_config: SamTunnelConfig, ) -> Result<Self, SamError>
Create a new SAM session.
- Connect to the SAM bridge at
host:port - Perform HELLO VERSION handshake (v3.1)
- Create a STREAM session with TRANSIENT destination
The control socket is kept alive for the session’s lifetime. Dropping
the SamSession closes the control socket and destroys the session.
Each STREAM CONNECT/ACCEPT opens a new TCP connection to the bridge.
§Errors
Returns an error if the session is shut down.
Sourcepub fn destination(&self) -> &I2pDestination
pub fn destination(&self) -> &I2pDestination
Our ephemeral I2P destination.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
The session ID.
Sourcepub async fn connect(
&self,
dest: &I2pDestination,
) -> Result<SamStream, SamError>
pub async fn connect( &self, dest: &I2pDestination, ) -> Result<SamStream, SamError>
Connect to a remote I2P destination.
Opens a new TCP connection to the SAM bridge and sends:
STREAM CONNECT ID=<session_id> DESTINATION=<dest> SILENT=false
On success, returns a SamStream whose underlying TCP socket carries
raw data to/from the remote destination.
§Errors
Returns an error if the connection or binding fails.
Sourcepub async fn accept(&self) -> Result<SamStream, SamError>
pub async fn accept(&self) -> Result<SamStream, SamError>
Accept an incoming I2P connection.
Opens a new TCP connection to the SAM bridge and sends:
STREAM ACCEPT ID=<session_id> SILENT=false
Blocks until a remote peer connects. Returns a SamStream whose
underlying TCP socket carries raw data from the connecting peer.
§Errors
Returns an error if the session is shut down.
Sourcepub async fn naming_lookup(
&self,
name: &str,
) -> Result<I2pDestination, SamError>
pub async fn naming_lookup( &self, name: &str, ) -> Result<I2pDestination, SamError>
Look up a .b32.i2p or .i2p hostname and return the full destination.
Sends: NAMING LOOKUP NAME=<name>
Expects: NAMING REPLY RESULT=OK NAME=<name> VALUE=<destination>
§Errors
Returns an error if the session is shut down.