fix bad free
[oweals/gnunet.git] / src / core / gnunet-service-core_sessions.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009-2014 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @file core/gnunet-service-core_neighbours.h
21  * @brief code for managing of 'encrypted' sessions (key exchange done)
22  * @author Christian Grothoff
23  */
24 #ifndef GNUNET_SERVICE_CORE_SESSIONS_H
25 #define GNUNET_SERVICE_CORE_SESSIONS_H
26
27 #include "gnunet-service-core.h"
28 #include "gnunet-service-core_kx.h"
29
30
31 /**
32  * Create a session, a key exchange was just completed.
33  *
34  * @param peer peer that is now connected
35  * @param kx key exchange that completed
36  */
37 void
38 GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
39                      struct GSC_KeyExchangeInfo *kx);
40
41
42 /**
43  * The other peer has indicated that he 'lost' the session
44  * (KX down), reinitialize the session on our end, in particular
45  * this means to restart the typemap transmission.
46  *
47  * @param peer peer that is now connected
48  */
49 void
50 GSC_SESSIONS_reinit (const struct GNUNET_PeerIdentity *peer);
51
52
53 /**
54  * The other peer has confirmed receiving our type map,
55  * check if it is current and if so, stop retransmitting it.
56  *
57  * @param peer peer that confirmed the type map
58  * @param msg confirmation message we received
59  */
60 void
61 GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer,
62                               const struct GNUNET_MessageHeader *msg);
63
64
65 /**
66  * End the session with the given peer (we are no longer
67  * connected).
68  *
69  * @param pid identity of peer to kill session with
70  */
71 void
72 GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid);
73
74
75 /**
76  * Traffic is being solicited for the given peer.  This means that the
77  * message queue on the transport-level (NEIGHBOURS subsystem) is now
78  * empty and it is now OK to transmit another (non-control) message.
79  *
80  * @param pid identity of peer ready to receive data
81  */
82 void
83 GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid);
84
85
86 /**
87  * Queue a request from a client for transmission to a particular peer.
88  *
89  * @param car request to queue; this handle is then shared between
90  *         the caller (CLIENTS subsystem) and SESSIONS and must not
91  *         be released by either until either 'GNUNET_SESSIONS_dequeue',
92  *         or 'GNUNET_CLIENTS_failed'
93  *         have been invoked on it
94  */
95 void
96 GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car);
97
98
99 /**
100  * Dequeue a request from a client from transmission to a particular peer.
101  *
102  * @param car request to dequeue; this handle will then be 'owned' by
103  *        the caller (CLIENTS sysbsystem)
104  */
105 void
106 GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car);
107
108
109 /**
110  * Transmit a message to a particular peer.
111  *
112  * @param car original request that was queued and then solicited,
113  *            ownership does not change (dequeue will be called soon).
114  * @param msg message to transmit
115  * @param cork is corking allowed?
116  * @param priority how important is this message
117  */
118 void
119 GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
120                        const struct GNUNET_MessageHeader *msg,
121                        int cork,
122                        enum GNUNET_CORE_Priority priority);
123
124
125 /**
126  * Broadcast an updated typemap message to all neighbours.
127  * Restarts the retransmissions until the typemaps are confirmed.
128  *
129  * @param msg message to transmit
130  */
131 void
132 GSC_SESSIONS_broadcast_typemap (const struct GNUNET_MessageHeader *msg);
133
134
135 /**
136  * We have a new client, notify it about all current sessions.
137  *
138  * @param client the new client
139  */
140 void
141 GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client);
142
143
144 /**
145  * We've received a typemap message from a peer, update ours.
146  * Notifies clients about the session.
147  *
148  * @param peer peer this is about
149  * @param msg typemap update message
150  */
151 void
152 GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
153                           const struct GNUNET_MessageHeader *msg);
154
155
156 /**
157  * The given peer send a message of the specified type.  Make sure the
158  * respective bit is set in its type-map and that clients are notified
159  * about the session.
160  *
161  * @param peer peer this is about
162  * @param type type of the message
163  */
164 void
165 GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
166                              uint16_t type);
167
168
169 /**
170  * Initialize sessions subsystem.
171  */
172 void
173 GSC_SESSIONS_init (void);
174
175
176 /**
177  * Shutdown sessions subsystem.
178  */
179 void
180 GSC_SESSIONS_done (void);
181
182
183
184 #endif