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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-duplicate peer connections during replication session updates #525

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- mDNS and AutoNAT disabled by default [#475](https://github.com/p2panda/aquadoggo/pull/475)
- By default, nodes support _any_ schema [#487](https://github.com/p2panda/aquadoggo/pull/487)
- Rework networking service [#502](https://github.com/p2panda/aquadoggo/pull/502)
- Deduplicate peer connections when initiating replication sessions [#525](https://github.com/p2panda/aquadoggo/pull/525)

### Fixed

Expand Down
19 changes: 12 additions & 7 deletions aquadoggo/src/replication/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,23 @@
.expect("Announcement state needs to be set with 'update_announcement'")
.supported_schema_ids;

// De-duplicate peer connections based on peer ids as we only need to pick one connection
// per peer.
let mut dedup_peers: HashMap<PeerId, (Peer, PeerStatus)> = HashMap::new();
for (peer, peer_status) in self.peers.iter() {
dedup_peers.insert(peer.id(), (*peer, peer_status.to_owned()));
}

// Iterate through all currently connected peers
let mut attempt_peers: Vec<(Peer, TargetSet)> = self
.peers
.clone()
.into_iter()
let mut attempt_peers: Vec<(Peer, TargetSet)> = dedup_peers
.values()
.filter_map(|(peer, status)| {
let sessions = self.sync_manager.get_sessions(&peer);
let sessions = self.sync_manager.get_sessions(peer);

// 1. Did we already receive this peers announcement state? If not we can't do
// anything yet and need to wait.
let remote_supported_schema_ids: TargetSet =
if let Some(announcement) = status.announcement {
if let Some(announcement) = status.clone().announcement {
announcement.supported_schema_ids
} else {
return None;
Expand Down Expand Up @@ -381,7 +386,7 @@
.any(|session| session.target_set() == target_set);

if active_sessions.len() < MAX_SESSIONS_PER_PEER && !has_active_target_set_session {
Some((peer, target_set))
Some((*peer, target_set))

Check warning on line 389 in aquadoggo/src/replication/service.rs

View check run for this annotation

Codecov / codecov/patch

aquadoggo/src/replication/service.rs#L389

Added line #L389 was not covered by tests
} else {
None
}
Expand Down