mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
Add Inbound/Outbound for connected peers
This commit is contained in:
parent
05d1c6c817
commit
b6a28ea16f
2 changed files with 14 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue