Browse Source

always use destination's thread to avoid race conditions

pull/122/head
orignal 10 years ago
parent
commit
4d640dac2a
  1. 22
      BOB.cpp
  2. 12
      BOB.h
  3. 8
      ClientContext.cpp
  4. 14
      I2PTunnel.cpp
  5. 13
      I2PTunnel.h

22
BOB.cpp

@ -8,10 +8,9 @@ namespace i2p
{ {
namespace client namespace client
{ {
BOBI2PInboundTunnel::BOBI2PInboundTunnel (boost::asio::io_service& service, int port, ClientDestination * localDestination): BOBI2PInboundTunnel::BOBI2PInboundTunnel (int port, ClientDestination * localDestination):
BOBI2PTunnel (service, localDestination), BOBI2PTunnel (localDestination),
m_Acceptor (service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)), m_Acceptor (localDestination->GetService (), boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)), m_Timer (localDestination->GetService ())
m_Timer (service)
{ {
} }
@ -142,8 +141,8 @@ namespace client
delete receiver; delete receiver;
} }
BOBI2POutboundTunnel::BOBI2POutboundTunnel (boost::asio::io_service& service, const std::string& address, int port, BOBI2POutboundTunnel::BOBI2POutboundTunnel (const std::string& address, int port,
ClientDestination * localDestination, bool quiet): BOBI2PTunnel (service, localDestination), ClientDestination * localDestination, bool quiet): BOBI2PTunnel (localDestination),
m_Endpoint (boost::asio::ip::address::from_string (address), port), m_IsQuiet (quiet) m_Endpoint (boost::asio::ip::address::from_string (address), port), m_IsQuiet (quiet)
{ {
} }
@ -177,8 +176,8 @@ namespace client
} }
} }
BOBDestination::BOBDestination (boost::asio::io_service& service, ClientDestination& localDestination): BOBDestination::BOBDestination (ClientDestination& localDestination):
m_Service (service), m_LocalDestination (localDestination), m_LocalDestination (localDestination),
m_OutboundTunnel (nullptr), m_InboundTunnel (nullptr) m_OutboundTunnel (nullptr), m_InboundTunnel (nullptr)
{ {
} }
@ -220,13 +219,13 @@ namespace client
void BOBDestination::CreateInboundTunnel (int port) void BOBDestination::CreateInboundTunnel (int port)
{ {
if (!m_InboundTunnel) if (!m_InboundTunnel)
m_InboundTunnel = new BOBI2PInboundTunnel (m_Service, port, &m_LocalDestination); m_InboundTunnel = new BOBI2PInboundTunnel (port, &m_LocalDestination);
} }
void BOBDestination::CreateOutboundTunnel (const std::string& address, int port, bool quiet) void BOBDestination::CreateOutboundTunnel (const std::string& address, int port, bool quiet)
{ {
if (!m_OutboundTunnel) if (!m_OutboundTunnel)
m_OutboundTunnel = new BOBI2POutboundTunnel (m_Service, address, port, &m_LocalDestination, quiet); m_OutboundTunnel = new BOBI2POutboundTunnel (address, port, &m_LocalDestination, quiet);
} }
BOBCommandSession::BOBCommandSession (BOBCommandChannel& owner): BOBCommandSession::BOBCommandSession (BOBCommandChannel& owner):
@ -384,8 +383,7 @@ namespace client
LogPrint (eLogDebug, "BOB: start ", m_Nickname); LogPrint (eLogDebug, "BOB: start ", m_Nickname);
if (!m_CurrentDestination) if (!m_CurrentDestination)
{ {
m_CurrentDestination = new BOBDestination (m_Owner.GetService (), m_CurrentDestination = new BOBDestination (*i2p::client::context.CreateNewLocalDestination (m_Keys, true, &m_Options));
*context.CreateNewLocalDestination (m_Keys, true, &m_Options));
m_Owner.AddDestination (m_Nickname, m_CurrentDestination); m_Owner.AddDestination (m_Nickname, m_CurrentDestination);
} }
if (m_InPort) if (m_InPort)

12
BOB.h

