create matching connection objects for inbound connections
[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  * Is the given connection currently ready for transmission?
38  *
39  * @param cc connection to transmit on
40  * @return #GNUNET_YES if we could transmit
41  */
42 int
43 GCC_is_ready (struct CadetConnection *cc);
44
45
46 /**
47  * Destroy a connection.
48  *
49  * @param cc connection to destroy
50  */
51 void
52 GCC_destroy (struct CadetConnection *cc);
53
54
55 /**
56  * Create a connection to @a destination via @a path and
57  * notify @a cb whenever we are ready for more data.
58  *
59  * @param destination where to go
60  * @param path which path to take (may not be the full path)
61  * @param ct which tunnel uses this connection
62  * @param ready_cb function to call when ready to transmit
63  * @param ready_cb_cls closure for @a cb
64  * @return handle to the connection
65  */
66 struct CadetConnection *
67 GCC_create (struct CadetPeer *destination,
68             struct CadetPeerPath *path,
69             struct CadetTConnection *ct,
70             GNUNET_SCHEDULER_TaskCallback ready_cb,
71             void *ready_cb_cls);
72
73
74 /**
75  * Create a connection to @a destination via @a path and
76  * notify @a cb whenever we are ready for more data.  This
77  * is an inbound tunnel, so we must use the existing @a cid
78  *
79  * @param destination where to go
80  * @param path which path to take (may not be the full path)
81  * @param ct which tunnel uses this connection
82  * @param ready_cb function to call when ready to transmit
83  * @param ready_cb_cls closure for @a cb
84  * @return handle to the connection
85  */
86 struct CadetConnection *
87 GCC_create_inbound (struct CadetPeer *destination,
88                     struct CadetPeerPath *path,
89                     struct CadetTConnection *ct,
90                     const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
91                     GNUNET_SCHEDULER_TaskCallback ready_cb,
92                     void *ready_cb_cls);
93
94
95 /**
96  * Transmit message @a msg via connection @a cc.  Must only be called
97  * (once) after the connection has signalled that it is ready via the
98  * `ready_cb`.  Clients can also use #GCC_is_ready() to check if the
99  * connection is right now ready for transmission.
100  *
101  * @param cc connection identification
102  * @param env envelope with message to transmit;
103  *            the #GNUNET_MQ_notify_send() must not have yet been used
104  *            for the envelope.  Also, the message better match the
105  *            connection identifier of this connection...
106  */
107 void
108 GCC_transmit (struct CadetConnection *cc,
109               struct GNUNET_MQ_Envelope *env);
110
111
112 /**
113  * An ACK was received for this connection, process it.
114  *
115  * @param cc the connection that got the ACK.
116  */
117 void
118 GCC_handle_connection_ack (struct CadetConnection *cc);
119
120
121 /**
122  * Handle KX message.
123  *
124  * @param cc connection that received encrypted message
125  * @param msg the key exchange message
126  */
127 void
128 GCC_handle_kx (struct CadetConnection *cc,
129                const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
130
131
132 /**
133  * Handle encrypted message.
134  *
135  * @param cc connection that received encrypted message
136  * @param msg the encrypted message to decrypt
137  */
138 void
139 GCC_handle_encrypted (struct CadetConnection *cc,
140                       const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
141
142
143 /**
144  * Return the tunnel associated with this connection.
145  *
146  * @param cc connection to query
147  * @return corresponding entry in the tunnel's connection list
148  */
149 struct CadetTConnection *
150 GCC_get_ct (struct CadetConnection *cc);
151
152
153 /**
154  * Obtain the path used by this connection.
155  *
156  * @param cc connection
157  * @return path to @a cc
158  */
159 struct CadetPeerPath *
160 GCC_get_path (struct CadetConnection *cc);
161
162
163 /**
164  * Obtain unique ID for the connection.
165  *
166  * @param cc connection.
167  * @return unique number of the connection
168  */
169 const struct GNUNET_CADET_ConnectionTunnelIdentifier *
170 GCC_get_id (struct CadetConnection *cc);
171
172
173 /**
174  * Log connection info.
175  *
176  * @param cc connection
177  * @param level Debug level to use.
178  */
179 void
180 GCC_debug (struct CadetConnection *cc,
181            enum GNUNET_ErrorType level);
182
183
184 #endif