Browse Source

SessionDestoryedMessage

pull/509/merge
orignal 9 years ago
parent
commit
153d883aeb
  1. 21
      I2CP.cpp
  2. 5
      I2CP.h

21
I2CP.cpp

@ -64,7 +64,6 @@ namespace client
m_NextMessage (nullptr), m_NextMessageLen (0), m_NextMessageOffset (0) m_NextMessage (nullptr), m_NextMessageLen (0), m_NextMessageOffset (0)
{ {
RAND_bytes ((uint8_t *)&m_SessionID, 2); RAND_bytes ((uint8_t *)&m_SessionID, 2);
ReadProtocolByte ();
} }
I2CPSession::~I2CPSession () I2CPSession::~I2CPSession ()
@ -72,7 +71,12 @@ namespace client
delete[] m_NextMessage; delete[] m_NextMessage;
} }
void I2CPSession::Close () void I2CPSession::Start ()
{
ReadProtocolByte ();
}
void I2CPSession::Stop ()
{ {
} }
@ -216,6 +220,7 @@ namespace client
auto identity = std::make_shared<i2p::data::IdentityEx>(); auto identity = std::make_shared<i2p::data::IdentityEx>();
size_t offset = identity->FromBuffer (buf, len); size_t offset = identity->FromBuffer (buf, len);
uint16_t optionsSize = bufbe16toh (buf + offset); uint16_t optionsSize = bufbe16toh (buf + offset);
offset += 2;
// TODO: extract options // TODO: extract options
offset += optionsSize; offset += optionsSize;
offset += 8; // date offset += 8; // date
@ -224,6 +229,7 @@ namespace client
m_Destination = std::make_shared<I2CPDestination>(*this, identity, false); m_Destination = std::make_shared<I2CPDestination>(*this, identity, false);
m_Destination->Start (); m_Destination->Start ();
SendSessionStatusMessage (1); // created SendSessionStatusMessage (1); // created
LogPrint (eLogDebug, "I2CP: session ", m_SessionID, " created");
} }
else else
{ {
@ -232,6 +238,13 @@ namespace client
} }
} }
void I2CPSession::DestroySessionMessageHandler (const uint8_t * buf, size_t len)
{
SendSessionStatusMessage (0); // destroy
LogPrint (eLogDebug, "I2CP: session ", m_SessionID, " destroyed");
Terminate ();
}
void I2CPSession::SendSessionStatusMessage (uint8_t status) void I2CPSession::SendSessionStatusMessage (uint8_t status)
{ {
uint8_t buf[3]; uint8_t buf[3];
@ -281,6 +294,7 @@ namespace client
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;
m_MessagesHandlers[I2CP_CREATE_SESSION_MESSAGE] = &I2CPSession::CreateSessionMessageHandler; m_MessagesHandlers[I2CP_CREATE_SESSION_MESSAGE] = &I2CPSession::CreateSessionMessageHandler;
m_MessagesHandlers[I2CP_DESTROY_SESSION_MESSAGE] = &I2CPSession::DestroySessionMessageHandler;
m_MessagesHandlers[I2CP_CREATE_LEASESET_MESSAGE] = &I2CPSession::CreateLeaseSetMessageHandler; m_MessagesHandlers[I2CP_CREATE_LEASESET_MESSAGE] = &I2CPSession::CreateLeaseSetMessageHandler;
m_MessagesHandlers[I2CP_SEND_MESSAGE_MESSAGE] = &I2CPSession::SendMessageMessageHandler; m_MessagesHandlers[I2CP_SEND_MESSAGE_MESSAGE] = &I2CPSession::SendMessageMessageHandler;
} }
@ -303,7 +317,7 @@ namespace client
m_IsRunning = false; m_IsRunning = false;
m_Acceptor.cancel (); m_Acceptor.cancel ();
for (auto it: m_Sessions) for (auto it: m_Sessions)
it.second->Close (); it.second->Stop ();
m_Sessions.clear (); m_Sessions.clear ();
m_Service.stop (); m_Service.stop ();
if (m_Thread) if (m_Thread)
@ -347,6 +361,7 @@ namespace client
LogPrint (eLogDebug, "I2CP: new connection from ", ep); LogPrint (eLogDebug, "I2CP: new connection from ", ep);
auto session = std::make_shared<I2CPSession>(*this, socket); auto session = std::make_shared<I2CPSession>(*this, socket);
m_Sessions[session->GetSessionID ()] = session; m_Sessions[session->GetSessionID ()] = session;
session->Start ();
} }
else else
LogPrint (eLogError, "I2CP: incoming connection error ", ec.message ()); LogPrint (eLogError, "I2CP: incoming connection error ", ec.message ());

5
I2CP.h

@ -32,6 +32,7 @@ namespace client
const uint8_t I2CP_SET_DATE_MESSAGE = 33; const uint8_t I2CP_SET_DATE_MESSAGE = 33;
const uint8_t I2CP_CREATE_SESSION_MESSAGE = 1; const uint8_t I2CP_CREATE_SESSION_MESSAGE = 1;
const uint8_t I2CP_SESSION_STATUS_MESSAGE = 20; const uint8_t I2CP_SESSION_STATUS_MESSAGE = 20;
const uint8_t I2CP_DESTROY_SESSION_MESSAGE = 3;
const uint8_t I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE = 37; const uint8_t I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE = 37;
const uint8_t I2CP_CREATE_LEASESET_MESSAGE = 4; const uint8_t I2CP_CREATE_LEASESET_MESSAGE = 4;
const uint8_t I2CP_SEND_MESSAGE_MESSAGE = 5; const uint8_t I2CP_SEND_MESSAGE_MESSAGE = 5;
@ -73,13 +74,15 @@ namespace client
I2CPSession (I2CPServer& owner, std::shared_ptr<boost::asio::ip::tcp::socket> socket); I2CPSession (I2CPServer& owner, std::shared_ptr<boost::asio::ip::tcp::socket> socket);
~I2CPSession (); ~I2CPSession ();
void Start ();
void Stop ();
uint16_t GetSessionID () const { return m_SessionID; }; uint16_t GetSessionID () const { return m_SessionID; };
void Close ();
void SendI2CPMessage (uint8_t type, const uint8_t * payload, size_t len); void SendI2CPMessage (uint8_t type, const uint8_t * payload, size_t len);
// message handlers // message handlers
void GetDateMessageHandler (const uint8_t * buf, size_t len); void GetDateMessageHandler (const uint8_t * buf, size_t len);
void CreateSessionMessageHandler (const uint8_t * buf, size_t len); void CreateSessionMessageHandler (const uint8_t * buf, size_t len);
void DestroySessionMessageHandler (const uint8_t * buf, size_t len);
void CreateLeaseSetMessageHandler (const uint8_t * buf, size_t len); void CreateLeaseSetMessageHandler (const uint8_t * buf, size_t len);
void SendMessageMessageHandler (const uint8_t * buf, size_t len); void SendMessageMessageHandler (const uint8_t * buf, size_t len);

Loading…
Cancel
Save