116 releases
Uses old Rust 2015
0.37.1 | Dec 1, 2020 |
---|---|
0.37.0 | Aug 28, 2018 |
0.36.0 | Apr 5, 2018 |
0.35.0 | Dec 27, 2017 |
0.2.8 | Jul 8, 2015 |
#74 in #send-message
120 downloads per month
Used in 9 crates
(8 directly)
1MB
18K
SLoC
This crate has been renamed to sn_routing https://crates.io/crates/sn_routing
lib.rs
:
Client and node implementations for a resilient decentralised network.
The network is based on the kademlia_routing_table
and uses the XOR metric to define the
"distance" between two XorName
s. XorName
s are used as addresses of nodes, clients as
well as data.
Messages are exchanged between authorities, where an Authority
can be an individual client
or node, or a collection of nodes called a "section", or a subset of a section called a "group".
In all cases, messages are cryptographically signed by the sender, and in the case of sections
and groups, it is verified that a sufficient number of members agree on the message: only if
that quorum is reached, the message is delivered. In addition, each message has a unique ID, and
is delivered only once.
Section and group authorities are also addressed using a single XorName
. The members are the
nodes that are closest to that name. Sections contain a minimum number of nodes with the minimum
value specified as a network-wide constant. Groups are of fixed size, defined as the above
minimum section size. Since nodes are assigned their name by the network, this provides
redundancy and resilience: a node has no control over which section or group authority it will
be a member of, and without a majority in the section or group it cannot forge a message from
there.
The library also provides different types for the messages' data.
Usage
A decentralised service based on the routing
library uses Client
to send requests to the
network of nodes and receive responses.
Node
is used to handle and send requests within that network, and to implement its
functionality, e.g. storing and retrieving data, validating permissions, managing metadata, etc.
Client creation
A client's name is a hash of its public keys. Upon creation, the client will attempt to connect to the network through any node, and exchange public keys with it. That node becomes a bootstrap node for the client, and messages to and from the client will be routed over it.
use std::sync::mpsc;
use routing::{Client, Event, FullId};
let (sender, receiver) = mpsc::channel::<Event>();
let full_id = FullId::new(); // Generate new keys.
let client = Client::new(sender, Some(full_id), None).unwrap();
Messages can be sent using the methods of client
, and received as Event
s from the
receiver
.
Node creation
Creating a node looks even simpler:
use routing::Node;
let node = Node::builder().create().unwrap();
Upon creation, the node will first connect to the network as a client. Once it has client status, it requests a new name from the network, and then integrates itself in the network with that new name, adding close nodes to its routing table.
Messages can be sent using the methods of node
, and received as Event
s from the receiver
.
The node can act as an individual node or as part of a section or group authority. Sending a
message as a section or group authority only has an effect if sufficiently many other nodes in
that authority send the same message.
Sequence diagrams
Dependencies
~19MB
~349K SLoC