mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
SessionDestoryedMessage
This commit is contained in:
parent
689432f627
commit
153d883aeb
21
I2CP.cpp
21
I2CP.cpp
@ -64,7 +64,6 @@ namespace client
|
||||
m_NextMessage (nullptr), m_NextMessageLen (0), m_NextMessageOffset (0)
|
||||
{
|
||||
RAND_bytes ((uint8_t *)&m_SessionID, 2);
|
||||
ReadProtocolByte ();
|
||||
}
|
||||
|
||||
I2CPSession::~I2CPSession ()
|
||||
@ -72,7 +71,12 @@ namespace client
|
||||
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>();
|
||||
size_t offset = identity->FromBuffer (buf, len);
|
||||
uint16_t optionsSize = bufbe16toh (buf + offset);
|
||||
offset += 2;
|
||||
// TODO: extract options
|
||||
offset += optionsSize;
|
||||
offset += 8; // date
|
||||
@ -224,6 +229,7 @@ namespace client
|
||||
m_Destination = std::make_shared<I2CPDestination>(*this, identity, false);
|
||||
m_Destination->Start ();
|
||||
SendSessionStatusMessage (1); // created
|
||||
LogPrint (eLogDebug, "I2CP: session ", m_SessionID, " created");
|
||||
}
|
||||
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)
|
||||
{
|
||||
uint8_t buf[3];
|
||||
@ -281,6 +294,7 @@ namespace client
|
||||
memset (m_MessagesHandlers, 0, sizeof (m_MessagesHandlers));
|
||||
m_MessagesHandlers[I2CP_GET_DATE_MESSAGE] = &I2CPSession::GetDateMessageHandler;
|
||||
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_SEND_MESSAGE_MESSAGE] = &I2CPSession::SendMessageMessageHandler;
|
||||
}
|
||||
@ -303,7 +317,7 @@ namespace client
|
||||
m_IsRunning = false;
|
||||
m_Acceptor.cancel ();
|
||||
for (auto it: m_Sessions)
|
||||
it.second->Close ();
|
||||
it.second->Stop ();
|
||||
m_Sessions.clear ();
|
||||
m_Service.stop ();
|
||||
if (m_Thread)
|
||||
@ -347,6 +361,7 @@ namespace client
|
||||
LogPrint (eLogDebug, "I2CP: new connection from ", ep);
|
||||
auto session = std::make_shared<I2CPSession>(*this, socket);
|
||||
m_Sessions[session->GetSessionID ()] = session;
|
||||
session->Start ();
|
||||
}
|
||||
else
|
||||
LogPrint (eLogError, "I2CP: incoming connection error ", ec.message ());
|
||||
|
5
I2CP.h
5
I2CP.h
@ -32,6 +32,7 @@ namespace client
|
||||
const uint8_t I2CP_SET_DATE_MESSAGE = 33;
|
||||
const uint8_t I2CP_CREATE_SESSION_MESSAGE = 1;
|
||||
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_CREATE_LEASESET_MESSAGE = 4;
|
||||
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 ();
|
||||
|
||||
void Start ();
|
||||
void Stop ();
|
||||
uint16_t GetSessionID () const { return m_SessionID; };
|
||||
void Close ();
|
||||
void SendI2CPMessage (uint8_t type, const uint8_t * payload, size_t len);
|
||||
|
||||
// message handlers
|
||||
void GetDateMessageHandler (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 SendMessageMessageHandler (const uint8_t * buf, size_t len);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user