Struct kademlia_routing_table::RoutingTable [] [src]

pub struct RoutingTable<T, U> where U: Eq + Hash {
    // some fields omitted
}

A routing table to manage connections for a node.

It maintains a list of NodeInfos representing connections to peer nodes, and provides algorithms for routing messages.

See the crate documentation for details.

Methods

impl<T, U> RoutingTable<T, U> where T: PartialEq + HasName + Debug + Clone, U: Eq + Debug + Clone + Hash
[src]

fn new(our_name: &XorName) -> RoutingTable<T, U>

Creates a new routing table for the node with the given name.

fn add_node(&mut self, node: NodeInfo<T, U>) -> Option<AddedNodeDetails<T, U>>

Adds a contact to the routing table, or updates it.

Returns None if the contact already existed. Otherwise it returns AddedNodeDetails.

fn add_connection(&mut self, their_name: &XorName, connection: U) -> bool

Adds a connection to an existing entry.

Should be called after has_node. Returns true if the given connection was added to an existing NodeInfo, and false if no such entry exists.

fn need_to_add(&self, their_name: &XorName) -> bool

Returns whether it is desirable to add the given contact to the routing table.

Returns false if adding the contact in question would not bring the routing table closer to satisfy the invariant. It returns true if and only if the new contact would be among the GROUP_SIZE closest nodes in its bucket.

fn allow_connection(&self, name: &XorName) -> bool

Returns whether we can allow the given contact to connect to us.

The connection is allowed if:

  • they already are one of our contacts,
  • we need them in our routing table to satisfy the invariant or
  • we are in the close group of one of their bucket addresses.

fn dynamic_quorum_size(&self) -> usize

Returns the current calculated quorum size.

If it is known that the network has at least GROUP_SIZE nodes, this returns the constant QUORUM_SIZE. For networks smaller than that, the quorum might not be reachable, so a smaller number is computed which represents a strict majority in the current network.

fn furthest_close_bucket(&self) -> usize

Returns the bucket index of the furthest close node.

fn remove(&mut self, node_to_drop: &XorName) -> Option<NodeInfo<T, U>>

Removes the contact from the table.

Returns the dropped node if the contact was present in the table.

fn drop_connection(&mut self, lost_connection: &U) -> Option<DroppedNodeDetails>

This should be called when a connection has dropped.

If no entry with that connection is found, None is returned. If the affected entry still has connections left after removing this one, the entry remains in the table and the result is also None. Otherwise, the entry is removed from the routing table and DroppedNodeDetails are returned.

fn closest_nodes_to(&self, target: &XorName, n: usize) -> Vec<NodeInfo<T, U>>

Returns the n nodes in our routing table that are closest to target.

Returns fewer than n nodes if the routing table doesn't have enough entries.

fn target_nodes(&self, dst: Destination, hop_type: HopType) -> Vec<NodeInfo<T, U>>

Returns a collection of nodes to which a message should be sent onwards.

If the message is addressed at a group and we are a member of that group, this returns all other members of that group once, and an empty collection for all further copies.

If the message is addressed at an individual node that is directly connected to us, this returns the destination node once, and an empty collection for all further copies.

If none of the above is the case and we are the original sender, it returns the PARALLELISM closest nodes to the target.

Otherwise it returns the n-th closest node to the target if this is the n-th copy of the message we are relaying.

fn is_recipient(&self, dst: Destination) -> bool

Returns whether the message is addressed to this node.

If this returns true, this node is either the single recipient of the message, or a member of the group authority to which it is addressed. It therefore needs to handle the message.

fn our_close_group(&self) -> Vec<NodeInfo<T, U>>

Returns the rest of our close group, i. e. the GROUP_SIZE - 1 nodes closest to our name.

If the network is smaller than that, all nodes are returned.

fn is_close(&self, name: &XorName) -> bool

Returns true if there are fewer than GROUP_SIZE nodes in our routing table that are closer to name than we are.

In other words, it returns true whenever we cannot rule out that we might be among the GROUP_SIZE closest nodes to name.

If the routing table is filled in such a way that each bucket contains GROUP_SIZE elements unless there aren't enough such nodes in the network, then this criterion is actually sufficient! In that case, true is returned if and only if we are among the GROUP_SIZE closest node to name in the network.

fn len(&self) -> usize

Number of entries in the routing table.

fn is_empty(&self) -> bool

Returns true if there are no entries in the routing table.

fn our_name(&self) -> &XorName

Returns the name of the node this routing table is for.

fn get(&self, name: &XorName) -> Option<&NodeInfo<T, U>>

Returns the NodeInfo with the given name, if it is in the routing table.