Heartbeating

pseud allows you to build your own Heartbeat Backend. Your implementation must conform to its Interface defined in pseud.interfaces.IHeartbeatBackend

Also all your plugin must adapts pseud.interfaces.IClient or pseud.interfaces.IServer and being registered thanks to pseud.utils.register_heartbeat_backend() decorator.

Heartbeat backends aim to define your the policy you need regarding exclusion of disconnected peer, e.g.. after 3 heartbeat missed, you can decide to exclude peer from list of known connected peers.

Also, very important, thanks to heartbeat backends you can maintain an accurate list of currently connected clients and their ids. It is up to you to decide to store this list in memory (simple dict), or to use redis if you think the number of peers will be huge.

You can start with the following snippet

@register_heartbeat_backend
@zope.interface.implementer(IHeartbeatBackend)
@zope.component.adapter(IClient)
class MyHeartbeatBackend(object):
    name = 'my_heartbeat_backend'

    def __init__(self, rpc):
        self.rpc = rpc

    def handle_heartbeat(self, user_id, routing_id):
        pass

    async def handle_timeout(self, user_id, routing_id):
        pass

    def configure(self):
        pass

    def stop(self):
        pass

In this example the name ‘my_heartbeat_backend’ will be used when instanciating your RPC endpoint.

client = pseud.Client('remote',
                      heartbeat_plugin='my_heartbeat_backend')

Read Protocol v1 for more explanation. Also in pseud.heartbeat you will find examples that are used in tests.