connect to NTCP2

This commit is contained in:
orignal 2018-06-11 12:29:30 -04:00
parent 5cb81f8532
commit 74c0b729c2
2 changed files with 129 additions and 8 deletions

View file

@ -18,6 +18,7 @@ namespace transport
NTCP2Session (NTCP2Server& server, std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter = nullptr); // TODO
~NTCP2Session ();
void Terminate ();
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
@ -25,32 +26,49 @@ namespace transport
private:
bool KeyDerivationFunction (const uint8_t * rs, const uint8_t * pub, uint8_t * derived);
bool KeyDerivationFunction1 (const uint8_t * rs, const uint8_t * pub, uint8_t * derived); // for SessionRequest
void CreateEphemeralKey (uint8_t * pub);
void SendSessionRequest ();
void HandleSessionRequestSent (const boost::system::error_code& ecode, std::size_t bytes_transferred);
void HandleSessionCreatedReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred);
private:
NTCP2Server& m_Server;
boost::asio::ip::tcp::socket m_Socket;
bool m_IsEstablished, m_IsTerminated;
uint8_t m_ExpandedPrivateKey[64]; // x25519 ephemeral key
uint8_t m_RemoteStaticKey[32], m_RemoteIV[16];
uint8_t * m_SessionRequestBuffer;
uint8_t * m_SessionRequestBuffer, * m_SessionCreatedBuffer;
};
class NTCP2Server
{
public:
NTCP2Server () {};
~NTCP2Server () {} ;
NTCP2Server ();
~NTCP2Server ();
void Start ();
void Stop ();
boost::asio::io_service& GetService () { return m_Service; };
void Connect(const boost::asio::ip::address & address, uint16_t port, std::shared_ptr<NTCP2Session> conn);
private:
void Run ();
void HandleConnect (const boost::system::error_code& ecode, std::shared_ptr<NTCP2Session> conn);
private:
bool m_IsRunning;
std::thread * m_Thread;
boost::asio::io_service m_Service;
boost::asio::io_service::work m_Work;
};
}
}