@@ -100,6 +100,53 @@ namespace client
100100 ss << " \" " << name << " \" :" << buf.str ();
101101 }
102102
103+ // LocalDestinationInfo
104+
105+ void I2PControlHandlers::LocalDestinationInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
106+ {
107+ auto & addressBook = i2p::client::context.GetAddressBook ();
108+ auto addr = addressBook.GetAddress (params.get <std::string> (" destination" , " " ));
109+ auto dest = addr && addr->IsIdentHash () ?
110+ i2p::client::context.FindLocalDestination (addr->identHash ) : nullptr ;
111+ if (!dest)
112+ {
113+ InsertParam (results, " error" , std::string (" destination not found" ));
114+ return ;
115+ }
116+ InsertParam (results, " destination" , addressBook.ToAddress (dest->GetIdentHash ()));
117+
118+ // arrays are written by hand: write_json makes an array only below the root
119+ results << " ,\" leasesets\" :[" ;
120+ bool first = true ;
121+ for (const auto & it: dest->GetLeaseSetsList ())
122+ {
123+ if (!it) continue ;
124+ boost::property_tree::ptree ls;
125+ ls.put (" address" , addressBook.ToAddress (it->GetIdentHash ()));
126+ ls.put (" type" , (int )it->GetStoreType ());
127+ ls.put (" encType" , (int )it->GetEncryptionType ());
128+ if (!first) results << " ," ;
129+ first = false ;
130+ boost::property_tree::write_json (results, ls, false );
131+ }
132+ results << " ],\" streams\" :[" ;
133+ first = true ;
134+ for (const auto & it: dest->GetAllStreams ())
135+ {
136+ if (!it) continue ;
137+ auto identity = it->GetRemoteIdentity ();
138+ boost::property_tree::ptree st;
139+ st.put (" id" , it->GetRecvStreamID ());
140+ st.put (" destination" , identity ? addressBook.ToAddress (identity->GetIdentHash ()) : " " );
141+ st.put (" sent" , it->GetNumSentBytes ());
142+ st.put (" received" , it->GetNumReceivedBytes ());
143+ if (!first) results << " ," ;
144+ first = false ;
145+ boost::property_tree::write_json (results, st, false );
146+ }
147+ results << " ]" ;
148+ }
149+
103150// RouterInfo
104151
105152 void I2PControlHandlers::RouterInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
@@ -308,13 +355,15 @@ namespace client
308355
309356 void I2PControlHandlers::ClientServicesInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
310357 {
358+ bool first = true ;
311359 for (auto it = params.begin (); it != params.end (); it++)
312360 {
313361 LogPrint (eLogDebug, " I2PControl: ClientServicesInfo request: " , it->first );
314362 auto it1 = m_ClientServicesInfoHandlers.find (it->first );
315363 if (it1 != m_ClientServicesInfoHandlers.end ())
316364 {
317- if (it != params.begin ()) results << " ," ;
365+ if (!first) results << " ," ;
366+ else first = false ;
318367 (this ->*(it1->second ))(results);
319368 }
320369 else
0 commit comments