mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-08-27 00:40:41 +00:00
added LocalDestinationInfo I2PControl request
This commit is contained in:
@@ -90,6 +90,7 @@ namespace client
|
||||
m_MethodHandlers["RouterManager"] = &I2PControlService::RouterManagerHandler;
|
||||
m_MethodHandlers["NetworkSetting"] = &I2PControlHandlers::NetworkSettingHandler;
|
||||
m_MethodHandlers["ClientServicesInfo"] = &I2PControlHandlers::ClientServicesInfoHandler;
|
||||
m_MethodHandlers["LocalDestinationInfo"] = &I2PControlHandlers::LocalDestinationInfoHandler;
|
||||
|
||||
// I2PControl
|
||||
m_I2PControlHandlers["i2pcontrol.password"] = &I2PControlService::PasswordHandler;
|
||||
|
||||
@@ -100,6 +100,53 @@ namespace client
|
||||
ss << "\"" << name << "\":" << buf.str();
|
||||
}
|
||||
|
||||
// LocalDestinationInfo
|
||||
|
||||
void I2PControlHandlers::LocalDestinationInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
|
||||
{
|
||||
auto& addressBook = i2p::client::context.GetAddressBook ();
|
||||
auto addr = addressBook.GetAddress (params.get<std::string> ("destination", ""));
|
||||
auto dest = addr && addr->IsIdentHash () ?
|
||||
i2p::client::context.FindLocalDestination (addr->identHash) : nullptr;
|
||||
if (!dest)
|
||||
{
|
||||
InsertParam (results, "error", std::string ("destination not found"));
|
||||
return;
|
||||
}
|
||||
InsertParam (results, "destination", addressBook.ToAddress (dest->GetIdentHash ()));
|
||||
|
||||
// arrays are written by hand: write_json makes an array only below the root
|
||||
results << ",\"leasesets\":[";
|
||||
bool first = true;
|
||||
for (const auto& it: dest->GetLeaseSetsList ())
|
||||
{
|
||||
if (!it) continue;
|
||||
boost::property_tree::ptree ls;
|
||||
ls.put ("address", addressBook.ToAddress (it->GetIdentHash ()));
|
||||
ls.put ("type", (int)it->GetStoreType ());
|
||||
ls.put ("encType", (int)it->GetEncryptionType ());
|
||||
if (!first) results << ",";
|
||||
first = false;
|
||||
boost::property_tree::write_json (results, ls, false);
|
||||
}
|
||||
results << "],\"streams\":[";
|
||||
first = true;
|
||||
for (const auto& it: dest->GetAllStreams ())
|
||||
{
|
||||
if (!it) continue;
|
||||
auto identity = it->GetRemoteIdentity ();
|
||||
boost::property_tree::ptree st;
|
||||
st.put ("id", it->GetRecvStreamID ());
|
||||
st.put ("destination", identity ? addressBook.ToAddress (identity->GetIdentHash ()) : "");
|
||||
st.put ("sent", it->GetNumSentBytes ());
|
||||
st.put ("received", it->GetNumReceivedBytes ());
|
||||
if (!first) results << ",";
|
||||
first = false;
|
||||
boost::property_tree::write_json (results, st, false);
|
||||
}
|
||||
results << "]";
|
||||
}
|
||||
|
||||
// RouterInfo
|
||||
|
||||
void I2PControlHandlers::RouterInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace client
|
||||
void RouterInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results);
|
||||
void NetworkSettingHandler (const boost::property_tree::ptree& params, std::ostringstream& results);
|
||||
void ClientServicesInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results);
|
||||
void LocalDestinationInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -1447,13 +1447,9 @@ namespace client
|
||||
{
|
||||
std::vector<std::shared_ptr<const i2p::stream::Stream> > ret;
|
||||
if (m_StreamingDestination)
|
||||
{
|
||||
for (auto& it: m_StreamingDestination->GetStreams ())
|
||||
ret.push_back (it.second);
|
||||
}
|
||||
m_StreamingDestination->GetStreamsList (ret);
|
||||
for (auto& it: m_StreamingDestinationsByPorts)
|
||||
for (auto& it1: it.second->GetStreams ())
|
||||
ret.push_back (it1.second);
|
||||
it.second->GetStreamsList (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <string.h>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
@@ -235,6 +236,16 @@ namespace client
|
||||
// for HTTP only
|
||||
int GetNumRemoteLeaseSets () const { return m_RemoteLeaseSets.size (); };
|
||||
const decltype(m_RemoteLeaseSets)& GetLeaseSets () const { return m_RemoteLeaseSets; };
|
||||
// copy for other threads, unlike GetLeaseSets which hands out the container itself
|
||||
std::vector<std::shared_ptr<i2p::data::LeaseSet> > GetLeaseSetsList () const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_RemoteLeaseSetsMutex);
|
||||
std::vector<std::shared_ptr<i2p::data::LeaseSet> > leaseSets;
|
||||
leaseSets.reserve (m_RemoteLeaseSets.size ());
|
||||
for (const auto& it: m_RemoteLeaseSets)
|
||||
leaseSets.push_back (it.second);
|
||||
return leaseSets;
|
||||
}
|
||||
bool IsEncryptedLeaseSet () const { return m_LeaseSetType == i2p::data::NETDB_STORE_TYPE_ENCRYPTED_LEASESET2; };
|
||||
bool IsPerClientAuth () const { return m_AuthType > 0; };
|
||||
};
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <unordered_map>
|
||||
#include <set>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@@ -391,6 +392,14 @@ namespace stream
|
||||
|
||||
// for HTTP only
|
||||
const decltype(m_Streams)& GetStreams () const { return m_Streams; };
|
||||
|
||||
// copy for other threads, unlike GetStreams which hands out the map itself
|
||||
void GetStreamsList (std::vector<std::shared_ptr<const Stream> >& streams)
|
||||
{
|
||||
std::unique_lock<std::mutex> l(m_StreamsMutex);
|
||||
for (const auto& it: m_Streams)
|
||||
streams.push_back (it.second);
|
||||
}
|
||||
};
|
||||
|
||||
//-------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user