aboutsummaryrefslogtreecommitdiff
path: root/src/core/core.h
blob: 021aa4184f532b46da7e6e3366c0e031402cdc4c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/*
     This file is part of GNUnet.
     (C) 2009, 2010 Christian Grothoff (and other contributing authors)

     GNUnet is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 3, or (at your
     option) any later version.

     GNUnet is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with GNUnet; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.
*/

/**
 * @file core/core.h
 * @brief common internal definitions for core service
 * @author Christian Grothoff
 */
#include "gnunet_bandwidth_lib.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_time_lib.h"

/**
 * General core debugging.
 */
#define DEBUG_CORE GNUNET_NO

/**
 * Debugging interaction core-clients.
 */
#define DEBUG_CORE_CLIENT GNUNET_NO

/**
 * Definition of bits in the InitMessage's options field that specify
 * which events this client cares about.  Note that inbound messages
 * for handlers that were specifically registered are always
 * transmitted to the client.
 */
#define GNUNET_CORE_OPTION_NOTHING             0
#define GNUNET_CORE_OPTION_SEND_CONNECT        1
#define GNUNET_CORE_OPTION_SEND_DISCONNECT     2
#define GNUNET_CORE_OPTION_SEND_STATUS_CHANGE  4
#define GNUNET_CORE_OPTION_SEND_FULL_INBOUND   8
#define GNUNET_CORE_OPTION_SEND_HDR_INBOUND   16
#define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 32
#define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND  64


/**
 * Message transmitted core clients to gnunet-service-core
 * to start the interaction.  This header is followed by
 * uint16_t type values specifying which messages this
 * client is interested in.
 */
struct InitMessage
{

  /**
   * Header with type GNUNET_MESSAGE_TYPE_CORE_INIT.
   */
  struct GNUNET_MessageHeader header;

  /**
   * Options, see GNUNET_CORE_OPTION_ values.
   */
  uint32_t options GNUNET_PACKED;

};


/**
 * Message transmitted by the gnunet-service-core process
 * to its clients in response to an INIT message.
 */
struct InitReplyMessage
{

  /**
   * Header with type GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY
   */
  struct GNUNET_MessageHeader header;

  /**
   * Always zero.
   */
  uint32_t reserved GNUNET_PACKED;

  /**
   * Public key of the local peer.
   */
  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey;

};


/**
 * Message sent by the service to clients to notify them
 * about a peer connecting.
 */
struct ConnectNotifyMessage
{
  /**
   * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT
   */
  struct GNUNET_MessageHeader header;

  /**
   * Distance to the peer.
   */
  uint32_t distance GNUNET_PACKED;

  /**
   * Currently observed latency.
   */
  struct GNUNET_TIME_RelativeNBO latency;

  /**
   * Identity of the connecting peer.
   */
  struct GNUNET_PeerIdentity peer;

};


/**
 * Message sent by the service to clients to notify them
 * about a peer changing status.
 */
struct PeerStatusNotifyMessage
{
  /**
   * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_PEER_STATUS
   */
  struct GNUNET_MessageHeader header;

  /**
   * Distance to the peer.
   */
  uint32_t distance GNUNET_PACKED;

  /**
   * Currently observed latency.
   */
  struct GNUNET_TIME_RelativeNBO latency;

  /**
   * When the peer would time out (unless we see activity)
   */
  struct GNUNET_TIME_AbsoluteNBO timeout;

  /**
   * Available bandwidth from the peer.
   */
  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;

  /**
   * Available bandwidth to the peer.
   */
  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;

  /**
   * Identity of the peer.
   */
  struct GNUNET_PeerIdentity peer;

};


/**
 * Message sent by the service to clients to notify them
 * about a peer disconnecting.
 */
struct DisconnectNotifyMessage
{
  /**
   * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
   */
  struct GNUNET_MessageHeader header;

  /**
   * Always zero.
   */
  uint32_t reserved GNUNET_PACKED;

  /**
   * Identity of the connecting peer.
   */
  struct GNUNET_PeerIdentity peer;

};



