Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Fix removal of disconnected peers in the peer manager #1182

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1618bf9
Explicitly end underlying connection
Alex6323 Feb 25, 2022
441a582
Fire 'ProtocolStopped' event in any connection-end case
Alex6323 Feb 25, 2022
ed696a7
Count dial attempts and signal 'PeerUnreachable'
Alex6323 Feb 25, 2022
d1e453b
Temporarly show peer count for gossip-peerlist and protocol-peer_ man…
Alex6323 Feb 25, 2022
f9970d9
Display error message when sending the shutdown signal to an autopeer…
Alex6323 Feb 25, 2022
a53300a
Remove unreachable discovered peers from peer manager
Alex6323 Feb 25, 2022
b6997d2
Remove unreachable discovered peers from gossip and peer manager
Alex6323 Feb 25, 2022
9a14c5c
Publish PeerUnreachable for peers that don't identify properly; Chang…
Alex6323 Feb 27, 2022
d875e8a
Reset dial attempt counter only if peer successfully identified itself
Alex6323 Feb 28, 2022
6d4a3a8
Remove temporary logs
Alex6323 Feb 28, 2022
30d831a
Alias macro starts with the significant part of peer id
Alex6323 Feb 28, 2022
1a06f38
Send PeerRemoved event for disconnected unknown peers
Alex6323 Feb 28, 2022
5d187bc
Alias macro starts with the significant part of peer id (for real)
Alex6323 Feb 28, 2022
e75ae76
Align autopeering peer id display
Alex6323 Feb 28, 2022
49eaf73
Ignore error if adding a local address fails
Alex6323 Feb 28, 2022
bc336d9
Change some log levels
Alex6323 Feb 28, 2022
4d231f7
Format; Introduce display offset constant, Update autopeering changelog
Alex6323 Feb 28, 2022
aa74ff3
Update changelogs; bump versions
Alex6323 Feb 28, 2022
f89f6c2
Nits
Alex6323 Mar 1, 2022
f2c9672
Fix typos and German comma in changelog
Alex6323 Mar 1, 2022
693a826
Fix docs
Alex6323 Mar 1, 2022
74c09b7
Address review comments
Alex6323 Mar 1, 2022
e65444b
Simplify 'add_local_addr' method
Alex6323 Mar 2, 2022
0016bab
Add explanation why sending commands to gossip layer cannot fail
Alex6323 Mar 2, 2022
a0502ac
Rename to 'identified_at'
Alex6323 Mar 2, 2022
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion bee-api/bee-rest-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security -->

## 0.2.0 - 2022-XX-XX
## 0.2.1 - 2022-02-28

- Update `bee-gossip` dependency to 0.5.0;

## 0.2.0 - 2022-01-28

### Added

Expand Down
4 changes: 2 additions & 2 deletions bee-api/bee-rest-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bee-rest-api"
version = "0.2.0"
version = "0.2.1"
authors = [ "IOTA Stiftung" ]
edition = "2021"
description = "The default REST API implementation for the IOTA Bee node software."
Expand All @@ -12,7 +12,7 @@ homepage = "https://www.iota.org"

[dependencies]
bee-common = { version = "0.6.0", path = "../../bee-common/bee-common", default-features = false, optional = true }
bee-gossip = { version = "0.4.0", path = "../../bee-network/bee-gossip", default-features = false, optional = true }
bee-gossip = { version = "0.5.0", path = "../../bee-network/bee-gossip", default-features = false, optional = true }
bee-ledger = { version = "0.6.1", path = "../../bee-ledger", default-features = false }
bee-message = { version = "0.1.6", path = "../../bee-message", default-features = false }
bee-pow = { version = "0.2.0", path = "../../bee-pow", default-features = false }
Expand Down
6 changes: 6 additions & 0 deletions bee-network/bee-autopeering/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security -->

## 0.4.1 - 2022-02-28

### Changed

- Displayed representation of `PeerId`s to start at the beginning of its significant part;

## 0.4.0 - 2022-02-11

### Added
Expand Down
2 changes: 1 addition & 1 deletion bee-network/bee-autopeering/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bee-autopeering"
version = "0.4.0"
version = "0.4.1"
authors = [ "IOTA Stiftung" ]
edition = "2021"
description = "Allows peers in the same IOTA network to automatically discover each other."
Expand Down
3 changes: 2 additions & 1 deletion bee-network/bee-autopeering/src/peer/peer_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::{
};

