mirror of https://github.com/PurpleI2P/i2pd
I2PTunnel added
parent
377d390dff
commit
0110b70195
@ -0,0 +1,53 @@
|
||||
#include <boost/bind.hpp>
|
||||
#include "I2PTunnel.h"
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
namespace stream
|
||||
{
|
||||
I2PTunnelConnection::I2PTunnelConnection (boost::asio::ip::tcp::socket * socket,
|
||||
const i2p::data::LeaseSet * leaseSet): m_Socket (socket)
|
||||
{
|
||||
m_Stream = i2p::stream::CreateStream (*leaseSet);
|
||||
}
|
||||
|
||||
I2PTunnelConnection::~I2PTunnelConnection ()
|
||||
{
|
||||
if (m_Stream)
|
||||
{
|
||||
m_Stream->Close ();
|
||||
DeleteStream (m_Stream);
|
||||
}
|
||||
|
||||
delete m_Socket;
|
||||
}
|
||||
|
||||
I2PClientTunnel::I2PClientTunnel (boost::asio::io_service& service, const std::string& destination, int port):
|
||||
m_Service (service), m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
|
||||
m_Destination (destination), m_RemoteLeaseSet (nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void I2PClientTunnel::Accept ()
|
||||
{
|
||||
auto newSocket = new boost::asio::ip::tcp::socket (m_Service);
|
||||
m_Acceptor.async_accept (*newSocket, boost::bind (&I2PClientTunnel::HandleAccept, this,
|
||||
boost::asio::placeholders::error, newSocket));
|
||||
}
|
||||
|
||||
void I2PClientTunnel::HandleAccept (const boost::system::error_code& ecode, boost::asio::ip::tcp::socket * socket)
|
||||
{
|
||||
if (!ecode)
|
||||
{
|
||||
if (m_RemoteLeaseSet)
|
||||
new I2PTunnelConnection (socket, m_RemoteLeaseSet);
|
||||
else
|
||||
delete socket;
|
||||
Accept ();
|
||||
}
|
||||
else
|
||||
delete socket;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
#ifndef I2PTUNNEL_H__
|
||||
#define I2PTUNNEL_H__
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <boost/asio.hpp>
|
||||
#include "Identity.h"
|
||||
#include "Streaming.h"
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
namespace stream
|
||||
{
|
||||
class I2PTunnelConnection
|
||||
{
|
||||
public:
|
||||
|
||||
I2PTunnelConnection (boost::asio::ip::tcp::socket * socket,
|
||||
const i2p::data::LeaseSet * leaseSet);
|
||||
~I2PTunnelConnection ();
|
||||
|
||||
private:
|
||||
|
||||
boost::asio::ip::tcp::socket * m_Socket;
|
||||
Stream * m_Stream;
|
||||
};
|
||||
|
||||
class I2PClientTunnel
|
||||
{
|
||||
public:
|
||||
|
||||
I2PClientTunnel (boost::asio::io_service& service, const std::string& destination, int port);
|
||||
|
||||
private:
|
||||
|
||||
void Accept ();
|
||||
void HandleAccept (const boost::system::error_code& ecode, boost::asio::ip::tcp::socket * socket);
|
||||
|
||||
private:
|
||||
|
||||
boost::asio::io_service& m_Service;
|
||||
boost::asio::ip::tcp::acceptor m_Acceptor;
|
||||
std::string m_Destination;
|
||||
i2p::data::IdentHash m_DestinationIdentHash;
|
||||
const i2p::data::LeaseSet * m_RemoteLeaseSet;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue