Browse Source

always use TCP/IP sockets for I2CP

pull/1742/head
orignal 3 years ago
parent
commit
48374d97df
  1. 8
      libi2pd_client/I2CP.cpp
  2. 10
      libi2pd_client/I2CP.h

8
libi2pd_client/I2CP.cpp

@ -274,7 +274,7 @@ namespace client
} }
} }
I2CPSession::I2CPSession (I2CPServer& owner, std::shared_ptr<proto::socket> socket): I2CPSession::I2CPSession (I2CPServer& owner, std::shared_ptr<boost::asio::ip::tcp::socket> socket):
m_Owner (owner), m_Socket (socket), m_SessionID (0xFFFF), m_Owner (owner), m_Socket (socket), m_SessionID (0xFFFF),
m_MessageID (0), m_IsSendAccepted (true), m_IsSending (false) m_MessageID (0), m_IsSendAccepted (true), m_IsSending (false)
{ {
@ -939,7 +939,7 @@ namespace client
I2CPServer::I2CPServer (const std::string& interface, int port, bool isSingleThread): I2CPServer::I2CPServer (const std::string& interface, int port, bool isSingleThread):
RunnableService ("I2CP"), m_IsSingleThread (isSingleThread), RunnableService ("I2CP"), m_IsSingleThread (isSingleThread),
m_Acceptor (GetIOService (), m_Acceptor (GetIOService (),
I2CPSession::proto::endpoint(boost::asio::ip::address::from_string(interface), port)) boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(interface), port))
{ {
memset (m_MessagesHandlers, 0, sizeof (m_MessagesHandlers)); memset (m_MessagesHandlers, 0, sizeof (m_MessagesHandlers));
m_MessagesHandlers[I2CP_GET_DATE_MESSAGE] = &I2CPSession::GetDateMessageHandler; m_MessagesHandlers[I2CP_GET_DATE_MESSAGE] = &I2CPSession::GetDateMessageHandler;
@ -981,13 +981,13 @@ namespace client
void I2CPServer::Accept () void I2CPServer::Accept ()
{ {
auto newSocket = std::make_shared<I2CPSession::proto::socket> (GetIOService ()); auto newSocket = std::make_shared<boost::asio::ip::tcp::socket> (GetIOService ());
m_Acceptor.async_accept (*newSocket, std::bind (&I2CPServer::HandleAccept, this, m_Acceptor.async_accept (*newSocket, std::bind (&I2CPServer::HandleAccept, this,
std::placeholders::_1, newSocket)); std::placeholders::_1, newSocket));
} }
void I2CPServer::HandleAccept(const boost::system::error_code& ecode, void I2CPServer::HandleAccept(const boost::system::error_code& ecode,
std::shared_ptr<I2CPSession::proto::socket> socket) std::shared_ptr<boost::asio::ip::tcp::socket> socket)
{ {
if (!ecode && socket) if (!ecode && socket)
{ {

10
libi2pd_client/I2CP.h

@ -142,9 +142,7 @@ namespace client
{ {
public: public:
typedef boost::asio::ip::tcp proto; I2CPSession (I2CPServer& owner, std::shared_ptr<boost::asio::ip::tcp::socket> socket);
I2CPSession (I2CPServer& owner, std::shared_ptr<proto::socket> socket);
~I2CPSession (); ~I2CPSession ();
@ -192,7 +190,7 @@ namespace client
private: private:
I2CPServer& m_Owner; I2CPServer& m_Owner;
std::shared_ptr<proto::socket> m_Socket; std::shared_ptr<boost::asio::ip::tcp::socket> m_Socket;
uint8_t m_Header[I2CP_HEADER_SIZE], m_Payload[I2CP_MAX_MESSAGE_LENGTH]; uint8_t m_Header[I2CP_HEADER_SIZE], m_Payload[I2CP_MAX_MESSAGE_LENGTH];
size_t m_PayloadLen; size_t m_PayloadLen;
@ -230,7 +228,7 @@ namespace client
void Accept (); void Accept ();
void HandleAccept(const boost::system::error_code& ecode, std::shared_ptr<I2CPSession::proto::socket> socket); void HandleAccept(const boost::system::error_code& ecode, std::shared_ptr<boost::asio::ip::tcp::socket> socket);
private: private:
@ -238,7 +236,7 @@ namespace client
I2CPMessageHandler m_MessagesHandlers[256]; I2CPMessageHandler m_MessagesHandlers[256];
std::map<uint16_t, std::shared_ptr<I2CPSession> > m_Sessions; std::map<uint16_t, std::shared_ptr<I2CPSession> > m_Sessions;
I2CPSession::proto::acceptor m_Acceptor; boost::asio::ip::tcp::acceptor m_Acceptor;
public: public:

Loading…
Cancel
Save