Crate melnet[][src]

Expand description

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.

Structs

A clonable structure representing a melnet state. All copies share the same routing table.

A Request<Req, Resp> carries a stdcode-compatible request of type `Req and can be responded to with responses of type Resp.

A single-use channel through which to send a response.

Enums

Constants

Traits

An Endpoint responds to Requests. Requests are responded to by calling Request::respond() rather than by return value to simplify asynchronous handling.

Functions

Does a melnet request to any given endpoint, using the global client.

Type Definitions