I2P SAM session.
More...
#include <i2p.h>
I2P SAM session.
Definition at line 57 of file i2p.h.
◆ Session()
Construct a session.
This will not initiate any IO, the session will be lazily created later when first used.
- Parameters
-
[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. Notice: only a pointer to the CThreadInterrupt object is saved, so it must not be destroyed earlier than this Session object. |
Definition at line 114 of file i2p.cpp.
◆ ~Session()
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 120 of file i2p.cpp.
◆ Accept()
Wait for and accept a new incoming connection.
- Parameters
-
[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. |
- Returns
- true on success
Definition at line 139 of file i2p.cpp.
◆ CheckControlSock()
void i2p::sam::Session::CheckControlSock |
( |
| ) |
|
|
private |
Check the control socket for errors and possibly disconnect.
Definition at line 302 of file i2p.cpp.
◆ Connect()
Connect to an I2P peer.
- Parameters
-
[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. |
- Returns
- true on success
Definition at line 165 of file i2p.cpp.
◆ CreateIfNotCreatedAlready()
void i2p::sam::Session::CreateIfNotCreatedAlready |
( |
| ) |
|
|
private |
Create the session if not already created.
Reads the private key file and connects to the SAM proxy.
- Exceptions
-
std::runtime_error | if an error occurs |
Definition at line 353 of file i2p.cpp.
◆ DestGenerate()
void i2p::sam::Session::DestGenerate |
( |
const Sock & |
sock | ) |
|
|
private |
Generate a new destination with the SAM proxy and set m_private_key
to it.
- Parameters
-
[in] | sock | Socket to use for talking to the SAM proxy. |
- Exceptions
-
std::runtime_error | if an error occurs |
Definition at line 312 of file i2p.cpp.
◆ Disconnect()
void i2p::sam::Session::Disconnect |
( |
| ) |
|
|
private |
Destroy the session, closing the internally used sockets.
Definition at line 410 of file i2p.cpp.
◆ GenerateAndSavePrivateKey()
void i2p::sam::Session::GenerateAndSavePrivateKey |
( |
const Sock & |
sock | ) |
|
|
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
.
- Parameters
-
[in] | sock | Socket to use for talking to the SAM proxy. |
- Exceptions
-
std::runtime_error | if an error occurs |
Definition at line 323 of file i2p.cpp.
◆ GUARDED_BY() [1/4]
◆ GUARDED_BY() [2/4]
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. See https://geti2p.net/en/docs/api/samv3
◆ GUARDED_BY() [3/4]
Our .b32.i2p address.
Derived from m_private_key
.
◆ GUARDED_BY() [4/4]
◆ Hello()
std::unique_ptr< Sock > i2p::sam::Session::Hello |
( |
| ) |
const |
|
private |
Open a new connection to the SAM proxy.
- Returns
- a connected socket
- Exceptions
-
std::runtime_error | if an error occurs |
Definition at line 284 of file i2p.cpp.
◆ Listen()
Start listening for an incoming connection.
- Parameters
-
[out] | conn | Upon successful completion the sock and me members will be set to the listening socket and address. |
- Returns
- true on success
Definition at line 125 of file i2p.cpp.
◆ Log()
template<typename... Args>
void i2p::sam::Session::Log |
( |
const std::string & |
fmt, |
|
|
const Args &... |
args |
|
) |
| const |
|
private |
Log a message in the BCLog::I2P
category.
- Parameters
-
[in] | fmt | printf(3)-like format string. |
[in] | args | printf(3)-like arguments that correspond to fmt . |
Definition at line 239 of file i2p.cpp.
◆ MyDestination()
Binary i2p::sam::Session::MyDestination |
( |
| ) |
const |
|
private |
◆ SendRequestAndGetReply()
Session::Reply i2p::sam::Session::SendRequestAndGetReply |
( |
const Sock & |
sock, |
|
|
const std::string & |
request, |
|
|
bool |
check_result_ok = true |
|
) |
| const |
|
private |
Send request and get a reply from the SAM proxy.
- Parameters
-
[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. |
- Exceptions
-
std::runtime_error | if an error occurs |
Definition at line 243 of file i2p.cpp.
◆ StreamAccept()
std::unique_ptr< Sock > i2p::sam::Session::StreamAccept |
( |
| ) |
|
|
private |
Open a new connection to the SAM proxy and issue "STREAM ACCEPT" request using the existing session id.
- Returns
- the idle socket that is waiting for a peer to connect to us
- Exceptions
-
std::runtime_error | if an error occurs |
Definition at line 388 of file i2p.cpp.
◆ m_control_host
const CService i2p::sam::Session::m_control_host |
|
private |
The host and port of the SAM control service.
Definition at line 240 of file i2p.h.
◆ m_interrupt
Cease network activity when this is signaled.
Definition at line 245 of file i2p.h.
◆ m_mutex
Mutex i2p::sam::Session::m_mutex |
|
mutableprivate |
Mutex protecting the members that can be concurrently accessed.
Definition at line 250 of file i2p.h.
◆ m_private_key_file
const fs::path i2p::sam::Session::m_private_key_file |
|
private |
The name of the file where this peer's private key is stored (in binary).
Definition at line 235 of file i2p.h.
The documentation for this class was generated from the following files: