[][src]Struct discv5::Discv5

pub struct Discv5 {
    events: VecDeque<Discv5Event>,
    config: Discv5Config,
    kbuckets: KBucketsTable<NodeId, RawEnr<CombinedKey>>,
    queries: QueryPool<QueryInfo, NodeId, RawEnr<CombinedKey>>,
    active_rpc_requests: FnvHashMap<RpcRequest, (Option<QueryId>, Request)>,
    active_nodes_responses: HashMap<NodeId, NodesResponse>,
    ip_votes: Option<IpVote>,
    connected_peers: HashMap<NodeId, Interval>,
    service: Service,
}

Fields

events: VecDeque<Discv5Event>

Events yielded by this behaviour.

config: Discv5Config

Configuration parameters for the Discv5 service

kbuckets: KBucketsTable<NodeId, RawEnr<CombinedKey>>

Storage of the ENR record for each node.

queries: QueryPool<QueryInfo, NodeId, RawEnr<CombinedKey>>

All the iterative queries we are currently performing.

active_rpc_requests: FnvHashMap<RpcRequest, (Option<QueryId>, Request)>

RPC requests that have been sent and are awaiting a response. Some requests are linked to a query.

active_nodes_responses: HashMap<NodeId, NodesResponse>

Keeps track of the number of responses received from a NODES response.

ip_votes: Option<IpVote>

A map of votes nodes have made about our external IP address. We accept the majority.

connected_peers: HashMap<NodeId, Interval>

List of peers we have established sessions with and an interval for when to send a PING.

service: Service

Main discv5 UDP service that establishes sessions with peers.

Implementations

impl Discv5[src]

pub fn new(
    local_enr: RawEnr<CombinedKey>,
    enr_key: CombinedKey,
    config: Discv5Config,
    listen_socket: SocketAddr
) -> Result<Self, Discv5Error>
[src]

Builds the Discv5 main struct.

local_enr is the ENR representing the local node. This contains node identifying information, such as IP addresses and ports which we wish to broadcast to other nodes via this discovery mechanism. The listen_socket determines which UDP socket address the behaviour will listen on.

pub fn add_enr(&mut self, enr: RawEnr<CombinedKey>) -> Result<(), &'static str>[src]

Adds a known ENR of a peer participating in Discv5 to the routing table.

This allows pre-populating the Kademlia routing table with known addresses, so that they can be used immediately in following DHT operations involving one of these peers, without having to dial them upfront.

pub fn remove_node(&mut self, node_id: &NodeId) -> bool[src]

Removes a node_id from the routing table.

This allows applications, for whatever reason, to remove nodes from the local routing table. Returns true if the node was in the table and false otherwise.

pub fn connected_peers(&self) -> usize[src]

Returns the number of connected peers the service knows about.

pub fn local_enr(&self) -> &RawEnr<CombinedKey>[src]

Returns the local ENR of the node.

pub fn update_local_enr_socket(
    &mut self,
    socket_addr: SocketAddr,
    is_tcp: bool
) -> bool
[src]

Allows the application layer to update the local ENR's UDP socket. The second parameter determines whether the port is a TCP port. If this parameter is false, this is interpreted as a UDP SocketAddr.

pub fn enr_insert(
    &mut self,
    key: &str,
    value: Vec<u8>
) -> Result<Option<Vec<u8>>, EnrError>
[src]

Allows application layer to insert an arbitrary field into the local ENR.

pub fn kbuckets_entries(&mut self) -> impl Iterator<Item = &NodeId>[src]

Returns an iterator over all ENR node IDs of nodes currently contained in a bucket of the Kademlia routing table.

pub fn enr_entries(&mut self) -> impl Iterator<Item = &RawEnr<CombinedKey>>[src]

Returns an iterator over all the ENR's of nodes currently contained in a bucket of the Kademlia routing table.

pub fn find_node(&mut self, target_node: NodeId) -> QueryId[src]

Starts an iterative FIND_NODE request.

This will eventually produce an event containing the nodes of the DHT closest to the requested PeerId.

pub fn find_enr_predicate<F>(
    &mut self,
    node_id: NodeId,
    predicate: F,
    num_nodes: usize
) -> QueryId where
    F: Fn(&RawEnr<CombinedKey>) -> bool + Send + Clone + 'static, 
[src]

Starts a FIND_NODE request.

This will eventually produce an event containing <= num nodes which satisfy the predicate with passed value.

pub fn find_enr(&mut self, node_id: &NodeId) -> Option<RawEnr<CombinedKey>>[src]

Returns an ENR if one is known for the given NodeId.

fn handle_rpc_request(
    &mut self,
    src: SocketAddr,
    node_id: NodeId,
    rpc_id: u64,
    req: Request
)
[src]

Processes an RPC request from a peer. Requests respond to the received socket address, rather than the IP of the known ENR.

fn handle_rpc_response(&mut self, node_id: NodeId, rpc_id: u64, res: Response)[src]

Processes an RPC response from a peer.

fn send_ping(&mut self, node_id: &NodeId)[src]

Sends a PING request to a node.

fn ping_connected_peers(&mut self)[src]

fn request_enr(&mut self, node_id: &NodeId, src: SocketAddr)[src]

Request an external node's ENR.

fn send_nodes_response(
    &mut self,
    dst: SocketAddr,
    dst_id: NodeId,
    rpc_id: u64,
    distance: u64
)
[src]

Sends a NODES response, given a list of found ENR's. This function splits the nodes up into multiple responses to ensure the response stays below the maximum packet size.

fn send_rpc_query(
    &mut self,
    query_id: QueryId,
    query_info: QueryInfo,
    return_peer: &ReturnPeer<NodeId>
)
[src]

Constructs and sends a request RPC to the session service given a QueryInfo.

fn send_rpc_request(
    &mut self,
    node_id: &NodeId,
    req: Request,
    query_id: Option<QueryId>
)
[src]

Sends generic RPC requests. Each request gets added to known outputs, awaiting a response.

fn start_findnode_query(&mut self, target_node: NodeId) -> QueryId[src]

Internal function that starts a query.

fn start_predicate_query<F>(
    &mut self,
    target_node: NodeId,
    predicate: F,
    num_nodes: usize
) -> QueryId where
    F: Fn(&RawEnr<CombinedKey>) -> bool + Send + Clone + 'static, 
[src]

Internal function that starts a query.

fn discovered(
    &mut self,
    source: &NodeId,
    enrs: Vec<RawEnr<CombinedKey>>,
    query_id: Option<QueryId>
)
[src]

Processes discovered peers from a query.

fn connection_updated(
    &mut self,
    node_id: NodeId,
    enr: Option<RawEnr<CombinedKey>>,
    new_status: NodeStatus
)
[src]

Update the connection status of a node in the routing table.

fn inject_session_established(&mut self, enr: RawEnr<CombinedKey>)[src]

The equivalent of libp2p inject_connected() for a udp session. We have no stream, but a session key-pair has been negotiated.

fn rpc_failure(&mut self, node_id: NodeId, failed_rpc_id: u64)[src]

A session could not be established or an RPC request timed-out (after a few retries, if specified).

Trait Implementations

impl Stream for Discv5[src]

type Item = Discv5Event

Values yielded by the stream.

Auto Trait Implementations

impl !RefUnwindSafe for Discv5

impl Send for Discv5

impl !Sync for Discv5

impl Unpin for Discv5

impl !UnwindSafe for Discv5

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<St> StreamExt for St where
    St: Stream + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,