Browse Source

moved io_service away from ClientDestination

pull/1474/head
orignal 5 years ago
parent
commit
d0e78be867
  1. 48
      libi2pd/Destination.cpp
  2. 21
      libi2pd/Destination.h
  3. 4
      libi2pd/api.cpp
  4. 4
      libi2pd_client/ClientContext.cpp
  5. 2
      libi2pd_client/MatchedDestination.cpp
  6. 2
      libi2pd_client/MatchedDestination.h

48
libi2pd/Destination.cpp

@ -822,11 +822,12 @@ namespace client @@ -822,11 +822,12 @@ namespace client
}
}
ClientDestination::ClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic, const std::map<std::string, std::string> * params):
RunnableService ("Destination"), LeaseSetDestination (GetIOService (), isPublic, params),
ClientDestination::ClientDestination (boost::asio::io_service& service, const i2p::data::PrivateKeys& keys,
bool isPublic, const std::map<std::string, std::string> * params):
LeaseSetDestination (service, isPublic, params),
m_Keys (keys), m_StreamingAckDelay (DEFAULT_INITIAL_ACK_DELAY),
m_DatagramDestination (nullptr), m_RefCounter (0),
m_ReadyChecker(GetService())
m_ReadyChecker(service)
{
if (keys.IsOfflineSignature () && GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_LEASESET)
SetLeaseSetType (i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2); // offline keys can be published with LS2 only
@ -892,26 +893,18 @@ namespace client @@ -892,26 +893,18 @@ namespace client
ClientDestination::~ClientDestination ()
{
if (IsRunning ())
Stop ();
}
void ClientDestination::Start ()
{
if (!IsRunning ())
{
LeaseSetDestination::Start ();
m_StreamingDestination = std::make_shared<i2p::stream::StreamingDestination> (GetSharedFromThis ()); // TODO:
m_StreamingDestination->Start ();
for (auto& it: m_StreamingDestinationsByPorts)
it.second->Start ();
StartIOService ();
}
}
void ClientDestination::Stop ()
{
if (IsRunning ())
{
LeaseSetDestination::Stop ();
m_ReadyChecker.cancel();
@ -929,8 +922,6 @@ namespace client @@ -929,8 +922,6 @@ namespace client
delete m_DatagramDestination;
m_DatagramDestination = nullptr;
}
StopIOService ();
}
}
#ifdef I2LUA
@ -1199,5 +1190,36 @@ namespace client @@ -1199,5 +1190,36 @@ namespace client
}
}
}
RunnableClientDestination::RunnableClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic, const std::map<std::string, std::string> * params):
RunnableService ("Destination"),
ClientDestination (GetIOService (), keys, isPublic, params)
{
}
RunnableClientDestination::~RunnableClientDestination ()
{
if (IsRunning ())
Stop ();
}
void RunnableClientDestination::Start ()
{
if (!IsRunning ())
{
ClientDestination::Start ();
StartIOService ();
}
}
void RunnableClientDestination::Stop ()
{
if (IsRunning ())
{
ClientDestination::Stop ();
StopIOService ();
}
}
}
}

21
libi2pd/Destination.h

@ -192,7 +192,7 @@ namespace client @@ -192,7 +192,7 @@ namespace client
bool IsPerClientAuth () const { return m_AuthType > 0; };
};
class ClientDestination: private i2p::util::RunnableService, public LeaseSetDestination
class ClientDestination: public LeaseSetDestination
{
public:
#ifdef I2LUA
@ -203,11 +203,12 @@ namespace client @@ -203,11 +203,12 @@ namespace client
void Ready(ReadyPromise & p);
#endif
ClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic, const std::map<std::string, std::string> * params = nullptr);
ClientDestination (boost::asio::io_service& service, const i2p::data::PrivateKeys& keys,
bool isPublic, const std::map<std::string, std::string> * params = nullptr);
~ClientDestination ();
virtual void Start ();
virtual void Stop ();
void Start ();
void Stop ();
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };
void Sign (const uint8_t * buf, int len, uint8_t * signature) const { m_Keys.Sign (buf, len, signature); };
@ -281,6 +282,18 @@ namespace client @@ -281,6 +282,18 @@ namespace client
// for HTTP only
std::vector<std::shared_ptr<const i2p::stream::Stream> > GetAllStreams () const;
};
class RunnableClientDestination: private i2p::util::RunnableService, public ClientDestination
{
public:
RunnableClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic, const std::map<std::string, std::string> * params = nullptr);
~RunnableClientDestination ();
void Start ();
void Stop ();
};
}
}

4
libi2pd/api.cpp

@ -77,7 +77,7 @@ namespace api @@ -77,7 +77,7 @@ namespace api
std::shared_ptr<i2p::client::ClientDestination> CreateLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic,
const std::map<std::string, std::string> * params)
{
auto localDestination = std::make_shared<i2p::client::ClientDestination> (keys, isPublic, params);
auto localDestination = std::make_shared<i2p::client::RunnableClientDestination> (keys, isPublic, params);
localDestination->Start ();
return localDestination;
}
@ -86,7 +86,7 @@ namespace api @@ -86,7 +86,7 @@ namespace api
const std::map<std::string, std::string> * params)
{
i2p::data::PrivateKeys keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType);
auto localDestination = std::make_shared<i2p::client::ClientDestination> (keys, isPublic, params);
auto localDestination = std::make_shared<i2p::client::RunnableClientDestination> (keys, isPublic, params);
localDestination->Start ();
return localDestination;
}

4
libi2pd_client/ClientContext.cpp

@ -305,7 +305,7 @@ namespace client @@ -305,7 +305,7 @@ namespace client
const std::map<std::string, std::string> * params)
{
i2p::data::PrivateKeys keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType, cryptoType);
auto localDestination = std::make_shared<ClientDestination> (keys, isPublic, params);
auto localDestination = std::make_shared<RunnableClientDestination> (keys, isPublic, params);
std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
localDestination->Start ();
@ -347,7 +347,7 @@ namespace client @@ -347,7 +347,7 @@ namespace client
it->second->Start (); // make sure to start
return it->second;
}
auto localDestination = std::make_shared<ClientDestination> (keys, isPublic, params);
auto localDestination = std::make_shared<RunnableClientDestination> (keys, isPublic, params);
std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations[keys.GetPublic ()->GetIdentHash ()] = localDestination;
localDestination->Start ();

2
libi2pd_client/MatchedDestination.cpp

@ -8,7 +8,7 @@ namespace i2p @@ -8,7 +8,7 @@ namespace i2p
namespace client
{
MatchedTunnelDestination::MatchedTunnelDestination(const i2p::data::PrivateKeys & keys, const std::string & remoteName, const std::map<std::string, std::string> * params)
: ClientDestination(keys, false, params),
: RunnableClientDestination(keys, false, params),
m_RemoteName(remoteName) {}

2
libi2pd_client/MatchedDestination.h

@ -10,7 +10,7 @@ namespace client @@ -10,7 +10,7 @@ namespace client
/**
client tunnel that uses same OBEP as IBGW of each remote lease for a remote destination
*/
class MatchedTunnelDestination : public ClientDestination, public i2p::tunnel::ITunnelPeerSelector
class MatchedTunnelDestination : public RunnableClientDestination, public i2p::tunnel::ITunnelPeerSelector
{
public:
MatchedTunnelDestination(const i2p::data::PrivateKeys& keys, const std::string & remoteName, const std::map<std::string, std::string> * params = nullptr);

Loading…
Cancel
Save