Struct kademlia_routing_table::RoutingTable
[−]
[src]
pub struct RoutingTable<T, U> { // some fields omitted }
The RoutingTable class is used to maintain a list of contacts to which the node is connected.
Methods
impl<T: PartialEq + HasName + Debug + Clone, U: PartialEq + Debug + Clone> RoutingTable<T, U>
[src]
fn new(our_name: &XorName) -> RoutingTable<T, U>
constructor
fn add_node(&mut self, their_info: NodeInfo<T, U>) -> (bool, Option<NodeInfo<T, U>>)
Adds a contact to the routing table. If the contact is added, the first return arg is true, otherwise false. If adding the contact caused another contact to be dropped, the dropped one is returned in the second field, otherwise the optional field is empty.
fn add_connection(&mut self, their_name: &XorName, connection: U) -> bool
Adds a connection to an existing entry. Should be called after has_node
. The return
indicates if the given connection was added to an existing NodeInfo.
fn want_to_add(&self, their_name: &XorName) -> bool
This is used to check whether it is worthwhile trying to connect to the peer with a view to
adding the contact to our routing table, i.e. would this contact improve our table. The
checking procedure is the same as for add_node
, except for the lack of a public key to
check in step 1.
fn dynamic_quorum_size(&self) -> usize
returns the current calculated quorum size. This is dependent on routing table size at any time
fn drop_node(&mut self, node_to_drop: &XorName)
This unconditionally removes the contact from the table.
fn drop_connection(&mut self, lost_connection: &U) -> Option<XorName>
This should be called when a connection has dropped. If the affected entry has no connections after removing this one, the entry is removed from the routing table and its name is returned. If the entry still has at least one connection, or an entry cannot be found for 'lost_connection', the function returns 'None'.
fn target_nodes(&self, target: &XorName) -> Vec<NodeInfo<T, U>>
This returns a collection of contacts to which a message should be sent onwards. It will return all of our close group (comprising 'group_size()' contacts) if the closest one to the target is within our close group. If not, it will return either the 'parallelism()' closest contacts to the target or a single contact if 'target' is the name of a contact in the table.
fn our_close_group(&self) -> Vec<NodeInfo<T, U>>
This returns our close group, i.e. the 'group_size()' contacts closest to our name (or the entire table if we hold less than 'group_size()' contacts in total) sorted by closeness to us.
fn is_close(&self, name: &XorName) -> bool
This returns true if the provided name is closer than or equal to the furthest node in our close group. If the routing table contains less than group_size() nodes, then every address is considered to be close.
fn len(&self) -> usize
number of elements
fn is_empty(&self) -> bool
empty
fn our_name(&self) -> &XorName
routing table name
fn has_node(&self, name: &XorName) -> bool
check is routing table contains name
fn try_confirm_safe_group_distance(&self, address1: &XorName, address2: &XorName) -> bool
Use this to calculate incoming messages for instance "fit" in this bucket distance when confirming a group is who it says it is. This is a partial check not full security