gnunet_multicast_service.h 30 KB

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