much work on connection/route/peer-level queue management
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet-new_connection.h
1
2 /*
3      This file is part of GNUnet.
4      Copyright (C) 2001-2017 GNUnet e.V.
5
6      GNUnet is free software; you can redistribute it and/or modify
7      it under the terms of the GNU General Public License as published
8      by the Free Software Foundation; either version 3, or (at your
9      option) any later version.
10
11      GNUnet is distributed in the hope that it will be useful, but
12      WITHOUT ANY WARRANTY; without even the implied warranty of
13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14      General Public License for more details.
15
16      You should have received a copy of the GNU General Public License
17      along with GNUnet; see the file COPYING.  If not, write to the
18      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19      Boston, MA 02110-1301, USA.
20 */
21
22 /**
23  * @file cadet/gnunet-service-cadet-new_connection.h
24  * @brief
25  * @author Bartlomiej Polot
26  * @author Christian Grothoff
27  */
28 #ifndef GNUNET_SERVICE_CADET_CONNECTION_H
29 #define GNUNET_SERVICE_CADET_CONNECTION_H
30
31 #include "gnunet_util_lib.h"
32 #include "gnunet-service-cadet-new.h"
33 #include "gnunet-service-cadet-new_peer.h"
34 #include "cadet_protocol.h"
35
36
37 /**
38  * Function called to notify tunnel about change in our readyness.
39  *
40  * @param cls closure
41  * @param is_ready #GNUNET_YES if the connection is now ready for transmission,
42  *                 #GNUNET_NO if the connection is no longer ready for transmission
43  */
44 typedef void
45 (*GCC_ReadyCallback)(void *cls,
46                      int is_ready);
47
48
49 /**
50  * Destroy a connection.
51  *
52  * @param cc connection to destroy
53  */
54 void
55 GCC_destroy (struct CadetConnection *cc);
56
57
58 /**
59  * Create a connection to @a destination via @a path and
60  * notify @a cb whenever we are ready for more data.
61  *
62  * @param destination where to go
63  * @param path which path to take (may not be the full path)
64  * @param ct which tunnel uses this connection
65  * @param ready_cb function to call when ready to transmit
66  * @param ready_cb_cls closure for @a cb
67  * @return handle to the connection
68  */
69 struct CadetConnection *
70 GCC_create (struct CadetPeer *destination,
71             struct CadetPeerPath *path,
72             struct CadetTConnection *ct,
73             GCC_ReadyCallback ready_cb,
74             void *ready_cb_cls);
75
76
77 /**
78  * Create a connection to @a destination via @a path and
79  * notify @a cb whenever we are ready for more data.  This
80  * is an inbound tunnel, so we must use the existing @a cid
81  *
82  * @param destination where to go
83  * @param path which path to take (may not be the full path)
84  * @param ct which tunnel uses this connection
85  * @param ready_cb function to call when ready to transmit
86  * @param ready_cb_cls closure for @a cb
87  * @return handle to the connection
88  */
89 struct CadetConnection *
90 GCC_create_inbound (struct CadetPeer *destination,
91                     struct CadetPeerPath *path,
92                     struct CadetTConnection *ct,
93                     const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
94                     GCC_ReadyCallback ready_cb,
95                     void *ready_cb_cls);
96
97
98 /**
99  * Transmit message @a msg via connection @a cc.  Must only be called
100  * (once) after the connection has signalled that it is ready via the
101  * `ready_cb`.  Clients can also use #GCC_is_ready() to check if the
102  * connection is right now ready for transmission.
103  *
104  * @param cc connection identification
105  * @param env envelope with message to transmit;
106  *            the #GNUNET_MQ_notify_send() must not have yet been used
107  *            for the envelope.  Also, the message better match the
108  *            connection identifier of this connection...
109  */
110 void
111 GCC_transmit (struct CadetConnection *cc,
112               struct GNUNET_MQ_Envelope *env);
113
114
115 /**
116  * An ACK was received for this connection, process it.
117  *
118  * @param cc the connection that got the ACK.
119  */
120 void
121 GCC_handle_connection_ack (struct CadetConnection *cc);
122
123
124 /**
125  * Handle KX message.
126  *
127  * @param cc connection that received encrypted message
128  * @param msg the key exchange message
129  */
130 void
131 GCC_handle_kx (struct CadetConnection *cc,
132                const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
133
134
135 /**
136  * Handle encrypted message.
137  *
138  * @param cc connection that received encrypted message
139  * @param msg the encrypted message to decrypt
140  */
141 void
142 GCC_handle_encrypted (struct CadetConnection *cc,
143                       const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
144
145
146 /**
147  * Return the tunnel associated with this connection.
148  *
149  * @param cc connection to query
150  * @return corresponding entry in the tunnel's connection list
151  */
152 struct CadetTConnection *
153 GCC_get_ct (struct CadetConnection *cc);
154
155
156 /**
157  * Obtain the path used by this connection.
158  *
159  * @param cc connection
160  * @return path to @a cc
161  */
162 struct CadetPeerPath *
163 GCC_get_path (struct CadetConnection *cc);
164
165
166 /**
167  * Obtain unique ID for the connection.
168  *
169  * @param cc connection.
170  * @return unique number of the connection
171  */
172 const struct GNUNET_CADET_ConnectionTunnelIdentifier *
173 GCC_get_id (struct CadetConnection *cc);
174
175
176 /**
177  * Get a (static) string for a connection.
178  *
179  * @param cc Connection.
180  */
181 const char *
182 GCC_2s (const struct CadetConnection *cc);
183
184
185 /**
186  * Log connection info.
187  *
188  * @param cc connection
189  * @param level Debug level to use.
190  */
191 void
192 GCC_debug (struct CadetConnection *cc,
193            enum GNUNET_ErrorType level);
194
195
196 #endif