Skip to content
/ i2pd Public
forked from PurpleI2P/i2pd

Commit

Permalink
pass destination port to client tunnel
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Mar 13, 2015
1 parent ad649ab commit 09f1966
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
23 changes: 13 additions & 10 deletions I2PTunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace i2p
{
namespace client
{
I2PTunnelConnection::I2PTunnelConnection (I2PService * owner,
boost::asio::ip::tcp::socket * socket, std::shared_ptr<const i2p::data::LeaseSet> leaseSet):
I2PTunnelConnection::I2PTunnelConnection (I2PService * owner, boost::asio::ip::tcp::socket * socket,
std::shared_ptr<const i2p::data::LeaseSet> leaseSet, int port):
I2PServiceHandler(owner), m_Socket (socket), m_RemoteEndpoint (socket->remote_endpoint ()),
m_IsQuiet (true)
{
m_Stream = GetOwner()->GetLocalDestination ()->CreateStream (leaseSet);
m_Stream = GetOwner()->GetLocalDestination ()->CreateStream (leaseSet, port);
}

I2PTunnelConnection::I2PTunnelConnection (I2PService * owner,
Expand Down Expand Up @@ -156,20 +156,23 @@ namespace client
{
public:
I2PClientTunnelHandler (I2PClientTunnel * parent, i2p::data::IdentHash destination,
boost::asio::ip::tcp::socket * socket):
I2PServiceHandler(parent), m_DestinationIdentHash(destination), m_Socket(socket) {}
int destinationPort, boost::asio::ip::tcp::socket * socket):
I2PServiceHandler(parent), m_DestinationIdentHash(destination),
m_DestinationPort (destinationPort), m_Socket(socket) {};
void Handle();
void Terminate();
private:
void HandleStreamRequestComplete (std::shared_ptr<i2p::stream::Stream> stream);
i2p::data::IdentHash m_DestinationIdentHash;
int m_DestinationPort;
boost::asio::ip::tcp::socket * m_Socket;
};

void I2PClientTunnelHandler::Handle()
{
GetOwner()->GetLocalDestination ()->CreateStream (std::bind (&I2PClientTunnelHandler::HandleStreamRequestComplete,
shared_from_this(), std::placeholders::_1), m_DestinationIdentHash);
GetOwner()->GetLocalDestination ()->CreateStream (
std::bind (&I2PClientTunnelHandler::HandleStreamRequestComplete, shared_from_this(), std::placeholders::_1),
m_DestinationIdentHash, m_DestinationPort);
}

void I2PClientTunnelHandler::HandleStreamRequestComplete (std::shared_ptr<i2p::stream::Stream> stream)
Expand Down Expand Up @@ -202,8 +205,8 @@ namespace client
Done(shared_from_this());
}

I2PClientTunnel::I2PClientTunnel (const std::string& destination, int port, std::shared_ptr<ClientDestination> localDestination):
TCPIPAcceptor (port,localDestination), m_Destination (destination), m_DestinationIdentHash (nullptr)
I2PClientTunnel::I2PClientTunnel (const std::string& destination, int port, std::shared_ptr<ClientDestination> localDestination, int destinationPort):
TCPIPAcceptor (port,localDestination), m_Destination (destination), m_DestinationIdentHash (nullptr), m_DestinationPort (destinationPort)
{}

void I2PClientTunnel::Start ()
Expand Down Expand Up @@ -238,7 +241,7 @@ namespace client
{
const i2p::data::IdentHash *identHash = GetIdentHash();
if (identHash)
return std::make_shared<I2PClientTunnelHandler>(this, *identHash, socket);
return std::make_shared<I2PClientTunnelHandler>(this, *identHash, m_DestinationPort, socket);
else
return nullptr;
}
Expand Down
5 changes: 3 additions & 2 deletions I2PTunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace client
public:

I2PTunnelConnection (I2PService * owner, boost::asio::ip::tcp::socket * socket,
std::shared_ptr<const i2p::data::LeaseSet> leaseSet); // to I2P
std::shared_ptr<const i2p::data::LeaseSet> leaseSet, int port = 0); // to I2P
I2PTunnelConnection (I2PService * owner, boost::asio::ip::tcp::socket * socket,
std::shared_ptr<i2p::stream::Stream> stream); // to I2P using simplified API :)
I2PTunnelConnection (I2PService * owner, std::shared_ptr<i2p::stream::Stream> stream, boost::asio::ip::tcp::socket * socket,
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace client

public:

I2PClientTunnel (const std::string& destination, int port, std::shared_ptr<ClientDestination> localDestination = nullptr);
I2PClientTunnel (const std::string& destination, int port, std::shared_ptr<ClientDestination> localDestination, int destinationPort = 0);
~I2PClientTunnel () {}

void Start ();
Expand All @@ -77,6 +77,7 @@ namespace client

std::string m_Destination;
const i2p::data::IdentHash * m_DestinationIdentHash;
int m_DestinationPort;
};

class I2PServerTunnel: public I2PService
Expand Down

0 comments on commit 09f1966

Please sign in to comment.