gnunet-service-fs_cadet.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2012, 2017 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 fs/gnunet-service-fs_cadet.h
  18. * @brief non-anonymous file-transfer
  19. * @author Christian Grothoff
  20. */
  21. #ifndef GNUNET_SERVICE_FS_CADET_H
  22. #define GNUNET_SERVICE_FS_CADET_H
  23. /**
  24. * Handle for a request that is going out via cadet API.
  25. */
  26. struct GSF_CadetRequest;
  27. /**
  28. * Function called with a reply from the cadet.
  29. *
  30. * @param cls closure
  31. * @param type type of the block, ANY on error
  32. * @param expiration expiration time for the block
  33. * @param data_size number of bytes in @a data, 0 on error
  34. * @param data reply block data, NULL on error
  35. */
  36. typedef void
  37. (*GSF_CadetReplyProcessor)(void *cls,
  38. enum GNUNET_BLOCK_Type type,
  39. struct GNUNET_TIME_Absolute expiration,
  40. size_t data_size,
  41. const void *data);
  42. /**
  43. * Look for a block by directly contacting a particular peer.
  44. *
  45. * @param target peer that should have the block
  46. * @param query hash to query for the block
  47. * @param type desired type for the block
  48. * @param proc function to call with result
  49. * @param proc_cls closure for @a proc
  50. * @return handle to cancel the operation
  51. */
  52. struct GSF_CadetRequest *
  53. GSF_cadet_query (const struct GNUNET_PeerIdentity *target,
  54. const struct GNUNET_HashCode *query,
  55. enum GNUNET_BLOCK_Type type,
  56. GSF_CadetReplyProcessor proc,
  57. void *proc_cls);
  58. /**
  59. * Function called on each active cadets to shut them down.
  60. *
  61. * @param cls NULL
  62. * @param key target peer, unused
  63. * @param value the `struct CadetHandle` to destroy
  64. * @return #GNUNET_YES (continue to iterate)
  65. */
  66. int
  67. GSF_cadet_release_clients (void *cls,
  68. const struct GNUNET_PeerIdentity *key,
  69. void *value);
  70. /**
  71. * Cancel an active request; must not be called after 'proc'
  72. * was calld.
  73. *
  74. * @param sr request to cancel
  75. */
  76. void
  77. GSF_cadet_query_cancel (struct GSF_CadetRequest *sr);
  78. /**
  79. * Initialize subsystem for non-anonymous file-sharing.
  80. */
  81. void
  82. GSF_cadet_start_server (void);
  83. /**
  84. * Shutdown subsystem for non-anonymous file-sharing.
  85. */
  86. void
  87. GSF_cadet_stop_server (void);
  88. /**
  89. * Cadet channel for creating outbound channels.
  90. */
  91. extern struct GNUNET_CADET_Handle *cadet_handle;
  92. /**
  93. * Map from peer identities to 'struct CadetHandles' with cadet
  94. * channels to those peers.
  95. */
  96. extern struct GNUNET_CONTAINER_MultiPeerMap *cadet_map;
  97. GNUNET_NETWORK_STRUCT_BEGIN
  98. /**
  99. * Query from one peer, asking the other for CHK-data.
  100. */
  101. struct CadetQueryMessage
  102. {
  103. /**
  104. * Type is GNUNET_MESSAGE_TYPE_FS_CADET_QUERY.
  105. */
  106. struct GNUNET_MessageHeader header;
  107. /**
  108. * Block type must be DBLOCK or IBLOCK.
  109. */
  110. uint32_t type GNUNET_PACKED;
  111. /**
  112. * Query hash from CHK (hash of encrypted block).
  113. */
  114. struct GNUNET_HashCode query;
  115. };
  116. /**
  117. * Reply to a CadetQueryMessage.
  118. */
  119. struct CadetReplyMessage
  120. {
  121. /**
  122. * Type is GNUNET_MESSAGE_TYPE_FS_CADET_REPLY.
  123. */
  124. struct GNUNET_MessageHeader header;
  125. /**
  126. * Block type must be DBLOCK or IBLOCK.
  127. */
  128. uint32_t type GNUNET_PACKED;
  129. /**
  130. * Expiration time for the block.
  131. */
  132. struct GNUNET_TIME_AbsoluteNBO expiration;
  133. /* followed by the encrypted block */
  134. };
  135. GNUNET_NETWORK_STRUCT_END
  136. #endif