/**
 * Message sent by the service to clients to notify them about
 * messages being received or transmitted.  This overall message is
 * followed by the real message, or just the header of the real
 * message (depending on the client's preferences).  The receiver can
 * tell if he got the full message or only a partial message by
 * looking at the size field in the header of NotifyTrafficMessage and
 * checking it with the size field in the message that follows.
 */
struct NotifyTrafficMessage
{
  /**
   * Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
   * or GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND.
   */
  struct GNUNET_MessageHeader header;

  /**
   * Distance to the peer.
   */
  uint32_t distance GNUNET_PACKED;

  /**
   * Currently observed latency.
   */
  struct GNUNET_TIME_RelativeNBO latency;

  /**
   * Identity of the receiver or sender.
   */
  struct GNUNET_PeerIdentity peer;

};


/**
 * Message sent to the core asking for configuration
 * information and possibly preference changes.
 */
struct RequestInfoMessage
{
  /**
   * Header with type GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE
   */
  struct GNUNET_MessageHeader header;

  /**
   * Always zero.
   */
  uint32_t reserved GNUNET_PACKED;

  /**
   * Limit the number of bytes of outbound traffic to this
   * peer to at most the specified amount (naturally, the
   * amount is also limited by the receiving peer).
   */
  struct GNUNET_BANDWIDTH_Value32NBO limit_outbound;

  /**
   * Number of bytes of inbound traffic to reserve, can
   * be negative (to unreserve).  NBO.
   */
  int32_t reserve_inbound GNUNET_PACKED;

  /**
   * Increment the current traffic preference for the given peer by
   * the specified amont.  The traffic preference is used to determine
   * the share of bandwidth this peer will typcially be assigned.
   */
  uint64_t preference_change GNUNET_PACKED;

  /**
   * Identity of the peer being configured.
   */
  struct GNUNET_PeerIdentity peer;

};


/**
 * Response from the core to a "RequestInfoMessage"
 * providing traffic status information for a peer.
 */
struct ConfigurationInfoMessage
{
  /**
   * Header with type GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO
   */
  struct GNUNET_MessageHeader header;

  /**
   * Amount of traffic (inbound number of bytes) that was reserved in
   * response to the configuration change request.  Negative for
   * "unreserved" bytes.
   */
  int32_t reserved_amount GNUNET_PACKED;

  /**
   * Available bandwidth in for this peer.
   * 0 if we have been disconnected.
   */
  struct GNUNET_BANDWIDTH_Value32NBO bw_in;

  /**
   * Available bandwidth out for this peer,
   * 0 if we have been disconnected.
   */
  struct GNUNET_BANDWIDTH_Value32NBO bw_out;

  /**
   * Current traffic preference for the peer.
   * 0 if we have been disconnected.
   */
  uint64_t preference;

  /**
   * Identity of the receiver or sender.
   */
  struct GNUNET_PeerIdentity peer;

};


/**
 * Client asking core to transmit a particular message to
 * a particular target.  
 */
struct SendMessage
{
  /**
   * Header with type GNUNET_MESSAGE_TYPE_CORE_SEND
   */
  struct GNUNET_MessageHeader header;

  /**
   * How important is this message?
   */
  uint32_t priority GNUNET_PACKED;

  /**
   * By what time would the sender really like to see this
   * message transmitted?
   */
  struct GNUNET_TIME_AbsoluteNBO deadline;

  /**
   * Identity of the receiver or sender.
   */
  struct GNUNET_PeerIdentity peer;

};


/**
 * Client asking core to connect to a particular target.  There is no
 * response from the core to this type of request (however, if an
 * actual connection is created or destroyed, be it because of this
 * type request or not, the core generally needs to notify the
 * clients).
 */
struct ConnectMessage
{
  /**
   * Header with type GNUNET_MESSAGE_TYPE_REQUEST_CONNECT or
   * GNUNET_MESSAGE_TYPE_REQUEST_DISCONNECT.
   */
  struct GNUNET_MessageHeader header;

  /**
   * For alignment.
   */
  uint32_t reserved GNUNET_PACKED;

  /**
   * When to time out.
   */
  struct GNUNET_TIME_RelativeNBO timeout;

  /**
   * Identity of the other peer.
   */
  struct GNUNET_PeerIdentity peer;

};

/* end of core.h */