@ -45,8 +45,8 @@ namespace client
{ {
public: public:
BOBI2PTunnel (boost::asio::io_service& service, ClientDestination * localDestination): BOBI2PTunnel (ClientDestination * localDestination):
I2PTunnel (service, localDestination) {}; I2PTunnel (localDestination) {};
virtual void Start () {}; virtual void Start () {};
virtual void Stop () {}; virtual void Stop () {};
@ -66,7 +66,7 @@ namespace client
public: public:
BOBI2PInboundTunnel (boost::asio::io_service& service, int port, ClientDestination * localDestination); BOBI2PInboundTunnel (int port, ClientDestination * localDestination);
~BOBI2PInboundTunnel (); ~BOBI2PInboundTunnel ();
void Start (); void Start ();
@ -95,8 +95,7 @@ namespace client
{ {
public: public:
BOBI2POutboundTunnel (boost::asio::io_service& service, const std::string& address, int port, BOBI2POutboundTunnel (const std::string& address, int port, ClientDestination * localDestination, bool quiet);
ClientDestination * localDestination, bool quiet);
void Start (); void Start ();
void Stop (); void Stop ();
@ -119,7 +118,7 @@ namespace client
{ {
public: public:
BOBDestination (boost::asio::io_service& service, ClientDestination& localDestination); BOBDestination (ClientDestination& localDestination);
~BOBDestination (); ~BOBDestination ();
void Start (); void Start ();
@ -131,7 +130,6 @@ namespace client
private: private:
boost::asio::io_service& m_Service;
ClientDestination& m_LocalDestination; ClientDestination& m_LocalDestination;
BOBI2POutboundTunnel * m_OutboundTunnel; BOBI2POutboundTunnel * m_OutboundTunnel;
BOBI2PInboundTunnel * m_InboundTunnel; BOBI2PInboundTunnel * m_InboundTunnel;

8
ClientContext.cpp

@ -48,8 +48,7 @@ namespace client
std::string ircKeys = i2p::util::config::GetArg("-irckeys", ""); std::string ircKeys = i2p::util::config::GetArg("-irckeys", "");
if (ircKeys.length () > 0) if (ircKeys.length () > 0)
localDestination = LoadLocalDestination (ircKeys, false); localDestination = LoadLocalDestination (ircKeys, false);
m_IrcTunnel = new I2PClientTunnel (m_SocksProxy->GetService (), ircDestination, m_IrcTunnel = new I2PClientTunnel (ircDestination, i2p::util::config::GetArg("-ircport", 6668), localDestination);
i2p::util::config::GetArg("-ircport", 6668), localDestination);
m_IrcTunnel->Start (); m_IrcTunnel->Start ();
LogPrint("IRC tunnel started"); LogPrint("IRC tunnel started");
} }
@ -57,9 +56,8 @@ namespace client
if (eepKeys.length () > 0) // eepkeys file is presented if (eepKeys.length () > 0) // eepkeys file is presented
{ {
auto localDestination = LoadLocalDestination (eepKeys, true); auto localDestination = LoadLocalDestination (eepKeys, true);
m_ServerTunnel = new I2PServerTunnel (m_SocksProxy->GetService (), m_ServerTunnel = new I2PServerTunnel (i2p::util::config::GetArg("-eephost", "127.0.0.1"),
i2p::util::config::GetArg("-eephost", "127.0.0.1"), i2p::util::config::GetArg("-eepport", 80), i2p::util::config::GetArg("-eepport", 80), localDestination);
localDestination);
m_ServerTunnel->Start (); m_ServerTunnel->Start ();
LogPrint("Server tunnel started"); LogPrint("Server tunnel started");
} }

14
I2PTunnel.cpp

@ -154,12 +154,11 @@ namespace client
m_Connections.clear (); m_Connections.clear ();
} }
I2PClientTunnel::I2PClientTunnel (boost::asio::io_service& service, const std::string& destination, I2PClientTunnel::I2PClientTunnel (const std::string& destination, int port, ClientDestination * localDestination):
int port, ClientDestination * localDestination): I2PTunnel (localDestination ? localDestination :
I2PTunnel (service, localDestination ? localDestination :
i2p::client::context.CreateNewLocalDestination (false, i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256)), i2p::client::context.CreateNewLocalDestination (false, i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256)),
m_Acceptor (service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)), m_Acceptor (GetService (), boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
m_Timer (service), m_Destination (destination), m_DestinationIdentHash (nullptr), m_Timer (GetService ()), m_Destination (destination), m_DestinationIdentHash (nullptr),
m_RemoteLeaseSet (nullptr) m_RemoteLeaseSet (nullptr)
{ {
} }
@ -260,9 +259,8 @@ namespace client
} }
} }
I2PServerTunnel::I2PServerTunnel (boost::asio::io_service& service, const std::string& address, int port, I2PServerTunnel::I2PServerTunnel (const std::string& address, int port, ClientDestination * localDestination):
ClientDestination * localDestination): I2PTunnel (service, localDestination), I2PTunnel (localDestination), m_Endpoint (boost::asio::ip::address::from_string (address), port)
m_Endpoint (boost::asio::ip::address::from_string (address), port)
{ {
} }

13
I2PTunnel.h

@ -58,8 +58,8 @@ namespace client
{ {
public: public:
I2PTunnel (boost::asio::io_service& service, ClientDestination * localDestination): I2PTunnel (ClientDestination * localDestination):
m_Service (service), m_LocalDestination (localDestination) {}; m_LocalDestination (localDestination) {};
virtual ~I2PTunnel () { ClearConnections (); }; virtual ~I2PTunnel () { ClearConnections (); };
void AddConnection (std::shared_ptr<I2PTunnelConnection> conn); void AddConnection (std::shared_ptr<I2PTunnelConnection> conn);
@ -68,11 +68,10 @@ namespace client
ClientDestination * GetLocalDestination () { return m_LocalDestination; }; ClientDestination * GetLocalDestination () { return m_LocalDestination; };
void SetLocalDestination (ClientDestination * dest) { m_LocalDestination = dest; }; void SetLocalDestination (ClientDestination * dest) { m_LocalDestination = dest; };
boost::asio::io_service& GetService () { return m_Service; }; boost::asio::io_service& GetService () { return m_LocalDestination->GetService (); };
private: private:
boost::asio::io_service& m_Service;
ClientDestination * m_LocalDestination; ClientDestination * m_LocalDestination;
std::set<std::shared_ptr<I2PTunnelConnection> > m_Connections; std::set<std::shared_ptr<I2PTunnelConnection> > m_Connections;
}; };
@ -81,8 +80,7 @@ namespace client
{ {
public: public:
I2PClientTunnel (boost::asio::io_service& service, const std::string& destination, int port, I2PClientTunnel (const std::string& destination, int port, ClientDestination * localDestination = nullptr);
ClientDestination * localDestination = nullptr);
~I2PClientTunnel (); ~I2PClientTunnel ();
void Start (); void Start ();
@ -108,8 +106,7 @@ namespace client
{ {
public: public:
I2PServerTunnel (boost::asio::io_service& service, const std::string& address, int port, I2PServerTunnel (const std::string& address, int port, ClientDestination * localDestination);
ClientDestination * localDestination);
void Start (); void Start ();
void Stop (); void Stop ();

Loading…
Cancel
Save