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

Download history 57/week @ 2023-11-20 40/week @ 2023-11-27 42/week @ 2023-12-04 160/week @ 2023-12-11 4/week @ 2023-12-18 91/week @ 2023-12-25 59/week @ 2024-01-01 9/week @ 2024-01-08 95/week @ 2024-01-15 58/week @ 2024-01-22 110/week @ 2024-01-29 37/week @ 2024-02-19 112/week @ 2024-02-26 5/week @ 2024-03-04

154 downloads per month
Used in 9 crates (8 directly)

GPL-3.0 license

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 XorNames. XorNames 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 Events 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 Events 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
~357K SLoC