Browse Source

I2PTunnel added

pull/93/head
orignal 10 years ago
parent
commit
0110b70195
  1. 53
      I2PTunnel.cpp
  2. 50
      I2PTunnel.h
  3. 4
      Win32/i2pd.vcxproj
  4. 2
      build/CMakeLists.txt
  5. 4
      filelist.mk

53
I2PTunnel.cpp

@ -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;
}
}
}

50
I2PTunnel.h

@ -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

4
Win32/i2pd.vcxproj

@ -44,6 +44,7 @@
<ClCompile Include="..\UPnP.cpp" /> <ClCompile Include="..\UPnP.cpp" />
<ClCompile Include="..\util.cpp" /> <ClCompile Include="..\util.cpp" />
<ClCompile Include="..\SOCKS.cpp" /> <ClCompile Include="..\SOCKS.cpp" />
<ClCompile Include="..\I2PTunnel.cpp" />
<ClCompile Include="Win32Service.cpp" /> <ClCompile Include="Win32Service.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -82,6 +83,7 @@
<ClInclude Include="..\UPnP.h" /> <ClInclude Include="..\UPnP.h" />
<ClInclude Include="..\util.h" /> <ClInclude Include="..\util.h" />
<ClInclude Include="..\SOCKS.h" /> <ClInclude Include="..\SOCKS.h" />
<ClInclude Include="..\I2PTunnel.h" />
<ClInclude Include="Win32Service.h" /> <ClInclude Include="Win32Service.h" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
@ -158,4 +160,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project> </Project>

2
build/CMakeLists.txt

@ -42,6 +42,7 @@ set ( SOURCES
aes.cpp aes.cpp
Daemon.cpp Daemon.cpp
SOCKS.cpp SOCKS.cpp
I2PTunnel.cpp
) )
set ( HEADERS set ( HEADERS
@ -74,6 +75,7 @@ set ( HEADERS
aes.h aes.h
Daemon.h Daemon.h
SOCKS.h SOCKS.h
I2PTunnel.h
) )
if (WIN32) if (WIN32)

4
filelist.mk

@ -4,14 +4,14 @@ CPP_FILES := CryptoConst.cpp base64.cpp NTCPSession.cpp RouterInfo.cpp Transport
RouterContext.cpp NetDb.cpp LeaseSet.cpp Tunnel.cpp TunnelEndpoint.cpp TunnelGateway.cpp \ RouterContext.cpp NetDb.cpp LeaseSet.cpp Tunnel.cpp TunnelEndpoint.cpp TunnelGateway.cpp \
TransitTunnel.cpp I2NPProtocol.cpp Log.cpp Garlic.cpp HTTPServer.cpp Streaming.cpp Identity.cpp \ TransitTunnel.cpp I2NPProtocol.cpp Log.cpp Garlic.cpp HTTPServer.cpp Streaming.cpp Identity.cpp \
SSU.cpp util.cpp Reseed.cpp DaemonLinux.cpp SSUData.cpp i2p.cpp aes.cpp SOCKS.cpp UPnP.cpp \ SSU.cpp util.cpp Reseed.cpp DaemonLinux.cpp SSUData.cpp i2p.cpp aes.cpp SOCKS.cpp UPnP.cpp \
TunnelPool.cpp HTTPProxy.cpp AddressBook.cpp Daemon.cpp TunnelPool.cpp HTTPProxy.cpp AddressBook.cpp Daemon.cpp I2PTunnel.cpp
H_FILES := CryptoConst.h base64.h NTCPSession.h RouterInfo.h Transports.h \ H_FILES := CryptoConst.h base64.h NTCPSession.h RouterInfo.h Transports.h \
RouterContext.h NetDb.h LeaseSet.h Tunnel.h TunnelEndpoint.h TunnelGateway.h \ RouterContext.h NetDb.h LeaseSet.h Tunnel.h TunnelEndpoint.h TunnelGateway.h \
TransitTunnel.h I2NPProtocol.h Log.h Garlic.h HTTPServer.h Streaming.h Identity.h \ TransitTunnel.h I2NPProtocol.h Log.h Garlic.h HTTPServer.h Streaming.h Identity.h \
SSU.h util.h Reseed.h DaemonLinux.h SSUData.h i2p.h aes.h SOCKS.h UPnP.h TunnelPool.h \ SSU.h util.h Reseed.h DaemonLinux.h SSUData.h i2p.h aes.h SOCKS.h UPnP.h TunnelPool.h \
HTTPProxy.h AddressBook.h Daemon.h HTTPProxy.h AddressBook.h Daemon.h I2PTunnel.h
OBJECTS = $(addprefix obj/, $(notdir $(CPP_FILES:.cpp=.o))) OBJECTS = $(addprefix obj/, $(notdir $(CPP_FILES:.cpp=.o)))

Loading…
Cancel
Save