error handling
[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      SPDX-License-Identifier: AGPL3.0-or-later
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  * The other peer has indicated that it 'lost' the session
46  * (KX down), reinitialize the session on our end, in particular
47  * this means to restart the typemap transmission.
48  *
49  * @param peer peer that is now connected
50  */
51 void
52 GSC_SESSIONS_reinit (const struct GNUNET_PeerIdentity *peer);
53
54
55 /**
56  * The other peer has confirmed receiving our type map,
57  * check if it is current and if so, stop retransmitting it.
58  *
59  * @param peer peer that confirmed the type map
60  * @param msg confirmation message we received
61  */
62 void
63 GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer,
64                               const struct GNUNET_MessageHeader *msg);
65
66
67 /**
68  * End the session with the given peer (we are no longer
69  * connected).
70  *
71  * @param pid identity of peer to kill session with
72  */
73 void
74 GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid);
75
76
77 /**
78  * Traffic is being solicited for the given peer.  This means that the
79  * message queue on the transport-level (NEIGHBOURS subsystem) is now
80  * empty and it is now OK to transmit another (non-control) message.
81  *
82  * @param pid identity of peer ready to receive data
83  */
84 void
85 GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid);
86
87
88 /**
89  * Queue a request from a client for transmission to a particular peer.
90  *
91  * @param car request to queue; this handle is then shared between
92  *         the caller (CLIENTS subsystem) and SESSIONS and must not
93  *         be released by either until either 'GNUNET_SESSIONS_dequeue',
94  *         or 'GNUNET_CLIENTS_failed'
95  *         have been invoked on it
96  */
97 void
98 GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car);
99
100
101 /**
102  * Dequeue a request from a client from transmission to a particular peer.
103  *
104  * @param car request to dequeue; this handle will then be 'owned' by
105  *        the caller (CLIENTS sysbsystem)
106  */
107 void
108 GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car);
109
110
111 /**
112  * Transmit a message to a particular peer.
113  *
114  * @param car original request that was queued and then solicited,
115  *            ownership does not change (dequeue will be called soon).
116  * @param msg message to transmit
117  * @param priority how important is this message
118  */
119 void
120 GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
121                        const struct GNUNET_MessageHeader *msg,
122                        enum GNUNET_MQ_PriorityPreferences 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 #endif