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
std::string ircDestination = i2p::util::config::GetArg("-ircdest", ""); std::string ircDestination = i2p::util::config::GetArg("-ircdest", "");
if (ircDestination.length () > 0) // ircdest is presented 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, 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 (); d.ircTunnel->Start ();
LogPrint("IRC tunnel started"); LogPrint("IRC tunnel started");
} }
@ -135,7 +139,7 @@ namespace i2p
auto localDestination = i2p::stream::LoadLocalDestination (eepKeys); auto localDestination = i2p::stream::LoadLocalDestination (eepKeys);
d.serverTunnel = new i2p::stream::I2PServerTunnel (d.socksProxy->GetService (), d.serverTunnel = new i2p::stream::I2PServerTunnel (d.socksProxy->GetService (),
i2p::util::config::GetArg("-eephost", "127.0.0.1"), i2p::util::config::GetArg("-eepport", 80), i2p::util::config::GetArg("-eephost", "127.0.0.1"), i2p::util::config::GetArg("-eepport", 80),
localDestination->GetIdentHash ()); localDestination);
d.serverTunnel->Start (); d.serverTunnel->Start ();
LogPrint("Server tunnel started"); LogPrint("Server tunnel started");
} }

22
I2PTunnel.cpp

@ -12,7 +12,7 @@ namespace stream
boost::asio::ip::tcp::socket * socket, const i2p::data::LeaseSet * leaseSet): boost::asio::ip::tcp::socket * socket, const i2p::data::LeaseSet * leaseSet):
m_Socket (socket), m_Owner (owner) 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 m_Stream->Send (m_Buffer, 0, 0); // connect
StreamReceive (); StreamReceive ();
Receive (); Receive ();
@ -138,8 +138,10 @@ namespace stream
m_Connections.clear (); m_Connections.clear ();
} }
I2PClientTunnel::I2PClientTunnel (boost::asio::io_service& service, const std::string& destination, int port): I2PClientTunnel::I2PClientTunnel (boost::asio::io_service& service, const std::string& destination,
I2PTunnel (service), m_Acceptor (service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)), 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) m_Destination (destination), m_DestinationIdentHash (nullptr), m_RemoteLeaseSet (nullptr)
{ {
} }
@ -170,7 +172,7 @@ namespace stream
} }
if (m_DestinationIdentHash) 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); m_RemoteLeaseSet = i2p::data::netdb.FindLeaseSet (*m_DestinationIdentHash);
} }
else else
@ -231,12 +233,9 @@ namespace stream
} }
I2PServerTunnel::I2PServerTunnel (boost::asio::io_service& service, const std::string& address, int port, 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_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 () void I2PServerTunnel::Start ()
@ -251,8 +250,11 @@ namespace stream
void I2PServerTunnel::Accept () void I2PServerTunnel::Accept ()
{ {
if (m_LocalDestination) auto localDestination = GetLocalDestination ();
m_LocalDestination->SetAcceptor (std::bind (&I2PServerTunnel::HandleAccept, this, std::placeholders::_1)); 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) void I2PServerTunnel::HandleAccept (i2p::stream::Stream * stream)

14
I2PTunnel.h

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

2
README.md

@ -54,7 +54,9 @@ Options
* --socksproxyport= - The port to listen on (SOCKS Proxy) * --socksproxyport= - The port to listen on (SOCKS Proxy)
* --ircport= - The local port of IRC tunnel to listen on. 6668 by default * --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 * --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 * --eepkeys= - File name containing destination keys. For example privKeys.dat
* --eephost= - Address incoming trafic forward to. 127.0.0.1 by default * --eephost= - Address incoming trafic forward to. 127.0.0.1 by default
* --eepport= - Port incoming trafic forward to. 80 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