pubsub.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright (c) 2001, Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * @file pubsub.h
  8. * @brief Header for OO publish-subscribe functionality.
  9. *
  10. * This module provides a wrapper around the "dispatch" module,
  11. * ensuring type-safety and allowing us to do static analysis on
  12. * publication and subscriptions.
  13. *
  14. * With this module, we enforce:
  15. * <ul>
  16. * <li>that every message has (potential) publishers and subscribers;
  17. * <li>that every message is published and subscribed from the correct
  18. * channels, with the correct type ID, every time it is published.
  19. * <li>that type IDs correspond to a single C type, and that the C types are
  20. * used correctly.
  21. * <li>that when a message is published or subscribed, it is done with
  22. * a correct subsystem identifier
  23. * </ul>
  24. *
  25. * We do this by making "publication requests" and "subscription requests"
  26. * into objects, and doing some computation on them before we create
  27. * a dispatch_t with them.
  28. *
  29. * Rather than using the dispatch module directly, a publishing module
  30. * receives a "binding" object that it uses to send messages with the right
  31. * settings.
  32. */
  33. /*
  34. *
  35. * Overview: Messages are sent over channels. Before sending a message on a
  36. * channel, or receiving a message on a channel, a subsystem needs to register
  37. * that it publishes, or subscribes, to that message, on that channel.
  38. *
  39. * Messages, channels, and subsystems are represented internally as short
  40. * integers, though they are associated with human-readable strings for
  41. * initialization and debugging.
  42. *
  43. * When registering for a message, a subsystem must say whether it is an
  44. * exclusive publisher/subscriber to that message type, or whether other
  45. * subsystems may also publish/subscribe to it.
  46. *
  47. * All messages and their publishers/subscribers must be registered early in
  48. * the initialization process.
  49. *
  50. * By default, it is an error for a message type to have publishers and no
  51. * subscribers on a channel, or subscribers and no publishers on a channel.
  52. *
  53. * A subsystem may register for a message with a note that delivery or
  54. * production is disabled -- for example, because the subsystem is
  55. * disabled at compile-time. It is not an error for a message type to
  56. * have all of its publishers or subscribers disabled.
  57. *
  58. * After a message is sent, it is delivered to every recipient. This
  59. * delivery happens from the top level of the event loop; it may be
  60. * interleaved with network events, timers, etc.
  61. *
  62. * Messages may have associated data. This data is typed, and is owned
  63. * by the message. Strings, byte-arrays, and integers have built-in
  64. * support. Other types may be added. If objects are to be sent,
  65. * they should be identified by handle. If an object requires cleanup,
  66. * it should be declared with an associated free function.
  67. *
  68. * Semantically, if two subsystems communicate only by this kind of
  69. * message passing, neither is considered to depend on the other, though
  70. * both are considered to have a dependency on the message and on any
  71. * types it contains.
  72. *
  73. * (Or generational index?)
  74. */
  75. #ifndef TOR_PUBSUB_PUBSUB_H
  76. #define TOR_PUBSUB_PUBSUB_H
  77. #include "lib/pubsub/pub_binding_st.h"
  78. #include "lib/pubsub/pubsub_connect.h"
  79. #include "lib/pubsub/pubsub_flags.h"
  80. #include "lib/pubsub/pubsub_publish.h"
  81. #endif