diff --git a/p2p/src/handshake.rs b/p2p/src/handshake.rs index 8fe8b0c2a..8018136e9 100644 --- a/p2p/src/handshake.rs +++ b/p2p/src/handshake.rs @@ -99,6 +99,7 @@ impl Handshake { addr: peer_addr, version: shake.version, total_difficulty: shake.total_difficulty, + direction: Direction::Outbound, }; // If denied then we want to close the connection @@ -106,7 +107,7 @@ impl Handshake { if Peer::is_denied(&self.config, &peer_info.addr) { return Err(Error::ConnectionClose); } - + debug!( LOGGER, "Connected! Cumulative {} offered from {:?} {:?} {:?}", @@ -127,7 +128,7 @@ impl Handshake { ) -> Result { let hand: Hand = read_message(conn, Type::Hand)?; - + // all the reasons we could refuse this connection for if hand.version != PROTOCOL_VERSION { return Err(Error::ProtocolMismatch { @@ -154,6 +155,7 @@ impl Handshake { addr: extract_ip(&hand.sender_addr.0, &conn), version: hand.version, total_difficulty: hand.total_difficulty, + direction: Direction::Inbound, }; // At this point we know the published ip and port of the peer diff --git a/p2p/src/types.rs b/p2p/src/types.rs index 02e297b4f..8216d65b7 100644 --- a/p2p/src/types.rs +++ b/p2p/src/types.rs @@ -123,6 +123,15 @@ bitflags! { } } +/// Types of connection +enum_from_primitive! { + #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] + pub enum Direction { + Inbound, + Outbound, + } +} + /// General information about a connected peer that's useful to other modules. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct PeerInfo { @@ -131,6 +140,7 @@ pub struct PeerInfo { pub version: u32, pub addr: SocketAddr, pub total_difficulty: Difficulty, + pub direction: Direction, } /// The full sumtree data along with indexes required for a consumer to