2020-05-22 13:18:41 +00:00
|
|
|
/*
|
2021-12-05 00:32:18 +00:00
|
|
|
* Copyright (c) 2013-2021, The PurpleI2P Project
|
2020-05-22 13:18:41 +00:00
|
|
|
*
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
|
|
*
|
|
|
|
* See full license text in LICENSE file at top of project tree
|
|
|
|
*/
|
|
|
|
|
2014-09-24 16:01:26 +00:00
|
|
|
#ifndef SAM_H__
|
|
|
|
#define SAM_H__
|
|
|
|
|
2014-09-24 18:59:03 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <string>
|
2014-09-24 20:39:31 +00:00
|
|
|
#include <map>
|
|
|
|
#include <list>
|
2021-05-13 23:30:54 +00:00
|
|
|
#include <set>
|
2014-09-24 16:01:26 +00:00
|
|
|
#include <thread>
|
2014-10-06 01:59:05 +00:00
|
|
|
#include <mutex>
|
2014-11-22 21:35:58 +00:00
|
|
|
#include <memory>
|
2014-09-24 16:01:26 +00:00
|
|
|
#include <boost/asio.hpp>
|
2020-02-04 16:48:56 +00:00
|
|
|
#include "util.h"
|
2014-10-02 16:42:28 +00:00
|
|
|
#include "Identity.h"
|
|
|
|
#include "LeaseSet.h"
|
2014-09-24 18:59:03 +00:00
|
|
|
#include "Streaming.h"
|
2014-10-22 15:46:54 +00:00
|
|
|
#include "Destination.h"
|
2014-09-24 16:01:26 +00:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
2014-10-16 14:28:44 +00:00
|
|
|
namespace client
|
2014-09-24 16:01:26 +00:00
|
|
|
{
|
2015-03-27 13:44:27 +00:00
|
|
|
const size_t SAM_SOCKET_BUFFER_SIZE = 8192;
|
2014-12-27 02:06:24 +00:00
|
|
|
const int SAM_SOCKET_CONNECTION_MAX_IDLE = 3600; // in seconds
|
2017-01-31 16:16:55 +00:00
|
|
|
const int SAM_SESSION_READINESS_CHECK_INTERVAL = 20; // in seconds
|
2014-09-24 18:59:03 +00:00
|
|
|
const char SAM_HANDSHAKE[] = "HELLO VERSION";
|
2014-12-16 20:54:02 +00:00
|
|
|
const char SAM_HANDSHAKE_REPLY[] = "HELLO REPLY RESULT=OK VERSION=%s\n";
|
2018-02-25 13:47:39 +00:00
|
|
|
const char SAM_HANDSHAKE_NOVERSION[] = "HELLO REPLY RESULT=NOVERSION\n";
|
2017-01-31 16:16:55 +00:00
|
|
|
const char SAM_HANDSHAKE_I2P_ERROR[] = "HELLO REPLY RESULT=I2P_ERROR\n";
|
2014-09-25 17:22:25 +00:00
|
|
|
const char SAM_SESSION_CREATE[] = "SESSION CREATE";
|
2014-10-03 01:40:15 +00:00
|
|
|
const char SAM_SESSION_CREATE_REPLY_OK[] = "SESSION STATUS RESULT=OK DESTINATION=%s\n";
|
2014-09-27 12:11:00 +00:00
|
|
|
const char SAM_SESSION_CREATE_DUPLICATED_ID[] = "SESSION STATUS RESULT=DUPLICATED_ID\n";
|
2017-01-31 16:16:55 +00:00
|
|
|
const char SAM_SESSION_CREATE_DUPLICATED_DEST[] = "SESSION STATUS RESULT=DUPLICATED_DEST\n";
|
2018-02-16 11:28:22 +00:00
|
|
|
const char SAM_SESSION_CREATE_INVALID_ID[] = "SESSION STATUS RESULT=INVALID_ID\n";
|
2015-06-24 19:19:10 +00:00
|
|
|
const char SAM_SESSION_STATUS_INVALID_KEY[] = "SESSION STATUS RESULT=INVALID_KEY\n";
|
2017-01-31 16:16:55 +00:00
|
|
|
const char SAM_SESSION_STATUS_I2P_ERROR[] = "SESSION STATUS RESULT=I2P_ERROR MESSAGE=%s\n";
|
2021-05-04 18:27:06 +00:00
|
|
|
const char SAM_SESSION_ADD[] = "SESSION ADD";
|
|
|
|
const char SAM_SESSION_REMOVE[] = "SESSION REMOVE";
|
2014-09-25 17:58:09 +00:00
|
|
|
const char SAM_STREAM_CONNECT[] = "STREAM CONNECT";
|
2014-09-27 12:11:00 +00:00
|
|
|
const char SAM_STREAM_STATUS_OK[] = "STREAM STATUS RESULT=OK\n";
|
|
|
|
const char SAM_STREAM_STATUS_INVALID_ID[] = "STREAM STATUS RESULT=INVALID_ID\n";
|
2019-03-29 13:29:28 +00:00
|
|
|
const char SAM_STREAM_STATUS_INVALID_KEY[] = "STREAM STATUS RESULT=INVALID_KEY\n";
|
2014-09-27 12:11:00 +00:00
|
|
|
const char SAM_STREAM_STATUS_CANT_REACH_PEER[] = "STREAM STATUS RESULT=CANT_REACH_PEER\n";
|
|
|
|
const char SAM_STREAM_STATUS_I2P_ERROR[] = "STREAM STATUS RESULT=I2P_ERROR\n";
|
2017-01-31 16:16:55 +00:00
|
|
|
const char SAM_STREAM_ACCEPT[] = "STREAM ACCEPT";
|
2020-10-25 21:20:15 +00:00
|
|
|
const char SAM_STREAM_FORWARD[] = "STREAM FORWARD";
|
2015-03-27 01:23:59 +00:00
|
|
|
const char SAM_DATAGRAM_SEND[] = "DATAGRAM SEND";
|
2019-07-10 17:30:31 +00:00
|
|
|
const char SAM_RAW_SEND[] = "RAW SEND";
|
2014-09-30 15:08:38 +00:00
|
|
|
const char SAM_DEST_GENERATE[] = "DEST GENERATE";
|
2017-01-31 16:16:55 +00:00
|
|
|
const char SAM_DEST_REPLY[] = "DEST REPLY PUB=%s PRIV=%s\n";
|
2014-09-30 15:08:38 +00:00
|
|
|
const char SAM_DEST_REPLY_I2P_ERROR[] = "DEST REPLY RESULT=I2P_ERROR\n";
|
2014-10-02 20:55:01 +00:00
|
|
|
const char SAM_NAMING_LOOKUP[] = "NAMING LOOKUP";
|
2020-12-19 01:48:08 +00:00
|
|
|
const char SAM_NAMING_REPLY[] = "NAMING REPLY RESULT=OK NAME=%s VALUE=%s\n";
|
2016-02-01 03:37:38 +00:00
|
|
|
const char SAM_DATAGRAM_RECEIVED[] = "DATAGRAM RECEIVED DESTINATION=%s SIZE=%lu\n";
|
2019-07-10 15:32:56 +00:00
|
|
|
const char SAM_RAW_RECEIVED[] = "RAW RECEIVED SIZE=%lu\n";
|
2014-10-03 19:08:41 +00:00
|
|
|
const char SAM_NAMING_REPLY_INVALID_KEY[] = "NAMING REPLY RESULT=INVALID_KEY NAME=%s\n";
|
2018-09-02 19:39:23 +00:00
|
|
|
const char SAM_NAMING_REPLY_KEY_NOT_FOUND[] = "NAMING REPLY RESULT=KEY_NOT_FOUND NAME=%s\n";
|
2017-01-31 16:16:55 +00:00
|
|
|
const char SAM_PARAM_MIN[] = "MIN";
|
|
|
|
const char SAM_PARAM_MAX[] = "MAX";
|
|
|
|
const char SAM_PARAM_STYLE[] = "STYLE";
|
|
|
|
const char SAM_PARAM_ID[] = "ID";
|
2014-09-29 18:18:06 +00:00
|
|
|
const char SAM_PARAM_SILENT[] = "SILENT";
|
2017-01-31 16:16:55 +00:00
|
|
|
const char SAM_PARAM_DESTINATION[] = "DESTINATION";
|
2014-12-16 21:23:42 +00:00
|
|
|
const char SAM_PARAM_NAME[] = "NAME";
|
2017-01-31 16:16:55 +00:00
|
|
|
const char SAM_PARAM_SIGNATURE_TYPE[] = "SIGNATURE_TYPE";
|
2017-11-14 20:05:07 +00:00
|
|
|
const char SAM_PARAM_CRYPTO_TYPE[] = "CRYPTO_TYPE";
|
2015-03-27 01:23:59 +00:00
|
|
|
const char SAM_PARAM_SIZE[] = "SIZE";
|
2020-10-25 21:20:15 +00:00
|
|
|
const char SAM_PARAM_HOST[] = "HOST";
|
|
|
|
const char SAM_PARAM_PORT[] = "PORT";
|
2021-05-13 23:30:54 +00:00
|
|
|
const char SAM_PARAM_FROM_PORT[] = "FROM_PORT";
|
2017-01-31 16:16:55 +00:00
|
|
|
const char SAM_VALUE_TRANSIENT[] = "TRANSIENT";
|
2014-10-22 20:42:26 +00:00
|
|
|
const char SAM_VALUE_STREAM[] = "STREAM";
|
|
|
|
const char SAM_VALUE_DATAGRAM[] = "DATAGRAM";
|
2017-01-31 16:16:55 +00:00
|
|
|
const char SAM_VALUE_RAW[] = "RAW";
|
2021-11-27 20:30:35 +00:00
|
|
|
const char SAM_VALUE_MASTER[] = "MASTER";
|
2017-01-31 16:16:55 +00:00
|
|
|
const char SAM_VALUE_TRUE[] = "true";
|
2017-01-30 01:38:18 +00:00
|
|
|
const char SAM_VALUE_FALSE[] = "false";
|
2014-09-25 17:22:25 +00:00
|
|
|
|
|
|
|
enum SAMSocketType
|
|
|
|
{
|
|
|
|
eSAMSocketTypeUnknown,
|
|
|
|
eSAMSocketTypeSession,
|
2014-09-26 19:40:57 +00:00
|
|
|
eSAMSocketTypeStream,
|
2014-11-23 02:56:59 +00:00
|
|
|
eSAMSocketTypeAcceptor,
|
2020-10-25 21:20:15 +00:00
|
|
|
eSAMSocketTypeForward,
|
2014-11-23 02:56:59 +00:00
|
|
|
eSAMSocketTypeTerminated
|
2014-09-25 17:22:25 +00:00
|
|
|
};
|
2014-09-24 18:59:03 +00:00
|
|
|
|
|
|
|
class SAMBridge;
|
2014-12-29 16:40:03 +00:00
|
|
|
struct SAMSession;
|
2018-04-25 15:27:56 +00:00
|
|
|
class SAMSocket: public std::enable_shared_from_this<SAMSocket>
|
2014-09-24 18:59:03 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2018-01-15 13:19:57 +00:00
|
|
|
typedef boost::asio::ip::tcp::socket Socket_t;
|
2018-04-24 13:45:16 +00:00
|
|
|
SAMSocket (SAMBridge& owner);
|
2020-03-01 10:25:50 +00:00
|
|
|
~SAMSocket ();
|
2014-12-04 16:24:00 +00:00
|
|
|
|
2018-04-24 13:45:16 +00:00
|
|
|
Socket_t& GetSocket () { return m_Socket; };
|
2014-09-24 18:59:03 +00:00
|
|
|
void ReceiveHandshake ();
|
2014-12-04 16:24:00 +00:00
|
|
|
void SetSocketType (SAMSocketType socketType) { m_SocketType = socketType; };
|
2015-02-21 03:47:36 +00:00
|
|
|
SAMSocketType GetSocketType () const { return m_SocketType; };
|
2014-09-24 18:59:03 +00:00
|
|
|
|
2018-01-15 13:25:58 +00:00
|
|
|
void Terminate (const char* reason);
|
2017-06-02 15:43:33 +00:00
|
|
|
|
2018-04-25 15:25:49 +00:00
|
|
|
bool IsSession(const std::string & id) const;
|
2020-03-01 10:25:50 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2018-04-25 15:25:49 +00:00
|
|
|
void TerminateClose() { Terminate(nullptr); }
|
2020-03-01 10:25:50 +00:00
|
|
|
|
2018-04-25 15:25:49 +00:00
|
|
|
void HandleHandshakeReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
2014-09-24 18:59:03 +00:00
|
|
|
void HandleHandshakeReplySent (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
2014-09-25 17:22:25 +00:00
|
|
|
void HandleMessage (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
2017-01-31 16:16:55 +00:00
|
|
|
void SendMessageReply (const char * msg, size_t len, bool close);
|
2014-09-25 17:22:25 +00:00
|
|
|
void HandleMessageReplySent (const boost::system::error_code& ecode, std::size_t bytes_transferred, bool close);
|
2014-09-24 18:59:03 +00:00
|
|
|
void Receive ();
|
|
|
|
void HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
|
|
|
|
2017-01-31 16:16:55 +00:00
|
|
|
void I2PReceive ();
|
2014-09-26 19:40:57 +00:00
|
|
|
void HandleI2PReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
2014-11-23 16:33:58 +00:00
|
|
|
void HandleI2PAccept (std::shared_ptr<i2p::stream::Stream> stream);
|
2020-10-25 21:20:15 +00:00
|
|
|
void HandleI2PForward (std::shared_ptr<i2p::stream::Stream> stream, boost::asio::ip::tcp::endpoint ep);
|
2018-01-15 13:25:58 +00:00
|
|
|
void HandleWriteI2PData (const boost::system::error_code& ecode, size_t sz);
|
2015-03-03 20:31:49 +00:00
|
|
|
void HandleI2PDatagramReceive (const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);
|
2019-07-10 15:32:56 +00:00
|
|
|
void HandleI2PRawDatagramReceive (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);
|
2014-09-24 18:59:03 +00:00
|
|
|
|
2014-09-25 17:22:25 +00:00
|
|
|
void ProcessSessionCreate (char * buf, size_t len);
|
2017-03-29 17:59:48 +00:00
|
|
|
void ProcessStreamConnect (char * buf, size_t len, size_t rem);
|
2014-09-26 19:40:57 +00:00
|
|
|
void ProcessStreamAccept (char * buf, size_t len);
|
2020-10-25 21:20:15 +00:00
|
|
|
void ProcessStreamForward (char * buf, size_t len);
|
2017-03-30 19:43:02 +00:00
|
|
|
void ProcessDestGenerate (char * buf, size_t len);
|
2014-10-02 20:55:01 +00:00
|
|
|
void ProcessNamingLookup (char * buf, size_t len);
|
2021-05-04 18:27:06 +00:00
|
|
|
void ProcessSessionAdd (char * buf, size_t len);
|
|
|
|
void ProcessSessionRemove (char * buf, size_t len);
|
2017-01-31 16:16:55 +00:00
|
|
|
void SendI2PError(const std::string & msg);
|
|
|
|
size_t ProcessDatagramSend (char * buf, size_t len, const char * data); // from SAM 1.0
|
2015-03-27 01:23:59 +00:00
|
|
|
void ExtractParams (char * buf, std::map<std::string, std::string>& params);
|
2014-09-25 17:22:25 +00:00
|
|
|
|
2020-06-18 01:06:35 +00:00
|
|
|
void Connect (std::shared_ptr<const i2p::data::LeaseSet> remote, std::shared_ptr<SAMSession> session = nullptr);
|
2015-04-07 16:02:25 +00:00
|
|
|
void HandleConnectLeaseSetRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet);
|
2020-12-19 01:48:08 +00:00
|
|
|
void SendNamingLookupReply (const std::string& name, std::shared_ptr<const i2p::data::IdentityEx> identity);
|
2019-03-29 15:59:59 +00:00
|
|
|
void HandleNamingLookupLeaseSetRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet, std::string name);
|
2014-10-16 20:36:12 +00:00
|
|
|
void HandleSessionReadinessCheckTimer (const boost::system::error_code& ecode);
|
|
|
|
void SendSessionCreateReplyOk ();
|
2014-10-02 16:42:28 +00:00
|
|
|
|
2018-01-15 13:25:58 +00:00
|
|
|
void WriteI2PData(size_t sz);
|
|
|
|
void WriteI2PDataImmediate(uint8_t * ptr, size_t sz);
|
2018-01-15 13:19:57 +00:00
|
|
|
|
2018-01-15 13:25:58 +00:00
|
|
|
void HandleWriteI2PDataImmediate(const boost::system::error_code & ec, uint8_t * buff);
|
2018-04-25 15:25:49 +00:00
|
|
|
void HandleStreamSend(const boost::system::error_code & ec);
|
2020-03-01 10:25:50 +00:00
|
|
|
|
2014-09-24 18:59:03 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
SAMBridge& m_Owner;
|
2018-04-24 13:45:16 +00:00
|
|
|
Socket_t m_Socket;
|
2014-10-02 16:42:28 +00:00
|
|
|
boost::asio::deadline_timer m_Timer;
|
2014-09-24 18:59:03 +00:00
|
|
|
char m_Buffer[SAM_SOCKET_BUFFER_SIZE + 1];
|
2015-03-27 18:02:27 +00:00
|
|
|
size_t m_BufferOffset;
|
2014-09-24 18:59:03 +00:00
|
|
|
uint8_t m_StreamBuffer[SAM_SOCKET_BUFFER_SIZE];
|
2014-09-25 17:22:25 +00:00
|
|
|
SAMSocketType m_SocketType;
|
|
|
|
std::string m_ID; // nickname
|
2014-09-29 18:18:06 +00:00
|
|
|
bool m_IsSilent;
|
2018-01-06 03:48:51 +00:00
|
|
|
bool m_IsAccepting; // for eSAMSocketTypeAcceptor only
|
2014-11-23 16:33:58 +00:00
|
|
|
std::shared_ptr<i2p::stream::Stream> m_Stream;
|
2017-01-31 16:16:55 +00:00
|
|
|
};
|
2014-09-24 18:59:03 +00:00
|
|
|
|
2019-07-10 15:32:56 +00:00
|
|
|
enum SAMSessionType
|
|
|
|
{
|
|
|
|
eSAMSessionTypeUnknown,
|
|
|
|
eSAMSessionTypeStream,
|
|
|
|
eSAMSessionTypeDatagram,
|
2021-04-21 23:30:20 +00:00
|
|
|
eSAMSessionTypeRaw,
|
|
|
|
eSAMSessionTypeMaster
|
2019-07-10 15:32:56 +00:00
|
|
|
};
|
|
|
|
|
2014-09-24 20:39:31 +00:00
|
|
|
struct SAMSession
|
|
|
|
{
|
2018-04-25 15:25:49 +00:00
|
|
|
SAMBridge & m_Bridge;
|
|
|
|
std::string Name;
|
2019-07-10 15:32:56 +00:00
|
|
|
SAMSessionType Type;
|
2021-04-27 01:11:36 +00:00
|
|
|
std::shared_ptr<boost::asio::ip::udp::endpoint> UDPEndpoint; // TODO: move
|
2021-11-27 20:30:35 +00:00
|
|
|
|
2021-04-27 01:11:36 +00:00
|
|
|
SAMSession (SAMBridge & parent, const std::string & name, SAMSessionType type);
|
|
|
|
virtual ~SAMSession () {};
|
2021-11-27 20:30:35 +00:00
|
|
|
|
2021-04-27 01:11:36 +00:00
|
|
|
virtual std::shared_ptr<ClientDestination> GetLocalDestination () = 0;
|
2021-05-04 18:27:06 +00:00
|
|
|
virtual void StopLocalDestination () = 0;
|
2021-05-13 23:30:54 +00:00
|
|
|
virtual void Close () { CloseStreams (); };
|
2021-11-27 20:30:35 +00:00
|
|
|
|
2014-12-17 20:21:50 +00:00
|
|
|
void CloseStreams ();
|
2014-09-24 20:39:31 +00:00
|
|
|
};
|
2021-04-27 01:11:36 +00:00
|
|
|
|
|
|
|
struct SAMSingleSession: public SAMSession
|
|
|
|
{
|
|
|
|
std::shared_ptr<ClientDestination> localDestination;
|
|
|
|
|
|
|
|
SAMSingleSession (SAMBridge & parent, const std::string & name, SAMSessionType type, std::shared_ptr<ClientDestination> dest);
|
|
|
|
~SAMSingleSession ();
|
|
|
|
|
|
|
|
std::shared_ptr<ClientDestination> GetLocalDestination () { return localDestination; };
|
2021-05-04 18:27:06 +00:00
|
|
|
void StopLocalDestination ();
|
2021-11-27 20:30:35 +00:00
|
|
|
};
|
2021-04-27 01:11:36 +00:00
|
|
|
|
|
|
|
struct SAMMasterSession: public SAMSingleSession
|
|
|
|
{
|
2021-05-13 23:30:54 +00:00
|
|
|
std::set<std::string> subsessions;
|
2021-04-27 01:11:36 +00:00
|
|
|
SAMMasterSession (SAMBridge & parent, const std::string & name, std::shared_ptr<ClientDestination> dest):
|
|
|
|
SAMSingleSession (parent, name, eSAMSessionTypeMaster, dest) {};
|
2021-11-27 20:30:35 +00:00
|
|
|
void Close ();
|
|
|
|
};
|
2021-05-04 18:27:06 +00:00
|
|
|
|
|
|
|
struct SAMSubSession: public SAMSession
|
|
|
|
{
|
|
|
|
std::shared_ptr<SAMMasterSession> masterSession;
|
|
|
|
int inPort;
|
|
|
|
|
|
|
|
SAMSubSession (std::shared_ptr<SAMMasterSession> master, const std::string& name, SAMSessionType type, int port);
|
|
|
|
// implements SAMSession
|
|
|
|
std::shared_ptr<ClientDestination> GetLocalDestination ();
|
|
|
|
void StopLocalDestination ();
|
2021-11-27 20:30:35 +00:00
|
|
|
};
|
|
|
|
|
2020-02-04 16:48:56 +00:00
|
|
|
class SAMBridge: private i2p::util::RunnableService
|
2014-09-24 16:01:26 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-02-04 20:31:04 +00:00
|
|
|
SAMBridge (const std::string& address, int port, bool singleThread);
|
2014-09-24 16:01:26 +00:00
|
|
|
~SAMBridge ();
|
|
|
|
|
|
|
|
void Start ();
|
|
|
|
void Stop ();
|
2017-01-31 16:16:55 +00:00
|
|
|
|
2020-02-04 16:48:56 +00:00
|
|
|
boost::asio::io_service& GetService () { return GetIOService (); };
|
2020-03-01 10:25:50 +00:00
|
|
|
std::shared_ptr<SAMSession> CreateSession (const std::string& id, SAMSessionType type, const std::string& destination, // empty string means transient
|
2014-12-16 21:23:42 +00:00
|
|
|
const std::map<std::string, std::string> * params);
|
2021-05-13 23:30:54 +00:00
|
|
|
bool AddSession (std::shared_ptr<SAMSession> session);
|
2014-09-24 20:39:31 +00:00
|
|
|
void CloseSession (const std::string& id);
|
2016-04-03 02:16:49 +00:00
|
|
|
std::shared_ptr<SAMSession> FindSession (const std::string& id) const;
|
2014-09-24 16:01:26 +00:00
|
|
|
|
2018-04-25 15:25:49 +00:00
|
|
|
std::list<std::shared_ptr<SAMSocket> > ListSockets(const std::string & id) const;
|
2018-04-24 13:45:16 +00:00
|
|
|
|
2017-01-31 16:16:55 +00:00
|
|
|
/** send raw data to remote endpoint from our UDP Socket */
|
2021-12-05 00:32:18 +00:00
|
|
|
void SendTo (const std::vector<boost::asio::const_buffer>& bufs, const boost::asio::ip::udp::endpoint& ep);
|
|
|
|
|
2020-10-25 21:20:15 +00:00
|
|
|
void AddSocket(std::shared_ptr<SAMSocket> socket);
|
2018-04-25 15:25:49 +00:00
|
|
|
void RemoveSocket(const std::shared_ptr<SAMSocket> & socket);
|
2020-03-01 10:25:50 +00:00
|
|
|
|
|
|
|
bool ResolveSignatureType (const std::string& name, i2p::data::SigningKeyType& type) const;
|
2019-01-23 15:52:17 +00:00
|
|
|
|
2014-09-24 16:01:26 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
void Accept ();
|
2018-04-25 15:25:49 +00:00
|
|
|
void HandleAccept(const boost::system::error_code& ecode, std::shared_ptr<SAMSocket> socket);
|
2014-09-24 16:01:26 +00:00
|
|
|
|
2014-10-22 20:42:26 +00:00
|
|
|
void ReceiveDatagram ();
|
|
|
|
void HandleReceivedDatagram (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
|
|
|
|
2014-09-24 16:01:26 +00:00
|
|
|
private:
|
|
|
|
|
2020-02-04 20:31:04 +00:00
|
|
|
bool m_IsSingleThread;
|
2014-09-24 16:01:26 +00:00
|
|
|
boost::asio::ip::tcp::acceptor m_Acceptor;
|
2014-10-22 20:42:26 +00:00
|
|
|
boost::asio::ip::udp::endpoint m_DatagramEndpoint, m_SenderEndpoint;
|
|
|
|
boost::asio::ip::udp::socket m_DatagramSocket;
|
2015-02-21 03:47:36 +00:00
|
|
|
mutable std::mutex m_SessionsMutex;
|
2016-04-03 02:16:49 +00:00
|
|
|
std::map<std::string, std::shared_ptr<SAMSession> > m_Sessions;
|
2018-04-25 15:25:49 +00:00
|
|
|
mutable std::mutex m_OpenSocketsMutex;
|
|
|
|
std::list<std::shared_ptr<SAMSocket> > m_OpenSockets;
|
2014-10-24 01:14:17 +00:00
|
|
|
uint8_t m_DatagramReceiveBuffer[i2p::datagram::MAX_DATAGRAM_SIZE+1];
|
2019-01-23 15:52:17 +00:00
|
|
|
std::map<std::string, i2p::data::SigningKeyType> m_SignatureTypes;
|
2015-02-21 03:47:36 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// for HTTP
|
|
|
|
const decltype(m_Sessions)& GetSessions () const { return m_Sessions; };
|
2017-01-31 16:16:55 +00:00
|
|
|
};
|
2014-09-24 16:01:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|