gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

gnunet-service-cadet.h (7651B)


      1 /*
      2      This file is part of GNUnet.
      3      Copyright (C) 2001-2017 GNUnet e.V.
      4 
      5      GNUnet is free software: you can redistribute it and/or modify it
      6      under the terms of the GNU Affero General Public License as published
      7      by the Free Software Foundation, either version 3 of the License,
      8      or (at your option) any later version.
      9 
     10      GNUnet is distributed in the hope that it will be useful, but
     11      WITHOUT ANY WARRANTY; without even the implied warranty of
     12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13      Affero General Public License for more details.
     14 
     15      You should have received a copy of the GNU Affero General Public License
     16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18      SPDX-License-Identifier: AGPL3.0-or-later
     19  */
     20 
     21 /**
     22  * @file cadet/gnunet-service-cadet.h
     23  * @brief Information we track per peer.
     24  * @author Bartlomiej Polot
     25  * @author Christian Grothoff
     26  */
     27 #ifndef GNUNET_SERVICE_CADET_H
     28 #define GNUNET_SERVICE_CADET_H
     29 
     30 #include "gnunet_pils_service.h"
     31 #include "gnunet_util_lib.h"
     32 #include "cadet_protocol.h"
     33 
     34 /**
     35  * A client to the CADET service.  Each client gets a unique handle.
     36  */
     37 struct CadetClient;
     38 
     39 /**
     40  * A peer in the GNUnet network.  Each peer we care about must have one globally
     41  * unique such handle within this process.
     42  */
     43 struct CadetPeer;
     44 
     45 /**
     46  * Tunnel from us to another peer.  There can only be at most one
     47  * tunnel per peer.
     48  */
     49 struct CadetTunnel;
     50 
     51 /**
     52  * Entry in the message queue of a `struct CadetTunnel`.
     53  */
     54 struct CadetTunnelQueueEntry;
     55 
     56 /**
     57  * A path of peer in the GNUnet network.  There must only be at most
     58  * once such path.  Paths may share disjoint prefixes, but must all
     59  * end at a unique suffix.  Paths must also not be proper subsets of
     60  * other existing paths.
     61  */
     62 struct CadetPeerPath;
     63 
     64 /**
     65  * Entry in a peer path.
     66  */
     67 struct CadetPeerPathEntry
     68 {
     69   /**
     70    * DLL of paths where the same @e peer is at the same offset.
     71    */
     72   struct CadetPeerPathEntry *next;
     73 
     74   /**
     75    * DLL of paths where the same @e peer is at the same offset.
     76    */
     77   struct CadetPeerPathEntry *prev;
     78 
     79   /**
     80    * The peer at this offset of the path.
     81    */
     82   struct CadetPeer *peer;
     83 
     84   /**
     85    * Path this entry belongs to.
     86    */
     87   struct CadetPeerPath *path;
     88 
     89   /**
     90    * Connection using this path, or NULL for none.
     91    */
     92   struct CadetConnection *cc;
     93 
     94   /**
     95    * Path's historic score up to this point.  Basically, how often did
     96    * we succeed or fail to use the path up to this entry in a
     97    * connection.  Positive values indicate good experiences, negative
     98    * values bad experiences.  Code updating the score must guard
     99    * against overflows.
    100    */
    101   int score;
    102 };
    103 
    104 /**
    105  * Entry in list of connections used by tunnel, with metadata.
    106  */
    107 struct CadetTConnection
    108 {
    109   /**
    110    * Next in DLL.
    111    */
    112   struct CadetTConnection *next;
    113 
    114   /**
    115    * Prev in DLL.
    116    */
    117   struct CadetTConnection *prev;
    118 
    119   /**
    120    * Connection handle.
    121    */
    122   struct CadetConnection *cc;
    123 
    124   /**
    125    * Tunnel this connection belongs to.
    126    */
    127   struct CadetTunnel *t;
    128 
    129   /**
    130    * Creation time, to keep oldest connection alive.
    131    */
    132   struct GNUNET_TIME_Absolute created;
    133 
    134   /**
    135    * Connection throughput, to keep fastest connection alive.
    136    */
    137   uint32_t throughput;
    138 
    139   /**
    140    * Is the connection currently ready for transmission?
    141    */
    142   int is_ready;
    143 };
    144 
    145 
    146 /**
    147  * Port opened by a client.
    148  */
    149 struct OpenPort
    150 {
    151   /**
    152    * Client that opened the port.
    153    */
    154   struct CadetClient *c;
    155 
    156   /**
    157    * Port number.
    158    */
    159   struct GNUNET_HashCode port;
    160 
    161   /**
    162    * Port hashed with our PID (matches incoming OPEN messages).
    163    */
    164   struct GNUNET_HashCode h_port;
    165 };
    166 
    167 
    168 /**
    169  * Active path through the network (used by a tunnel).  There may
    170  * be at most one connection per path.
    171  */
    172 struct CadetConnection;
    173 
    174 /**
    175  * Description of a segment of a `struct CadetConnection` at the
    176  * intermediate peers.  Routes are basically entries in a peer's
    177  * routing table for forwarding traffic.  At both endpoints, the
    178  * routes are terminated by a `struct CadetConnection`, which knows
    179  * the complete `struct CadetPath` that is formed by the individual
    180  * routes.
    181  */
    182 struct CadetRoute;
    183 
    184 /**
    185  * Logical end-to-end connection between clients.  There can be
    186  * any number of channels between clients.
    187  */
    188 struct CadetChannel;
    189 
    190 /**
    191  * Handle to our configuration.
    192  */
    193 extern const struct GNUNET_CONFIGURATION_Handle *cfg;
    194 
    195 /**
    196  * Handle to the statistics service.
    197  */
    198 extern struct GNUNET_STATISTICS_Handle *stats;
    199 
    200 /**
    201  * Handle to Transport service.
    202  */
    203 extern struct GNUNET_TRANSPORT_ApplicationHandle *transport;
    204 
    205 /**
    206  * Handle to Pils service.
    207  */
    208 extern struct GNUNET_PILS_Handle *pils;
    209 
    210 /**
    211  * All ports clients of this peer have opened.  Maps from
    212  * a hashed port to a `struct OpenPort`.
    213  */
    214 extern struct GNUNET_CONTAINER_MultiHashMap *open_ports;
    215 
    216 /**
    217  * Map from `struct GNUNET_CADET_ConnectionTunnelIdentifier`
    218  * hash codes to `struct CadetConnection` objects.
    219  */
    220 extern struct GNUNET_CONTAINER_MultiShortmap *connections;
    221 
    222 /**
    223  * Map from ports to channels where the ports were closed at the
    224  * time we got the inbound connection.
    225  * Indexed by h_port, contains `struct CadetChannel`.
    226  */
    227 extern struct GNUNET_CONTAINER_MultiHashMap *loose_channels;
    228 
    229 /**
    230  * Map from PIDs to `struct CadetPeer` entries.
    231  */
    232 extern struct GNUNET_CONTAINER_MultiPeerMap *peers;
    233 
    234 /**
    235  * How many messages are needed to trigger an AXOLOTL ratchet advance.
    236  */
    237 extern unsigned long long ratchet_messages;
    238 
    239 /**
    240  * How long until we trigger a ratched advance due to time.
    241  */
    242 extern struct GNUNET_TIME_Relative ratchet_time;
    243 
    244 /**
    245  * How frequently do we send KEEPALIVE messages on idle connections?
    246  */
    247 extern struct GNUNET_TIME_Relative keepalive_period;
    248 
    249 /**
    250  * Signal that shutdown is happening: prevent recovery measures.
    251  */
    252 extern int shutting_down;
    253 
    254 /**
    255  * Set to non-zero values to create random drops to test retransmissions.
    256  */
    257 extern unsigned long long drop_percent;
    258 
    259 
    260 /**
    261  * Send a message to a client.
    262  *
    263  * @param c client to get the message
    264  * @param env envelope with the message
    265  */
    266 void
    267 GSC_send_to_client (struct CadetClient *c,
    268                     struct GNUNET_MQ_Envelope *env);
    269 
    270 
    271 /**
    272  * A channel was destroyed by the other peer. Tell our client.
    273  *
    274  * @param c client that lost a channel
    275  * @param ccn channel identification number for the client
    276  * @param ch the channel object
    277  */
    278 void
    279 GSC_handle_remote_channel_destroy (struct CadetClient *c,
    280                                    struct GNUNET_CADET_ClientChannelNumber ccn,
    281                                    struct CadetChannel *ch);
    282 
    283 /**
    284  * A client that created a loose channel that was not bound to a port
    285  * disconnected, drop it from the #loose_channels list.
    286  *
    287  * @param h_port the hashed port the channel was trying to bind to
    288  * @param ch the channel that was lost
    289  */
    290 void
    291 GSC_drop_loose_channel (const struct GNUNET_HashCode *h_port,
    292                         struct CadetChannel *ch);
    293 
    294 
    295 /**
    296  * Bind incoming channel to this client, and notify client
    297  * about incoming connection.
    298  *
    299  * @param c client to bind to
    300  * @param ch channel to be bound
    301  * @param dest peer that establishes the connection
    302  * @param port port number
    303  * @param options options
    304  * @return local channel number assigned to the new client
    305  */
    306 struct GNUNET_CADET_ClientChannelNumber
    307 GSC_bind (struct CadetClient *c,
    308           struct CadetChannel *ch,
    309           struct CadetPeer *dest,
    310           const struct GNUNET_HashCode *port,
    311           uint32_t options);
    312 
    313 
    314 /**
    315  * Return identifier for a client as a string.
    316  *
    317  * @param c client to identify
    318  * @return string for debugging
    319  */
    320 const char *
    321 GSC_2s (struct CadetClient *c);
    322 
    323 
    324 #endif