You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

926 lines
30 KiB

  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2012, 2013 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. * @author Gabor X Toth
  18. * @author Christian Grothoff
  19. *
  20. * @file
  21. * Multicast service; multicast messaging via CADET
  22. *
  23. * @defgroup multicast Multicast service
  24. * Multicast messaging via CADET.
  25. * @{
  26. */
  27. #ifndef GNUNET_MULTICAST_SERVICE_H
  28. #define GNUNET_MULTICAST_SERVICE_H
  29. #ifdef __cplusplus
  30. extern "C"
  31. {
  32. #if 0 /* keep Emacsens' auto-indent happy */
  33. }
  34. #endif
  35. #endif
  36. #include "gnunet_util_lib.h"
  37. #include "gnunet_transport_service.h"
  38. /**
  39. * Version number of GNUnet-multicast API.
  40. */
  41. #define GNUNET_MULTICAST_VERSION 0x00000000
  42. /**
  43. * Opaque handle for a multicast group member.
  44. */
  45. struct GNUNET_MULTICAST_Member;
  46. /**
  47. * Handle for the origin of a multicast group.
  48. */
  49. struct GNUNET_MULTICAST_Origin;
  50. enum GNUNET_MULTICAST_MessageFlags
  51. {
  52. /**
  53. * First fragment of a message.
  54. */
  55. GNUNET_MULTICAST_MESSAGE_FIRST_FRAGMENT = 1 << 0,
  56. /**
  57. * Last fragment of a message.
  58. */
  59. GNUNET_MULTICAST_MESSAGE_LAST_FRAGMENT = 1 << 1,
  60. /**
  61. * OR'ed flags if message is not fragmented.
  62. */
  63. GNUNET_MULTICAST_MESSAGE_NOT_FRAGMENTED
  64. = GNUNET_MULTICAST_MESSAGE_FIRST_FRAGMENT
  65. | GNUNET_MULTICAST_MESSAGE_LAST_FRAGMENT,
  66. /**
  67. * Historic message, used only locally when replaying messages from local
  68. * storage.
  69. */
  70. GNUNET_MULTICAST_MESSAGE_HISTORIC = 1 << 30
  71. };
  72. GNUNET_NETWORK_STRUCT_BEGIN
  73. /**
  74. * Header of a multicast message fragment.
  75. *
  76. * This format is public as the replay mechanism must replay message fragments using the
  77. * same format. This is needed as we want to integrity-check message fragments within
  78. * the multicast layer to avoid multicasting mal-formed messages.
  79. */
  80. struct GNUNET_MULTICAST_MessageHeader
  81. {
  82. /**
  83. * Header for all multicast message fragments from the origin.
  84. */
  85. struct GNUNET_MessageHeader header;
  86. /**
  87. * Number of hops this message fragment has taken since the origin.
  88. *
  89. * Helpful to determine shortest paths to the origin among honest peers for
  90. * unicast requests from members. Updated at each hop and thus not signed and
  91. * not secure.
  92. */
  93. uint32_t hop_counter GNUNET_PACKED;
  94. /**
  95. * ECC signature of the message fragment.
  96. *
  97. * Signature must match the public key of the multicast group.
  98. */
  99. struct GNUNET_CRYPTO_EddsaSignature signature;
  100. /**
  101. * Purpose for the signature and size of the signed data.
  102. */
  103. struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
  104. /**
  105. * Number of the message fragment, monotonically increasing starting from 1.
  106. */
  107. uint64_t fragment_id GNUNET_PACKED;
  108. /**
  109. * Byte offset of this @e fragment of the @e message.
  110. */
  111. uint64_t fragment_offset GNUNET_PACKED;
  112. /**
  113. * Number of the message this fragment belongs to.
  114. *
  115. * Set in GNUNET_MULTICAST_origin_to_all().
  116. */
  117. uint64_t message_id GNUNET_PACKED;
  118. /**
  119. * Counter that monotonically increases whenever a member parts the group.
  120. *
  121. * Set in GNUNET_MULTICAST_origin_to_all().
  122. *
  123. * It has significance in case of replay requests: when a member has missed
  124. * messages and gets a replay request: in this case if the @a group_generation
  125. * is still the same before and after the missed messages, it means that no
  126. * @e join or @e part operations happened during the missed messages.
  127. */
  128. uint64_t group_generation GNUNET_PACKED;
  129. /**
  130. * Flags for this message fragment.
  131. *
  132. * @see enum GNUNET_MULTICAST_MessageFlags
  133. */
  134. uint32_t flags GNUNET_PACKED;
  135. /* Followed by message body. */
  136. };
  137. /**
  138. * Header of a request from a member to the origin.
  139. */
  140. struct GNUNET_MULTICAST_RequestHeader
  141. {
  142. /**
  143. * Header for all requests from a member to the origin.
  144. */
  145. struct GNUNET_MessageHeader header;
  146. /**
  147. * Public key of the sending member.
  148. */
  149. struct GNUNET_CRYPTO_EcdsaPublicKey member_pub_key;
  150. /**
  151. * ECC signature of the request fragment.
  152. *
  153. * Signature must match the public key of the multicast group.
  154. */
  155. struct GNUNET_CRYPTO_EcdsaSignature signature;
  156. /**
  157. * Purpose for the signature and size of the signed data.
  158. */
  159. struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
  160. /**
  161. * Number of the request fragment.
  162. * Monotonically increasing from 1.
  163. */
  164. uint64_t fragment_id GNUNET_PACKED;
  165. /**
  166. * Byte offset of this @e fragment of the @e request.
  167. */
  168. uint64_t fragment_offset GNUNET_PACKED;
  169. /**
  170. * Number of the request this fragment belongs to.
  171. *
  172. * Set in GNUNET_MULTICAST_origin_to_all().
  173. */
  174. uint64_t request_id GNUNET_PACKED;
  175. /**
  176. * Flags for this request.
  177. */
  178. enum GNUNET_MULTICAST_MessageFlags flags GNUNET_PACKED;
  179. /* Followed by request body. */
  180. };
  181. GNUNET_NETWORK_STRUCT_END
  182. /**
  183. * Maximum size of a multicast message fragment.
  184. */
  185. #define GNUNET_MULTICAST_FRAGMENT_MAX_SIZE (63 * 1024)
  186. #define GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD \
  187. (GNUNET_MULTICAST_FRAGMENT_MAX_SIZE \
  188. - sizeof (struct GNUNET_MULTICAST_MessageHeader))
  189. /**
  190. * Handle that identifies a join request.
  191. *
  192. * Used to match calls to #GNUNET_MULTICAST_JoinRequestCallback to the
  193. * corresponding calls to #GNUNET_MULTICAST_join_decision().
  194. */
  195. struct GNUNET_MULTICAST_JoinHandle;
  196. /**
  197. * Function to call with the decision made for a join request.
  198. *
  199. * Must be called once and only once in response to an invocation of the
  200. * #GNUNET_MULTICAST_JoinRequestCallback.
  201. *
  202. * @param jh
  203. * Join request handle.
  204. * @param is_admitted
  205. * #GNUNET_YES if the join is approved,
  206. * #GNUNET_NO if it is disapproved,
  207. * #GNUNET_SYSERR if we cannot answer the request.
  208. * @param relay_count
  209. * Number of relays given.
  210. * @param relays
  211. * Array of suggested peers that might be useful relays to use
  212. * when joining the multicast group (essentially a list of peers that
  213. * are already part of the multicast group and might thus be willing
  214. * to help with routing). If empty, only this local peer (which must
  215. * be the multicast origin) is a good candidate for building the
  216. * multicast tree. Note that it is unnecessary to specify our own
  217. * peer identity in this array.
  218. * @param join_resp
  219. * Message to send in response to the joining peer;
  220. * can also be used to redirect the peer to a different group at the
  221. * application layer; this response is to be transmitted to the
  222. * peer that issued the request even if admission is denied.
  223. */
  224. struct GNUNET_MULTICAST_ReplayHandle *
  225. GNUNET_MULTICAST_join_decision (struct GNUNET_MULTICAST_JoinHandle *jh,
  226. int is_admitted,
  227. uint16_t relay_count,
  228. const struct GNUNET_PeerIdentity *relays,
  229. const struct GNUNET_MessageHeader *join_resp);
  230. /**
  231. * Method called whenever another peer wants to join the multicast group.
  232. *
  233. * Implementations of this function must call GNUNET_MULTICAST_join_decision()
  234. * with the decision.
  235. *
  236. * @param cls
  237. * Closure.
  238. * @param member_pub_key
  239. * Public key of the member requesting join.
  240. * @param join_msg
  241. * Application-dependent join message from the new member.
  242. * @param jh
  243. * Join handle to pass to GNUNET_MULTICAST_join_decison().
  244. */
  245. typedef void
  246. (*GNUNET_MULTICAST_JoinRequestCallback) (void *cls,
  247. const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
  248. const struct GNUNET_MessageHeader *join_msg,
  249. struct GNUNET_MULTICAST_JoinHandle *jh);
  250. /**
  251. * Method called to inform about the decision in response to a join request.
  252. *
  253. * If @a is_admitted is not #GNUNET_YES, then the multicast service disconnects
  254. * the client and the multicast member handle returned by
  255. * GNUNET_MULTICAST_member_join() is invalidated.
  256. *
  257. * @param cls
  258. * Closure.
  259. * @param is_admitted
  260. * #GNUNET_YES or #GNUNET_NO or #GNUNET_SYSERR
  261. * @param peer
  262. * The peer we are connected to and the join decision is from.
  263. * @param relay_count
  264. * Number of peers in the @a relays array.
  265. * @param relays
  266. * Peer identities of members of the group, which serve as relays
  267. * and can be used to join the group at. If empty, only the origin can
  268. * be used to connect to the group.
  269. * @param join_msg
  270. * Application-dependent join message from the origin.
  271. */
  272. typedef void
  273. (*GNUNET_MULTICAST_JoinDecisionCallback) (void *cls,
  274. int is_admitted,
  275. const struct GNUNET_PeerIdentity *peer,
  276. uint16_t relay_count,
  277. const struct GNUNET_PeerIdentity *relays,
  278. const struct GNUNET_MessageHeader *join_msg);
  279. /**
  280. * Function called whenever a group member has transmitted a request
  281. * to the origin (other than joining or leaving).
  282. *
  283. * FIXME: need to distinguish between origin cancelling a message (some fragments
  284. * were sent, then the rest 'discarded') and the case where we got disconnected;
  285. * right now, both would mean 'msg' is NULL, but they could be quite different...
  286. * So the semantics from the receiver side of
  287. * GNUNET_MULTICAST_member_to_origin_cancel() are not clear here. Maybe we
  288. * should do something with the flags in this case?
  289. *
  290. * @param cls
  291. * Closure (set from GNUNET_MULTICAST_origin_start).
  292. * @param sender
  293. * Identity of the sender.
  294. * @param req
  295. * Request to the origin.
  296. * @param flags
  297. * Flags for the request.
  298. */
  299. typedef void
  300. (*GNUNET_MULTICAST_RequestCallback) (void *cls,
  301. const struct GNUNET_MULTICAST_RequestHeader *req);
  302. /**
  303. * Function called whenever a group member is receiving a message fragment from
  304. * the origin.
  305. *
  306. * If admission to the group is denied, this function is called once with the
  307. * response of the @e origin (as given to GNUNET_MULTICAST_join_decision()) and
  308. * then a second time with NULL to indicate that the connection failed for good.
  309. *
  310. * FIXME: need to distinguish between origin cancelling a message (some fragments
  311. * were sent, then the rest 'discarded') and the case where we got disconnected;
  312. * right now, both would mean 'msg' is NULL, but they could be quite different...
  313. * So the semantics from the receiver side of
  314. * GNUNET_MULTICAST_origin_to_all_cancel() are not clear here.
  315. *
  316. * @param cls
  317. * Closure (set from GNUNET_MULTICAST_member_join())
  318. * @param msg
  319. * Message from the origin, NULL if the origin shut down
  320. * (or we were kicked out, and we should thus call
  321. * GNUNET_MULTICAST_member_part() next)
  322. */
  323. typedef void
  324. (*GNUNET_MULTICAST_MessageCallback) (void *cls,
  325. const struct GNUNET_MULTICAST_MessageHeader *msg);
  326. /**
  327. * Opaque handle to a replay request from the multicast service.
  328. */
  329. struct GNUNET_MULTICAST_ReplayHandle;
  330. /**
  331. * Functions with this signature are called whenever the multicast service needs
  332. * a message fragment to be replayed by fragment_id.
  333. *
  334. * Implementations of this function MUST call GNUNET_MULTICAST_replay() ONCE
  335. * (with a message or an error); however, if the origin is destroyed or the
  336. * group is left, the replay handle must no longer be used.
  337. *
  338. * @param cls
  339. * Closure (set from GNUNET_MULTICAST_origin_start()
  340. * or GNUNET_MULTICAST_member_join()).
  341. * @param member_pub_key
  342. * The member requesting replay.
  343. * @param fragment_id
  344. * Which message fragment should be replayed.
  345. * @param flags
  346. * Flags for the replay.
  347. * @param rh
  348. * Handle to pass to message transmit function.
  349. */
  350. typedef void
  351. (*GNUNET_MULTICAST_ReplayFragmentCallback) (void *cls,
  352. const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
  353. uint64_t fragment_id,
  354. uint64_t flags,
  355. struct GNUNET_MULTICAST_ReplayHandle *rh);
  356. /**
  357. * Functions with this signature are called whenever the multicast service needs
  358. * a message fragment to be replayed by message_id and fragment_offset.
  359. *
  360. * Implementations of this function MUST call GNUNET_MULTICAST_replay() ONCE
  361. * (with a message or an error); however, if the origin is destroyed or the
  362. * group is left, the replay handle must no longer be used.
  363. *
  364. * @param cls
  365. * Closure (set from GNUNET_MULTICAST_origin_start()
  366. * or GNUNET_MULTICAST_member_join()).
  367. * @param member_pub_key
  368. * The member requesting replay.
  369. * @param message_id
  370. * Which message should be replayed.
  371. * @param fragment_offset
  372. * Offset of the fragment within of @a message_id to be replayed.
  373. * @param flags
  374. * Flags for the replay.
  375. * @param rh
  376. * Handle to pass to message transmit function.
  377. */
  378. typedef void
  379. (*GNUNET_MULTICAST_ReplayMessageCallback) (void *cls,
  380. const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
  381. uint64_t message_id,
  382. uint64_t fragment_offset,
  383. uint64_t flags,
  384. struct GNUNET_MULTICAST_ReplayHandle *rh);
  385. /**
  386. * Possible error codes during replay.
  387. */
  388. enum GNUNET_MULTICAST_ReplayErrorCode
  389. {
  390. /**
  391. * Everything is fine.
  392. */
  393. GNUNET_MULTICAST_REC_OK = 0,
  394. /**
  395. * Message fragment not found in the message store.
  396. *
  397. * Either discarded if it is too old, or not arrived yet if this member has
  398. * missed some messages.
  399. */
  400. GNUNET_MULTICAST_REC_NOT_FOUND = 1,
  401. /**
  402. * Fragment ID counter was larger than the highest counter this
  403. * replay function has ever encountered; thus it is likely the
  404. * origin never sent it and we're at the HEAD of the multicast
  405. * stream as far as this node is concerned.
  406. *
  407. * FIXME: needed?
  408. */
  409. GNUNET_MULTICAST_REC_PAST_HEAD = 2,
  410. /**
  411. * Access is denied to the requested fragment, membership test did not pass.
  412. */
  413. GNUNET_MULTICAST_REC_ACCESS_DENIED = 3,
  414. /**
  415. * Internal error (i.e. database error). Try some other peer.
  416. */
  417. GNUNET_MULTICAST_REC_INTERNAL_ERROR = 4
  418. };
  419. /**
  420. * Replay a message fragment for the multicast group.
  421. *
  422. * @param rh
  423. * Replay handle identifying which replay operation was requested.
  424. * @param msg
  425. * Replayed message fragment, NULL if not found / an error occurred.
  426. * @param ec
  427. * Error code. See enum GNUNET_MULTICAST_ReplayErrorCode
  428. * If not #GNUNET_MULTICAST_REC_OK, the replay handle is invalidated.
  429. */
  430. void
  431. GNUNET_MULTICAST_replay_response (struct GNUNET_MULTICAST_ReplayHandle *rh,
  432. const struct GNUNET_MessageHeader *msg,
  433. enum GNUNET_MULTICAST_ReplayErrorCode ec);
  434. /**
  435. * Indicate the end of the replay session.
  436. *
  437. * Invalidates the replay handle.
  438. *
  439. * @param rh Replay session to end.
  440. */
  441. void
  442. GNUNET_MULTICAST_replay_response_end (struct GNUNET_MULTICAST_ReplayHandle *rh);
  443. /**
  444. * Function called to provide data for a transmission for a replay.
  445. *
  446. * @see GNUNET_MULTICAST_replay2()
  447. */
  448. typedef int
  449. (*GNUNET_MULTICAST_ReplayTransmitNotify) (void *cls,
  450. size_t *data_size,
  451. void *data);
  452. /**
  453. * Replay a message for the multicast group.
  454. *
  455. * @param rh
  456. * Replay handle identifying which replay operation was requested.
  457. * @param notify
  458. * Function to call to get the message.
  459. * @param notify_cls
  460. * Closure for @a notify.
  461. */
  462. void
  463. GNUNET_MULTICAST_replay_response2 (struct GNUNET_MULTICAST_ReplayHandle *rh,
  464. GNUNET_MULTICAST_ReplayTransmitNotify notify,
  465. void *notify_cls);
  466. /**
  467. * Start a multicast group.
  468. *
  469. * Peers that issue GNUNET_MULTICAST_member_join() can transmit a join request
  470. * to either an existing group member or to the origin. If the joining is
  471. * approved, the member is cleared for @e replay and will begin to receive
  472. * messages transmitted to the group. If joining is disapproved, the failed
  473. * candidate will be given a response. Members in the group can send messages
  474. * to the origin.
  475. *
  476. * TODO: This function could optionally offer to advertise the origin in the
  477. * P2P overlay network(where?) under the respective public key so that other
  478. * peers can find an alternate PeerId to join it. Higher level protocols may
  479. * however provide other means of solving the problem of the offline host
  480. * (see secushare specs about that) and therefore merely need a way to provide
  481. * a list of possible PeerIds.
  482. *
  483. * @param cfg
  484. * Configuration to use.
  485. * @param priv_key
  486. * ECC key that will be used to sign messages for this
  487. * multicast session; public key is used to identify the multicast group;
  488. * @param max_fragment_id
  489. * Maximum fragment ID already sent to the group.
  490. * 0 for a new group.
  491. * @param join_request_cb
  492. * Function called to approve / disapprove joining of a peer.
  493. * @param replay_frag_cb
  494. * Function that can be called to replay a message fragment.
  495. * @param replay_msg_cb
  496. * Function that can be called to replay a message.
  497. * @param request_cb
  498. * Function called with message fragments from group members.
  499. * @param message_cb
  500. * Function called with the message fragments sent to the
  501. * network by GNUNET_MULTICAST_origin_to_all(). These message fragments
  502. * should be stored for answering replay requests later.
  503. * @param cls
  504. * Closure for the various callbacks that follow.
  505. *
  506. * @return Handle for the origin, NULL on error.
  507. */
  508. struct GNUNET_MULTICAST_Origin *
  509. GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
  510. const struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key,
  511. uint64_t max_fragment_id,
  512. GNUNET_MULTICAST_JoinRequestCallback join_request_cb,
  513. GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb,
  514. GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb,
  515. GNUNET_MULTICAST_RequestCallback request_cb,
  516. GNUNET_MULTICAST_MessageCallback message_cb,
  517. void *cls);
  518. /**
  519. * Function called to provide data for a transmission from the origin to all
  520. * members.
  521. *
  522. * Note that returning #GNUNET_OK or #GNUNET_SYSERR (but not #GNUNET_NO)
  523. * invalidates the respective transmission handle.
  524. *
  525. * @param cls
  526. * Closure.
  527. * @param[in,out] data_size
  528. * Initially set to the number of bytes available in
  529. * @a data, should be set to the number of bytes written to data.
  530. * @param[out] data
  531. * Where to write the body of the message to give to the
  532. * method. The function must copy at most @a data_size bytes to @a data.
  533. *
  534. * @return #GNUNET_SYSERR on error (fatal, aborts transmission)
  535. * #GNUNET_NO on success, if more data is to be transmitted later.
  536. * Should be used if @a data_size was not big enough to take all the
  537. * data. If 0 is returned in @a data_size the transmission is paused,
  538. * and can be resumed with GNUNET_MULTICAST_origin_to_all_resume().
  539. * #GNUNET_YES if this completes the transmission (all data supplied)
  540. * @deprecated should move to MQ-style API!
  541. */
  542. typedef int
  543. (*GNUNET_MULTICAST_OriginTransmitNotify) (void *cls,
  544. size_t *data_size,
  545. void *data);
  546. /**
  547. * Handle for a request to send a message to all multicast group members
  548. * (from the origin).
  549. */
  550. struct GNUNET_MULTICAST_OriginTransmitHandle;
  551. /**
  552. * Send a message to the multicast group.
  553. *
  554. * @param origin
  555. * Handle to the multicast group.
  556. * @param message_id
  557. * Application layer ID for the message. Opaque to multicast.
  558. * @param group_generation
  559. * Group generation of the message. Documented in
  560. * struct GNUNET_MULTICAST_MessageHeader.
  561. * @param notify
  562. * Function to call to get the message.
  563. * @param notify_cls
  564. * Closure for @a notify.
  565. *
  566. * @return NULL on error (i.e. request already pending).
  567. * @deprecated should move to MQ-style API!
  568. */
  569. struct GNUNET_MULTICAST_OriginTransmitHandle *
  570. GNUNET_MULTICAST_origin_to_all (struct GNUNET_MULTICAST_Origin *origin,
  571. uint64_t message_id,
  572. uint64_t group_generation,
  573. GNUNET_MULTICAST_OriginTransmitNotify notify,
  574. void *notify_cls);
  575. /**
  576. * Resume message transmission to multicast group.
  577. *
  578. * @param th Transmission to cancel.
  579. */
  580. void
  581. GNUNET_MULTICAST_origin_to_all_resume (struct GNUNET_MULTICAST_OriginTransmitHandle *th);
  582. /**
  583. * Cancel request for message transmission to multicast group.
  584. *
  585. * @param th Transmission to cancel.
  586. */
  587. void
  588. GNUNET_MULTICAST_origin_to_all_cancel (struct GNUNET_MULTICAST_OriginTransmitHandle *th);
  589. /**
  590. * Stop a multicast group.
  591. *
  592. * @param origin Multicast group to stop.
  593. */
  594. void
  595. GNUNET_MULTICAST_origin_stop (struct GNUNET_MULTICAST_Origin *origin,
  596. GNUNET_ContinuationCallback stop_cb,
  597. void *stop_cls);
  598. /**
  599. * Join a multicast group.
  600. *
  601. * The entity joining is always the local peer. Further information about the
  602. * candidate can be provided in @a join_msg. If the join fails, the
  603. * @a message_cb is invoked with a (failure) response and then with NULL. If
  604. * the join succeeds, outstanding (state) messages and ongoing multicast
  605. * messages will be given to the @a message_cb until the member decides to part
  606. * the group. The @a mem_test_cb and @a replay_cb functions may be called at
  607. * anytime by the multicast service to support relaying messages to other
  608. * members of the group.
  609. *
  610. * @param cfg
  611. * Configuration to use.
  612. * @param group_key
  613. * ECC public key that identifies the group to join.
  614. * @param member_pub_key
  615. * ECC key that identifies the member
  616. * and used to sign requests sent to the origin.
  617. * @param origin
  618. * Peer ID of the origin to send unicast requsets to. If NULL,
  619. * unicast requests are sent back via multiple hops on the reverse path
  620. * of multicast messages.
  621. * @param relay_count
  622. * Number of peers in the @a relays array.
  623. * @param relays
  624. * Peer identities of members of the group, which serve as relays
  625. * and can be used to join the group at. and send the @a join_request to.
  626. * If empty, the @a join_request is sent directly to the @a origin.
  627. * @param join_msg
  628. * Application-dependent join message to be passed to the peer @a origin.
  629. * @param join_request_cb
  630. * Function called to approve / disapprove joining of a peer.
  631. * @param join_decision_cb
  632. * Function called to inform about the join decision.
  633. * @param replay_frag_cb
  634. * Function that can be called to replay message fragments
  635. * this peer already knows from this group. NULL if this
  636. * client is unable to support replay.
  637. * @param replay_msg_cb
  638. * Function that can be called to replay message fragments
  639. * this peer already knows from this group. NULL if this
  640. * client is unable to support replay.
  641. * @param message_cb
  642. * Function to be called for all message fragments we
  643. * receive from the group, excluding those our @a replay_cb
  644. * already has.
  645. * @param cls
  646. * Closure for callbacks.
  647. *
  648. * @return Handle for the member, NULL on error.
  649. */
  650. struct GNUNET_MULTICAST_Member *
  651. GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
  652. const struct GNUNET_CRYPTO_EddsaPublicKey *group_key,
  653. const struct GNUNET_CRYPTO_EcdsaPrivateKey *member_pub_key,
  654. const struct GNUNET_PeerIdentity *origin,
  655. uint16_t relay_count,
  656. const struct GNUNET_PeerIdentity *relays,
  657. const struct GNUNET_MessageHeader *join_request,
  658. GNUNET_MULTICAST_JoinRequestCallback join_request_cb,
  659. GNUNET_MULTICAST_JoinDecisionCallback join_decision_cb,
  660. GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb,
  661. GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb,
  662. GNUNET_MULTICAST_MessageCallback message_cb,
  663. void *cls);
  664. /**
  665. * Handle for a replay request.
  666. */
  667. struct GNUNET_MULTICAST_MemberReplayHandle;
  668. /**
  669. * Request a fragment to be replayed by fragment ID.
  670. *
  671. * Useful if messages below the @e max_known_fragment_id given when joining are
  672. * needed and not known to the client.
  673. *
  674. * @param member
  675. * Membership handle.
  676. * @param fragment_id
  677. * ID of a message fragment that this client would like to see replayed.
  678. * @param flags
  679. * Additional flags for the replay request.
  680. * It is used and defined by GNUNET_MULTICAST_ReplayFragmentCallback
  681. *
  682. * @return Replay request handle, NULL on error.
  683. */
  684. struct GNUNET_MULTICAST_MemberReplayHandle *
  685. GNUNET_MULTICAST_member_replay_fragment (struct GNUNET_MULTICAST_Member *member,
  686. uint64_t fragment_id,
  687. uint64_t flags);
  688. /**
  689. * Request a message fr to be replayed.
  690. *
  691. * Useful if messages below the @e max_known_fragment_id given when joining are
  692. * needed and not known to the client.
  693. *
  694. * @param member
  695. * Membership handle.
  696. * @param message_id
  697. * ID of the message this client would like to see replayed.
  698. * @param fragment_offset
  699. * Offset of the fragment within the message to replay.
  700. * @param flags
  701. * Additional flags for the replay request.
  702. * It is used & defined by GNUNET_MULTICAST_ReplayMessageCallback
  703. *
  704. * @return Replay request handle, NULL on error.
  705. */
  706. struct GNUNET_MULTICAST_MemberReplayHandle *
  707. GNUNET_MULTICAST_member_replay_message (struct GNUNET_MULTICAST_Member *member,
  708. uint64_t message_id,
  709. uint64_t fragment_offset,
  710. uint64_t flags);
  711. /**
  712. * Cancel a replay request.
  713. *
  714. * @param rh
  715. * Request to cancel.
  716. */
  717. void
  718. GNUNET_MULTICAST_member_replay_cancel (struct GNUNET_MULTICAST_MemberReplayHandle *rh);
  719. /**
  720. * Part a multicast group.
  721. *
  722. * Disconnects from all group members and invalidates the @a member handle.
  723. *
  724. * An application-dependent part message can be transmitted beforehand using
  725. * #GNUNET_MULTICAST_member_to_origin())
  726. *
  727. * @param member
  728. * Membership handle.
  729. */
  730. void
  731. GNUNET_MULTICAST_member_part (struct GNUNET_MULTICAST_Member *member,
  732. GNUNET_ContinuationCallback part_cb,
  733. void *part_cls);
  734. /**
  735. * Function called to provide data for a transmission from a member to the origin.
  736. *
  737. * Note that returning #GNUNET_OK or #GNUNET_SYSERR (but not #GNUNET_NO)
  738. * invalidates the respective transmission handle.
  739. *
  740. * @param cls
  741. * Closure.
  742. * @param[in,out] data_size
  743. * Initially set to the number of bytes available in
  744. * @a data, should be set to the number of bytes written to data.
  745. * @param[out] data
  746. * Where to write the body of the message to give to the
  747. * method. The function must copy at most @a data_size bytes to @a data.
  748. *
  749. * @return #GNUNET_SYSERR on error (fatal, aborts transmission)
  750. * #GNUNET_NO on success, if more data is to be transmitted later.
  751. * Should be used if @a data_size was not big enough to take all the
  752. * data. If 0 is returned in @a data_size the transmission is paused,
  753. * and can be resumed with GNUNET_MULTICAST_member_to_origin_resume().
  754. * #GNUNET_YES if this completes the transmission (all data supplied)
  755. * @deprecated should move to MQ-style API!
  756. */
  757. typedef int
  758. (*GNUNET_MULTICAST_MemberTransmitNotify) (void *cls,
  759. size_t *data_size,
  760. void *data);
  761. /**
  762. * Handle for a message to be delivered from a member to the origin.
  763. */
  764. struct GNUNET_MULTICAST_MemberTransmitHandle;
  765. /**
  766. * Send a message to the origin of the multicast group.
  767. *
  768. * @param member
  769. * Membership handle.
  770. * @param request_id
  771. * Application layer ID for the request. Opaque to multicast.
  772. * @param notify
  773. * Callback to call to get the message.
  774. * @param notify_cls
  775. * Closure for @a notify.
  776. *
  777. * @return Handle to cancel request, NULL on error (i.e. request already pending).
  778. * @deprecated should move to MQ-style API!
  779. */
  780. struct GNUNET_MULTICAST_MemberTransmitHandle *
  781. GNUNET_MULTICAST_member_to_origin (struct GNUNET_MULTICAST_Member *member,
  782. uint64_t request_id,
  783. GNUNET_MULTICAST_MemberTransmitNotify notify,
  784. void *notify_cls);
  785. /**
  786. * Resume message transmission to origin.
  787. *
  788. * @param th
  789. * Transmission to cancel.
  790. */
  791. void
  792. GNUNET_MULTICAST_member_to_origin_resume (struct GNUNET_MULTICAST_MemberTransmitHandle *th);
  793. /**
  794. * Cancel request for message transmission to origin.
  795. *
  796. * @param th
  797. * Transmission to cancel.
  798. */
  799. void
  800. GNUNET_MULTICAST_member_to_origin_cancel (struct GNUNET_MULTICAST_MemberTransmitHandle *th);
  801. #if 0 /* keep Emacsens' auto-indent happy */
  802. {
  803. #endif
  804. #ifdef __cplusplus
  805. }
  806. #endif
  807. /* ifndef GNUNET_MULTICAST_SERVICE_H */
  808. #endif
  809. /** @} */ /* end of group */