mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
don't delete BOBDestination if used by another BOBSession
This commit is contained in:
parent
5f43026986
commit
b8f998f76a
|
@ -357,13 +357,13 @@ namespace client
|
|||
os << data << std::endl;
|
||||
}
|
||||
|
||||
void BOBCommandSession::BuildStatusLine(bool currentTunnel, BOBDestination *dest, std::string &out)
|
||||
void BOBCommandSession::BuildStatusLine(bool currentTunnel, std::shared_ptr<BOBDestination> dest, std::string &out)
|
||||
{
|
||||
// helper lambdas
|
||||
const auto issetStr = [](const std::string &str) { return str.empty() ? "not_set" : str; }; // for inhost, outhost
|
||||
const auto issetNum = [&issetStr](const int p) { return issetStr(p == 0 ? "" : std::to_string(p)); }; // for inport, outport
|
||||
const auto destExists = [](const BOBDestination * const dest) { return dest != nullptr; };
|
||||
const auto destReady = [](const BOBDestination * const dest) { return dest->IsRunning(); };
|
||||
const auto destReady = [](const BOBDestination * const dest) { return dest && dest->IsRunning(); };
|
||||
const auto bool_str = [](const bool v) { return v ? "true" : "false"; }; // bool -> str
|
||||
|
||||
// tunnel info
|
||||
|
@ -373,9 +373,9 @@ namespace client
|
|||
const std::string outhost = issetStr(currentTunnel ? m_OutHost : dest->GetOutHost());
|
||||
const std::string inport = issetNum(currentTunnel ? m_InPort : dest->GetInPort());
|
||||
const std::string outport = issetNum(currentTunnel ? m_OutPort : dest->GetOutPort());
|
||||
const bool keys = destExists(dest); // key must exist when destination is created
|
||||
const bool starting = destExists(dest) && !destReady(dest);
|
||||
const bool running = destExists(dest) && destReady(dest);
|
||||
const bool keys = destExists(dest.get ()); // key must exist when destination is created
|
||||
const bool starting = destExists(dest.get ()) && !destReady(dest.get ());
|
||||
const bool running = destExists(dest.get ()) && destReady(dest.get ());
|
||||
const bool stopping = false;
|
||||
|
||||
// build line
|
||||
|
@ -446,7 +446,7 @@ namespace client
|
|||
|
||||
if (!m_CurrentDestination)
|
||||
{
|
||||
m_CurrentDestination = new BOBDestination (i2p::client::context.CreateNewLocalDestination (m_Keys, true, &m_Options), // deleted in clear command
|
||||
m_CurrentDestination = std::make_shared<BOBDestination> (i2p::client::context.CreateNewLocalDestination (m_Keys, true, &m_Options), // deleted in clear command
|
||||
m_Nickname, m_InHost, m_OutHost, m_InPort, m_OutPort, m_IsQuiet);
|
||||
m_Owner.AddDestination (m_Nickname, m_CurrentDestination);
|
||||
}
|
||||
|
@ -666,7 +666,8 @@ namespace client
|
|||
SendReplyError ("Address Not found");
|
||||
return;
|
||||
}
|
||||
auto localDestination = m_CurrentDestination ? m_CurrentDestination->GetLocalDestination () : i2p::client::context.GetSharedLocalDestination ();
|
||||
auto localDestination = (m_CurrentDestination && m_CurrentDestination->IsRunning ()) ?
|
||||
m_CurrentDestination->GetLocalDestination () : i2p::client::context.GetSharedLocalDestination ();
|
||||
if (!localDestination)
|
||||
{
|
||||
SendReplyError ("No local destination");
|
||||
|
@ -880,8 +881,6 @@ namespace client
|
|||
{
|
||||
if (IsRunning ())
|
||||
Stop ();
|
||||
for (const auto& it: m_Destinations)
|
||||
delete it.second;
|
||||
}
|
||||
|
||||
void BOBCommandChannel::Start ()
|
||||
|
@ -898,9 +897,9 @@ namespace client
|
|||
StopIOService ();
|
||||
}
|
||||
|
||||
void BOBCommandChannel::AddDestination (const std::string& name, BOBDestination * dest)
|
||||
void BOBCommandChannel::AddDestination (const std::string& name, std::shared_ptr<BOBDestination> dest)
|
||||
{
|
||||
m_Destinations[name] = dest;
|
||||
m_Destinations.emplace (name, dest);
|
||||
}
|
||||
|
||||
void BOBCommandChannel::DeleteDestination (const std::string& name)
|
||||
|
@ -909,12 +908,11 @@ namespace client
|
|||
if (it != m_Destinations.end ())
|
||||
{
|
||||
it->second->Stop ();
|
||||
delete it->second;
|
||||
m_Destinations.erase (it);
|
||||
}
|
||||
}
|
||||
|
||||
BOBDestination * BOBCommandChannel::FindDestination (const std::string& name)
|
||||
std::shared_ptr<BOBDestination> BOBCommandChannel::FindDestination (const std::string& name)
|
||||
{
|
||||
auto it = m_Destinations.find (name);
|
||||
if (it != m_Destinations.end ())
|
||||
|
|
|
@ -228,7 +228,7 @@ namespace client
|
|||
void SendReplyError (const char * msg);
|
||||
void SendRaw (const char * data);
|
||||
|
||||
void BuildStatusLine(bool currentTunnel, BOBDestination *destination, std::string &out);
|
||||
void BuildStatusLine(bool currentTunnel, std::shared_ptr<BOBDestination> destination, std::string &out);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -240,7 +240,7 @@ namespace client
|
|||
uint16_t m_InPort, m_OutPort;
|
||||
i2p::data::PrivateKeys m_Keys;
|
||||
std::map<std::string, std::string> m_Options;
|
||||
BOBDestination * m_CurrentDestination;
|
||||
std::shared_ptr<BOBDestination> m_CurrentDestination;
|
||||
};
|
||||
typedef void (BOBCommandSession::*BOBCommandHandler)(const char * operand, size_t len);
|
||||
|
||||
|
@ -255,9 +255,9 @@ namespace client
|
|||
void Stop ();
|
||||
|
||||
boost::asio::io_service& GetService () { return GetIOService (); };
|
||||
void AddDestination (const std::string& name, BOBDestination * dest);
|
||||
void AddDestination (const std::string& name, std::shared_ptr<BOBDestination> dest);
|
||||
void DeleteDestination (const std::string& name);
|
||||
BOBDestination * FindDestination (const std::string& name);
|
||||
std::shared_ptr<BOBDestination> FindDestination (const std::string& name);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -267,7 +267,7 @@ namespace client
|
|||
private:
|
||||
|
||||
boost::asio::ip::tcp::acceptor m_Acceptor;
|
||||
std::map<std::string, BOBDestination *> m_Destinations;
|
||||
std::map<std::string, std::shared_ptr<BOBDestination> > m_Destinations;
|
||||
std::map<std::string, BOBCommandHandler> m_CommandHandlers;
|
||||
std::map<std::string, std::string> m_HelpStrings;
|
||||
|
||||
|
|
Loading…
Reference in a new issue