18#include <unordered_map>
33 std::unique_ptr<Sock>
sock;
137 std::unordered_map<std::string, std::optional<std::string>>
keys;
150 std::string
Get(
const std::string &key)
const;
158 template <
typename... Args>
159 void Log(
const std::string &fmt,
const Args &...args)
const;
172 const std::string &request,
173 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.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
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.
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.
const CService m_control_host
The host and port of the SAM control service.
Session(const fs::path &private_key_file, const CService &control_host, CThreadInterrupt *interrupt)
Construct a session.
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.
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.
CThreadInterrupt *const m_interrupt
Cease network activity when this is signaled.
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.
void Log(const std::string &fmt, const Args &...args) const
Log a message in the BCLog::I2P category.
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.
Filesystem operations and types.
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.
Implement std::hash so RCUPtr can be used as a key for maps or sets.
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(...)