Admin add/remove peer (#7198)

N/A


  Adds endpoints to add and remove trusted peers from the http api. The added peers are trusted peers so they won't be disconnected for bad scores. We try to maintain a connection to the peer in case they disconnect from us by trying to dial it every heartbeat.
This commit is contained in:
Pawan Dhananjay
2025-03-28 05:59:09 -07:00
committed by GitHub
parent a5ea05ce2a
commit 54aef2d043
10 changed files with 217 additions and 7 deletions

View File

@@ -9,7 +9,7 @@ use std::net::IpAddr;
use std::time::Instant;
use std::{cmp::Ordering, fmt::Display};
use std::{
collections::{HashMap, HashSet},
collections::{hash_map::Entry, HashMap, HashSet},
fmt::Formatter,
};
use sync_status::SyncStatus;
@@ -79,6 +79,33 @@ impl<E: EthSpec> PeerDB<E> {
self.peers.iter()
}
pub fn set_trusted_peer(&mut self, enr: Enr) {
match self.peers.entry(enr.peer_id()) {
Entry::Occupied(mut info) => {
let entry = info.get_mut();
entry.score = Score::max_score();
entry.is_trusted = true;
}
Entry::Vacant(entry) => {
entry.insert(PeerInfo::trusted_peer_info());
}
}
}
pub fn unset_trusted_peer(&mut self, enr: Enr) {
if let Some(info) = self.peers.get_mut(&enr.peer_id()) {
info.is_trusted = false;
info.score = Score::default();
}
}
pub fn trusted_peers(&self) -> Vec<PeerId> {
self.peers
.iter()
.filter_map(|(id, info)| if info.is_trusted { Some(*id) } else { None })
.collect()
}
/// Gives the ids of all known peers.
pub fn peer_ids(&self) -> impl Iterator<Item = &PeerId> {
self.peers.keys()