New peer architectureΒΆ

Peer and Broker derive from BasePeer class. BasePeer is derived from ZmqAsyncioTaskManager. ZmqAsyncioTaskManager is derived from AsyncioTaskManager.

AsyncioTaskManager manages a set of tasks running inside asyncio message loop. Message loop can be owned by AsyncioTaskManager or borrowed. When message loop is owned new message loop is started in a new thread.

ZmqAsyncioTaskManager adds ZMQ asyncio context lifetime management to AsyncioTaskManager. ZMQ context can be borrowed or owned.

BasePeer extends ZmqAsyncioTaskManager by adding three ZMQ sockets:

  • SUB used to receive broadcast messages, connects to Broker’s XPUB
  • PUB used to send broadcast messages, connects to Broker’s XSUB
  • REP used to answer synchronous messages (messages requiring an answer)

In ZMQ 3+ messages are filtered on PUB socket, so no redundant messages will be sent to clients.

Broker extends BasePeer by adding:

  • XPUB/XSUB message proxy
  • centralized peer registration authority
  • query authority
  • heartbeat monitor

Peer extends BasePeer by adding:

  • initialization code/Broker connection code
  • heartbeat message sending