void findSucc(NodeID& _return, const std::string& key) { NodeID pred; findPred(pred, key); if (pred.id == current.id) { _return = successor; _return.__set_count(pred.count); return; } shared_ptr<DHTNodeClient> client(connectClientAgency(pred.ip, pred.port)); client->getNodeSucc(_return); _return.__set_count(pred.count); }
void findPred(NodeID& _return, const std::string& key) { string left = current.id; string middle = key; string right = successor.id; /* bool flag; flag = right > left ? (middle > left && middle <= right) : ((middle > left && middle > right) || (middle < left && middle <= right)); **/ if (keyCompare(current.id, key, successor.id)) { _return = current; _return.__set_count(0); return ; } for(int i = 255; i >= 0; i--) { if (ftable[i].id.empty()) continue; if (keyCompare(current.id, ftable[i].id, key)) { boost::shared_ptr<TSocket> socket(new TSocket(ftable[i].ip.c_str(), ftable[i].port)); boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket)); boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport)); boost::shared_ptr<DHTNodeClient> client(new DHTNodeClient(protocol)); transport->open(); try { client->findPred(_return, key); } catch (...) { client = boost::shared_ptr<DHTNodeClient>(); transport->close(); } transport->close(); _return.__set_count(_return.count + 1); return ; } } assert(false); }