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

fix: disallowed loop connections #7719

Merged
merged 17 commits into from
Oct 4, 2022
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
10 changes: 5 additions & 5 deletions chain/network/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
pub use crate::peer_manager::peer_manager_actor::{Event, PeerManagerActor};
pub use crate::peer_manager::peer_store::iter_peers_from_store;
#[cfg(feature = "test_features")]
pub use crate::stats::metrics::RECEIVED_INFO_ABOUT_ITSELF;

mod accounts_data;
mod concurrency;
mod network_protocol;
mod peer;
mod peer_manager;
mod private_actix;
mod stats;
mod store;

pub mod actix;
pub mod blacklist;
pub mod config;
pub mod config_json;
pub(crate) mod private_actix;
pub mod routing;
pub(crate) mod stats;
pub(crate) mod store;

pub mod tcp;
pub mod test_utils;
pub mod time;
pub mod types;
Expand Down
15 changes: 3 additions & 12 deletions chain/network/src/network_protocol/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ pub struct PartialEdgeInfo {

impl PartialEdgeInfo {
pub fn new(peer0: &PeerId, peer1: &PeerId, nonce: u64, secret_key: &SecretKey) -> Self {
let data = if peer0 < peer1 {
Edge::build_hash(peer0, peer1, nonce)
} else {
Edge::build_hash(peer1, peer0, nonce)
};

let data = Edge::build_hash(peer0, peer1, nonce);
let signature = secret_key.sign(data.as_ref());
Self { nonce, signature }
}
Expand Down Expand Up @@ -114,7 +109,7 @@ impl Edge {
/// Build the hash of the edge given its content.
/// It is important that peer0 < peer1 at this point.
pub fn build_hash(peer0: &PeerId, peer1: &PeerId, nonce: u64) -> CryptoHash {
debug_assert!(peer0 < peer1);
let (peer0, peer1) = if peer0 < peer1 { (peer0, peer1) } else { (peer1, peer0) };
CryptoHash::hash_borsh(&(peer0, peer1, nonce))
}

Expand All @@ -130,11 +125,7 @@ impl Edge {
/// to verify the signature.
pub fn partial_verify(peer0: &PeerId, peer1: &PeerId, edge_info: &PartialEdgeInfo) -> bool {
let pk = peer1.public_key();
let data = if peer0 < peer1 {
Edge::build_hash(peer0, peer1, edge_info.nonce)
} else {
Edge::build_hash(peer1, peer0, edge_info.nonce)
};
let data = Edge::build_hash(peer0, peer1, edge_info.nonce);
edge_info.signature.verify(data.as_ref(), pk)
}

Expand Down
Loading