5 releases

0.2.0 Aug 26, 2021
0.1.3 Aug 24, 2021
0.1.2 Aug 24, 2021
0.1.1 Aug 24, 2021
0.1.0 Aug 24, 2021

#24 in #proposal

MIT license

28KB
694 lines

Cold IO

It is the wrapper over mio. Allows to write a network application as a state machine to simplify testing.

Proposer

The core entity is Proposer it working with the state machine that user implemented.

The Proposer provides the state machine a sequence of Proposal. For each Proposal state machine can return some Request.

Proposal

It containing random number generator, elapsed time from previous proposal and one of the following messages:

  • Wake - The first message that Proposer sends to the state machine. It needed for the state machine to provide a first request.
  • Idle - The message that means nothing happened during some time.
  • OnReadable/OnWritable - Some remote peer is ready to transmit/receive data. With this message a managed stream is provided. This object can be used only once.

Managed Stream

The state machine receive ReadOnce object along with OnReadable event. The state machine can read it, or drop, or store for further use. The proposer will not send another ReadOnce until previous did not consumed. It can be dropped and the connection part (read or write) will be closed. If the state machine read the object, it will know how many bytes was read, and whether there will be more.

The state machine receive WriteOnce object along with OnWritable event. It is very similar to ReadOnce.

Request

There are following elemental requests:

  • Source of incoming connections. It can be a port, or nothing. It is planned to receive incoming connections from another thread.
  • Blacklist a peer or a batch of peers.
  • Connect to a peer or to a batch of peers.

Dependencies

~0.7–1.2MB
~20K SLoC