Browse Source

specify separate local destination for client I2PTunnels

pull/102/head
orignal 10 years ago
parent
commit
53a2a3eb46
  1. 8
      Daemon.cpp
  2. 22
      I2PTunnel.cpp
  3. 14
      I2PTunnel.h
  4. 2
      README.md

8
Daemon.cpp

@ -124,8 +124,12 @@ namespace i2p @@ -124,8 +124,12 @@ namespace i2p
std::string ircDestination = i2p::util::config::GetArg("-ircdest", "");
if (ircDestination.length () > 0) // ircdest is presented
{
i2p::stream::StreamingDestination * localDestination = nullptr;
std::string ircKeys = i2p::util::config::GetArg("-irckeys", "");
if (ircKeys.length () > 0)
localDestination = i2p::stream::LoadLocalDestination (ircKeys);
d.ircTunnel = new i2p::stream::I2PClientTunnel (d.socksProxy->GetService (), ircDestination,
i2p::util::config::GetArg("-ircport", 6668));
i2p::util::config::GetArg("-ircport", 6668), localDestination);
d.ircTunnel->Start ();
LogPrint("IRC tunnel started");
}
@ -135,7 +139,7 @@ namespace i2p @@ -135,7 +139,7 @@ namespace i2p
auto localDestination = i2p::stream::LoadLocalDestination (eepKeys);
d.serverTunnel = new i2p::stream::I2PServerTunnel (d.socksProxy->GetService (),
i2p::util::config::GetArg("-eephost", "127.0.0.1"), i2p::util::config::GetArg("-eepport", 80),
localDestination->GetIdentHash ());
localDestination);
d.serverTunnel->Start ();
LogPrint("Server tunnel started");
}

22
I2PTunnel.cpp

@ -12,7 +12,7 @@ namespace stream @@ -12,7 +12,7 @@ namespace stream
boost::asio::ip::tcp::socket * socket, const i2p::data::LeaseSet * leaseSet):
m_Socket (socket), m_Owner (owner)
{
m_Stream = i2p::stream::CreateStream (*leaseSet);
m_Stream = m_Owner->GetLocalDestination ()->CreateNewOutgoingStream (*leaseSet);
m_Stream->Send (m_Buffer, 0, 0); // connect
StreamReceive ();
Receive ();
@ -138,8 +138,10 @@ namespace stream @@ -138,8 +138,10 @@ namespace stream
m_Connections.clear ();
}
I2PClientTunnel::I2PClientTunnel (boost::asio::io_service& service, const std::string& destination, int port):
I2PTunnel (service), m_Acceptor (service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
I2PClientTunnel::I2PClientTunnel (boost::asio::io_service& service, const std::string& destination,
int port, StreamingDestination * localDestination):
I2PTunnel (service, localDestination ? localDestination : GetSharedLocalDestination ()),
m_Acceptor (service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
m_Destination (destination), m_DestinationIdentHash (nullptr), m_RemoteLeaseSet (nullptr)
{
}
@ -170,7 +172,7 @@ namespace stream @@ -170,7 +172,7 @@ namespace stream
}
if (m_DestinationIdentHash)
{
i2p::data::netdb.Subscribe (*m_DestinationIdentHash, GetSharedLocalDestination ()->GetTunnelPool ());
i2p::data::netdb.Subscribe (*m_DestinationIdentHash, GetLocalDestination ()->GetTunnelPool ());
m_RemoteLeaseSet = i2p::data::netdb.FindLeaseSet (*m_DestinationIdentHash);
}
else
@ -231,12 +233,9 @@ namespace stream @@ -231,12 +233,9 @@ namespace stream
}
I2PServerTunnel::I2PServerTunnel (boost::asio::io_service& service, const std::string& address, int port,
const i2p::data::IdentHash& localDestination): I2PTunnel (service),
StreamingDestination * localDestination): I2PTunnel (service, localDestination),
m_Endpoint (boost::asio::ip::address::from_string (address), port)
{
m_LocalDestination = FindLocalDestination (localDestination);
if (!m_LocalDestination)
LogPrint ("Local destination ", localDestination.ToBase64 (), " not found");
}
void I2PServerTunnel::Start ()
@ -251,8 +250,11 @@ namespace stream @@ -251,8 +250,11 @@ namespace stream
void I2PServerTunnel::Accept ()
{
if (m_LocalDestination)
m_LocalDestination->SetAcceptor (std::bind (&I2PServerTunnel::HandleAccept, this, std::placeholders::_1));
auto localDestination = GetLocalDestination ();
if (localDestination)
localDestination->SetAcceptor (std::bind (&I2PServerTunnel::HandleAccept, this, std::placeholders::_1));
else
LogPrint ("Local destination not set for server tunnel");
}
void I2PServerTunnel::HandleAccept (i2p::stream::Stream * stream)

14
I2PTunnel.h

@ -50,18 +50,22 @@ namespace stream @@ -50,18 +50,22 @@ namespace stream
{
public:
I2PTunnel (boost::asio::io_service& service): m_Service (service) {};
I2PTunnel (boost::asio::io_service& service, StreamingDestination * localDestination):
m_Service (service), m_LocalDestination (localDestination) {};
virtual ~I2PTunnel () { ClearConnections (); };
void AddConnection (I2PTunnelConnection * conn);
void RemoveConnection (I2PTunnelConnection * conn);
void ClearConnections ();
StreamingDestination * GetLocalDestination () { return m_LocalDestination; };
void SetLocalDestination (StreamingDestination * dest) { m_LocalDestination = dest; };
boost::asio::io_service& GetService () { return m_Service; };
private:
boost::asio::io_service& m_Service;
StreamingDestination * m_LocalDestination;
std::set<I2PTunnelConnection *> m_Connections;
};
@ -69,7 +73,8 @@ namespace stream @@ -69,7 +73,8 @@ namespace stream
{
public:
I2PClientTunnel (boost::asio::io_service& service, const std::string& destination, int port);
I2PClientTunnel (boost::asio::io_service& service, const std::string& destination, int port,
StreamingDestination * localDestination = nullptr);
~I2PClientTunnel ();
void Start ();
@ -93,7 +98,7 @@ namespace stream @@ -93,7 +98,7 @@ namespace stream
public:
I2PServerTunnel (boost::asio::io_service& service, const std::string& address, int port,
const i2p::data::IdentHash& localDestination);
StreamingDestination * localDestination);
void Start ();
void Stop ();
@ -105,7 +110,6 @@ namespace stream @@ -105,7 +110,6 @@ namespace stream
private:
StreamingDestination * m_LocalDestination;
boost::asio::ip::tcp::endpoint m_Endpoint;
};
}

2
README.md

@ -54,7 +54,9 @@ Options @@ -54,7 +54,9 @@ Options
* --socksproxyport= - The port to listen on (SOCKS Proxy)
* --ircport= - The local port of IRC tunnel to listen on. 6668 by default
* --ircdest= - I2P destination address of IRC server. For example irc.postman.i2p
* --irckeys= - optional keys file for local destination
* --eepkeys= - File name containing destination keys. For example privKeys.dat
* --eephost= - Address incoming trafic forward to. 127.0.0.1 by default
* --eepport= - Port incoming trafic forward to. 80 by default
* --samport= - Port of SAM bridge. Usually 7656. SAM is off if not specified

Loading…
Cancel
Save