本文整理汇总了C++中node::Ptr::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::getType方法的具体用法?C++ Ptr::getType怎么用?C++ Ptr::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类node::Ptr
的用法示例。
在下文中一共展示了Ptr::getType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkExpiration
/*
* Remove dead nodes
*/
bool KBucket::checkExpiration(uint64_t currentTime)
{
bool dirty = false;
// we should ping oldest node from every bucket here
// but since we have only one bucket now, simulate it by pinging more nodes
unsigned int pingCount = max(K, min((int)2 * K, (int)(nodes.size() / (K * 10)) + 1)); // <-- pings 10 - 20 oldest nodes
unsigned int pinged = 0;
dcdrun(unsigned int removed = 0);
// first, remove dead nodes
NodeList::iterator i = nodes.begin();
while(i != nodes.end())
{
Node::Ptr& node = *i;
if(node->getType() == 4 && node->expires > 0 && node->expires <= currentTime)
{
if(node->unique(2))
{
// node is dead, remove it
string ip = node->getIdentity().getIp();
string port = node->getIdentity().getUdpPort();
ipMap.erase(ip + ":" + port);
if(node->isOnline())
{
ClientManager::getInstance()->putOffline(node.get());
node->dec();
}
i = nodes.erase(i);
dirty = true;
dcdrun(removed++);
}
else
{
++i;
}
continue;
}
if(node->expires == 0)
node->expires = currentTime;
// select the oldest expired node
if(pinged < pingCount && node->getType() < 4 && node->expires <= currentTime)
{
// ping the oldest (expired) node
node->setTimeout(currentTime);
DHT::getInstance()->info(node->getIdentity().getIp(), static_cast<uint16_t>(Util::toInt(node->getIdentity().getUdpPort())), DHT::PING, node->getUser()->getCID(), node->getUdpKey());
pinged++;
}
++i;
}
#ifdef _DEBUG
int verified = 0; int types[5] = { 0 };
for(NodeList::const_iterator j = nodes.begin(); j != nodes.end(); j++)
{
Node::Ptr n = *j;
if(n->isIpVerified()) verified++;
dcassert(n->getType() >= 0 && n->getType() <= 4);
types[n->getType()]++;
}
dcdebug("DHT Nodes: %d (%d verified), Types: %d/%d/%d/%d/%d, pinged %d of %d, removed %d\n", nodes.size(), verified, types[0], types[1], types[2], types[3], types[4], pinged, pingCount, removed);
#endif
return dirty;
}