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

12
BOB.h

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

8
ClientContext.cpp

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

14
I2PTunnel.cpp

@ -154,12 +154,11 @@ namespace client @@ -154,12 +154,11 @@ namespace client
m_Connections.clear ();
}
I2PClientTunnel::I2PClientTunnel (boost::asio::io_service& service, const std::string& destination,
int port, ClientDestination * localDestination):
I2PTunnel (service, localDestination ? localDestination :
I2PClientTunnel::I2PClientTunnel (const std::string& destination, int port, ClientDestination * localDestination):
I2PTunnel (localDestination ? localDestination :
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_Timer (service), m_Destination (destination), m_DestinationIdentHash (nullptr),
m_Acceptor (GetService (), boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
m_Timer (GetService ()), m_Destination (destination), m_DestinationIdentHash (nullptr),
m_RemoteLeaseSet (nullptr)
{
}
@ -260,9 +259,8 @@ namespace client @@ -260,9 +259,8 @@ namespace client
}
}
I2PServerTunnel::I2PServerTunnel (boost::asio::io_service& service, const std::string& address, int port,
ClientDestination * localDestination): I2PTunnel (service, localDestination),
m_Endpoint (boost::asio::ip::address::from_string (address), port)
I2PServerTunnel::I2PServerTunnel (const std::string& address, int port, ClientDestination * localDestination):
I2PTunnel (localDestination), m_Endpoint (boost::asio::ip::address::from_string (address), port)
{
}

13
I2PTunnel.h

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

Loading…
Cancel
Save