mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-13 04:46:38 +01:00
handle protocol byte
This commit is contained in:
parent
67f1e07508
commit
4c2d4009da
2 changed files with 64 additions and 0 deletions
40
I2CP.cpp
40
I2CP.cpp
|
@ -5,6 +5,46 @@ namespace i2p
|
||||||
{
|
{
|
||||||
namespace client
|
namespace client
|
||||||
{
|
{
|
||||||
|
I2CPSession::I2CPSession (std::shared_ptr<boost::asio::ip::tcp::socket> socket):
|
||||||
|
m_Socket (socket)
|
||||||
|
{
|
||||||
|
ReadProtocolByte ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void I2CPSession::ReadProtocolByte ()
|
||||||
|
{
|
||||||
|
if (m_Socket)
|
||||||
|
{
|
||||||
|
auto s = shared_from_this ();
|
||||||
|
m_Socket->async_read_some (boost::asio::buffer (m_Buffer, 1),
|
||||||
|
[s](const boost::system::error_code& ecode, std::size_t bytes_transferred)
|
||||||
|
{
|
||||||
|
if (!ecode && bytes_transferred > 0 && s->m_Buffer[0] == I2CP_PRTOCOL_BYTE)
|
||||||
|
s->Receive ();
|
||||||
|
else
|
||||||
|
s->Terminate ();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void I2CPSession::Receive ()
|
||||||
|
{
|
||||||
|
m_Socket->async_read_some (boost::asio::buffer (m_Buffer, I2CP_SESSION_BUFFER_SIZE),
|
||||||
|
std::bind (&I2CPSession::HandleReceived, shared_from_this (), std::placeholders::_1, std::placeholders::_2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void I2CPSession::HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred)
|
||||||
|
{
|
||||||
|
if (ecode)
|
||||||
|
Terminate ();
|
||||||
|
else
|
||||||
|
Receive ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void I2CPSession::Terminate ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
I2CPServer::I2CPServer (const std::string& interface, int port)
|
I2CPServer::I2CPServer (const std::string& interface, int port)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
24
I2CP.h
24
I2CP.h
|
@ -1,13 +1,37 @@
|
||||||
#ifndef I2CP_H__
|
#ifndef I2CP_H__
|
||||||
#define I2CP_H__
|
#define I2CP_H__
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace client
|
namespace client
|
||||||
{
|
{
|
||||||
|
const uint8_t I2CP_PRTOCOL_BYTE = 0x2A;
|
||||||
|
const size_t I2CP_SESSION_BUFFER_SIZE = 8192;
|
||||||
|
|
||||||
|
class I2CPSession: public std::enable_shared_from_this<I2CPSession>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
I2CPSession (std::shared_ptr<boost::asio::ip::tcp::socket> socket);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void ReadProtocolByte ();
|
||||||
|
void Receive ();
|
||||||
|
void HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||||
|
void Terminate ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::shared_ptr<boost::asio::ip::tcp::socket> m_Socket;
|
||||||
|
uint8_t m_Buffer[I2CP_SESSION_BUFFER_SIZE];
|
||||||
|
};
|
||||||
|
|
||||||
class I2CPServer
|
class I2CPServer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue