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

feat(network): add peer tag support #5

Merged
merged 9 commits into from
Jul 16, 2020
Prev Previous commit
Next Next commit
fix(network): clippy warnings
zeroqn committed Jul 16, 2020
commit 75264c7190e28cfc8c1d8097d3499248e3e17d20
2 changes: 1 addition & 1 deletion core/network/src/config.rs
Original file line number Diff line number Diff line change
@@ -267,7 +267,7 @@ impl NetworkConfig {
Ok(self)
}

pub fn allowlist<'a, S: AsRef<[String]>>(mut self, peer_id_strs: S) -> ProtocolResult<Self> {
pub fn allowlist<S: AsRef<[String]>>(mut self, peer_id_strs: S) -> ProtocolResult<Self> {
let peer_ids = {
let str_iter = peer_id_strs.as_ref().iter();
let to_peer_ids = str_iter.map(PeerId::from_str_ext);
4 changes: 2 additions & 2 deletions core/network/src/peer_manager/mod.rs
Original file line number Diff line number Diff line change
@@ -304,7 +304,7 @@ impl Inner {

/// If peer exists, return false
pub fn add_peer(&self, peer: ArcPeer) -> bool {
self.peers.write().insert(peer.clone())
self.peers.write().insert(peer)
}

pub fn peer_count(&self) -> usize {
@@ -580,7 +580,7 @@ impl PeerManager {
let remote_peer = opt_peer.unwrap_or_else(|| ArcPeer::new(remote_peer_id.clone()));

if !remote_peer.has_pubkey() {
if let Err(e) = remote_peer.set_pubkey(pubkey.clone()) {
if let Err(e) = remote_peer.set_pubkey(pubkey) {
error!("impossible, set public key failed {}", e);
error!("new session without peer pubkey, chain book will not be updated");
}
6 changes: 3 additions & 3 deletions core/network/src/peer_manager/tags.rs
Original file line number Diff line number Diff line change
@@ -28,9 +28,9 @@ impl Tags {

pub fn insert_ban(&self, timeout: Duration) -> Result<(), ErrorKind> {
if self.contains(&PeerTag::Consensus) || self.contains(&PeerTag::AlwaysAllow) {
return Err(ErrorKind::Untaggable(format!(
"consensus and always allow cannot be ban"
)));
return Err(ErrorKind::Untaggable(
"consensus and always allow cannot be ban".to_owned(),
));
}

let until = Duration::from_secs(time::now()) + timeout;