gnunet-service-core_typemap.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2011 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file core/gnunet-service-core_typemap.h
  18. * @brief management of map that specifies which message types this peer supports
  19. * @author Christian Grothoff
  20. */
  21. #ifndef GNUNET_SERVICE_CORE_TYPEMAP_H
  22. #define GNUNET_SERVICE_CORE_TYPEMAP_H
  23. #include "gnunet_util_lib.h"
  24. #include "gnunet_transport_service.h"
  25. /**
  26. * Map specifying which message types a peer supports.
  27. */
  28. struct GSC_TypeMap;
  29. /**
  30. * Add a set of types to our type map.
  31. *
  32. * @param types array of message types supported by this peer
  33. * @param tlen number of entries in @a types
  34. */
  35. void
  36. GSC_TYPEMAP_add (const uint16_t *types,
  37. unsigned int tlen);
  38. /**
  39. * Remove a set of message types from our type map.
  40. *
  41. * @param types array of message types no longer supported by this peer
  42. * @param tlen number of entries in @a types
  43. */
  44. void
  45. GSC_TYPEMAP_remove (const uint16_t *types,
  46. unsigned int tlen);
  47. /**
  48. * Compute a type map message for this peer.
  49. *
  50. * @return this peers current type map message.
  51. */
  52. struct GNUNET_MessageHeader *
  53. GSC_TYPEMAP_compute_type_map_message (void);
  54. /**
  55. * Check if the given hash matches our current type map.
  56. *
  57. * @param hc hash code to check if it matches our type map
  58. * @return #GNUNET_YES if the hash matches, #GNUNET_NO if not
  59. */
  60. int
  61. GSC_TYPEMAP_check_hash (const struct GNUNET_HashCode *hc);
  62. /**
  63. * Hash the contents of a type map.
  64. *
  65. * @param tm map to hash
  66. * @param hc where to store the hash code
  67. */
  68. void
  69. GSC_TYPEMAP_hash (const struct GSC_TypeMap *tm,
  70. struct GNUNET_HashCode *hc);
  71. /**
  72. * Extract a type map from a
  73. * #GNUNET_MESSAGE_TYPE_CORE_COMRESSED_TYPE_MAP or
  74. * #GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP message.
  75. *
  76. * @param msg a type map message
  77. * @return NULL on error
  78. */
  79. struct GSC_TypeMap *
  80. GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg);
  81. /**
  82. * Test if any of the types from the types array is in the
  83. * given type map.
  84. *
  85. * @param tmap map to test
  86. * @param types array of types
  87. * @param tcnt number of entries in @a types
  88. * @return #GNUNET_YES if a type is in the map, #GNUNET_NO if not
  89. */
  90. int
  91. GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap,
  92. const uint16_t *types,
  93. unsigned int tcnt);
  94. /**
  95. * Add additional types to a given typemap.
  96. *
  97. * @param tmap map to extend (not changed)
  98. * @param types array of types to add
  99. * @param tcnt number of entries in @a types
  100. * @return updated type map (fresh copy)
  101. */
  102. struct GSC_TypeMap *
  103. GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap,
  104. const uint16_t *types,
  105. unsigned int tcnt);
  106. /**
  107. * Create an empty type map.
  108. *
  109. * @return an empty type map
  110. */
  111. struct GSC_TypeMap *
  112. GSC_TYPEMAP_create (void);
  113. /**
  114. * Free the given type map.
  115. *
  116. * @param tmap a type map
  117. */
  118. void
  119. GSC_TYPEMAP_destroy (struct GSC_TypeMap *tmap);
  120. /**
  121. * Initialize typemap subsystem.
  122. */
  123. void
  124. GSC_TYPEMAP_init (void);
  125. /**
  126. * Shutdown typemap subsystem.
  127. */
  128. void
  129. GSC_TYPEMAP_done (void);
  130. #endif
  131. /* end of gnunet-service-core_typemap.h */