MCPcopy Create free account
hub / github.com/ElementsProject/elements / CompareNodeNetworkTime

Class CompareNodeNetworkTime

src/net.cpp:938–948  ·  view source on GitHub ↗

* Sort eviction candidates by network/localhost and connection uptime. * Candidates near the beginning are more likely to be evicted, and those * near the end are more likely to be protected, e.g. less likely to be evicted. * - First, nodes that are not `is_local` and that do not belong to `network`, * sorted by increasing uptime (from most recently connected to connected longer). * - Then,

Source from the content-addressed store, hash-verified

936 * - Then, nodes that are `is_local` or belong to `network`, sorted by increasing uptime.
937 */
938struct CompareNodeNetworkTime {
939 const bool m_is_local;
940 const Network m_network;
941 CompareNodeNetworkTime(bool is_local, Network network) : m_is_local(is_local), m_network(network) {}
942 bool operator()(const NodeEvictionCandidate& a, const NodeEvictionCandidate& b) const
943 {
944 if (m_is_local && a.m_is_local != b.m_is_local) return b.m_is_local;
945 if ((a.m_network == m_network) != (b.m_network == m_network)) return b.m_network == m_network;
946 return a.m_connected > b.m_connected;
947 };
948};
949
950//! Sort an array by the specified comparator, then erase the last K elements where predicate is true.
951template <typename T, typename Comparator>

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected