CympleTech / chamomile

Lightweight p2p library. Support build robust connection on decentralized network.
Apache License 2.0
113 stars 18 forks source link

RFC: Add request/response network state message. #12

Closed sunhuachuang closed 4 years ago

sunhuachuang commented 4 years ago

Why

When want to know current network state, need a function to get.

How

enum SendMessage {
    ...
    /// Request for return the network current state info.
    /// params is request type, and return channel's sender (async).
    NetworkState(StateRequest, Sender<StateResponse>),
}

/// Network state info response.
#[derive(Debug, Clone)]
pub enum StateRequest {
    Stable,
    DHT,
    Seed,
}

/// Network state info response.
#[derive(Debug, Clone)]
pub enum StateResponse {
    /// response is peer list and peer is relay or directly.
    Stable(Vec<(PeerId, bool)>),
    /// response is peer list.
    DHT(Vec<PeerId>),
    /// response is socket list.
    Seed(Vec<SocketAddr>),
}
sunhuachuang commented 4 years ago

Ok, finished.