Struct bitcoin_sam::SAMSession

source ·
pub struct SAMSession { /* private fields */ }
Expand description

| I2P SAM session. |

Implementations§

source§

impl SAMSession

source

pub fn new( private_key_file: &Path, control_host: &Service, interrupt: Amo<ThreadInterrupt> ) -> Self

| Construct a session. This will not initiate | any IO, the session will be lazily created | later when first used. | | ———– | @param[in] private_key_file | | Path to a private key file. If the file | does not exist then the private key will | be generated and saved into the file. | ––––– | @param[in] control_host | | Location of the SAM proxy. | ––––– | @param[in,out] interrupt | | If this is signaled then all operations | are canceled as soon as possible and | executing methods throw an exception. | Notice: only a pointer to the CThreadInterrupt | object is saved, so it must not be destroyed | earlier than this Session object. |

source

pub fn listen(&mut self, conn: &mut Connection) -> bool

| Start listening for an incoming connection. | | ———– | @param[out] conn | | Upon successful completion the sock | and me members will be set to the listening | socket and address. | | ———– | @return | | true on success |

source

pub fn accept(&mut self, conn: &mut Connection) -> bool

| Wait for and accept a new incoming connection. | | ———– | @param[in,out] conn | | The sock member is used for waiting | and accepting. Upon successful completion | the peer member will be set to the address | of the incoming peer. | | ———– | @return | | true on success |

source

pub fn connect( &mut self, to: &Service, conn: &mut Connection, proxy_error: &mut bool ) -> bool

| Connect to an I2P peer. | | ———– | @param[in] to | | Peer to connect to. | ––––– | @param[out] conn | | Established connection. Only set if | true is returned. | ––––– | @param[out] proxy_error | | If an error occurs due to proxy or general | network failure, then this is set to | true. If an error occurs due to unreachable | peer (likely peer is down), then it is | set to false. Only set if false is | returned. | | ———– | @return | | true on success |

source

pub fn log<Args>(&self, fmt: &str, args: &Args)

| Log a message in the BCLog::I2P category. | | ———– | @param[in] fmt | | printf(3)-like format string. | ––––– | @param[in] args | | printf(3)-like arguments that correspond | to fmt. |

source

pub fn send_request_and_get_reply( &self, sock: &Sock, request: &str, check_result_ok: Option<bool> ) -> SAMSessionReply

| Send request and get a reply from the | SAM proxy. | | ———– | @param[in] sock | | A socket that is connected to the SAM | proxy. | ––––– | @param[in] request | | Raw request to send, a newline terminator | is appended to it. | ––––– | @param[in] check_result_ok | | If true then after receiving the reply | a check is made whether it contains “RESULT=OK” | and an exception is thrown if it does | not. @throws std::runtime_error if | an error occurs |

source

pub fn hello(&self) -> Box<Sock>

| Open a new connection to the SAM proxy. | | | ———– | @return | | a connected socket @throws std::runtime_error | if an error occurs |

source

pub fn check_control_sock(&mut self)

| Check the control socket for errors | and possibly disconnect. |

source

pub fn dest_generate(&mut self, sock: &Sock)

| Generate a new destination with the | SAM proxy and set m_private_key to | it. | | ———– | @param[in] sock | | Socket to use for talking to the SAM proxy. | @throws std::runtime_error if an error | occurs |

source

pub fn generate_and_save_private_key(&mut self, sock: &Sock)

| Generate a new destination with the | SAM proxy, set m_private_key to it | and save it on disk to m_private_key_file. | | ———– | @param[in] sock | | Socket to use for talking to the SAM proxy. | @throws std::runtime_error if an error | occurs |

source

pub fn my_destination(&self) -> Binary

| Derive own destination from m_private_key. | @see https://geti2p.net/spec/common-structures#destination | | | ———– | @return | | an I2P destination |

source

pub fn create_if_not_created_already(&mut self)

| Create the session if not already created. | Reads the private key file and connects | to the | | SAM proxy. @throws std::runtime_error | if an error occurs |

source

pub fn stream_accept(&mut self) -> Box<Sock>

| Open a new connection to the SAM proxy | and issue “STREAM ACCEPT” request using | the existing session id. | | | ———– | @return | | the idle socket that is waiting for a | peer to connect to us @throws std::runtime_error | if an error occurs |

source

pub fn disconnect(&mut self)

| Destroy the session, closing the internally | used sockets. |

Trait Implementations§

source§

impl Drop for SAMSession

source§

fn drop(&mut self)

| Destroy the session, closing the internally | used sockets. The sockets that have | been returned by Accept() or Connect() | will not be closed, but they will be closed | by the SAM proxy because the session | is destroyed. So they will return an | error next time we try to read or write | to them. |

source§

impl Send for SAMSession

source§

impl Sync for SAMSession

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
§

impl<T, U> CastInto<U> for Twhere U: CastFrom<T>,

§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> StaticUpcast<T> for T

§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V