gnunet-service-cadet_channel.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 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., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file cadet/gnunet-service-cadet_channel.h
  19. * @brief cadet service; dealing with end-to-end channels
  20. * @author Bartlomiej Polot
  21. *
  22. * All functions in this file should use the prefix GMCH (Gnunet Cadet CHannel)
  23. */
  24. #ifndef GNUNET_SERVICE_CADET_CHANNEL_H
  25. #define GNUNET_SERVICE_CADET_CHANNEL_H
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #if 0 /* keep Emacsens' auto-indent happy */
  30. }
  31. #endif
  32. #endif
  33. #include "platform.h"
  34. #include "gnunet_util_lib.h"
  35. #include "cadet_protocol.h"
  36. #include "cadet.h"
  37. /**
  38. * Struct containing all information regarding a channel to a remote client.
  39. */
  40. struct CadetChannel;
  41. #include "gnunet-service-cadet_tunnel.h"
  42. #include "gnunet-service-cadet_local.h"
  43. /**
  44. * Destroy a channel and free all resources.
  45. *
  46. * @param ch Channel to destroy.
  47. */
  48. void
  49. GCCH_destroy (struct CadetChannel *ch);
  50. /**
  51. * Get the channel's public ID.
  52. *
  53. * @param ch Channel.
  54. *
  55. * @return ID used to identify the channel with the remote peer.
  56. */
  57. CADET_ChannelNumber
  58. GCCH_get_id (const struct CadetChannel *ch);
  59. /**
  60. * Get the channel tunnel.
  61. *
  62. * @param ch Channel to get the tunnel from.
  63. *
  64. * @return tunnel of the channel.
  65. */
  66. struct CadetTunnel *
  67. GCCH_get_tunnel (const struct CadetChannel *ch);
  68. /**
  69. * Get free buffer space towards the client on a specific channel.
  70. *
  71. * @param ch Channel.
  72. * @param fwd Is query about FWD traffic?
  73. *
  74. * @return Free buffer space [0 - 64]
  75. */
  76. unsigned int
  77. GCCH_get_buffer (struct CadetChannel *ch, int fwd);
  78. /**
  79. * Get flow control status of end point: is client allow to send?
  80. *
  81. * @param ch Channel.
  82. * @param fwd Is query about FWD traffic? (Request root status).
  83. *
  84. * @return #GNUNET_YES if client is allowed to send us data.
  85. */
  86. int
  87. GCCH_get_allowed (struct CadetChannel *ch, int fwd);
  88. /**
  89. * Is the root client for this channel on this peer?
  90. *
  91. * @param ch Channel.
  92. * @param fwd Is this for fwd traffic?
  93. *
  94. * @return #GNUNET_YES in case it is.
  95. */
  96. int
  97. GCCH_is_origin (struct CadetChannel *ch, int fwd);
  98. /**
  99. * Is the destination client for this channel on this peer?
  100. *
  101. * @param ch Channel.
  102. * @param fwd Is this for fwd traffic?
  103. *
  104. * @return #GNUNET_YES in case it is.
  105. */
  106. int
  107. GCCH_is_terminal (struct CadetChannel *ch, int fwd);
  108. /**
  109. * Send an end-to-end ACK message for the most recent in-sequence payload.
  110. *
  111. * If channel is not reliable, do nothing.
  112. *
  113. * @param ch Channel this is about.
  114. * @param fwd Is for FWD traffic? (ACK dest->owner)
  115. */
  116. void
  117. GCCH_send_data_ack (struct CadetChannel *ch, int fwd);
  118. /**
  119. * Notify the destination client that a new incoming channel was created.
  120. *
  121. * @param ch Channel that was created.
  122. */
  123. void
  124. GCCH_send_create (struct CadetChannel *ch);
  125. /**
  126. * Allow a client to send us more data, in case it was choked.
  127. *
  128. * @param ch Channel.
  129. * @param fwd Is this about FWD traffic? (Root client).
  130. */
  131. void
  132. GCCH_allow_client (struct CadetChannel *ch, int fwd);
  133. /**
  134. * Log channel info.
  135. *
  136. * @param ch Channel.
  137. */
  138. void
  139. GCCH_debug (struct CadetChannel *ch);
  140. /**
  141. * Handle an ACK given by a client.
  142. *
  143. * Mark client as ready and send him any buffered data we could have for him.
  144. *
  145. * @param ch Channel.
  146. * @param fwd Is this a "FWD ACK"? (FWD ACKs are sent by root and go BCK)
  147. */
  148. void
  149. GCCH_handle_local_ack (struct CadetChannel *ch, int fwd);
  150. /**
  151. * Handle data given by a client.
  152. *
  153. * Check whether the client is allowed to send in this tunnel, save if channel
  154. * is reliable and send an ACK to the client if there is still buffer space
  155. * in the tunnel.
  156. *
  157. * @param ch Channel.
  158. * @param c Client which sent the data.
  159. * @param fwd Is this a FWD data?
  160. * @param message Data message.
  161. * @param size Size of data.
  162. *
  163. * @return GNUNET_OK if everything goes well, GNUNET_SYSERR in case of en error.
  164. */
  165. int
  166. GCCH_handle_local_data (struct CadetChannel *ch,
  167. struct CadetClient *c, int fwd,
  168. const struct GNUNET_MessageHeader *message,
  169. size_t size);
  170. /**
  171. * Handle a channel destroy requested by a client.
  172. *
  173. * Destroy the channel and the tunnel in case this was the last channel.
  174. *
  175. * @param ch Channel.
  176. * @param c Client that requested the destruction (to avoid notifying him).
  177. * @param is_root Is the request coming from root?
  178. */
  179. void
  180. GCCH_handle_local_destroy (struct CadetChannel *ch,
  181. struct CadetClient *c,
  182. int is_root);
  183. /**
  184. * Handle a channel create requested by a client.
  185. *
  186. * Create the channel and the tunnel in case this was the first0 channel.
  187. *
  188. * @param c Client that requested the creation (will be the root).
  189. * @param msg Create Channel message.
  190. *
  191. * @return GNUNET_OK if everything went fine, GNUNET_SYSERR otherwise.
  192. */
  193. int
  194. GCCH_handle_local_create (struct CadetClient *c,
  195. struct GNUNET_CADET_ChannelMessage *msg);
  196. /**
  197. * Handler for cadet network payload traffic.
  198. *
  199. * @param ch Channel for the message.
  200. * @param msg Unencryted data message.
  201. * @param fwd Is this message fwd? This only is meaningful in loopback channels.
  202. * #GNUNET_YES if message is FWD on the respective channel (loopback)
  203. * #GNUNET_NO if message is BCK on the respective channel (loopback)
  204. * #GNUNET_SYSERR if message on a one-ended channel (remote)
  205. */
  206. void
  207. GCCH_handle_data (struct CadetChannel *ch,
  208. const struct GNUNET_CADET_Data *msg,
  209. int fwd);
  210. /**
  211. * Handler for cadet network traffic end-to-end ACKs.
  212. *
  213. * @param ch Channel on which we got this message.
  214. * @param msg Data message.
  215. * @param fwd Is this message fwd? This only is meaningful in loopback channels.
  216. * #GNUNET_YES if message is FWD on the respective channel (loopback)
  217. * #GNUNET_NO if message is BCK on the respective channel (loopback)
  218. * #GNUNET_SYSERR if message on a one-ended channel (remote)
  219. */
  220. void
  221. GCCH_handle_data_ack (struct CadetChannel *ch,
  222. const struct GNUNET_CADET_DataACK *msg,
  223. int fwd);
  224. /**
  225. * Handler for channel create messages.
  226. *
  227. * Does not have fwd parameter because it's always 'FWD': channel is incoming.
  228. *
  229. * @param t Tunnel this channel will be in.
  230. * @param msg Channel crate message.
  231. */
  232. struct CadetChannel *
  233. GCCH_handle_create (struct CadetTunnel *t,
  234. const struct GNUNET_CADET_ChannelCreate *msg);
  235. /**
  236. * Handler for channel NACK messages.
  237. *
  238. * NACK messages always go dest -> root, no need for 'fwd' or 'msg' parameter.
  239. *
  240. * @param ch Channel.
  241. */
  242. void
  243. GCCH_handle_nack (struct CadetChannel *ch);
  244. /**
  245. * Handler for channel ack messages.
  246. *
  247. * @param ch Channel this channel is to be created in.
  248. * @param msg Message.
  249. * @param fwd Is this message fwd? This only is meaningful in loopback channels.
  250. * #GNUNET_YES if message is FWD on the respective channel (loopback)
  251. * #GNUNET_NO if message is BCK on the respective channel (loopback)
  252. * #GNUNET_SYSERR if message on a one-ended channel (remote)
  253. */
  254. void
  255. GCCH_handle_ack (struct CadetChannel *ch,
  256. const struct GNUNET_CADET_ChannelManage *msg,
  257. int fwd);
  258. /**
  259. * Handler for channel destroy messages.
  260. *
  261. * @param ch Channel this channel is to be destroyed of.
  262. * @param msg Message.
  263. * @param fwd Is this message fwd? This only is meaningful in loopback channels.
  264. * #GNUNET_YES if message is FWD on the respective channel (loopback)
  265. * #GNUNET_NO if message is BCK on the respective channel (loopback)
  266. * #GNUNET_SYSERR if message on a one-ended channel (remote)
  267. */
  268. void
  269. GCCH_handle_destroy (struct CadetChannel *ch,
  270. const struct GNUNET_CADET_ChannelManage *msg,
  271. int fwd);
  272. /**
  273. * Sends an already built message on a channel.
  274. *
  275. * If the channel is on a loopback tunnel, notifies the appropriate destination
  276. * client locally.
  277. *
  278. * On a normal channel passes the message to the tunnel for encryption and
  279. * sending on a connection.
  280. *
  281. * This function DOES NOT save the message for retransmission.
  282. *
  283. * @param message Message to send. Function makes a copy of it.
  284. * @param ch Channel on which this message is transmitted.
  285. * @param fwd Is this a fwd message?
  286. * @param existing_copy This is a retransmission, don't save a copy.
  287. */
  288. void
  289. GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
  290. struct CadetChannel *ch, int fwd,
  291. void *existing_copy);
  292. /**
  293. * Get the static string for identification of the channel.
  294. *
  295. * @param ch Channel.i
  296. *
  297. * @return Static string with the channel IDs.
  298. */
  299. const char *
  300. GCCH_2s (const struct CadetChannel *ch);
  301. #if 0 /* keep Emacsens' auto-indent happy */
  302. {
  303. #endif
  304. #ifdef __cplusplus
  305. }
  306. #endif
  307. /* ifndef GNUNET_SERVICE_CADET_CHANNEL_H */
  308. #endif
  309. /* end of gnunet-service-cadet_channel.h */