14#include <util/threadinterrupt.h> 
   19#include <unordered_map> 
   34    std::unique_ptr<Sock> 
sock;
 
   68    Session(
const fs::path& private_key_file,
 
   69            const Proxy& control_host,
 
   70            std::shared_ptr<CThreadInterrupt> interrupt);
 
   81    Session(
const Proxy& control_host, std::shared_ptr<CThreadInterrupt> interrupt);
 
  140        std::unordered_map<std::string, std::optional<std::string>> 
keys;
 
  152        std::string 
Get(
const std::string& key) 
const;
 
  164                                 const std::string& request,
 
  165                                 bool check_result_ok = 
true) 
const;
 
A combination of a network address (CNetAddr) and a (TCP) port.
 
A helper class for interruptible sleeps.
 
RAII helper class that manages a socket and closes it automatically when it goes out of scope.
 
const fs::path m_private_key_file
The name of the file where this peer's private key is stored (in binary).
 
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.
 
Session(const fs::path &private_key_file, const Proxy &control_host, std::shared_ptr< CThreadInterrupt > interrupt)
Construct a session.
 
bool Listen(Connection &conn) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Start listening for an incoming connection.
 
void CreateIfNotCreatedAlready() EXCLUSIVE_LOCKS_REQUIRED(m_mutex)
Create the session if not already created.
 
void Disconnect() EXCLUSIVE_LOCKS_REQUIRED(m_mutex)
Destroy the session, closing the internally used sockets.
 
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.
 
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 i...
 
Binary MyDestination() const EXCLUSIVE_LOCKS_REQUIRED(m_mutex)
Derive own destination from m_private_key.
 
~Session()
Destroy the session, closing the internally used sockets.
 
const bool m_transient
Whether this is a transient session (the I2P private key will not be read or written to disk).
 
const std::shared_ptr< CThreadInterrupt > m_interrupt
Cease network activity when this is signaled.
 
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_priva...
 
bool Connect(const CService &to, Connection &conn, bool &proxy_error) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Connect to an I2P peer.
 
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.
 
Binary m_private_key GUARDED_BY(m_mutex)
The private key of this peer.
 
Mutex m_mutex
Mutex protecting the members that can be concurrently accessed.
 
bool Accept(Connection &conn) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Wait for and accept a new incoming connection.
 
const Proxy m_control_host
The SAM control service proxy.
 
static constexpr size_t MAX_MSG_SIZE
The maximum size of an incoming message from the I2P SAM proxy (in bytes).
 
std::vector< uint8_t > Binary
Binary data.
 
An established connection with another peer.
 
std::unique_ptr< Sock > sock
Connected socket.
 
CService me
Our I2P address.
 
CService peer
The peer's I2P address.
 
A reply from the SAM proxy.
 
std::string Get(const std::string &key) const
Get the value of a given key.
 
std::string full
Full, unparsed reply.
 
std::unordered_map< std::string, std::optional< std::string > > keys
A map of keywords from the parsed reply.
 
std::string request
Request, used for detailed error reporting.
 
#define EXCLUSIVE_LOCKS_REQUIRED(...)