[design] Pluggable message handlers and asynchronous operation #4382

issue sipa opened this issue on June 21, 2014
  1. sipa commented at 5:12 PM on June 21, 2014: member

    Right now, there is a single ProcessMessages handler (which is somewhat pluggable through the use of boost::signals2), but it still implies:

    • A single method needing to deal with everything.
    • Only a single network handler thread (because it assumes everything needs cs_main anyway).
    • No way to process messages asynchronously (we want to process everything from a single peer in-order, but there is no need why a pong reply to peer B's ping needs to wait while we're waiting for the hard disk to find a block in response to peer A's getdata).

    So, what I would like is pluggable modules that can independently install handlers for specific network messages, that can have independent state, and can run independently and asynchronously, while still maintaining the guarantee that a single peer's messages are always processed in-order.

    I'll try to post an idea for a design soon.

  2. sipa added the label Brainstorming on Jun 21, 2014
  3. sipa added the label Improvement on Jun 21, 2014
  4. sipa added the label P2P on Jun 21, 2014
  5. jgarzik commented at 5:26 PM on June 21, 2014: contributor

    Seems like we get most of this for free, simply by using boost::asio's M-T socket handling? a la https://github.com/jgarzik/rpcsrv

    It sounds like a more complicated design than the more common design pattern of simply servicing multiple sockets in parallel threads using boost::asio dispatch.

  6. sipa commented at 5:31 PM on June 21, 2014: member

    I'm not a fan of asio. Perhaps unnecessarily so, but all I've seen of it is wasteful resource usage and hard to read code.

    And simply processing multiple sockets in parallel is not enough. If two sockets both have a 'block' message to be processed, having two threads will still only allow only one to work (as it needs cs_main, or whatever its successor is), even though there may be other threads that do have messages that can be processed without it.

  7. sipa commented at 5:39 PM on June 21, 2014: member

    Also, that's mostly an implementation issue - what I really want is a nice API so handling of P2P messages can be broken out into separate modules with their own state. The implementation of the base networking code that implements the API is still open.

  8. sipa commented at 5:41 PM on January 23, 2017: member

    After discussion with @theuni I'm closing this. There seems too much state shared between multiple messages handlers to separate them.

    I believe this can still be revisited as a concept after the current network refactors, but as a layer on top instead.

  9. sipa closed this on Jan 23, 2017

  10. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-19 09:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me