const DISPLAY_LENGTH: usize = 16;
const DISPLAY_OFFSET: usize = 8;

/// Represents the unique identity of a peer in the network.
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -98,7 +99,7 @@ impl fmt::Debug for PeerId {

impl fmt::Display for PeerId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.libp2p_peer_id().to_base58()[..DISPLAY_LENGTH].fmt(f)
self.libp2p_peer_id().to_base58()[DISPLAY_OFFSET..DISPLAY_OFFSET + DISPLAY_LENGTH].fmt(f)
}
}

Expand Down
5 changes: 4 additions & 1 deletion bee-network/bee-autopeering/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ impl<S: PeerStore> TaskManager<S> {
let shutdown_tx = shutdown_senders.remove(&task_name).unwrap();

log::trace!("Shutting down: {}", task_name);
shutdown_tx.send(()).expect("error sending shutdown signal");

if shutdown_tx.send(()).is_err() {
log::error!("Error sending shutdown signal to task {task_name}.");
}
}

// Wait for all tasks to shutdown down in a certain order and maximum amount of time.
Expand Down
15 changes: 15 additions & 0 deletions bee-network/bee-gossip/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security -->

## 0.5.0 - 2022-02-28

### Added

- `PeerMetrics` type that keeps a count of dial attempts and identification timestamp;
- `PeerUnreachable` event that is fired after a certain number of unsuccessful dial attempts;

### Changed

- `PeerList` type keeps metrics for each peer;

### Fixed

- Missing `PeerRemoved` event for disconnected unknown peers;

## 0.4.0 - 2022-01-20

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion bee-network/bee-gossip/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bee-gossip"
version = "0.4.0"
version = "0.5.0"
authors = [ "IOTA Stiftung" ]
edition = "2021"
description = "Allows peers in the same IOTA network to exchange gossip messages with each other."
Expand Down
4 changes: 2 additions & 2 deletions bee-network/bee-gossip/src/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#[macro_export]
macro_rules! alias {
($peer_id:expr) => {
&$peer_id.to_base58()[46..]
&$peer_id.to_base58()[8..24]
};
($peer_id:expr, $len:expr) => {
&$peer_id.to_base58()[(52 - $len)..]
&$peer_id.to_base58()[8..8 + $len]
};
}
38 changes: 29 additions & 9 deletions bee-network/bee-gossip/src/network/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,8 @@ async fn process_swarm_event(
})
.expect("send error");

peerlist
.0
.write()
.await
.insert_local_addr(address)
.expect("insert_local_addr");
// Note: We don't care if the inserted address is a duplicate.
let _ = peerlist.0.write().await.add_local_addr(address);
}
SwarmEvent::ConnectionEstablished { peer_id, .. } => {
debug!("Swarm event: connection established with {}.", alias!(peer_id));
Expand Down Expand Up @@ -182,6 +178,7 @@ async fn process_internal_command(internal_command: Command, swarm: &mut Swarm<S
warn!("Dialing peer {} failed. Cause: {}", alias!(peer_id), e);
}
}
Command::DisconnectPeer { peer_id } => hang_up(swarm, peer_id).await,
_ => {}
}
}
Expand Down Expand Up @@ -209,13 +206,36 @@ async fn dial_peer(swarm: &mut Swarm<SwarmBehaviour>, peer_id: PeerId, peerlist:
// We just checked, that the peer is fine to be dialed.
let PeerInfo {
address: addr, alias, ..
} = peerlist.0.read().await.info(&peer_id).unwrap();

debug!("Dialing peer: {} ({}).", alias, alias!(peer_id));
} = peerlist.0.read().await.info(&peer_id).expect("peer must exist");

let mut dial_attempt = 0;

peerlist
.0
.write()
.await
.update_metrics(&peer_id, |m| {
m.num_dials += 1;
dial_attempt = m.num_dials;
})
.expect("peer must exist");

debug!(
"Dialing peer: {} ({}) attempt: #{}.",
alias,
alias!(peer_id),
dial_attempt
);

// TODO: We also use `Swarm::dial_addr` here (instead of `Swarm::dial`) for now. See if it's better to change
// that.
Swarm::dial_addr(swarm, addr).map_err(|e| Error::DialingPeerFailed(peer_id, e))?;

Ok(())
}

async fn hang_up(swarm: &mut Swarm<SwarmBehaviour>, peer_id: PeerId) {
debug!("Hanging up on: {}.", alias!(peer_id));

let _ = Swarm::disconnect_peer_id(swarm, peer_id);
}
Loading