Skip to main content

SamSession

Struct SamSession 

Source
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

Source

pub async fn create( host: &str, port: u16, session_id: &str, tunnel_config: SamTunnelConfig, ) -> Result<Self, SamError>

Create a new SAM session.

  1. Connect to the SAM bridge at host:port
  2. Perform HELLO VERSION handshake (v3.1)
  3. 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.

Source

pub fn destination(&self) -> &I2pDestination

Our ephemeral I2P destination.

Source

pub fn session_id(&self) -> &str

The session ID.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for SamSession

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more