-ftbfs
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_connection.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_connection.h
23  * @brief mesh service; dealing with connections
24  * @author Bartlomiej Polot
25  *
26  * All functions in this file should use the prefix GMC (Gnunet Mesh Connection)
27  */
28
29 #ifndef GNUNET_SERVICE_MESH_CONNECTION_H
30 #define GNUNET_SERVICE_MESH_CONNECTION_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 "gnunet_util_lib.h"
41
42 /**
43  * Struct containing all information regarding a connection to a peer.
44  */
45 struct MeshConnection;
46
47 /**
48  * Initialize the connections subsystem
49  *
50  * @param c Configuration handle.
51  */
52 void
53 GMC_init (const struct GNUNET_CONFIGURATION_Handle *c);
54
55 /**
56  * Shut down the connections subsystem.
57  */
58 void
59 GMC_shutdown (void);
60
61 /**
62  * Create a connection.
63  *
64  * @param cid Connection ID.
65  */
66 struct MeshConnection *
67 GMC_new (const struct GNUNET_HashCode *cid);
68
69 /**
70  * Connection is no longer needed: destroy it and remove from tunnel.
71  *
72  * @param c Connection to destroy.
73  */
74 void
75 GMC_destroy (struct MeshConnection *c);
76
77 /**
78  * Count connections in a DLL.
79  */
80 unsigned int
81 GMC_count (const struct MeshConnection *head);
82
83 /**
84  * Send FWD keepalive packets for a connection.
85  *
86  * @param cls Closure (connection for which to send the keepalive).
87  * @param tc Notification context.
88  */
89 void
90 GMC_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
91
92 /**
93  * Send BCK keepalive packets for a connection.
94  *
95  * @param cls Closure (connection for which to send the keepalive).
96  * @param tc Notification context.
97  */
98 void
99 GMC_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
100
101
102 /**
103  * Change the tunnel state.
104  *
105  * @param c Connection whose state to change.
106  * @param state New state.
107  */
108 void
109 GMC_change_state (struct MeshConnection* c, enum MeshConnectionState state);
110
111 /**
112  * Notify other peers on a connection of a broken link. Mark connections
113  * to destroy after all traffic has been sent.
114  *
115  * @param c Connection on which there has been a disconnection.
116  * @param peer Peer that disconnected.
117  * @param my_full_id My ID (to send to other peers).
118  */
119 void
120 GMC_notify_broken (struct MeshConnection *c,
121                    struct MeshPeer *peer,
122                    struct GNUNET_PeerIdentity *my_full_id);
123
124 /**
125  * @brief Queue and pass message to core when possible.
126  *
127  * @param cls Closure (@c type dependant). It will be used by queue_send to
128  *            build the message to be sent if not already prebuilt.
129  * @param type Type of the message, 0 for a raw message.
130  * @param size Size of the message.
131  * @param c Connection this message belongs to (cannot be NULL).
132  * @param ch Channel this message belongs to, if applicable (otherwise NULL).
133  * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
134  */
135 void
136 GMC_queue_add (void* cls,
137                uint16_t type,
138                size_t size,
139                struct MeshConnection* c,
140                struct MeshChannel* ch,
141                int fwd);
142
143
144 /**
145  * Free a transmission that was already queued with all resources
146  * associated to the request.
147  *
148  * @param queue Queue handler to cancel.
149  * @param clear_cls Is it necessary to free associated cls?
150  */
151 void
152 GMC_queue_destroy (struct MeshPeerQueue *queue, int clear_cls);
153
154
155 /**
156  * Core callback to write a queued packet to core buffer
157  *
158  * @param cls Closure (peer info).
159  * @param size Number of bytes available in buf.
160  * @param buf Where the to write the message.
161  *
162  * @return number of bytes written to buf
163  */
164 size_t
165 GMC_queue_send (void *cls, size_t size, void *buf);
166
167
168
169 /**
170  * Is this peer the first one on the connection?
171  *
172  * @param c Connection.
173  * @param fwd Is this about fwd traffic?
174  *
175  * @return GNUNET_YES if origin, GNUNET_NO if relay/terminal.
176  */
177 int
178 GMC_is_origin (struct MeshConnection *c, int fwd);
179
180 /**
181  * Is this peer the last one on the connection?
182  *
183  * @param c Connection.
184  * @param fwd Is this about fwd traffic?
185  *            Note that the ROOT is the terminal for BCK traffic!
186  *
187  * @return GNUNET_YES if terminal, GNUNET_NO if relay/origin.
188  */
189 int
190 GMC_is_terminal (struct MeshConnection *c, int fwd);
191
192 /**
193  * Sends an already built message on a connection, properly registering
194  * all used resources.
195  *
196  * @param message Message to send. Function makes a copy of it.
197  *                If message is not hop-by-hop, decrements TTL of copy.
198  * @param c Connection on which this message is transmitted.
199  * @param ch Channel on which this message is transmitted, or NULL.
200  * @param fwd Is this a fwd message?
201  */
202 void
203 GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
204                            struct MeshConnection *c,
205                            struct MeshChannel *ch,
206                            int fwd);
207
208
209 #if 0                           /* keep Emacsens' auto-indent happy */
210 {
211 #endif
212 #ifdef __cplusplus
213 }
214 #endif
215
216 /* ifndef GNUNET_SERVICE_MESH_CONNECTION_H */
217 #endif
218 /* end of gnunet-service-mesh_connection.h */