i2pd/SSU.h

74 lines
1.4 KiB
C
Raw Normal View History

2014-01-24 01:10:33 +04:00
#ifndef SSU_H__
#define SSU_H__
#include <inttypes.h>
2014-01-25 01:30:07 +04:00
#include <map>
2014-01-24 01:10:33 +04:00
#include <boost/asio.hpp>
namespace i2p
{
namespace ssu
{
const int SSU_MTU = 1484;
2014-01-25 01:30:07 +04:00
// payload types (4 bits)
const uint8_t PAYLOAD_TYPE_SESSION_REQUEST = 0;
const uint8_t PAYLOAD_TYPE_SESSION_CREATED = 1;
const uint8_t PAYLOAD_TYPE_SESSION_CONFIRMED = 2;
const uint8_t PAYLOAD_TYPE_RELAY_REQUEST = 3;
const uint8_t PAYLOAD_TYPE_RELAY_RESPONSE = 4;
const uint8_t PAYLOAD_TYPE_RELAY_INTRO = 5;
const uint8_t PAYLOAD_TYPE_DATA = 6;
const uint8_t PAYLOAD_TYPE_TEST = 7;
enum SessionState
{
eSessionStateUnknown,
eSessionStateRequestSent,
eSessionStateRequestReceived,
eSessionStateCreatedSent,
eSessionStateCreatedReceived,
eSessionStateConfirmedSent,
eSessionStateConfirmedReceived,
eSessionStateEstablised
};
class SSUSession
{
public:
SSUSession ();
void ProcessNextMessage (uint8_t * buf, std::size_t len);
private:
SessionState m_State;
};
2014-01-24 01:10:33 +04:00
class SSUServer
{
public:
SSUServer (boost::asio::io_service& service, int port);
2014-01-25 01:30:07 +04:00
~SSUServer ();
2014-01-24 01:10:33 +04:00
void Start ();
void Stop ();
private:
void Receive ();
void HandleReceivedFrom (const boost::system::error_code& ecode, std::size_t bytes_transferred);
private:
boost::asio::ip::udp::socket m_Socket;
boost::asio::ip::udp::endpoint m_SenderEndpoint;
uint8_t m_ReceiveBuffer[SSU_MTU];
2014-01-25 01:30:07 +04:00
std::map<boost::asio::ip::udp::endpoint, SSUSession *> m_Sessions;
2014-01-24 01:10:33 +04:00
};
}
}
#endif