Skip to content

Commit

Permalink
feat(node): prevent free upload via replication
Browse files Browse the repository at this point in the history
This is achieved by:
 * only trust replication source with enough healthy status
 * when not having enough healthy knowledge, only trust majority
  • Loading branch information
maqi committed Jan 17, 2025
1 parent 1770122 commit 0b897b2
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 90 deletions.
11 changes: 11 additions & 0 deletions ant-networking/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ pub enum LocalSwarmCmd {
AddNetworkDensitySample {
distance: Distance,
},
/// Send peer scores (collected from storage challenge) to replication_fetcher
NotifyPeerScores {
peer_scores: Vec<(PeerId, bool)>,
},
}

/// Commands to send to the Swarm
Expand Down Expand Up @@ -312,6 +316,9 @@ impl Debug for LocalSwarmCmd {
LocalSwarmCmd::AddNetworkDensitySample { distance } => {
write!(f, "LocalSwarmCmd::AddNetworkDensitySample({distance:?})")
}
LocalSwarmCmd::NotifyPeerScores { peer_scores } => {
write!(f, "LocalSwarmCmd::NotifyPeerScores({peer_scores:?})")
}
}
}
}
Expand Down Expand Up @@ -932,6 +939,10 @@ impl SwarmDriver {
cmd_string = "AddNetworkDensitySample";
self.network_density_samples.add(distance);
}
LocalSwarmCmd::NotifyPeerScores { peer_scores } => {
cmd_string = "NotifyPeerScores";
self.replication_fetcher.add_peer_scores(peer_scores);
}
}

self.log_handling(cmd_string.to_string(), start.elapsed());
Expand Down
9 changes: 5 additions & 4 deletions ant-networking/src/event/request_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl SwarmDriver {
channel: MsgResponder::FromPeer(channel),
});

self.add_keys_to_replication_fetcher(holder, keys);
self.add_keys_to_replication_fetcher(holder, keys, false);
}
Request::Cmd(ant_protocol::messages::Cmd::PeerConsideredAsBad {
detected_by,
Expand Down Expand Up @@ -160,6 +160,7 @@ impl SwarmDriver {
&mut self,
sender: NetworkAddress,
incoming_keys: Vec<(NetworkAddress, ValidationType)>,
is_fresh_replicate: bool,
) {
let holder = if let Some(peer_id) = sender.as_peer_id() {
peer_id
Expand Down Expand Up @@ -192,9 +193,9 @@ impl SwarmDriver {
.kademlia
.store_mut()
.record_addresses_ref();
let keys_to_fetch = self
.replication_fetcher
.add_keys(holder, incoming_keys, all_keys);
let keys_to_fetch =
self.replication_fetcher
.add_keys(holder, incoming_keys, all_keys, is_fresh_replicate);
if keys_to_fetch.is_empty() {
debug!("no waiting keys to fetch from the network");
} else {
Expand Down
4 changes: 4 additions & 0 deletions ant-networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,10 @@ impl Network {
self.send_local_swarm_cmd(LocalSwarmCmd::AddNetworkDensitySample { distance })
}

pub fn notify_peer_scores(&self, peer_scores: Vec<(PeerId, bool)>) {
self.send_local_swarm_cmd(LocalSwarmCmd::NotifyPeerScores { peer_scores })
}

/// Helper to send NetworkSwarmCmd
fn send_network_swarm_cmd(&self, cmd: NetworkSwarmCmd) {
send_network_swarm_cmd(self.network_swarm_cmd_sender().clone(), cmd);
Expand Down
Loading

0 comments on commit 0b897b2

Please sign in to comment.