gnunet-service-cadet_channel.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2001-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 cadet/gnunet-service-cadet_channel.h
  18. * @brief GNUnet CADET service with encryption
  19. * @author Bartlomiej Polot
  20. * @author Christian Grothoff
  21. */
  22. #ifndef GNUNET_SERVICE_CADET_CHANNEL_H
  23. #define GNUNET_SERVICE_CADET_CHANNEL_H
  24. #include "gnunet-service-cadet.h"
  25. #include "gnunet-service-cadet_peer.h"
  26. #include "cadet_protocol.h"
  27. /**
  28. * A channel is a bidirectional connection between two CADET
  29. * clients. Communiation can be reliable, unreliable, in-order
  30. * or out-of-order. One client is the "local" client, this
  31. * one initiated the connection. The other client is the
  32. * "incoming" client, this one listened on a port to accept
  33. * the connection from the "local" client.
  34. */
  35. struct CadetChannel;
  36. /**
  37. * Hash the @a port and @a initiator and @a listener to
  38. * calculate the "challenge" @a h_port we send to the other
  39. * peer on #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN.
  40. *
  41. * @param[out] h_port set to the hash of @a port, @a initiator and @a listener
  42. * @param port cadet port, as seen by CADET clients
  43. * @param listener peer that is listining on @a port
  44. */
  45. void
  46. GCCH_hash_port(struct GNUNET_HashCode *h_port,
  47. const struct GNUNET_HashCode *port,
  48. const struct GNUNET_PeerIdentity *listener);
  49. /**
  50. * Get the static string for identification of the channel.
  51. *
  52. * @param ch Channel.
  53. *
  54. * @return Static string with the channel IDs.
  55. */
  56. const char *
  57. GCCH_2s(const struct CadetChannel *ch);
  58. /**
  59. * Log channel info.
  60. *
  61. * @param ch Channel.
  62. * @param level Debug level to use.
  63. */
  64. void
  65. GCCH_debug(struct CadetChannel *ch,
  66. enum GNUNET_ErrorType level);
  67. /**
  68. * Get the channel's public ID.
  69. *
  70. * @param ch Channel.
  71. *
  72. * @return ID used to identify the channel with the remote peer.
  73. */
  74. struct GNUNET_CADET_ChannelTunnelNumber
  75. GCCH_get_id(const struct CadetChannel *ch);
  76. /**
  77. * Create a new channel.
  78. *
  79. * @param owner local client owning the channel
  80. * @param owner_id local chid of this channel at the @a owner
  81. * @param destination peer to which we should build the channel
  82. * @param port desired port at @a destination
  83. * @param options options for the channel
  84. * @return handle to the new channel
  85. */
  86. struct CadetChannel *
  87. GCCH_channel_local_new(struct CadetClient *owner,
  88. struct GNUNET_CADET_ClientChannelNumber owner_id,
  89. struct CadetPeer *destination,
  90. const struct GNUNET_HashCode *port,
  91. uint32_t options);
  92. /**
  93. * A client is bound to the port that we have a channel
  94. * open to. Send the acknowledgement for the connection
  95. * request and establish the link with the client.
  96. *
  97. * @param ch open incoming channel
  98. * @param c client listening on the respective @a port
  99. * @param port port number @a c is listening on
  100. */
  101. void
  102. GCCH_bind(struct CadetChannel *ch,
  103. struct CadetClient *c,
  104. const struct GNUNET_HashCode *port);
  105. /**
  106. * Destroy locally created channel. Called by the
  107. * local client, so no need to tell the client.
  108. *
  109. * @param ch channel to destroy
  110. * @param c client that caused the destruction
  111. * @param ccn client number of the client @a c
  112. */
  113. void
  114. GCCH_channel_local_destroy(struct CadetChannel *ch,
  115. struct CadetClient *c,
  116. struct GNUNET_CADET_ClientChannelNumber ccn);
  117. /**
  118. * Function called once and only once after a channel was bound
  119. * to its tunnel via #GCT_add_channel() is ready for transmission.
  120. * Note that this is only the case for channels that this peer
  121. * initiates, as for incoming channels we assume that they are
  122. * ready for transmission immediately upon receiving the open
  123. * message. Used to bootstrap the #GCT_send() process.
  124. *
  125. * @param ch the channel for which the tunnel is now ready
  126. */
  127. void
  128. GCCH_tunnel_up(struct CadetChannel *ch);
  129. /**
  130. * Create a new channel based on a request coming in over the network.
  131. *
  132. * @param t tunnel to the remote peer
  133. * @param chid identifier of this channel in the tunnel
  134. * @param origin peer to who initiated the channel
  135. * @param h_port hash of desired local port
  136. * @param options options for the channel
  137. * @return handle to the new channel
  138. */
  139. struct CadetChannel *
  140. GCCH_channel_incoming_new(struct CadetTunnel *t,
  141. struct GNUNET_CADET_ChannelTunnelNumber chid,
  142. const struct GNUNET_HashCode *h_port,
  143. uint32_t options);
  144. /**
  145. * We got a #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN message again for
  146. * this channel. If the binding was successful, (re)transmit the
  147. * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK.
  148. *
  149. * @param ch channel that got the duplicate open
  150. * @param cti identifier of the connection that delivered the message
  151. */
  152. void
  153. GCCH_handle_duplicate_open(struct CadetChannel *ch,
  154. const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti);
  155. /**
  156. * We got payload data for a channel. Pass it on to the client.
  157. *
  158. * @param ch channel that got data
  159. * @param cti identifier of the connection that delivered the message
  160. * @param msg message that was received
  161. */
  162. void
  163. GCCH_handle_channel_plaintext_data(struct CadetChannel *ch,
  164. const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
  165. const struct GNUNET_CADET_ChannelAppDataMessage *msg);
  166. /**
  167. * We got an acknowledgement for payload data for a channel.
  168. * Possibly resume transmissions.
  169. *
  170. * @param ch channel that got the ack
  171. * @param cti identifier of the connection that delivered the message
  172. * @param ack details about what was received
  173. */
  174. void
  175. GCCH_handle_channel_plaintext_data_ack(struct CadetChannel *ch,
  176. const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
  177. const struct GNUNET_CADET_ChannelDataAckMessage *ack);
  178. /**
  179. * We got an acknowledgement for the creation of the channel
  180. * (the port is open on the other side). Begin transmissions.
  181. *
  182. * @param ch channel to destroy
  183. * @param cti identifier of the connection that delivered the message,
  184. * NULL if the ACK was inferred because we got payload or are on loopback
  185. * @param port port number (needed to verify receiver knows the port)
  186. */
  187. void
  188. GCCH_handle_channel_open_ack(struct CadetChannel *ch,
  189. const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
  190. const struct GNUNET_HashCode *port);
  191. /**
  192. * Destroy channel, based on the other peer closing the
  193. * connection. Also needs to remove this channel from
  194. * the tunnel.
  195. *
  196. * FIXME: need to make it possible to defer destruction until we have
  197. * received all messages up to the destroy, and right now the destroy
  198. * message (and this API) fails to give is the information we need!
  199. *
  200. * FIXME: also need to know if the other peer got a destroy from
  201. * us before!
  202. *
  203. * @param ch channel to destroy
  204. * @param cti identifier of the connection that delivered the message,
  205. * NULL during shutdown
  206. */
  207. void
  208. GCCH_handle_remote_destroy(struct CadetChannel *ch,
  209. const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti);
  210. /**
  211. * Handle data given by a client.
  212. *
  213. * Check whether the client is allowed to send in this tunnel, save if
  214. * channel is reliable and send an ACK to the client if there is still
  215. * buffer space in the tunnel.
  216. *
  217. * @param ch Channel.
  218. * @param sender_ccn ccn of the sender
  219. * @param buf payload to transmit.
  220. * @param buf_len number of bytes in @a buf
  221. * @return #GNUNET_OK if everything goes well,
  222. * #GNUNET_SYSERR in case of an error.
  223. */
  224. int
  225. GCCH_handle_local_data(struct CadetChannel *ch,
  226. struct GNUNET_CADET_ClientChannelNumber sender_ccn,
  227. const char *buf,
  228. size_t buf_len);
  229. /**
  230. * Handle ACK from client on local channel.
  231. *
  232. * @param ch channel to destroy
  233. * @param client_ccn ccn of the client sending the ack
  234. */
  235. void
  236. GCCH_handle_local_ack(struct CadetChannel *ch,
  237. struct GNUNET_CADET_ClientChannelNumber client_ccn);
  238. #endif