swarm icon indicating copy to clipboard operation
swarm copied to clipboard

Asynchronous message handling in protocols package

Open janos opened this issue 6 years ago • 0 comments

Package protocols uses Peer.Run function to call handlers on received messages. It was observed that that synchronicity negatively impact message exchange. Upon message read, handling of that message should be asynchronous. This was somehow achieved in every swarm protocol as required, for example in network/retrieval.Retrieval.handleMsg, where handlers are called in goroutines, ignoring errors that are returned from them. Such handling should be removed from all protocols.

Message handling should:

  • [x] be asynchronous
  • handle different errors and error types differently to achieve:
    • [x] peer drop functionality
    • [ ] peer blacklisting

In the first stage of async handling implementation, any error may be considered as a reason to drop a peer. This would remove the need to call protocols.Peer.Drop in handlers, like in network/stream.Registry.serverHandleGetRange and other places. That would simplify handlers code in many places.

At the later stage peer blacklisting should be implemented based on specific errors returned by handlers.

This change may impact the stability of simulations in tests and should be carefully tested with smoke tests using integration clusters.

janos avatar Dec 03 '19 12:12 janos