Browse Source

cleanup

cl-refactor
subtly 10 years ago
parent
commit
12fbcc8b5f
  1. 50
      libp2p/NodeTable.cpp

50
libp2p/NodeTable.cpp

@ -218,24 +218,22 @@ vector<shared_ptr<NodeEntry>> NodeTable::nearestNodeEntries(NodeId _target)
Guard l(x_state); Guard l(x_state);
for (auto n: m_state[head].nodes) for (auto n: m_state[head].nodes)
if (auto p = n.lock()) if (auto p = n.lock())
if (!!p->endpoint && p->endpoint.isAllowed()) {
if (count < s_bucketSize)
found[distance(_target, p->id)].push_back(p);
else
break;
}
if (count < s_bucketSize && tail)
for (auto n: m_state[tail].nodes)
if (auto p = n.lock())
{ {
if (count < s_bucketSize) if (count < s_bucketSize)
found[distance(_target, p->id)].push_back(p); found[distance(_target, p->id)].push_back(p);
else else
break; break;
} }
if (count < s_bucketSize && tail)
for (auto n: m_state[tail].nodes)
if (auto p = n.lock())
if (!!p->endpoint && p->endpoint.isAllowed())
{
if (count < s_bucketSize)
found[distance(_target, p->id)].push_back(p);
else
break;
}
head++; head++;
if (tail) if (tail)
@ -247,13 +245,12 @@ vector<shared_ptr<NodeEntry>> NodeTable::nearestNodeEntries(NodeId _target)
Guard l(x_state); Guard l(x_state);
for (auto n: m_state[head].nodes) for (auto n: m_state[head].nodes)
if (auto p = n.lock()) if (auto p = n.lock())
if (!!p->endpoint && p->endpoint.isAllowed()) {
{ if (count < s_bucketSize)
if (count < s_bucketSize) found[distance(_target, p->id)].push_back(p);
found[distance(_target, p->id)].push_back(p); else
else break;
break; }
}
head++; head++;
} }
else else
@ -262,20 +259,19 @@ vector<shared_ptr<NodeEntry>> NodeTable::nearestNodeEntries(NodeId _target)
Guard l(x_state); Guard l(x_state);
for (auto n: m_state[tail].nodes) for (auto n: m_state[tail].nodes)
if (auto p = n.lock()) if (auto p = n.lock())
if (!!p->endpoint && p->endpoint.isAllowed()) {
{ if (count < s_bucketSize)
if (count < s_bucketSize) found[distance(_target, p->id)].push_back(p);
found[distance(_target, p->id)].push_back(p); else
else break;
break; }
}
tail--; tail--;
} }
vector<shared_ptr<NodeEntry>> ret; vector<shared_ptr<NodeEntry>> ret;
for (auto& nodes: found) for (auto& nodes: found)
for (auto n: nodes.second) for (auto n: nodes.second)
if (ret.size() < s_bucketSize && n->endpoint.isAllowed()) if (ret.size() < s_bucketSize && !!n->endpoint && n->endpoint.isAllowed())
ret.push_back(n); ret.push_back(n);
return move(ret); return move(ret);
} }

Loading…
Cancel
Save