Remove cruft from PeersHandler::handleGetInactiveUsers

Move documentaion to header
This commit is contained in:
Gioacchino Mazzurco 2017-09-15 09:33:01 +02:00
parent 341c94ee6c
commit 62eefa4fed
2 changed files with 23 additions and 40 deletions

View File

@ -779,29 +779,14 @@ void PeersHandler::handleRemoveNode(Request &req, Response &resp)
else resp.setFail("handleRemoveNode Invalid peer_id");
}
/**
* \brief Retrieve inactive user list before specific UNIX time
*
* \param [in] req request from user, datatime in UNIX timestamp.
* \param [in] resp response to request
* \return a pgp_id list.
*
* \details Combine this with handleRemoveNode,
* batch remove inactive users are possible and convenient.
*/
void PeersHandler::handleGetInactiveUsers(Request &req, Response &resp)
{
std::string datetime;
req.mStream << makeKeyValueReference("datetime", datetime);
uint32_t before = strtoul(datetime.c_str(), NULL, 10);
if(datetime.empty())
{
std::cerr << "PeersHandler:datetime is empty" << std::endl;
before = time(NULL);
}
uint32_t before;
if(datetime.empty()) before = time(NULL);
else before = strtoul(datetime.c_str(), NULL, 10);
// list all peers
std::list<RsPeerId> peers;
@ -811,7 +796,8 @@ void PeersHandler::handleGetInactiveUsers(Request &req, Response &resp)
std::map<RsPgpId, uint32_t> mapRsPgpId;
// get all peers' infomations
for(std::list<RsPeerId>::iterator lt = peers.begin(); lt != peers.end(); ++lt)
for( std::list<RsPeerId>::iterator lt = peers.begin(); lt != peers.end();
++lt )
{
RsPeerDetails details;
mRsPeers->getPeerDetails(*lt, details);
@ -823,9 +809,9 @@ void PeersHandler::handleGetInactiveUsers(Request &req, Response &resp)
}
else
{
mapRsPgpId.insert(std::make_pair(details.gpg_id, details.lastConnect));
mapRsPgpId.insert(
std::make_pair(details.gpg_id, details.lastConnect) );
}
}
// mark response as list, in case it is empty
@ -834,27 +820,18 @@ void PeersHandler::handleGetInactiveUsers(Request &req, Response &resp)
std::map<RsPgpId, uint32_t>::iterator lit;
for( lit = mapRsPgpId.begin(); lit != mapRsPgpId.end(); ++lit)
{
if (lit->second < before)
{
std::cerr << "YES Adding OLD: " << mRsPeers->getGPGName(lit->first);
std::cerr << "last_contact: " << lit->second <<std::endl;
StreamBase& itemStream = resp.mDataStream.getStreamToMember();
itemStream << makeKeyValue("pgp_id", lit->first.toStdString());
itemStream << makeKeyValue("name", mRsPeers->getGPGName(lit->first));
itemStream << makeKeyValue("last_contact", lit->second);
resp.mDataStream.getStreamToMember()
<< makeKeyValue("pgp_id", lit->first.toStdString())
<< makeKeyValue("name", mRsPeers->getGPGName(lit->first))
<< makeKeyValue("last_contact", lit->second);
}
}
resp.setOk();
}
void PeersHandler::handleGetNetworkOptions(Request& /*req*/, Response& resp)
{
RsPeerDetails detail;

View File

@ -81,7 +81,13 @@ private:
*/
void handleRemoveNode(Request &req, Response &resp);
/**
* \brief Retrieve inactive user list before specific UNIX time
*
* \param [in] req request from user, datatime in UNIX timestamp.
* \param [in] resp response to request
* \return a pgp_id list.
*/
void handleGetInactiveUsers(Request &req, Response &resp);
/// Helper which ensures proper mutex locking