gnunet-service-cadet.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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.h
  18. * @brief Information we track per peer.
  19. * @author Bartlomiej Polot
  20. * @author Christian Grothoff
  21. */
  22. #ifndef GNUNET_SERVICE_CADET_H
  23. #define GNUNET_SERVICE_CADET_H
  24. #include "gnunet_util_lib.h"
  25. #include "cadet_protocol.h"
  26. /**
  27. * A client to the CADET service. Each client gets a unique handle.
  28. */
  29. struct CadetClient;
  30. /**
  31. * A peer in the GNUnet network. Each peer we care about must have one globally
  32. * unique such handle within this process.
  33. */
  34. struct CadetPeer;
  35. /**
  36. * Tunnel from us to another peer. There can only be at most one
  37. * tunnel per peer.
  38. */
  39. struct CadetTunnel;
  40. /**
  41. * Entry in the message queue of a `struct CadetTunnel`.
  42. */
  43. struct CadetTunnelQueueEntry;
  44. /**
  45. * A path of peer in the GNUnet network. There must only be at most
  46. * once such path. Paths may share disjoint prefixes, but must all
  47. * end at a unique suffix. Paths must also not be proper subsets of
  48. * other existing paths.
  49. */
  50. struct CadetPeerPath;
  51. /**
  52. * Entry in a peer path.
  53. */
  54. struct CadetPeerPathEntry
  55. {
  56. /**
  57. * DLL of paths where the same @e peer is at the same offset.
  58. */
  59. struct CadetPeerPathEntry *next;
  60. /**
  61. * DLL of paths where the same @e peer is at the same offset.
  62. */
  63. struct CadetPeerPathEntry *prev;
  64. /**
  65. * The peer at this offset of the path.
  66. */
  67. struct CadetPeer *peer;
  68. /**
  69. * Path this entry belongs to.
  70. */
  71. struct CadetPeerPath *path;
  72. /**
  73. * Connection using this path, or NULL for none.
  74. */
  75. struct CadetConnection *cc;
  76. /**
  77. * Path's historic score up to this point. Basically, how often did
  78. * we succeed or fail to use the path up to this entry in a
  79. * connection. Positive values indicate good experiences, negative
  80. * values bad experiences. Code updating the score must guard
  81. * against overflows.
  82. */
  83. int score;
  84. };
  85. /**
  86. * Entry in list of connections used by tunnel, with metadata.
  87. */
  88. struct CadetTConnection
  89. {
  90. /**
  91. * Next in DLL.
  92. */
  93. struct CadetTConnection *next;
  94. /**
  95. * Prev in DLL.
  96. */
  97. struct CadetTConnection *prev;
  98. /**
  99. * Connection handle.
  100. */
  101. struct CadetConnection *cc;
  102. /**
  103. * Tunnel this connection belongs to.
  104. */
  105. struct CadetTunnel *t;
  106. /**
  107. * Creation time, to keep oldest connection alive.
  108. */
  109. struct GNUNET_TIME_Absolute created;
  110. /**
  111. * Connection throughput, to keep fastest connection alive.
  112. */
  113. uint32_t throughput;
  114. /**
  115. * Is the connection currently ready for transmission?
  116. */
  117. int is_ready;
  118. };
  119. /**
  120. * Port opened by a client.
  121. */
  122. struct OpenPort
  123. {
  124. /**
  125. * Client that opened the port.
  126. */
  127. struct CadetClient *c;
  128. /**
  129. * Port number.
  130. */
  131. struct GNUNET_HashCode port;
  132. /**
  133. * Port hashed with our PID (matches incoming OPEN messages).
  134. */
  135. struct GNUNET_HashCode h_port;
  136. };
  137. /**
  138. * Active path through the network (used by a tunnel). There may
  139. * be at most one connection per path.
  140. */
  141. struct CadetConnection;
  142. /**
  143. * Description of a segment of a `struct CadetConnection` at the
  144. * intermediate peers. Routes are basically entries in a peer's
  145. * routing table for forwarding traffic. At both endpoints, the
  146. * routes are terminated by a `struct CadetConnection`, which knows
  147. * the complete `struct CadetPath` that is formed by the individual
  148. * routes.
  149. */
  150. struct CadetRoute;
  151. /**
  152. * Logical end-to-end conenction between clients. There can be
  153. * any number of channels between clients.
  154. */
  155. struct CadetChannel;
  156. /**
  157. * Handle to our configuration.
  158. */
  159. extern const struct GNUNET_CONFIGURATION_Handle *cfg;
  160. /**
  161. * Handle to the statistics service.
  162. */
  163. extern struct GNUNET_STATISTICS_Handle *stats;
  164. /**
  165. * Handle to communicate with ATS.
  166. */
  167. extern struct GNUNET_ATS_ConnectivityHandle *ats_ch;
  168. /**
  169. * Local peer own ID.
  170. */
  171. extern struct GNUNET_PeerIdentity my_full_id;
  172. /**
  173. * Own private key.
  174. */
  175. extern struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
  176. /**
  177. * All ports clients of this peer have opened. Maps from
  178. * a hashed port to a `struct OpenPort`.
  179. */
  180. extern struct GNUNET_CONTAINER_MultiHashMap *open_ports;
  181. /**
  182. * Map from `struct GNUNET_CADET_ConnectionTunnelIdentifier`
  183. * hash codes to `struct CadetConnection` objects.
  184. */
  185. extern struct GNUNET_CONTAINER_MultiShortmap *connections;
  186. /**
  187. * Map from ports to channels where the ports were closed at the
  188. * time we got the inbound connection.
  189. * Indexed by h_port, contains `struct CadetChannel`.
  190. */
  191. extern struct GNUNET_CONTAINER_MultiHashMap *loose_channels;
  192. /**
  193. * Map from PIDs to `struct CadetPeer` entries.
  194. */
  195. extern struct GNUNET_CONTAINER_MultiPeerMap *peers;
  196. /**
  197. * How many messages are needed to trigger an AXOLOTL ratchet advance.
  198. */
  199. extern unsigned long long ratchet_messages;
  200. /**
  201. * How long until we trigger a ratched advance due to time.
  202. */
  203. extern struct GNUNET_TIME_Relative ratchet_time;
  204. /**
  205. * How frequently do we send KEEPALIVE messages on idle connections?
  206. */
  207. extern struct GNUNET_TIME_Relative keepalive_period;
  208. /**
  209. * Signal that shutdown is happening: prevent recovery measures.
  210. */
  211. extern int shutting_down;
  212. /**
  213. * Set to non-zero values to create random drops to test retransmissions.
  214. */
  215. extern unsigned long long drop_percent;
  216. /**
  217. * Send a message to a client.
  218. *
  219. * @param c client to get the message
  220. * @param env envelope with the message
  221. */
  222. void
  223. GSC_send_to_client (struct CadetClient *c,
  224. struct GNUNET_MQ_Envelope *env);
  225. /**
  226. * A channel was destroyed by the other peer. Tell our client.
  227. *
  228. * @param c client that lost a channel
  229. * @param ccn channel identification number for the client
  230. * @param ch the channel object
  231. */
  232. void
  233. GSC_handle_remote_channel_destroy (struct CadetClient *c,
  234. struct GNUNET_CADET_ClientChannelNumber ccn,
  235. struct CadetChannel *ch);
  236. /**
  237. * A client that created a loose channel that was not bound to a port
  238. * disconnected, drop it from the #loose_channels list.
  239. *
  240. * @param h_port the hashed port the channel was trying to bind to
  241. * @param ch the channel that was lost
  242. */
  243. void
  244. GSC_drop_loose_channel (const struct GNUNET_HashCode *h_port,
  245. struct CadetChannel *ch);
  246. /**
  247. * Bind incoming channel to this client, and notify client
  248. * about incoming connection.
  249. *
  250. * @param c client to bind to
  251. * @param ch channel to be bound
  252. * @param dest peer that establishes the connection
  253. * @param port port number
  254. * @param options options
  255. * @return local channel number assigned to the new client
  256. */
  257. struct GNUNET_CADET_ClientChannelNumber
  258. GSC_bind (struct CadetClient *c,
  259. struct CadetChannel *ch,
  260. struct CadetPeer *dest,
  261. const struct GNUNET_HashCode *port,
  262. uint32_t options);
  263. /**
  264. * Return identifier for a client as a string.
  265. *
  266. * @param c client to identify
  267. * @return string for debugging
  268. */
  269. const char *
  270. GSC_2s (struct CadetClient *c);
  271. #endif