mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
moved io_service away from ClientDestination
This commit is contained in:
parent
cbedebc9dd
commit
d0e78be867
|
@ -822,11 +822,12 @@ namespace client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientDestination::ClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic, const std::map<std::string, std::string> * params):
|
ClientDestination::ClientDestination (boost::asio::io_service& service, const i2p::data::PrivateKeys& keys,
|
||||||
RunnableService ("Destination"), LeaseSetDestination (GetIOService (), isPublic, params),
|
bool isPublic, const std::map<std::string, std::string> * params):
|
||||||
|
LeaseSetDestination (service, isPublic, params),
|
||||||
m_Keys (keys), m_StreamingAckDelay (DEFAULT_INITIAL_ACK_DELAY),
|
m_Keys (keys), m_StreamingAckDelay (DEFAULT_INITIAL_ACK_DELAY),
|
||||||
m_DatagramDestination (nullptr), m_RefCounter (0),
|
m_DatagramDestination (nullptr), m_RefCounter (0),
|
||||||
m_ReadyChecker(GetService())
|
m_ReadyChecker(service)
|
||||||
{
|
{
|
||||||
if (keys.IsOfflineSignature () && GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_LEASESET)
|
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
|
SetLeaseSetType (i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2); // offline keys can be published with LS2 only
|
||||||
|
@ -892,26 +893,18 @@ namespace client
|
||||||
|
|
||||||
ClientDestination::~ClientDestination ()
|
ClientDestination::~ClientDestination ()
|
||||||
{
|
{
|
||||||
if (IsRunning ())
|
|
||||||
Stop ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientDestination::Start ()
|
void ClientDestination::Start ()
|
||||||
{
|
|
||||||
if (!IsRunning ())
|
|
||||||
{
|
{
|
||||||
LeaseSetDestination::Start ();
|
LeaseSetDestination::Start ();
|
||||||
m_StreamingDestination = std::make_shared<i2p::stream::StreamingDestination> (GetSharedFromThis ()); // TODO:
|
m_StreamingDestination = std::make_shared<i2p::stream::StreamingDestination> (GetSharedFromThis ()); // TODO:
|
||||||
m_StreamingDestination->Start ();
|
m_StreamingDestination->Start ();
|
||||||
for (auto& it: m_StreamingDestinationsByPorts)
|
for (auto& it: m_StreamingDestinationsByPorts)
|
||||||
it.second->Start ();
|
it.second->Start ();
|
||||||
StartIOService ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientDestination::Stop ()
|
void ClientDestination::Stop ()
|
||||||
{
|
|
||||||
if (IsRunning ())
|
|
||||||
{
|
{
|
||||||
LeaseSetDestination::Stop ();
|
LeaseSetDestination::Stop ();
|
||||||
m_ReadyChecker.cancel();
|
m_ReadyChecker.cancel();
|
||||||
|
@ -929,8 +922,6 @@ namespace client
|
||||||
delete m_DatagramDestination;
|
delete m_DatagramDestination;
|
||||||
m_DatagramDestination = nullptr;
|
m_DatagramDestination = nullptr;
|
||||||
}
|
}
|
||||||
StopIOService ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef I2LUA
|
#ifdef I2LUA
|
||||||
|
@ -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 ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,7 @@ namespace client
|
||||||
bool IsPerClientAuth () const { return m_AuthType > 0; };
|
bool IsPerClientAuth () const { return m_AuthType > 0; };
|
||||||
};
|
};
|
||||||
|
|
||||||
class ClientDestination: private i2p::util::RunnableService, public LeaseSetDestination
|
class ClientDestination: public LeaseSetDestination
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
#ifdef I2LUA
|
#ifdef I2LUA
|
||||||
|
@ -203,11 +203,12 @@ namespace client
|
||||||
void Ready(ReadyPromise & p);
|
void Ready(ReadyPromise & p);
|
||||||
#endif
|
#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 ();
|
~ClientDestination ();
|
||||||
|
|
||||||
virtual void Start ();
|
void Start ();
|
||||||
virtual void Stop ();
|
void Stop ();
|
||||||
|
|
||||||
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };
|
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); };
|
void Sign (const uint8_t * buf, int len, uint8_t * signature) const { m_Keys.Sign (buf, len, signature); };
|
||||||
|
@ -281,6 +282,18 @@ namespace client
|
||||||
// for HTTP only
|
// for HTTP only
|
||||||
std::vector<std::shared_ptr<const i2p::stream::Stream> > GetAllStreams () const;
|
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 ();
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace api
|
||||||
std::shared_ptr<i2p::client::ClientDestination> CreateLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic,
|
std::shared_ptr<i2p::client::ClientDestination> CreateLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic,
|
||||||
const std::map<std::string, std::string> * params)
|
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 ();
|
localDestination->Start ();
|
||||||
return localDestination;
|
return localDestination;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ namespace api
|
||||||
const std::map<std::string, std::string> * params)
|
const std::map<std::string, std::string> * params)
|
||||||
{
|
{
|
||||||
i2p::data::PrivateKeys keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType);
|
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 ();
|
localDestination->Start ();
|
||||||
return localDestination;
|
return localDestination;
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,7 +305,7 @@ namespace client
|
||||||
const std::map<std::string, std::string> * params)
|
const std::map<std::string, std::string> * params)
|
||||||
{
|
{
|
||||||
i2p::data::PrivateKeys keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType, cryptoType);
|
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);
|
std::unique_lock<std::mutex> l(m_DestinationsMutex);
|
||||||
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
|
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
|
||||||
localDestination->Start ();
|
localDestination->Start ();
|
||||||
|
@ -347,7 +347,7 @@ namespace client
|
||||||
it->second->Start (); // make sure to start
|
it->second->Start (); // make sure to start
|
||||||
return it->second;
|
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);
|
std::unique_lock<std::mutex> l(m_DestinationsMutex);
|
||||||
m_Destinations[keys.GetPublic ()->GetIdentHash ()] = localDestination;
|
m_Destinations[keys.GetPublic ()->GetIdentHash ()] = localDestination;
|
||||||
localDestination->Start ();
|
localDestination->Start ();
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace i2p
|
||||||
namespace client
|
namespace client
|
||||||
{
|
{
|
||||||
MatchedTunnelDestination::MatchedTunnelDestination(const i2p::data::PrivateKeys & keys, const std::string & remoteName, const std::map<std::string, std::string> * params)
|
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) {}
|
m_RemoteName(remoteName) {}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace client
|
||||||
/**
|
/**
|
||||||
client tunnel that uses same OBEP as IBGW of each remote lease for a remote destination
|
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:
|
public:
|
||||||
MatchedTunnelDestination(const i2p::data::PrivateKeys& keys, const std::string & remoteName, const std::map<std::string, std::string> * params = nullptr);
|
MatchedTunnelDestination(const i2p::data::PrivateKeys& keys, const std::string & remoteName, const std::map<std::string, std::string> * params = nullptr);
|
||||||
|
|
Loading…
Reference in a new issue