You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
i2pd/libi2pd/NTCP2.h

80 lines
2.0 KiB
C

6 years ago
#ifndef NTCP2_H__
#define NTCP2_H__
#include <inttypes.h>
#include <memory>
#include <thread>
#include <boost/asio.hpp>
6 years ago
#include "RouterInfo.h"
#include "TransportSession.h"
namespace i2p
{
namespace transport
{
class NTCP2Server;
6 years ago
class NTCP2Session: public TransportSession, public std::enable_shared_from_this<NTCP2Session>
{
public:
NTCP2Session (NTCP2Server& server, std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter = nullptr);
6 years ago
~NTCP2Session ();
6 years ago
void Terminate ();
void Done ();
6 years ago
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
void ClientLogin (); // Alice
void SendI2NPMessages (const std::vector<std::shared_ptr<I2NPMessage> >& msgs) {}; // TODO
6 years ago
private:
bool KeyDerivationFunction1 (const uint8_t * rs, const uint8_t * pub, uint8_t * derived); // for SessionRequest
6 years ago
void CreateEphemeralKey (uint8_t * pub);
void SendSessionRequest ();
void HandleSessionRequestSent (const boost::system::error_code& ecode, std::size_t bytes_transferred);
6 years ago
void HandleSessionCreatedReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred);
6 years ago
private:
NTCP2Server& m_Server;
boost::asio::ip::tcp::socket m_Socket;
6 years ago
bool m_IsEstablished, m_IsTerminated;
6 years ago
uint8_t m_ExpandedPrivateKey[64]; // x25519 ephemeral key
uint8_t m_RemoteStaticKey[32], m_IV[16], m_H[32];
6 years ago
uint8_t * m_SessionRequestBuffer, * m_SessionCreatedBuffer;
};
class NTCP2Server
{
public:
6 years ago
NTCP2Server ();
~NTCP2Server ();
void Start ();
void Stop ();
boost::asio::io_service& GetService () { return m_Service; };
6 years ago
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:
6 years ago
bool m_IsRunning;
std::thread * m_Thread;
boost::asio::io_service m_Service;
6 years ago
boost::asio::io_service::work m_Work;
6 years ago
};
}
}
#endif