Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve P2P address book #178

Open
Boog900 opened this issue Jun 19, 2024 · 2 comments
Open

Improve P2P address book #178

Boog900 opened this issue Jun 19, 2024 · 2 comments
Assignees
Labels
A-p2p Related to P2P. C-feature This is an issue/PR that adds a new feature. E-medium Medium difficulty. Experience needed to fix: Intermediate.

Comments

@Boog900
Copy link
Member

Boog900 commented Jun 19, 2024

This is a tracking issue of things that should be improved in our P2P address book:

Don't replace addresses unless unreachable

We should not replace peers in either peer list (white or gray) unless they are unreachable, this should reduce an attackers ability to fill our peer list.

We should set up a task that periodically pulls unused peers from either the gray or white lists and attempts to ping them to see if they are reachable. If they are not we will keep them removed from the address book. When a new addresses come in they should only be added if there is space in the address book.

The function to ping peers:

pub async fn ping<N: NetworkZone>(addr: N::Addr) -> Result<u64, HandshakeError> {

Bucket addresses

We should use a bucket system like Bitcoin to store our p2p address, so that we guarantee a more diverse range of addresses.

Persist banned peers

Currently banned peers are forgotten on restarts, we should keep them in the p2p_store.

The functions where the peer filer is saved and loaded:

pub fn save_peers_to_disk<Z: BorshNetworkZone>(
cfg: &AddressBookConfig,
white_list: &PeerList<Z>,
gray_list: &PeerList<Z>,
) -> JoinHandle<std::io::Result<()>> {
// maybe move this to another thread but that would require cloning the data ... this
// happens so infrequently that it's probably not worth it.
let data = to_vec(&SerPeerDataV1 {
white_list: white_list.peers.values().collect::<Vec<_>>(),
gray_list: gray_list.peers.values().collect::<Vec<_>>(),
})
.unwrap();
let file = cfg.peer_store_file.clone();
spawn_blocking(move || fs::write(&file, &data))
}
pub async fn read_peers_from_disk<Z: BorshNetworkZone>(
cfg: &AddressBookConfig,
) -> Result<
(
Vec<ZoneSpecificPeerListEntryBase<Z::Addr>>,
Vec<ZoneSpecificPeerListEntryBase<Z::Addr>>,
),
std::io::Error,
> {
let file = cfg.peer_store_file.clone();
let data = spawn_blocking(move || fs::read(file)).await.unwrap()?;
let de_ser: DeserPeerDataV1<Z::Addr> = from_slice(&data)?;
Ok((de_ser.white_list, de_ser.gray_list))
}

These functions should be changed to allow the ban list to be stored as well:

banned_peers: HashMap<<Z::Addr as NetZoneAddress>::BanID, Instant>,

Properly implement an anchor system

TODO

@Boog900 Boog900 added A-p2p Related to P2P. C-feature This is an issue/PR that adds a new feature. E-medium Medium difficulty. Experience needed to fix: Intermediate. labels Jun 19, 2024
@willco-1
Copy link

willco-1 commented Sep 7, 2024

i'll take a shot at this!

@Boog900 Boog900 assigned Boog900 and willco-1 and unassigned Boog900 Sep 7, 2024
willco-1 added a commit to willco-1/cuprate that referenced this issue Sep 10, 2024
@SyntheticBird45 SyntheticBird45 self-assigned this Nov 6, 2024
@SyntheticBird45
Copy link
Member

Heyo @willco-1 are you still working on persistent ban list ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-p2p Related to P2P. C-feature This is an issue/PR that adds a new feature. E-medium Medium difficulty. Experience needed to fix: Intermediate.
Projects
None yet
Development

No branches or pull requests

3 participants