Package: messi
⚽ MessiReliable message passing in distributed systems.Highlights:Guaranteed in order message delivery.Client automatically reconnects when the server connection is lost.Protocols defined in GooglesProtocol Bufferslanguage version 3.Designed to work in resource constrained systems.CandPythonsource code generators.Project homepage:https://github.com/eerimoq/messiInstallation$pipinstallmessiC source codeGenerate server and client side C source code.$ messi generate_c_source examples/my_protocol/my_protocol.protoUse-p/--platformto select which platform to generate code
for.Use-s/--sideto select which side (client and/or server) to
generate code for.Supported platforms:Linux, using TCP sockets,epollandtimerfd.Theasyncframework (client only).The generated code isnotthread safe.Known limitations:The connection is immediately dropped ifwrite()does not accept
exaxtly given amount of bytes. Buffering of remaining data may be
added at some point.Linux client sideSeetests/files/my_protocol/linux/my_protocol_client.hfor the
generated code andexamples/my_protocol/client/linux/main.cfor
example usage.Linux server sideSeetests/files/my_protocol/linux/my_protocol_server.hfor the
generated code andexamples/my_protocol/server/linux/main.cfor
example usage.Async client sideSeetests/files/my_protocol/async/my_protocol_client.hfor the
generated code andexamples/my_protocol/client/async/main.cfor
example usage.Python source codeGenerate client side Python source code.$ messi generate_py_source examples/my_protocol/my_protocol.protoUse-s/--sideto select which side (client and/or server) to
generate code for.Client sideSeetests/files/my_protocol/my_protocol_client.pyfor the generated
code andexamples/my_protocol/client/python/main.pyfor example
usage.Server sideNot yet implemented.ArchitectureAMessisystem consists of servers and clients. Once a client has
successfully connected to a server, messages defined in their protocol
specification can be reliably sent between them.Messiguarantees that all sent messages are delivered in order to
the peer. However, just as for TCP, any data/messages in flight when
the connection is lost will likely be lost.Below is a sequence diagram showing typical communication between a
server and a client. The messagesFooReq,FooRsp,BarInd,FieReqandFieRspare defined in the protocolmy_protocol,
which is defined later in this document.Each step (1 to 6) is described in detail after the sequence diagram.+--------+                               +--------+
              | client |                               | server |
              +--------+                               +--------+
                  |             1. TCP connect              |
                  |========================================>|
   on_connected() |                2. ping                  | on_client_connected()
                  |---------------------------------------->|
                  |                   pong                  |
                  |<----------------------------------------|
           send() |               3. FooReq                 |
                  |========================================>|
                  |                  FooRsp                 | reply()
                  |<========================================|
           send() |               4. BarInd                 |
                  |========================================>|
           send() |                  BarInd                 |
                  |========================================>|
                  |               5. FieReq                 | send()
                  |<========================================|
           send() |                  FieRsp                 |
                  |========================================>|
                  .                                         .
                  .                                         .
                  .                                         .
                  |                6. ping                  |
                  |---------------------------------------->|
                  .                                         .
on_disconnected() .                                         . on_client_disconnected()
                  .                                         .

Legend:

  ---: Background communication. No user interaction needed.

  ===: User initiated communication.Step by step description:The client connects to the server.on_connected()andon_client_connected()are called to notify the user that the
connection has been established.The client sends a ping message to the server, which responds with
a pong message. This is done in the background. No user interaction
needed.The client sendsFooReqto the server, which responds withFooRsp.The client sendsBarIndtwice to the server. No response is
defined.The server sendsFieReqto the client, which responds withFieRsp.The client sends another ping message. This time the server does
not respond.on_disconnected()andon_client_disconnected()are called to notify the user about the disconnection.Messi protocol specificationAll messages sent on the wire consists of a type, a size and optional
payload. This enables both streaming and packet based transport
protocols. The transport protocol must be reliable (guaranteed in
order delivery).Type and size are in network byte order (big endian).+---------+---------+-----------------+
| 1b type | 3b size | <size>b payload |
+---------+---------+-----------------+

TYPE  SIZE  DESCRIPTION
------------------------------------------------------------------
   1     n  Client to server user message (client --> server).

            Encoded "message ClientToServer" messages.

   2     n  Server to client user message (server --> client).

            Encoded "message ServerToClient" messages.

   3     0  Ping message (client --> server).
   4     0  Pong message (server --> client).User messagesUser messages are defined in GooglesProtocol Bufferslanguage
version 3.Here is an example defining a protocol calledmy_protocol. The two
messagesClientToServerandServerToClientmust be present in
every protocol specification.ClientToServercontains all messages
sent from clients to servers, andServerToClientcontains all
messages sent from servers to clients.syntax="proto3";// The protocol name.packagemy_protocol;// Messages sent from client to server.messageClientToServer{oneofmessages{FooReqfoo_req=1;BarIndbar_ind=2;FieRspfie_rsp=3;}}// Messages sent from server to client.messageServerToClient{oneofmessages{FooRspfoo_rsp=1;FieReqfie_req=2;}}// Message definitions.messageFooReq{}messageFooRsp{}messageBarInd{}messageFieReq{}messageFieRsp{}Ping and pong messagesA client pings its server periodically. A client will close the
connection and report an error if the server does not answer with pong
within given time. Likewise, the server will close the connection and
report an error if it does not receive ping within given time.The ping-pong mechanism is only used if the transport layer does not
provide equivalent functionality.Error handlingMessiaims to minimize the amount of error handling code in the user
application. Almost all functions always succeeds from the caller
point of view. For example,my_protocol_client_send()returnsvoid. If an error occurs, likely a connection issue, the
disconnect callback is called to notify the user that the connection
was dropped.Similar solutionsgRPCwith bidirectional streaming.Embedded RPC.