Struct bitcoin_sam::SAMSession
source · pub struct SAMSession { /* private fields */ }Expand description
| I2P SAM session. |
Implementations§
source§impl SAMSession
impl SAMSession
sourcepub fn new(
private_key_file: &Path,
control_host: &Service,
interrupt: Amo<ThreadInterrupt>
) -> Self
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.
|
sourcepub fn listen(&mut self, conn: &mut Connection) -> bool
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
|
sourcepub fn accept(&mut self, conn: &mut Connection) -> bool
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
|
sourcepub fn connect(
&mut self,
to: &Service,
conn: &mut Connection,
proxy_error: &mut bool
) -> bool
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
|
sourcepub fn log<Args>(&self, fmt: &str, args: &Args)
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.
|
sourcepub fn send_request_and_get_reply(
&self,
sock: &Sock,
request: &str,
check_result_ok: Option<bool>
) -> SAMSessionReply
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 |
sourcepub fn hello(&self) -> Box<Sock>
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 |
sourcepub fn check_control_sock(&mut self)
pub fn check_control_sock(&mut self)
| Check the control socket for errors | and possibly disconnect. |
sourcepub fn dest_generate(&mut self, sock: &Sock)
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
|
sourcepub fn generate_and_save_private_key(&mut self, sock: &Sock)
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
|
sourcepub fn my_destination(&self) -> Binary
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
|
sourcepub fn create_if_not_created_already(&mut self)
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 |
sourcepub fn stream_accept(&mut self) -> Box<Sock>
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 |
sourcepub fn disconnect(&mut self)
pub fn disconnect(&mut self)
| Destroy the session, closing the internally | used sockets. |
Trait Implementations§
source§impl Drop for SAMSession
impl Drop for SAMSession
source§fn drop(&mut self)
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.
|