@@ -877,6 +877,14 @@ class CompareNetGroupKeyed
877
877
}
878
878
};
879
879
880
+ /* * Try to find a connection to evict when the node is full.
881
+ * Extreme care must be taken to avoid opening the node to attacker
882
+ * triggered network partitioning.
883
+ * The strategy used here is to protect a small number of peers
884
+ * for each of several distinct characteristics which are difficult
885
+ * to forge. In order to partition a node the attacker must be
886
+ * simultaneously better at all of them than honest peers.
887
+ */
880
888
static bool AttemptToEvictConnection (bool fPreferNewConnection ) {
881
889
std::vector<CNodeRef> vEvictionCandidates;
882
890
{
@@ -905,15 +913,15 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
905
913
906
914
if (vEvictionCandidates.empty ()) return false ;
907
915
908
- // Protect the 8 nodes with the best ping times .
916
+ // Protect the 8 nodes with the lowest minimum ping time .
909
917
// An attacker cannot manipulate this metric without physically moving nodes closer to the target.
910
918
std::sort (vEvictionCandidates.begin (), vEvictionCandidates.end (), ReverseCompareNodeMinPingTime);
911
919
vEvictionCandidates.erase (vEvictionCandidates.end () - std::min (8 , static_cast <int >(vEvictionCandidates.size ())), vEvictionCandidates.end ());
912
920
913
921
if (vEvictionCandidates.empty ()) return false ;
914
922
915
923
// Protect the half of the remaining nodes which have been connected the longest.
916
- // This replicates the existing implicit behavior.
924
+ // This replicates the non-eviction implicit behavior, and precludes attacks that start later .
917
925
std::sort (vEvictionCandidates.begin (), vEvictionCandidates.end (), ReverseCompareNodeTimeConnected);
918
926
vEvictionCandidates.erase (vEvictionCandidates.end () - static_cast <int >(vEvictionCandidates.size () / 2 ), vEvictionCandidates.end ());
919
927
@@ -941,6 +949,7 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
941
949
vEvictionCandidates = mapAddrCounts[naMostConnections];
942
950
943
951
// Do not disconnect peers if there is only one unprotected connection from their network group.
952
+ // This step excessively favors netgroup diversity, and should be removed once more protective criteria are established.
944
953
if (vEvictionCandidates.size () <= 1 )
945
954
// unless we prefer the new connection (for whitelisted peers)
946
955
if (!fPreferNewConnection )
0 commit comments