-fixing #2434, plus some code cleanup
[oweals/gnunet.git] / src / core / gnunet-service-core_sessions.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010, 2011 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 core/gnunet-service-core_neighbours.h
23  * @brief code for managing of 'encrypted' sessions (key exchange done)
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_SERVICE_CORE_SESSIONS_H
27 #define GNUNET_SERVICE_CORE_SESSIONS_H
28
29 #include "gnunet-service-core.h"
30 #include "gnunet-service-core_kx.h"
31
32
33 /**
34  * Create a session, a key exchange was just completed.
35  *
36  * @param peer peer that is now connected
37  * @param kx key exchange that completed
38  */
39 void
40 GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
41                      struct GSC_KeyExchangeInfo *kx);
42
43
44 /**
45  * End the session with the given peer (we are no longer
46  * connected).
47  *
48  * @param pid identity of peer to kill session with
49  */
50 void
51 GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid);
52
53
54 /**
55  * Traffic is being solicited for the given peer.  This means that the
56  * message queue on the transport-level (NEIGHBOURS subsystem) is now
57  * empty and it is now OK to transmit another (non-control) message.
58  *
59  * @param pid identity of peer ready to receive data
60  */
61 void
62 GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid);
63
64
65 /**
66  * Queue a request from a client for transmission to a particular peer.
67  *
68  * @param car request to queue; this handle is then shared between
69  *         the caller (CLIENTS subsystem) and SESSIONS and must not
70  *         be released by either until either 'GNUNET_SESSIONS_dequeue',
71  *         or 'GNUNET_CLIENTS_failed'
72  *         have been invoked on it
73  */
74 void
75 GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car);
76
77
78 /**
79  * Dequeue a request from a client from transmission to a particular peer.
80  *
81  * @param car request to dequeue; this handle will then be 'owned' by
82  *        the caller (CLIENTS sysbsystem)
83  */
84 void
85 GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car);
86
87
88 /**
89  * Transmit a message to a particular peer.
90  *
91  * @param car original request that was queued and then solicited,
92  *            ownership does not change (dequeue will be called soon).
93  * @param msg message to transmit
94  * @param cork is corking allowed?
95  */
96 void
97 GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
98                        const struct GNUNET_MessageHeader *msg, int cork);
99
100
101 /**
102  * Broadcast a message to all neighbours.
103  *
104  * @param msg message to transmit
105  */
106 void
107 GSC_SESSIONS_broadcast (const struct GNUNET_MessageHeader *msg);
108
109
110 /**
111  * We have a new client, notify it about all current sessions.
112  *
113  * @param client the new client
114  */
115 void
116 GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client);
117
118 /**
119  * We've received a typemap message from a peer, update ours.
120  * Notifies clients about the session.
121  *
122  * @param peer peer this is about
123  * @param msg typemap update message
124  */
125 void
126 GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
127                           const struct GNUNET_MessageHeader *msg);
128
129
130 /**
131  * The given peer send a message of the specified type.  Make sure the
132  * respective bit is set in its type-map and that clients are notified
133  * about the session.
134  *
135  * @param peer peer this is about
136  * @param type type of the message
137  */
138 void
139 GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
140                              uint16_t type);
141
142
143 /**
144  * Handle CORE_ITERATE_PEERS request.  For this request type, the client
145  * does not have to have transmitted an INIT request.  All current peers
146  * are returned, regardless of which message types they accept.
147  *
148  * @param cls unused
149  * @param client client sending the iteration request
150  * @param message iteration request message
151  */
152 void
153 GSC_SESSIONS_handle_client_iterate_peers (void *cls,
154                                           struct GNUNET_SERVER_Client *client,
155                                           const struct GNUNET_MessageHeader
156                                           *message);
157
158
159 /**
160  * Handle CORE_PEER_CONNECTED request.  Notify client about connection
161  * to the given neighbour.  For this request type, the client does not
162  * have to have transmitted an INIT request.  All current peers are
163  * returned, regardless of which message types they accept.
164  *
165  * @param cls unused
166  * @param client client sending the iteration request
167  * @param message iteration request message
168  */
169 void
170 GSC_SESSIONS_handle_client_have_peer (void *cls,
171                                       struct GNUNET_SERVER_Client *client,
172                                       const struct GNUNET_MessageHeader
173                                       *message);
174
175
176
177 /**
178  * Initialize sessions subsystem.
179  */
180 void
181 GSC_SESSIONS_init (void);
182
183
184 /**
185  * Shutdown sessions subsystem.
186  */
187 void
188 GSC_SESSIONS_done (void);
189
190
191
192 #endif