void KClosestNodesSearch::tryInsert(const KBucketEntry & e) { // calculate distance between key and e dht::Key d = dht::Key::distance(key,e.getID()); if (emap.size() < max_entries) { // room in the map so just insert emap.insert(std::make_pair(d,e)); } else { // now find the max distance // seeing that the last element of the map has also // the biggest distance to key (std::map is sorted on the distance) // we just take the last const dht::Key & max = emap.rbegin()->first; if (d < max) { // insert if d is smaller then max emap.insert(std::make_pair(d,e)); // erase the old max value emap.erase(max); } } }
void NodeLookup::callFinished(RPCCall* ,MsgBase* rsp) { // Out() << "NodeLookup::callFinished" << endl; if (isFinished()) return; // check the response and see if it is a good one if (rsp->getMethod() == dht::FIND_NODE && rsp->getType() == dht::RSP_MSG) { FindNodeRsp* fnr = (FindNodeRsp*)rsp; const QByteArray & nodes = fnr->getNodes(); Uint32 nnodes = nodes.size() / 26; for (Uint32 j = 0;j < nnodes;j++) { // unpack an entry and add it to the todo list KBucketEntry e = UnpackBucketEntry(nodes,j*26); // lets not talk to ourself if (e.getID() != node->getOurID() && !todo.contains(e) && !visited.contains(e)) todo.append(e); } num_nodes_rsp++; } }