- fixing channel functions
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_local.h
1 /*
2      This file is part of GNUnet.
3      (C) 2013 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file mesh/gnunet-service-mesh_local.h
23  * @brief mesh service; dealing with local clients
24  * @author Bartlomiej Polot
25  *
26  * All functions in this file should use the prefix GML (Gnunet Mesh Local)
27  */
28
29 #ifndef GNUNET_SERVICE_MESH_LOCAL_H
30 #define GNUNET_SERVICE_MESH_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 #include "gnunet-service-mesh_channel.h"
44
45 /**
46  * Struct containing information about a client of the service
47  */
48 struct MeshClient;
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 chennel from a client
76  *
77  * @param client the client to check
78  * @param chid Channel ID
79  *
80  * @return non-NULL if channel exists in the global DLL
81  */
82 struct MeshChannel *
83 GML_channel_get (struct MeshClient *client, uint32_t chid);
84
85 /**
86  * Add a channel to a client
87  *
88  * @param client Client.
89  * @param chid Channel ID.
90  * @param ch Channel.
91  */
92 void
93 GML_channel_add (struct MeshClient *client,
94                  uint32_t chid,
95                  struct MeshChannel *ch);
96
97 /**
98  * Remove a channel from a client
99  *
100  * @param client Client.
101  * @param chid Channel ID.
102  * @param ch Channel.
103  */
104 void
105 GML_channel_remove (struct MeshClient *client,
106                     uint32_t chid,
107                     struct MeshChannel *ch);
108
109 /**
110  * Check if client has registered with the service and has not disconnected
111  *
112  * @param client the client to check
113  *
114  * @return non-NULL if client exists in the global DLL
115  */
116 struct MeshClient *
117 GML_client_get (struct GNUNET_SERVER_Client *client);
118
119 /**
120  * Find a client that has opened a port
121  *
122  * @param port Port to check.
123  *
124  * @return non-NULL if a client has the port.
125  */
126 struct MeshClient *
127 GML_client_get_by_port (uint32_t port);
128
129 /**
130  * Deletes a tunnel from a client (either owner or destination).
131  *
132  * @param c Client whose tunnel to delete.
133  * @param ch Channel which should be deleted.
134  */
135 void
136 GML_client_delete_channel (struct MeshClient *c, struct MeshChannel *ch);
137
138 /**
139  * Build a local ACK message and send it to a local client, if needed.
140  *
141  * If the client was already allowed to send data, do nothing.
142  *
143  * @param ch Channel on which to send the ACK.
144  * @param c Client to whom send the ACK.
145  * @param fwd Set to GNUNET_YES for FWD ACK (dest->root)
146  */
147 void
148 GML_send_ack (struct MeshChannel *ch, int fwd);
149
150 /**
151  * Notify the appropriate client that a new incoming channel was created.
152  *
153  * @param ch Channel that was created.
154  */
155 void
156 GML_send_channel_create (struct MeshClient *c,
157                          uint32_t id, uint32_t port, uint32_t opt,
158                          struct GNUNET_PeerIdentity *peer);
159
160 /**
161  * Notify a client that a channel is no longer valid.
162  *
163  * @param c Client.
164  * @param id ID of the channel that is destroyed.
165  */
166 void
167 GML_send_channel_destroy (struct MeshClient *c, uint32_t id);
168
169 /**
170  * Modify the mesh message TID from global to local and send to client.
171  *
172  * @param ch Channel on which to send the message.
173  * @param msg Message to modify and send.
174  * @param c Client to send to.
175  * @param tid Tunnel ID to use (c can be both owner and client).
176  */
177 void
178 GML_send_data (struct MeshChannel *ch,
179                const struct GNUNET_MESH_Data *msg,
180                struct MeshClient *c, MESH_ChannelNumber id);
181
182 /**
183  * Get the static string to represent a client.
184  *
185  * @param c Client.
186  *
187  * @return Static string for the client.
188  */
189 const char *
190 GML_2s (const struct MeshClient *c);
191
192
193 #if 0                           /* keep Emacsens' auto-indent happy */
194 {
195 #endif
196 #ifdef __cplusplus
197 }
198 #endif
199
200 /* ifndef GNUNET_MESH_SERVICE_LOCAL_H */
201 #endif
202 /* end of gnunet-mesh-service_LOCAL.h */