Add Inbound/Outbound for connected peers (#725)

* Add Inbound/Outbound for connected peers

* Fix tests

* Undo removing trailing commas

* Revert "Fix tests"

This reverts commit 0d024188d4f98950d24c3aeab482b4fd417182ce.
This commit is contained in:
Quentin Le Sceller
2018-02-24 16:00:38 -05:00
committed by Antioch Peverell
parent 16d778a99b
commit ccf8eb9eeb
2 changed files with 14 additions and 2 deletions
+4 -2
View File
@@ -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<PeerInfo, Error> {
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
+10
View File
@@ -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