|
|
|
@ -2,6 +2,7 @@
@@ -2,6 +2,7 @@
|
|
|
|
|
#define SSU_H__ |
|
|
|
|
|
|
|
|
|
#include <inttypes.h> |
|
|
|
|
#include <map> |
|
|
|
|
#include <boost/asio.hpp> |
|
|
|
|
|
|
|
|
|
namespace i2p |
|
|
|
@ -10,11 +11,46 @@ namespace ssu
@@ -10,11 +11,46 @@ namespace ssu
|
|
|
|
|
{ |
|
|
|
|
const int SSU_MTU = 1484; |
|
|
|
|
|
|
|
|
|
// 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; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class SSUServer |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
SSUServer (boost::asio::io_service& service, int port); |
|
|
|
|
~SSUServer (); |
|
|
|
|
void Start (); |
|
|
|
|
void Stop (); |
|
|
|
|
|
|
|
|
@ -28,6 +64,7 @@ namespace ssu
@@ -28,6 +64,7 @@ namespace ssu
|
|
|
|
|
boost::asio::ip::udp::socket m_Socket; |
|
|
|
|
boost::asio::ip::udp::endpoint m_SenderEndpoint; |
|
|
|
|
uint8_t m_ReceiveBuffer[SSU_MTU]; |
|
|
|
|
std::map<boost::asio::ip::udp::endpoint, SSUSession *> m_Sessions; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|