pubsub_builder_st.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_builder_st.h
  8. *
  9. * @brief private structures used for configuring dispatchers and messages.
  10. */
  11. #ifndef TOR_PUBSUB_BUILDER_ST_H
  12. #define TOR_PUBSUB_BUILDER_ST_H
  13. #ifdef PUBSUB_PRIVATE
  14. #include <stdbool.h>
  15. #include <stddef.h>
  16. struct dispatch_cfg_t;
  17. struct smartlist_t;
  18. struct pub_binding_t;
  19. /**
  20. * Configuration for a single publication or subscription request.
  21. *
  22. * These can be stored while the dispatcher is in use, but are only used for
  23. * setup, teardown, and debugging.
  24. *
  25. * There are various fields in this request describing the message; all of
  26. * them must match other descriptions of the message, or a bug has occurred.
  27. **/
  28. typedef struct pubsub_cfg_t {
  29. /** True if this is a publishing request; false for a subscribing request. */
  30. bool is_publish;
  31. /** The system making this request. */
  32. subsys_id_t subsys;
  33. /** The channel on which the message is to be sent. */
  34. channel_id_t channel;
  35. /** The message ID to be sent or received. */
  36. message_id_t msg;
  37. /** The C type associated with the message. */
  38. msg_type_id_t type;
  39. /** One or more DISP_FLAGS_* items, combined with bitwise OR. */
  40. unsigned flags;
  41. /**
  42. * Publishing only: a pub_binding object that will receive the binding for
  43. * this request. We will finish filling this in when the dispatcher is
  44. * constructed, so that the subsystem can publish then and not before.
  45. */
  46. struct pub_binding_t *pub_binding;
  47. /**
  48. * Subscribing only: a function to receive message objects for this request.
  49. */
  50. recv_fn_t recv_fn;
  51. /** The file from which this message was configured */
  52. const char *added_by_file;
  53. /** The line at which this message was configured */
  54. unsigned added_by_line;
  55. } pubsub_cfg_t;
  56. /**
  57. * Configuration request for a single C type.
  58. *
  59. * These are stored while the dispatcher is in use, but are only used for
  60. * setup, teardown, and debugging.
  61. **/
  62. typedef struct pubsub_type_cfg_t {
  63. /**
  64. * The identifier for this type.
  65. */
  66. msg_type_id_t type;
  67. /**
  68. * Functions to use when manipulating the type.
  69. */
  70. dispatch_typefns_t fns;
  71. /** The subsystem that configured this type. */
  72. subsys_id_t subsys;
  73. /** The file from which this type was configured */
  74. const char *added_by_file;
  75. /** The line at which this type was configured */
  76. unsigned added_by_line;
  77. } pubsub_type_cfg_t;
  78. /**
  79. * The set of configuration requests for a dispatcher, as made by various
  80. * subsystems.
  81. **/
  82. struct pubsub_items_t {
  83. /** List of pubsub_cfg_t. */
  84. struct smartlist_t *items;
  85. /** List of pubsub_type_cfg_t. */
  86. struct smartlist_t *type_items;
  87. };
  88. /**
  89. * Type used to construct a dispatcher. We use this type to build up the
  90. * configuration for a dispatcher, and then pass ownership of that
  91. * configuration to the newly constructed dispatcher.
  92. **/
  93. struct pubsub_builder_t {
  94. /** Number of outstanding pubsub_connector_t objects pointing to this
  95. * pubsub_builder_t. */
  96. int n_connectors;
  97. /** Number of errors encountered while constructing this object so far. */
  98. int n_errors;
  99. /** In-progress configuration that we're constructing, as a list of the
  100. * requests that have been made. */
  101. struct pubsub_items_t *items;
  102. /** In-progress configuration that we're constructing, in a form that can
  103. * be converted to a dispatch_t. */
  104. struct dispatch_cfg_t *cfg;
  105. };
  106. /**
  107. * Type given to a subsystem when adding connections to a pubsub_builder_t.
  108. * We use this type to force each subsystem to get blamed for the
  109. * publications, subscriptions, and types that it adds.
  110. **/
  111. struct pubsub_connector_t {
  112. /** The pubsub_builder that this connector refers to. */
  113. struct pubsub_builder_t *builder;
  114. /** The subsystem that has been given this connector. */
  115. subsys_id_t subsys_id;
  116. };
  117. /**
  118. * Helper structure used when constructing a dispatcher that sorts the
  119. * pubsub_cfg_t objects in various ways.
  120. **/
  121. typedef struct pubsub_adjmap_t {
  122. /* XXXX The next three fields are currently constructed but not yet
  123. * XXXX used. I believe we'll want them in the future, though. -nickm
  124. */
  125. /** Number of subsystems; length of the *_by_subsys arrays. */
  126. size_t n_subsystems;
  127. /** Array of lists of publisher pubsub_cfg_t objects, indexed by
  128. * subsystem. */
  129. struct smartlist_t **pub_by_subsys;
  130. /** Array of lists of subscriber pubsub_cfg_t objects, indexed by
  131. * subsystem. */
  132. struct smartlist_t **sub_by_subsys;
  133. /** Number of message IDs; length of the *_by_msg arrays. */
  134. size_t n_msgs;
  135. /** Array of lists of publisher pubsub_cfg_t objects, indexed by
  136. * message ID. */
  137. struct smartlist_t **pub_by_msg;
  138. /** Array of lists of subscriber pubsub_cfg_t objects, indexed by
  139. * message ID. */
  140. struct smartlist_t **sub_by_msg;
  141. } pubsub_adjmap_t;
  142. #endif
  143. #endif