From f0a06fa1153db6f5b53c86a513f7604daa78af19 Mon Sep 17 00:00:00 2001 From: subtly Date: Fri, 16 Jan 2015 21:37:21 -0500 Subject: [PATCH] evictions logic --- libp2p/NodeTable.cpp | 14 +++++++++++++- libp2p/NodeTable.h | 13 +++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 635f91bfb..1e6d54682 100644 --- a/libp2p/NodeTable.cpp +++ b/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(); 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; } diff --git a/libp2p/NodeTable.h b/libp2p/NodeTable.h index a68d42426..66f445827 100644 --- a/libp2p/NodeTable.h +++ b/libp2p/NodeTable.h @@ -125,19 +125,19 @@ protected: * shared_ptr replacement instead of mutating values. * * [Integration] - * @todo deadline-timer which maintains tcp/peer connections * @todo restore nodes: affects refreshbuckets * @todo TCP endpoints * @todo makeRequired: don't try to evict node if node isRequired. * @todo makeRequired: exclude bucket from refresh if we have node as peer. * * [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 Pong to include ip:port where ping was received * @todo expiration and sha3(id) 'to' for messages which are replies (prevents replay) - * @todo std::shared_ptr m_cachedPingPacket; - * @todo std::shared_ptr m_cachedFindSelfPacket; - * @todo store root node in table? + * @todo cache Ping and FindSelf * * [Networking] * @todo TCP endpoints @@ -145,11 +145,8 @@ protected: * @todo firewall * * [Protocol] - * @todo post-eviction pong * @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 optimize (use tree for state and/or custom compare for cache) - * @todo reputation (aka universal siblings lists) + * @todo ^ s_bitsPerStep = 8; // Denoted by b in [Kademlia]. Bits by which address space is divided. */ class NodeTable: UDPSocketEvents, public std::enable_shared_from_this {