Browse Source

evictions logic

cl-refactor
subtly 10 years ago
parent
commit
f0a06fa115
  1. 14
      libp2p/NodeTable.cpp
  2. 13
      libp2p/NodeTable.h

14
libp2p/NodeTable.cpp

@ -374,7 +374,19 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes
// clog(NodeTableMessageSummary) << "Received Pong from " << _from.address().to_string() << ":" << _from.port(); // clog(NodeTableMessageSummary) << "Received Pong from " << _from.address().to_string() << ":" << _from.port();
Pong in = Pong::fromBytesConstRef(_from, rlpBytes); Pong in = Pong::fromBytesConstRef(_from, rlpBytes);
// whenever a pong is received, first check if it's in m_evictions // whenever a pong is received, check if it's in m_evictions
Guard le(x_evictions);
for (auto it = m_evictions.begin(); it != m_evictions.end(); it++)
if (it->first.first == nodeid && it->first.second > std::chrono::steady_clock::now())
{
if (auto n = getNodeEntry(it->second))
dropNode(n);
if (auto n = (*this)[it->first.first])
addNode(n);
m_evictions.erase(it);
}
break; break;
} }

13
libp2p/NodeTable.h

@ -125,19 +125,19 @@ protected:
* shared_ptr replacement instead of mutating values. * shared_ptr replacement instead of mutating values.
* *
* [Integration] * [Integration]
* @todo deadline-timer which maintains tcp/peer connections
* @todo restore nodes: affects refreshbuckets * @todo restore nodes: affects refreshbuckets
* @todo TCP endpoints * @todo TCP endpoints
* @todo makeRequired: don't try to evict node if node isRequired. * @todo makeRequired: don't try to evict node if node isRequired.
* @todo makeRequired: exclude bucket from refresh if we have node as peer. * @todo makeRequired: exclude bucket from refresh if we have node as peer.
* *
* [Optimization] * [Optimization]
* @todo serialize evictions per-bucket
* @todo store evictions in map, unit-test eviction logic
* @todo store root node in table
* @todo encapsulate doFindNode into NetworkAlgorithm (task) * @todo encapsulate doFindNode into NetworkAlgorithm (task)
* @todo Pong to include ip:port where ping was received * @todo Pong to include ip:port where ping was received
* @todo expiration and sha3(id) 'to' for messages which are replies (prevents replay) * @todo expiration and sha3(id) 'to' for messages which are replies (prevents replay)
* @todo std::shared_ptr<PingNode> m_cachedPingPacket; * @todo cache Ping and FindSelf
* @todo std::shared_ptr<FindNeighbours> m_cachedFindSelfPacket;
* @todo store root node in table?
* *
* [Networking] * [Networking]
* @todo TCP endpoints * @todo TCP endpoints
@ -145,11 +145,8 @@ protected:
* @todo firewall * @todo firewall
* *
* [Protocol] * [Protocol]
* @todo post-eviction pong
* @todo optimize knowledge at opposite edges; eg, s_bitsPerStep lookups. (Can be done via pointers to NodeBucket) * @todo optimize knowledge at opposite edges; eg, s_bitsPerStep lookups. (Can be done via pointers to NodeBucket)
* @todo ^ s_bitsPerStep = 5; // Denoted by b in [Kademlia]. Bits by which address space is divided. * @todo ^ s_bitsPerStep = 8; // Denoted by b in [Kademlia]. Bits by which address space is divided.
* @todo optimize (use tree for state and/or custom compare for cache)
* @todo reputation (aka universal siblings lists)
*/ */
class NodeTable: UDPSocketEvents, public std::enable_shared_from_this<NodeTable> class NodeTable: UDPSocketEvents, public std::enable_shared_from_this<NodeTable>
{ {

Loading…
Cancel
Save