fair, global message buffer implemented
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet_local.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2013 GNUnet e.V.
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @file cadet/gnunet-service-cadet_local.h
23  * @brief cadet service; dealing with local clients
24  * @author Bartlomiej Polot
25  *
26  * All functions in this file should use the prefix GML (Gnunet Cadet Local)
27  */
28
29 #ifndef GNUNET_SERVICE_CADET_LOCAL_H
30 #define GNUNET_SERVICE_CADET_LOCAL_H
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 #include "platform.h"
41 #include "gnunet_util_lib.h"
42
43 /**
44  * Struct containing information about a client of the service
45  */
46 struct CadetClient;
47
48 #include "gnunet-service-cadet_channel.h"
49
50 /******************************************************************************/
51 /********************************    API    ***********************************/
52 /******************************************************************************/
53
54 /**
55  * Initialize server subsystem.
56  *
57  * @param handle Server handle.
58  */
59 void
60 GML_init (struct GNUNET_SERVER_Handle *handle);
61
62 /**
63  * Install server (service) handlers and start listening to clients.
64  */
65 void
66 GML_start (void);
67
68 /**
69  * Shutdown server.
70  */
71 void
72 GML_shutdown (void);
73
74 /**
75  * Get a channel from a client.
76  *
77  * @param c Client to check.
78  * @param ccn Channel ID, must be local (> 0x800...).
79  *
80  * @return non-NULL if channel exists in the clients lists
81  */
82 struct CadetChannel *
83 GML_channel_get (struct CadetClient *c,
84                  struct GNUNET_CADET_ClientChannelNumber ccn);
85
86 /**
87  * Add a channel to a client
88  *
89  * @param client Client.
90  * @param ccn Channel ID.
91  * @param ch Channel.
92  */
93 void
94 GML_channel_add (struct CadetClient *client,
95                  struct GNUNET_CADET_ClientChannelNumber ccn,
96                  struct CadetChannel *ch);
97
98 /**
99  * Remove a channel from a client
100  *
101  * @param client Client.
102  * @param ccn Channel ID.
103  * @param ch Channel.
104  */
105 void
106 GML_channel_remove (struct CadetClient *client,
107                     struct GNUNET_CADET_ClientChannelNumber ccn,
108                     struct CadetChannel *ch);
109
110 /**
111  * Get the tunnel's next free local channel ID.
112  *
113  * @param c Client.
114  *
115  * @return LID of a channel free to use.
116  */
117 struct GNUNET_CADET_ClientChannelNumber
118 GML_get_next_ccn (struct CadetClient *c);
119
120 /**
121  * Check if client has registered with the service and has not disconnected
122  *
123  * @param client the client to check
124  *
125  * @return non-NULL if client exists in the global DLL
126  */
127 struct CadetClient *
128 GML_client_get (struct GNUNET_SERVER_Client *client);
129
130 /**
131  * Find a client that has opened a port
132  *
133  * @param port Port to check.
134  *
135  * @return non-NULL if a client has the port.
136  */
137 struct CadetClient *
138 GML_client_get_by_port (const struct GNUNET_HashCode *port);
139
140 /**
141  * Deletes a tunnel from a client (either owner or destination).
142  *
143  * @param c Client whose tunnel to delete.
144  * @param ch Channel which should be deleted.
145  * @param id Channel ID.
146  */
147 void
148 GML_client_delete_channel (struct CadetClient *c,
149                            struct CadetChannel *ch,
150                            struct GNUNET_CADET_ClientChannelNumber id);
151
152 /**
153  * Build a local ACK message and send it to a local client, if needed.
154  *
155  * If the client was already allowed to send data, do nothing.
156  *
157  * @param c Client to whom send the ACK.
158  * @param id Channel ID to use
159  */
160 void
161 GML_send_ack (struct CadetClient *c,
162               struct GNUNET_CADET_ClientChannelNumber id);
163
164 /**
165  * Notify the appropriate client that a new incoming channel was created.
166  *
167  * @param c Client to notify.
168  * @param id Channel ID.
169  * @param port Channel's destination port.
170  * @param opt Options (bit array).
171  * @param peer Origin peer.
172  */
173 void
174 GML_send_channel_create (struct CadetClient *c,
175                          struct GNUNET_CADET_ClientChannelNumber id,
176                          const struct GNUNET_HashCode *port,
177                          uint32_t opt,
178                          const struct GNUNET_PeerIdentity *peer);
179
180 /**
181  * Build a local channel NACK message and send it to a local client.
182  *
183  * @param c Client to whom send the NACK.
184  * @param id Channel ID to use
185  */
186 void
187 GML_send_channel_nack (struct CadetClient *c,
188                        struct GNUNET_CADET_ClientChannelNumber id);
189
190
191 /**
192  * Notify a client that a channel is no longer valid.
193  *
194  * @param c Client.
195  * @param id ID of the channel that is destroyed.
196  */
197 void
198 GML_send_channel_destroy (struct CadetClient *c,
199                           struct GNUNET_CADET_ClientChannelNumber id);
200
201
202 /**
203  * Modify the cadet message ID from global to local and send to client.
204  *
205  * @param c Client to send to.
206  * @param msg Message to modify and send.
207  * @param id Channel ID to use (c can be both owner and client).
208  */
209 void
210 GML_send_data (struct CadetClient *c,
211                const struct GNUNET_CADET_ChannelAppDataMessage *msg,
212                struct GNUNET_CADET_ClientChannelNumber id);
213
214 /**
215  * Get the static string to represent a client.
216  *
217  * @param c Client.
218  *
219  * @return Static string for the client.
220  */
221 const char *
222 GML_2s (const struct CadetClient *c);
223
224
225 #if 0                           /* keep Emacsens' auto-indent happy */
226 {
227 #endif
228 #ifdef __cplusplus
229 }
230 #endif
231
232 /* ifndef GNUNET_CADET_SERVICE_LOCAL_H */
233 #endif
234 /* end of gnunet-cadet-service_LOCAL.h */