core.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2009-2014 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/core.h
  18. * @brief common internal definitions for core service
  19. * @author Christian Grothoff
  20. */
  21. #ifndef CORE_H
  22. #define CORE_H
  23. #include "gnunet_bandwidth_lib.h"
  24. #include "gnunet_transport_service.h"
  25. #include "gnunet_crypto_lib.h"
  26. #include "gnunet_time_lib.h"
  27. /**
  28. * General core debugging.
  29. */
  30. #define DEBUG_CORE GNUNET_EXTRA_LOGGING
  31. /**
  32. * Definition of bits in the InitMessage's options field that specify
  33. * which events this client cares about. Note that inbound messages
  34. * for handlers that were specifically registered are always
  35. * transmitted to the client.
  36. */
  37. #define GNUNET_CORE_OPTION_NOTHING 0
  38. /**
  39. * Client cares about connectivity changes.
  40. */
  41. #define GNUNET_CORE_OPTION_SEND_STATUS_CHANGE 4
  42. /**
  43. * Client wants all inbound messages in full.
  44. */
  45. #define GNUNET_CORE_OPTION_SEND_FULL_INBOUND 8
  46. /**
  47. * Client just wants the 4-byte message headers of
  48. * all inbound messages.
  49. */
  50. #define GNUNET_CORE_OPTION_SEND_HDR_INBOUND 16
  51. /**
  52. * Client wants all outbound messages in full.
  53. */
  54. #define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 32
  55. /**
  56. * Client just wants the 4-byte message headers of
  57. * all outbound messages.
  58. */
  59. #define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND 64
  60. GNUNET_NETWORK_STRUCT_BEGIN
  61. /**
  62. * Message transmitted core clients to gnunet-service-core
  63. * to start the interaction. This header is followed by
  64. * uint16_t type values specifying which messages this
  65. * client is interested in.
  66. */
  67. struct InitMessage
  68. {
  69. /**
  70. * Header with type #GNUNET_MESSAGE_TYPE_CORE_INIT.
  71. */
  72. struct GNUNET_MessageHeader header;
  73. /**
  74. * Options, see GNUNET_CORE_OPTION_ values.
  75. */
  76. uint32_t options GNUNET_PACKED;
  77. };
  78. /**
  79. * Message transmitted by the gnunet-service-core process
  80. * to its clients in response to an INIT message.
  81. */
  82. struct InitReplyMessage
  83. {
  84. /**
  85. * Header with type #GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY
  86. */
  87. struct GNUNET_MessageHeader header;
  88. /**
  89. * Always zero.
  90. */
  91. uint32_t reserved GNUNET_PACKED;
  92. /**
  93. * Public key of the local peer.
  94. */
  95. struct GNUNET_PeerIdentity my_identity;
  96. };
  97. /**
  98. * Message sent by the service to clients to notify them
  99. * about a peer connecting.
  100. */
  101. struct ConnectNotifyMessage
  102. {
  103. /**
  104. * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT
  105. */
  106. struct GNUNET_MessageHeader header;
  107. /**
  108. * Always zero.
  109. */
  110. uint32_t reserved GNUNET_PACKED;
  111. /**
  112. * Identity of the connecting peer.
  113. */
  114. struct GNUNET_PeerIdentity peer;
  115. };
  116. /**
  117. * Message sent by the service to clients to notify them
  118. * about a peer disconnecting.
  119. */
  120. struct DisconnectNotifyMessage
  121. {
  122. /**
  123. * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
  124. */
  125. struct GNUNET_MessageHeader header;
  126. /**
  127. * Always zero.
  128. */
  129. uint32_t reserved GNUNET_PACKED;
  130. /**
  131. * Identity of the connecting peer.
  132. */
  133. struct GNUNET_PeerIdentity peer;
  134. };
  135. /**
  136. * Message sent by the service to clients to notify them about
  137. * messages being received or transmitted. This overall message is
  138. * followed by the real message, or just the header of the real
  139. * message (depending on the client's preferences). The receiver can
  140. * tell if it got the full message or only a partial message by
  141. * looking at the size field in the header of NotifyTrafficMessage and
  142. * checking it with the size field in the message that follows.
  143. */
  144. struct NotifyTrafficMessage
  145. {
  146. /**
  147. * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
  148. * or #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND.
  149. */
  150. struct GNUNET_MessageHeader header;
  151. /**
  152. * Identity of the receiver or sender.
  153. */
  154. struct GNUNET_PeerIdentity peer;
  155. /* Followed by payload (message or just header), variable size */
  156. };
  157. /**
  158. * Client notifying core about the maximum-priority
  159. * message it has in the queue for a particular target.
  160. */
  161. struct SendMessageRequest
  162. {
  163. /**
  164. * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST
  165. */
  166. struct GNUNET_MessageHeader header;
  167. /**
  168. * How important is this message?
  169. */
  170. uint32_t priority GNUNET_PACKED;
  171. /**
  172. * By what time would the sender really like to see this
  173. * message transmitted?
  174. */
  175. struct GNUNET_TIME_AbsoluteNBO deadline;
  176. /**
  177. * Identity of the intended target.
  178. */
  179. struct GNUNET_PeerIdentity peer;
  180. /**
  181. * Always zero.
  182. */
  183. uint32_t reserved GNUNET_PACKED;
  184. /**
  185. * How large is the message?
  186. */
  187. uint16_t size GNUNET_PACKED;
  188. /**
  189. * Counter for this peer to match SMRs to replies.
  190. */
  191. uint16_t smr_id GNUNET_PACKED;
  192. };
  193. /**
  194. * Core notifying client that it is allowed to now
  195. * transmit a message to the given target
  196. * (response to #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST).
  197. */
  198. struct SendMessageReady
  199. {
  200. /**
  201. * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND_READY
  202. */
  203. struct GNUNET_MessageHeader header;
  204. /**
  205. * How many bytes are allowed for transmission?
  206. * Guaranteed to be at least as big as the requested size,
  207. * or ZERO if the request is rejected (will timeout,
  208. * peer disconnected, queue full, etc.).
  209. */
  210. uint16_t size GNUNET_PACKED;
  211. /**
  212. * smr_id from the request.
  213. */
  214. uint16_t smr_id GNUNET_PACKED;
  215. /**
  216. * Identity of the intended target.
  217. */
  218. struct GNUNET_PeerIdentity peer;
  219. };
  220. /**
  221. * Client asking core to transmit a particular message to a particular
  222. * target (response to #GNUNET_MESSAGE_TYPE_CORE_SEND_READY).
  223. */
  224. struct SendMessage
  225. {
  226. /**
  227. * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND
  228. */
  229. struct GNUNET_MessageHeader header;
  230. /**
  231. * How important is this message? Contains a
  232. * `enum GNUNET_MQ_PriorityPreferences` in NBO.
  233. */
  234. uint32_t priority GNUNET_PACKED;
  235. /**
  236. * By what time would the sender really like to see this
  237. * message transmitted?
  238. */
  239. struct GNUNET_TIME_AbsoluteNBO deadline;
  240. /**
  241. * Identity of the intended receiver.
  242. */
  243. struct GNUNET_PeerIdentity peer;
  244. };
  245. /**
  246. * Message sent by the service to monitor clients to notify them
  247. * about a peer changing status.
  248. */
  249. struct MonitorNotifyMessage
  250. {
  251. /**
  252. * Header with type #GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY
  253. */
  254. struct GNUNET_MessageHeader header;
  255. /**
  256. * New peer state, an `enum GNUNET_CORE_KxState` in NBO.
  257. */
  258. uint32_t state GNUNET_PACKED;
  259. /**
  260. * Identity of the peer.
  261. */
  262. struct GNUNET_PeerIdentity peer;
  263. /**
  264. * How long will we stay in this state (if nothing else happens)?
  265. */
  266. struct GNUNET_TIME_AbsoluteNBO timeout;
  267. };
  268. GNUNET_NETWORK_STRUCT_END
  269. #endif
  270. /* end of core.h */