![]() |
Bitcoin Core 31.1.0
P2P Digital Currency
|
I2P SAM session. More...
#include <i2p.h>
Classes | |
| struct | Reply |
| A reply from the SAM proxy. More... | |
Public Member Functions | |
| Session (const fs::path &private_key_file, const Proxy &control_host, std::shared_ptr< CThreadInterrupt > interrupt) | |
| Construct a session. | |
| Session (const Proxy &control_host, std::shared_ptr< CThreadInterrupt > interrupt) | |
| Construct a transient session which will generate its own I2P private key rather than read the one from disk (it will not be saved on disk either and will be lost once this object is destroyed). | |
| ~Session () | |
| Destroy the session, closing the internally used sockets. | |
| bool | Listen (Connection &conn) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) |
| Start listening for an incoming connection. | |
| bool | Accept (Connection &conn) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) |
| Wait for and accept a new incoming connection. | |
| bool | Connect (const CService &to, Connection &conn, bool &proxy_error) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) |
| Connect to an I2P peer. | |
Private Member Functions | |
| Reply | SendRequestAndGetReply (const Sock &sock, const std::string &request, bool check_result_ok=true) const |
| Send request and get a reply from the SAM proxy. | |
| std::unique_ptr< Sock > | Hello () const EXCLUSIVE_LOCKS_REQUIRED(m_mutex) |
| Open a new connection to the SAM proxy. | |
| void | CheckControlSock () EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) |
| Check the control socket for errors and possibly disconnect. | |
| void | DestGenerate (const Sock &sock) EXCLUSIVE_LOCKS_REQUIRED(m_mutex) |
| Generate a new destination with the SAM proxy and set m_private_key to it. | |
| void | GenerateAndSavePrivateKey (const Sock &sock) EXCLUSIVE_LOCKS_REQUIRED(m_mutex) |
| Generate a new destination with the SAM proxy, set m_private_key to it and save it on disk to m_private_key_file. | |
| Binary | MyDestination () const EXCLUSIVE_LOCKS_REQUIRED(m_mutex) |
| Derive own destination from m_private_key. | |
| void | CreateIfNotCreatedAlready () EXCLUSIVE_LOCKS_REQUIRED(m_mutex) |
| Create the session if not already created. | |
| std::unique_ptr< Sock > | StreamAccept () EXCLUSIVE_LOCKS_REQUIRED(m_mutex) |
| Open a new connection to the SAM proxy and issue "STREAM ACCEPT" request using the existing session id. | |
| void | Disconnect () EXCLUSIVE_LOCKS_REQUIRED(m_mutex) |
| Destroy the session, closing the internally used sockets. | |
| Binary m_private_key | GUARDED_BY (m_mutex) |
| The private key of this peer. | |
| std::unique_ptr< Sock > m_control_sock | GUARDED_BY (m_mutex) |
| SAM control socket. | |
| CService m_my_addr | GUARDED_BY (m_mutex) |
| Our .b32.i2p address. | |
| std::string m_session_id | GUARDED_BY (m_mutex) |
| SAM session id. | |
Private Attributes | |
| const fs::path | m_private_key_file |
| The name of the file where this peer's private key is stored (in binary). | |
| const Proxy | m_control_host |
| The SAM control service proxy. | |
| const std::shared_ptr< CThreadInterrupt > | m_interrupt |
| Cease network activity when this is signaled. | |
| Mutex | m_mutex |
| Mutex protecting the members that can be concurrently accessed. | |
| const bool | m_transient |
| Whether this is a transient session (the I2P private key will not be read or written to disk). | |
| i2p::sam::Session::Session | ( | const fs::path & | private_key_file, |
| const Proxy & | control_host, | ||
| std::shared_ptr< CThreadInterrupt > | interrupt ) |
Construct a session.
This will not initiate any IO, the session will be lazily created later when first used.
| [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. |
| [in] | control_host | Location of the SAM proxy. |
| [in,out] | interrupt | If this is signaled then all operations are canceled as soon as possible and executing methods throw an exception. |
| i2p::sam::Session::Session | ( | const Proxy & | control_host, |
| std::shared_ptr< CThreadInterrupt > | interrupt ) |
Construct a transient session which will generate its own I2P private key rather than read the one from disk (it will not be saved on disk either and will be lost once this object is destroyed).
This will not initiate any IO, the session will be lazily created later when first used.
| [in] | control_host | Location of the SAM proxy. |
| [in,out] | interrupt | If this is signaled then all operations are canceled as soon as possible and executing methods throw an exception. |
| i2p::sam::Session::~Session | ( | ) |
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.
Definition at line 137 of file i2p.cpp.
| bool i2p::sam::Session::Accept | ( | Connection & | conn | ) |
Wait for and accept a new incoming connection.
| [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. |
Definition at line 158 of file i2p.cpp.
|
private |
| bool i2p::sam::Session::Connect | ( | const CService & | to, |
| Connection & | conn, | ||
| bool & | proxy_error ) |
Connect to an I2P peer.
| [in] | to | Peer to connect to. |
| [out] | conn | Established connection. Only set if true is returned. |
| [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. |
Definition at line 222 of file i2p.cpp.
|
private |
|
private |
Generate a new destination with the SAM proxy and set m_private_key to it.
| [in] | sock | Socket to use for talking to the SAM proxy. |
| std::runtime_error | if an error occurs |
Definition at line 353 of file i2p.cpp.
|
private |
|
private |
Generate a new destination with the SAM proxy, set m_private_key to it and save it on disk to m_private_key_file.
| [in] | sock | Socket to use for talking to the SAM proxy. |
| std::runtime_error | if an error occurs |
Definition at line 364 of file i2p.cpp.
|
private |
SAM session id.
SAM control socket.
Used to connect to the I2P SAM service and create a session ("SESSION CREATE"). With the established session id we later open other connections to the SAM service to accept incoming I2P connections and make outgoing ones. If not connected then this unique_ptr will be empty. See https://geti2p.net/en/docs/api/samv3
The private key of this peer.
|
private |
| bool i2p::sam::Session::Listen | ( | Connection & | conn | ) |
Start listening for an incoming connection.
| [out] | conn | Upon successful completion the sock and me members will be set to the listening socket and address. |
Definition at line 143 of file i2p.cpp.
|
private |
|
private |
Send request and get a reply from the SAM proxy.
| [in] | sock | A socket that is connected to the SAM proxy. |
| [in] | request | Raw request to send, a newline terminator is appended to it. |
| [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. |
| std::runtime_error | if an error occurs |
Definition at line 293 of file i2p.cpp.
|
private |
Open a new connection to the SAM proxy and issue "STREAM ACCEPT" request using the existing session id.
| std::runtime_error | if an error occurs |
Definition at line 461 of file i2p.cpp.
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |