#peer-to-peer #rpc #protocol #low-level

bin+lib melnet

Low-level RPC protocol used throughout Themelio for peer-to-peer communciations

11 releases

0.1.10 Sep 1, 2021
0.1.9 Sep 1, 2021
0.1.7 Aug 17, 2021
0.1.1 Jun 30, 2021

#740 in Magic Beans

Download history 33/week @ 2021-06-15 17/week @ 2021-06-22 25/week @ 2021-06-29 36/week @ 2021-07-06 17/week @ 2021-07-13 54/week @ 2021-07-20 52/week @ 2021-07-27 115/week @ 2021-08-03 41/week @ 2021-08-10 52/week @ 2021-08-17 16/week @ 2021-08-24 62/week @ 2021-08-31 51/week @ 2021-09-07

154 downloads per month
Used in themelio-nodeprot

MPL-2.0 license

30KB
677 lines


lib.rs:

Melnet serves as Themelio's peer-to-peer network layer, based on a randomized topology and gossip. Peers are divided into servers, which have a publicly reachable address, and clients, which do not. It's based on a simple stdcode request-response protocol, where the only way to "push" a message is to send a request to a server. There is no multiplexing --- the whole thing works like HTTP/1.1. TCP connections are pretty cheap these days.

This also means that clients never receive notifications, and must poll servers.

The general way to use melnet is as follows:

  1. Create a NetState. This holds the routing table, RPC verb handlers, and other "global" data.
  2. If running as a server, register RPC verbs with NetState::register_verb and run NetState::run_server in the background.
  3. Use a Client, like the global one returned by g_client(), to make RPC calls to other servers. Servers are simply identified by a std::net::SocketAddr.

Dependencies

~11MB
~225K SLoC