glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / core / gnunet-service-core.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009, 2010, 2011 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
16 /**
17  * @file core/gnunet-service-core.h
18  * @brief Globals for gnunet-service-core
19  * @author Christian Grothoff
20  */
21 #ifndef GNUNET_SERVICE_CORE_H
22 #define GNUNET_SERVICE_CORE_H
23
24 #include "gnunet_statistics_service.h"
25 #include "gnunet_core_service.h"
26 #include "core.h"
27 #include "gnunet-service-core_typemap.h"
28
29
30 /**
31  * Opaque handle to a client.
32  */
33 struct GSC_Client;
34
35
36 /**
37  * Record kept for each request for transmission issued by a
38  * client that is still pending. (This struct is used by
39  * both the 'CLIENTS' and 'SESSIONS' subsystems.)
40  */
41 struct GSC_ClientActiveRequest
42 {
43
44   /**
45    * Active requests are kept in a doubly-linked list of
46    * the respective target peer.
47    */
48   struct GSC_ClientActiveRequest *next;
49
50   /**
51    * Active requests are kept in a doubly-linked list of
52    * the respective target peer.
53    */
54   struct GSC_ClientActiveRequest *prev;
55
56   /**
57    * Handle to the client.
58    */
59   struct GSC_Client *client_handle;
60
61   /**
62    * Which peer is the message going to be for?
63    */
64   struct GNUNET_PeerIdentity target;
65
66   /**
67    * At what time did we first see this request?
68    */
69   struct GNUNET_TIME_Absolute received_time;
70
71   /**
72    * By what time would the client want to see this message out?
73    */
74   struct GNUNET_TIME_Absolute deadline;
75
76   /**
77    * How important is this request.
78    */
79   enum GNUNET_CORE_Priority priority;
80
81   /**
82    * Has this request been solicited yet?
83    */
84   int was_solicited;
85
86   /**
87    * How many bytes does the client intend to send?
88    */
89   uint16_t msize;
90
91   /**
92    * Unique request ID (in big endian).
93    */
94   uint16_t smr_id;
95
96 };
97
98
99 /**
100  * Tell a client that we are ready to receive the message.
101  *
102  * @param car request that is now ready; the responsibility
103  *        for the handle remains shared between CLIENTS
104  *        and SESSIONS after this call.
105  */
106 void
107 GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car);
108
109
110 /**
111  * We will never be ready to transmit the given message in (disconnect
112  * or invalid request).  Frees resources associated with @a car.  We
113  * don't explicitly tell the client, he'll learn with the disconnect
114  * (or violated the protocol).
115  *
116  * @param car request that now permanently failed; the
117  *        responsibility for the handle is now returned
118  *        to CLIENTS (SESSIONS is done with it).
119  * @param drop_client #GNUNET_YES if the client violated the protocol
120  *        and we should thus drop the connection
121  */
122 void
123 GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car,
124                             int drop_client);
125
126
127 /**
128  * Notify a particular client about a change to existing connection to
129  * one of our neighbours (check if the client is interested).  Called
130  * from #GSC_SESSIONS_notify_client_about_sessions().
131  *
132  * @param client client to notify
133  * @param neighbour identity of the neighbour that changed status
134  * @param tmap_old previous type map for the neighbour, NULL for connect
135  * @param tmap_new updated type map for the neighbour, NULL for disconnect
136  */
137 void
138 GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
139                                            const struct GNUNET_PeerIdentity *neighbour,
140                                            const struct GSC_TypeMap *tmap_old,
141                                            const struct GSC_TypeMap *tmap_new);
142
143
144 /**
145  * Deliver P2P message to interested clients.  Caller must have checked
146  * that the sending peer actually lists the given message type as one
147  * of its types.
148  *
149  * @param sender peer who sent us the message
150  * @param msg the message
151  * @param msize number of bytes to transmit
152  * @param options options for checking which clients should
153  *        receive the message
154  */
155 void
156 GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
157                              const struct GNUNET_MessageHeader *msg,
158                              uint16_t msize,
159                              uint32_t options);
160
161
162 /**
163  * Notify all clients about a change to existing session.
164  * Called from SESSIONS whenever there is a change in sessions
165  * or types processed by the respective peer.
166  *
167  * @param neighbour identity of the neighbour that changed status
168  * @param tmap_old previous type map for the neighbour, NULL for connect
169  * @param tmap_new updated type map for the neighbour, NULL for disconnect
170  */
171 void
172 GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour,
173                                             const struct GSC_TypeMap *tmap_old,
174                                             const struct GSC_TypeMap *tmap_new);
175
176
177 /**
178  * Our configuration.
179  */
180 extern const struct GNUNET_CONFIGURATION_Handle *GSC_cfg;
181
182 /**
183  * For creating statistics.
184  */
185 extern struct GNUNET_STATISTICS_Handle *GSC_stats;
186
187 /**
188  * Our identity.
189  */
190 extern struct GNUNET_PeerIdentity GSC_my_identity;
191
192
193 #endif