Browse Source

distance isn't hamming

cl-refactor
subtly 10 years ago
parent
commit
70b4389b09
  1. 10
      libp2p/NodeTable.cpp
  2. 6
      libp2p/NodeTable.h

10
libp2p/NodeTable.cpp

@ -135,7 +135,7 @@ std::vector<std::shared_ptr<NodeTable::NodeEntry>> NodeTable::findNearest(Addres
{
// send s_alpha FindNode packets to nodes we know, closest to target
static unsigned lastBin = s_bins - 1;
unsigned head = hammingDist(m_node.id, _target);
unsigned head = dist(m_node.id, _target);
unsigned tail = head == 0 ? lastBin : (head - 1) % s_bins;
std::map<unsigned, std::list<std::shared_ptr<NodeEntry>>> found;
@ -150,7 +150,7 @@ std::vector<std::shared_ptr<NodeTable::NodeEntry>> NodeTable::findNearest(Addres
if (auto p = n.lock())
{
if (count < s_bucketSize)
found[hammingDist(_target, p->id)].push_back(p);
found[dist(_target, p->id)].push_back(p);
else
break;
}
@ -160,7 +160,7 @@ std::vector<std::shared_ptr<NodeTable::NodeEntry>> NodeTable::findNearest(Addres
if (auto p = n.lock())
{
if (count < s_bucketSize)
found[hammingDist(_target, p->id)].push_back(p);
found[dist(_target, p->id)].push_back(p);
else
break;
}
@ -177,7 +177,7 @@ std::vector<std::shared_ptr<NodeTable::NodeEntry>> NodeTable::findNearest(Addres
if (auto p = n.lock())
{
if (count < s_bucketSize)
found[hammingDist(_target, p->id)].push_back(p);
found[dist(_target, p->id)].push_back(p);
else
break;
}
@ -191,7 +191,7 @@ std::vector<std::shared_ptr<NodeTable::NodeEntry>> NodeTable::findNearest(Addres
if (auto p = n.lock())
{
if (count < s_bucketSize)
found[hammingDist(_target, p->id)].push_back(p);
found[dist(_target, p->id)].push_back(p);
else
break;
}

6
libp2p/NodeTable.h

@ -95,8 +95,8 @@ class NodeTable: UDPSocketEvents, public std::enable_shared_from_this<NodeTable>
*/
struct NodeEntry: public Node
{
NodeEntry(Node _src, Address _id, Public _pubk, NodeDefaultEndpoint _gw): Node(_id, _pubk, _gw), distance(hammingDist(_src.id,_id)) {}
NodeEntry(Node _src, Address _id, Public _pubk, bi::udp::endpoint _udp): Node(_id, _pubk, NodeDefaultEndpoint(_udp)), distance(hammingDist(_src.id,_id)) {}
NodeEntry(Node _src, Address _id, Public _pubk, NodeDefaultEndpoint _gw): Node(_id, _pubk, _gw), distance(dist(_src.id,_id)) {}
NodeEntry(Node _src, Address _id, Public _pubk, bi::udp::endpoint _udp): Node(_id, _pubk, NodeDefaultEndpoint(_udp)), distance(dist(_src.id,_id)) {}
const unsigned distance; ///< Node's distance from _src (see constructor).
};
@ -130,7 +130,7 @@ public:
std::chrono::milliseconds const c_reqTimeout = std::chrono::milliseconds(300); ///< How long to wait for requests (evict, find iterations).
std::chrono::seconds const c_bucketRefresh = std::chrono::seconds(3600); ///< Refresh interval prevents bucket from becoming stale. [Kademlia]
static unsigned hammingDist(Address const& _a, Address const& _b) { u160 d = _a ^ _b; unsigned ret; for (ret = 0; d >>= 1; ++ret) {}; return ret; }
static unsigned dist(Address const& _a, Address const& _b) { u160 d = _a ^ _b; unsigned ret; for (ret = 0; d >>= 1; ++ret) {}; return ret; }
void join();

Loading…
Cancel
Save