Mininode is a tiny p2p client for prototyping p2p protocols. It is a specification for a set of interfaces that I made to make it easier to think about this stuff.
A node is a daemon
managing one (or later maybe more than one) engine
.
A message is some data from a peer. We call it a mail
. The job of the daemon
is to mediate interactions between the engine and the outside world (in particular, the network).
mail = [peer type body]
- A
peer
is a public key. Mininode interface spec is transport agnostic, we will specify the interface that transport plugins need to implement later, right now we will use native auto http+websockets provided by node. There should be a natural way to turn this peer key plus host/port into a libp2p multiaddr, we will defer all that for later. - A
type
is a blob, most values are ignored by the daemon, but the engine can use it to trigger disconnects. - A
body
is deserialized RLP (recursive lists of bytes). If you want to put raw bytes, just do so and then encode it as such in RLP, it will add just the length as overhead.
The engine returns a list of messages.
- If the type starts with
end
, the daemon will send that message and disconnect the peer. - If the type starts with
ann
, the daemon will broadcast it to all peers. - If the type starts with
req
, the daemon will broadcast it to a random subset of peers (or configurable). - If the type starts with
res
, the daemon will send that message to the peer specified in the message.