3 This file is part of GNUnet.
4 Copyright (C) 2001-2017 GNUnet e.V.
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.
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.
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.
23 * @file cadet/gnunet-service-cadet-new_connection.h
25 * @author Bartlomiej Polot
26 * @author Christian Grothoff
28 #ifndef GNUNET_SERVICE_CADET_CONNECTION_H
29 #define GNUNET_SERVICE_CADET_CONNECTION_H
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"
38 * Function called to notify tunnel about change in our readyness.
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
45 (*GCC_ReadyCallback)(void *cls,
50 * Destroy a connection, called when the CORE layer is already done
51 * (i.e. has received a BROKEN message), but if we still have to
52 * communicate the destruction of the connection to the tunnel (if one
55 * @param cc connection to destroy
58 GCC_destroy_without_core (struct CadetConnection *cc);
62 * Destroy a connection, called if the tunnel association with the
63 * connection was already broken, but we still need to notify the CORE
64 * layer about the breakage.
66 * @param cc connection to destroy
69 GCC_destroy_without_tunnel (struct CadetConnection *cc);
73 * Create a connection to @a destination via @a path and
74 * notify @a cb whenever we are ready for more data.
76 * @param destination where to go
77 * @param path which path to take (may not be the full path)
78 * @param options options for the connection
79 * @param ct which tunnel uses this connection
80 * @param ready_cb function to call when ready to transmit
81 * @param ready_cb_cls closure for @a cb
82 * @return handle to the connection
84 struct CadetConnection *
85 GCC_create (struct CadetPeer *destination,
86 struct CadetPeerPath *path,
87 enum GNUNET_CADET_ChannelOption options,
88 struct CadetTConnection *ct,
89 GCC_ReadyCallback ready_cb,
94 * Create a connection to @a destination via @a path and
95 * notify @a cb whenever we are ready for more data. This
96 * is an inbound tunnel, so we must use the existing @a cid
98 * @param destination where to go
99 * @param path which path to take (may not be the full path)
100 * @param options options for the connection
101 * @param ct which tunnel uses this connection
102 * @param ready_cb function to call when ready to transmit
103 * @param ready_cb_cls closure for @a cb
104 * @return handle to the connection, NULL if we already have
105 * a connection that takes precedence on @a path
107 struct CadetConnection *
108 GCC_create_inbound (struct CadetPeer *destination,
109 struct CadetPeerPath *path,
110 enum GNUNET_CADET_ChannelOption options,
111 struct CadetTConnection *ct,
112 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
113 GCC_ReadyCallback ready_cb,
118 * Transmit message @a msg via connection @a cc. Must only be called
119 * (once) after the connection has signalled that it is ready via the
120 * `ready_cb`. Clients can also use #GCC_is_ready() to check if the
121 * connection is right now ready for transmission.
123 * @param cc connection identification
124 * @param env envelope with message to transmit;
125 * the #GNUNET_MQ_notify_send() must not have yet been used
126 * for the envelope. Also, the message better match the
127 * connection identifier of this connection...
130 GCC_transmit (struct CadetConnection *cc,
131 struct GNUNET_MQ_Envelope *env);
135 * A CREATE_ACK was received for this connection, process it.
137 * @param cc the connection that got the ACK.
140 GCC_handle_connection_create_ack (struct CadetConnection *cc);
144 * We got a #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE for a
145 * connection that we already have. Either our ACK got lost
146 * or something is fishy. Consider retransmitting the ACK.
148 * @param cc connection that got the duplicate CREATE
151 GCC_handle_duplicate_create (struct CadetConnection *cc);
157 * @param cc connection that received encrypted message
158 * @param msg the key exchange message
161 GCC_handle_kx (struct CadetConnection *cc,
162 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
166 * Handle KX_AUTH message.
168 * @param cc connection that received encrypted message
169 * @param msg the key exchange message
172 GCC_handle_kx_auth (struct CadetConnection *cc,
173 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg);
177 * Handle encrypted message.
179 * @param cc connection that received encrypted message
180 * @param msg the encrypted message to decrypt
183 GCC_handle_encrypted (struct CadetConnection *cc,
184 const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
188 * Return the tunnel associated with this connection.
190 * @param cc connection to query
191 * @return corresponding entry in the tunnel's connection list
193 struct CadetTConnection *
194 GCC_get_ct (struct CadetConnection *cc);
198 * Obtain the path used by this connection.
200 * @param cc connection
201 * @return path to @a cc
203 struct CadetPeerPath *
204 GCC_get_path (struct CadetConnection *cc);
208 * Obtain unique ID for the connection.
210 * @param cc connection.
211 * @return unique number of the connection
213 const struct GNUNET_CADET_ConnectionTunnelIdentifier *
214 GCC_get_id (struct CadetConnection *cc);
218 * Get a (static) string for a connection.
220 * @param cc Connection.
223 GCC_2s (const struct CadetConnection *cc);
227 * Log connection info.
229 * @param cc connection
230 * @param level Debug level to use.
233 GCC_debug (struct CadetConnection *cc,
234 enum GNUNET_ErrorType level);