starting re-implementation of CADET service
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet-new_channel.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_channel.h
24  * @brief GNUnet CADET service with encryption
25  * @author Bartlomiej Polot
26  * @author Christian Grothoff
27  */
28 #ifndef GNUNET_SERVICE_CADET_CHANNEL_H
29 #define GNUNET_SERVICE_CADET_CHANNEL_H
30
31 #include "gnunet-service-cadet-new.h"
32 #include "gnunet-service-cadet-new_peer.h"
33
34
35 /**
36  * A channel is a bidirectional connection between two CADET
37  * clients.  Communiation can be reliable, unreliable, in-order
38  * or out-of-order.  One client is the "local" client, this
39  * one initiated the connection.   The other client is the
40  * "incoming" client, this one listened on a port to accept
41  * the connection from the "local" client.
42  */
43 struct CadetChannel;
44
45
46 /**
47  * Get the static string for identification of the channel.
48  *
49  * @param ch Channel.
50  *
51  * @return Static string with the channel IDs.
52  */
53 const char *
54 GCCH_2s (const struct CadetChannel *ch);
55
56
57 /**
58  * Log channel info.
59  *
60  * @param ch Channel.
61  * @param level Debug level to use.
62  */
63 void
64 GCCH_debug (struct CadetChannel *ch,
65             enum GNUNET_ErrorType level);
66
67
68 /**
69  * Get the channel's public ID.
70  *
71  * @param ch Channel.
72  *
73  * @return ID used to identify the channel with the remote peer.
74  */
75 struct GCT_ChannelTunnelNumber
76 GCCH_get_id (const struct CadetChannel *ch);
77
78
79 /**
80  * Create a new channel.
81  *
82  * @param owner local client owning the channel
83  * @param owner_id local chid of this channel at the @a owner
84  * @param destination peer to which we should build the channel
85  * @param port desired port at @a destination
86  * @param options options for the channel
87  * @return handle to the new channel
88  */
89 struct CadetChannel *
90 GCCH_channel_local_new (struct CadetClient *owner,
91                         struct GNUNET_CADET_ClientChannelNumber owner_id,
92                         struct CadetPeer *destination,
93                         const struct GNUNET_HashCode *port,
94                         uint32_t options);
95
96
97 /**
98  * A client is bound to the port that we have a channel
99  * open to.  Send the acknowledgement for the connection
100  * request and establish the link with the client.
101  *
102  * @param ch open incoming channel
103  * @param c client listening on the respective port
104  */
105 void
106 GCCH_bind (struct CadetChannel *ch,
107            struct CadetClient *c);
108
109
110
111 /**
112  * Destroy locally created channel.  Called by the
113  * local client, so no need to tell the client.
114  *
115  * @param ch channel to destroy
116  */
117 void
118 GCCH_channel_local_destroy (struct CadetChannel *ch);
119
120
121 /**
122  * Create a new channel.
123  *
124  * @param t tunnel to the remote peer
125  * @param gid identifier of this channel in the tunnel
126  * @param origin peer to who initiated the channel
127  * @param port desired local port
128  * @param options options for the channel
129  * @return handle to the new channel
130  */
131 struct CadetChannel *
132 GCCH_channel_incoming_new (struct CadetTunnel *t,
133                            struct GCT_ChannelTunnelNumber gid,
134                            const struct GNUNET_HashCode *port,
135                            uint32_t options);
136
137
138 /**
139  * Destroy channel that was incoming.  Called by the
140  * local client, so no need to tell the client.
141  *
142  * @param ch channel to destroy
143  */
144 void
145 GCCH_channel_incoming_destroy (struct CadetChannel *ch);
146
147
148 /**
149  * Handle data given by a client.
150  *
151  * Check whether the client is allowed to send in this tunnel, save if
152  * channel is reliable and send an ACK to the client if there is still
153  * buffer space in the tunnel.
154  *
155  * @param ch Channel.
156  * @param message payload to transmit.
157  * @return #GNUNET_OK if everything goes well,
158  *         #GNUNET_SYSERR in case of an error.
159  */
160 int
161 GCCH_handle_local_data (struct CadetChannel *ch,
162                         const struct GNUNET_MessageHeader *message);
163
164
165 /**
166  * Handle ACK from client on local channel.
167  *
168  * @param ch channel to destroy
169  */
170 void
171 GCCH_handle_local_ack (struct CadetChannel *ch);
172
173 #endif