diff options
Diffstat (limited to 'src/core/gnunet-service-core.c')
-rw-r--r-- | src/core/gnunet-service-core.c | 897 |
1 files changed, 447 insertions, 450 deletions
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 740707ce1..505798683 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file core/gnunet-service-core.c | 22 | * @file core/gnunet-service-core.c |
@@ -50,8 +50,7 @@ | |||
50 | /** | 50 | /** |
51 | * Data structure for each client connected to the CORE service. | 51 | * Data structure for each client connected to the CORE service. |
52 | */ | 52 | */ |
53 | struct GSC_Client | 53 | struct GSC_Client { |
54 | { | ||
55 | /** | 54 | /** |
56 | * Clients are kept in a linked list. | 55 | * Clients are kept in a linked list. |
57 | */ | 56 | */ |
@@ -149,11 +148,11 @@ static struct GSC_Client *client_tail; | |||
149 | * @return #GNUNET_YES if @a c is interested, #GNUNET_NO if not. | 148 | * @return #GNUNET_YES if @a c is interested, #GNUNET_NO if not. |
150 | */ | 149 | */ |
151 | static int | 150 | static int |
152 | type_match (uint16_t type, struct GSC_Client *c) | 151 | type_match(uint16_t type, struct GSC_Client *c) |
153 | { | 152 | { |
154 | if ((0 == c->tcnt) && (0 != c->options)) | 153 | if ((0 == c->tcnt) && (0 != c->options)) |
155 | return GNUNET_YES; /* peer without handlers and inbound/outbond | 154 | return GNUNET_YES; /* peer without handlers and inbound/outbond |
156 | callbacks matches ALL */ | 155 | callbacks matches ALL */ |
157 | if (NULL == c->types) | 156 | if (NULL == c->types) |
158 | return GNUNET_NO; | 157 | return GNUNET_NO; |
159 | for (unsigned int i = 0; i < c->tcnt; i++) | 158 | for (unsigned int i = 0; i < c->tcnt; i++) |
@@ -171,7 +170,7 @@ type_match (uint16_t type, struct GSC_Client *c) | |||
171 | * @return #GNUNET_OK if @a im is well-formed | 170 | * @return #GNUNET_OK if @a im is well-formed |
172 | */ | 171 | */ |
173 | static int | 172 | static int |
174 | check_client_init (void *cls, const struct InitMessage *im) | 173 | check_client_init(void *cls, const struct InitMessage *im) |
175 | { | 174 | { |
176 | return GNUNET_OK; | 175 | return GNUNET_OK; |
177 | } | 176 | } |
@@ -184,7 +183,7 @@ check_client_init (void *cls, const struct InitMessage *im) | |||
184 | * @param im the `struct InitMessage` | 183 | * @param im the `struct InitMessage` |
185 | */ | 184 | */ |
186 | static void | 185 | static void |
187 | handle_client_init (void *cls, const struct InitMessage *im) | 186 | handle_client_init(void *cls, const struct InitMessage *im) |
188 | { | 187 | { |
189 | struct GSC_Client *c = cls; | 188 | struct GSC_Client *c = cls; |
190 | struct GNUNET_MQ_Envelope *env; | 189 | struct GNUNET_MQ_Envelope *env; |
@@ -193,33 +192,33 @@ handle_client_init (void *cls, const struct InitMessage *im) | |||
193 | const uint16_t *types; | 192 | const uint16_t *types; |
194 | 193 | ||
195 | /* check that we don't have an entry already */ | 194 | /* check that we don't have an entry already */ |
196 | msize = ntohs (im->header.size) - sizeof (struct InitMessage); | 195 | msize = ntohs(im->header.size) - sizeof(struct InitMessage); |
197 | types = (const uint16_t *) &im[1]; | 196 | types = (const uint16_t *)&im[1]; |
198 | c->tcnt = msize / sizeof (uint16_t); | 197 | c->tcnt = msize / sizeof(uint16_t); |
199 | c->options = ntohl (im->options); | 198 | c->options = ntohl(im->options); |
200 | c->got_init = GNUNET_YES; | 199 | c->got_init = GNUNET_YES; |
201 | all_client_options |= c->options; | 200 | all_client_options |= c->options; |
202 | c->types = GNUNET_malloc (msize); | 201 | c->types = GNUNET_malloc(msize); |
203 | GNUNET_assert (GNUNET_YES == | 202 | GNUNET_assert(GNUNET_YES == |
204 | GNUNET_CONTAINER_multipeermap_put ( | 203 | GNUNET_CONTAINER_multipeermap_put( |
205 | c->connectmap, | 204 | c->connectmap, |
206 | &GSC_my_identity, | 205 | &GSC_my_identity, |
207 | NULL, | 206 | NULL, |
208 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 207 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
209 | for (unsigned int i = 0; i < c->tcnt; i++) | 208 | for (unsigned int i = 0; i < c->tcnt; i++) |
210 | c->types[i] = ntohs (types[i]); | 209 | c->types[i] = ntohs(types[i]); |
211 | GSC_TYPEMAP_add (c->types, c->tcnt); | 210 | GSC_TYPEMAP_add(c->types, c->tcnt); |
212 | GNUNET_log ( | 211 | GNUNET_log( |
213 | GNUNET_ERROR_TYPE_DEBUG, | 212 | GNUNET_ERROR_TYPE_DEBUG, |
214 | "Client connecting to core service is interested in %u message types\n", | 213 | "Client connecting to core service is interested in %u message types\n", |
215 | (unsigned int) c->tcnt); | 214 | (unsigned int)c->tcnt); |
216 | /* send init reply message */ | 215 | /* send init reply message */ |
217 | env = GNUNET_MQ_msg (irm, GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY); | 216 | env = GNUNET_MQ_msg(irm, GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY); |
218 | irm->reserved = htonl (0); | 217 | irm->reserved = htonl(0); |
219 | irm->my_identity = GSC_my_identity; | 218 | irm->my_identity = GSC_my_identity; |
220 | GNUNET_MQ_send (c->mq, env); | 219 | GNUNET_MQ_send(c->mq, env); |
221 | GSC_SESSIONS_notify_client_about_sessions (c); | 220 | GSC_SESSIONS_notify_client_about_sessions(c); |
222 | GNUNET_SERVICE_client_continue (c->client); | 221 | GNUNET_SERVICE_client_continue(c->client); |
223 | } | 222 | } |
224 | 223 | ||
225 | 224 | ||
@@ -236,17 +235,17 @@ handle_client_init (void *cls, const struct InitMessage *im) | |||
236 | * and we should thus drop the connection | 235 | * and we should thus drop the connection |
237 | */ | 236 | */ |
238 | void | 237 | void |
239 | GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car, | 238 | GSC_CLIENTS_reject_request(struct GSC_ClientActiveRequest *car, |
240 | int drop_client) | 239 | int drop_client) |
241 | { | 240 | { |
242 | GNUNET_assert ( | 241 | GNUNET_assert( |
243 | GNUNET_YES == | 242 | GNUNET_YES == |
244 | GNUNET_CONTAINER_multipeermap_remove (car->client_handle->requests, | 243 | GNUNET_CONTAINER_multipeermap_remove(car->client_handle->requests, |
245 | &car->target, | 244 | &car->target, |
246 | car)); | 245 | car)); |
247 | if (GNUNET_YES == drop_client) | 246 | if (GNUNET_YES == drop_client) |
248 | GNUNET_SERVICE_client_drop (car->client_handle->client); | 247 | GNUNET_SERVICE_client_drop(car->client_handle->client); |
249 | GNUNET_free (car); | 248 | GNUNET_free(car); |
250 | } | 249 | } |
251 | 250 | ||
252 | 251 | ||
@@ -258,7 +257,7 @@ GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car, | |||
258 | * and SESSIONS after this call. | 257 | * and SESSIONS after this call. |
259 | */ | 258 | */ |
260 | void | 259 | void |
261 | GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car) | 260 | GSC_CLIENTS_solicit_request(struct GSC_ClientActiveRequest *car) |
262 | { | 261 | { |
263 | struct GSC_Client *c; | 262 | struct GSC_Client *c; |
264 | struct GNUNET_MQ_Envelope *env; | 263 | struct GNUNET_MQ_Envelope *env; |
@@ -268,31 +267,31 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car) | |||
268 | 267 | ||
269 | c = car->client_handle; | 268 | c = car->client_handle; |
270 | if (GNUNET_YES != | 269 | if (GNUNET_YES != |
271 | GNUNET_CONTAINER_multipeermap_contains (c->connectmap, &car->target)) | 270 | GNUNET_CONTAINER_multipeermap_contains(c->connectmap, &car->target)) |
272 | { | 271 | { |
273 | /* connection has gone down since, drop request */ | 272 | /* connection has gone down since, drop request */ |
274 | GNUNET_assert (0 != memcmp (&car->target, | 273 | GNUNET_assert(0 != memcmp(&car->target, |
275 | &GSC_my_identity, | 274 | &GSC_my_identity, |
276 | sizeof (struct GNUNET_PeerIdentity))); | 275 | sizeof(struct GNUNET_PeerIdentity))); |
277 | GSC_SESSIONS_dequeue_request (car); | 276 | GSC_SESSIONS_dequeue_request(car); |
278 | GSC_CLIENTS_reject_request (car, GNUNET_NO); | 277 | GSC_CLIENTS_reject_request(car, GNUNET_NO); |
279 | return; | 278 | return; |
280 | } | 279 | } |
281 | delay = GNUNET_TIME_absolute_get_duration (car->received_time); | 280 | delay = GNUNET_TIME_absolute_get_duration(car->received_time); |
282 | left = GNUNET_TIME_absolute_get_duration (car->deadline); | 281 | left = GNUNET_TIME_absolute_get_duration(car->deadline); |
283 | if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) | 282 | if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) |
284 | GNUNET_log ( | 283 | GNUNET_log( |
285 | GNUNET_ERROR_TYPE_WARNING, | 284 | GNUNET_ERROR_TYPE_WARNING, |
286 | "Client waited %s for permission to transmit to `%s'%s (priority %u)\n", | 285 | "Client waited %s for permission to transmit to `%s'%s (priority %u)\n", |
287 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), | 286 | GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), |
288 | GNUNET_i2s (&car->target), | 287 | GNUNET_i2s(&car->target), |
289 | (0 == left.rel_value_us) ? " (past deadline)" : "", | 288 | (0 == left.rel_value_us) ? " (past deadline)" : "", |
290 | car->priority); | 289 | car->priority); |
291 | env = GNUNET_MQ_msg (smr, GNUNET_MESSAGE_TYPE_CORE_SEND_READY); | 290 | env = GNUNET_MQ_msg(smr, GNUNET_MESSAGE_TYPE_CORE_SEND_READY); |
292 | smr->size = htons (car->msize); | 291 | smr->size = htons(car->msize); |
293 | smr->smr_id = car->smr_id; | 292 | smr->smr_id = car->smr_id; |
294 | smr->peer = car->target; | 293 | smr->peer = car->target; |
295 | GNUNET_MQ_send (c->mq, env); | 294 | GNUNET_MQ_send(c->mq, env); |
296 | } | 295 | } |
297 | 296 | ||
298 | 297 | ||
@@ -303,87 +302,85 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car) | |||
303 | * @param req the `struct SendMessageRequest` | 302 | * @param req the `struct SendMessageRequest` |
304 | */ | 303 | */ |
305 | static void | 304 | static void |
306 | handle_client_send_request (void *cls, const struct SendMessageRequest *req) | 305 | handle_client_send_request(void *cls, const struct SendMessageRequest *req) |
307 | { | 306 | { |
308 | struct GSC_Client *c = cls; | 307 | struct GSC_Client *c = cls; |
309 | struct GSC_ClientActiveRequest *car; | 308 | struct GSC_ClientActiveRequest *car; |
310 | int is_loopback; | 309 | int is_loopback; |
311 | 310 | ||
312 | if (NULL == c->requests) | 311 | if (NULL == c->requests) |
313 | c->requests = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO); | 312 | c->requests = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_NO); |
314 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 313 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
315 | "Client asked for transmission to `%s'\n", | 314 | "Client asked for transmission to `%s'\n", |
316 | GNUNET_i2s (&req->peer)); | 315 | GNUNET_i2s(&req->peer)); |
317 | is_loopback = (0 == memcmp (&req->peer, | 316 | is_loopback = (0 == memcmp(&req->peer, |
318 | &GSC_my_identity, | 317 | &GSC_my_identity, |
319 | sizeof (struct GNUNET_PeerIdentity))); | 318 | sizeof(struct GNUNET_PeerIdentity))); |
320 | if ((! is_loopback) && | 319 | if ((!is_loopback) && |
321 | (GNUNET_YES != | 320 | (GNUNET_YES != |
322 | GNUNET_CONTAINER_multipeermap_contains (c->connectmap, &req->peer))) | 321 | GNUNET_CONTAINER_multipeermap_contains(c->connectmap, &req->peer))) |
323 | { | 322 | { |
324 | /* neighbour must have disconnected since request was issued, | 323 | /* neighbour must have disconnected since request was issued, |
325 | * ignore (client will realize it once it processes the | 324 | * ignore (client will realize it once it processes the |
326 | * disconnect notification) */ | 325 | * disconnect notification) */ |
327 | GNUNET_STATISTICS_update (GSC_stats, | 326 | GNUNET_STATISTICS_update(GSC_stats, |
328 | gettext_noop ( | 327 | gettext_noop( |
329 | "# send requests dropped (disconnected)"), | 328 | "# send requests dropped (disconnected)"), |
330 | 1, | 329 | 1, |
331 | GNUNET_NO); | 330 | GNUNET_NO); |
332 | GNUNET_SERVICE_client_continue (c->client); | 331 | GNUNET_SERVICE_client_continue(c->client); |
333 | return; | 332 | return; |
334 | } | 333 | } |
335 | 334 | ||
336 | car = GNUNET_CONTAINER_multipeermap_get (c->requests, &req->peer); | 335 | car = GNUNET_CONTAINER_multipeermap_get(c->requests, &req->peer); |
337 | if (NULL == car) | 336 | if (NULL == car) |
338 | { | 337 | { |
339 | /* create new entry */ | 338 | /* create new entry */ |
340 | car = GNUNET_new (struct GSC_ClientActiveRequest); | 339 | car = GNUNET_new(struct GSC_ClientActiveRequest); |
341 | GNUNET_assert (GNUNET_OK == | 340 | GNUNET_assert(GNUNET_OK == |
342 | GNUNET_CONTAINER_multipeermap_put ( | 341 | GNUNET_CONTAINER_multipeermap_put( |
343 | c->requests, | 342 | c->requests, |
344 | &req->peer, | 343 | &req->peer, |
345 | car, | 344 | car, |
346 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 345 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
347 | car->client_handle = c; | 346 | car->client_handle = c; |
348 | } | 347 | } |
349 | else | 348 | else |
350 | { | 349 | { |
351 | /* dequeue and recycle memory from pending request, there can only | 350 | /* dequeue and recycle memory from pending request, there can only |
352 | be at most one per client and peer */ | 351 | be at most one per client and peer */ |
353 | GNUNET_STATISTICS_update (GSC_stats, | 352 | GNUNET_STATISTICS_update(GSC_stats, |
354 | gettext_noop ( | 353 | gettext_noop( |
355 | "# dequeuing CAR (duplicate request)"), | 354 | "# dequeuing CAR (duplicate request)"), |
356 | 1, | 355 | 1, |
357 | GNUNET_NO); | 356 | GNUNET_NO); |
358 | GSC_SESSIONS_dequeue_request (car); | 357 | GSC_SESSIONS_dequeue_request(car); |
359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 358 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
360 | "Transmission request to `%s' was a duplicate!\n", | 359 | "Transmission request to `%s' was a duplicate!\n", |
361 | GNUNET_i2s (&req->peer)); | 360 | GNUNET_i2s(&req->peer)); |
362 | } | 361 | } |
363 | car->target = req->peer; | 362 | car->target = req->peer; |
364 | car->received_time = GNUNET_TIME_absolute_get (); | 363 | car->received_time = GNUNET_TIME_absolute_get(); |
365 | car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline); | 364 | car->deadline = GNUNET_TIME_absolute_ntoh(req->deadline); |
366 | car->priority = (enum GNUNET_MQ_PriorityPreferences) ntohl (req->priority); | 365 | car->priority = (enum GNUNET_MQ_PriorityPreferences)ntohl(req->priority); |
367 | car->msize = ntohs (req->size); | 366 | car->msize = ntohs(req->size); |
368 | car->smr_id = req->smr_id; | 367 | car->smr_id = req->smr_id; |
369 | car->was_solicited = GNUNET_NO; | 368 | car->was_solicited = GNUNET_NO; |
370 | GNUNET_SERVICE_client_continue (c->client); | 369 | GNUNET_SERVICE_client_continue(c->client); |
371 | if (is_loopback) | 370 | if (is_loopback) |
372 | { | 371 | { |
373 | /* loopback, satisfy immediately */ | 372 | /* loopback, satisfy immediately */ |
374 | GSC_CLIENTS_solicit_request (car); | 373 | GSC_CLIENTS_solicit_request(car); |
375 | return; | 374 | return; |
376 | } | 375 | } |
377 | GSC_SESSIONS_queue_request (car); | 376 | GSC_SESSIONS_queue_request(car); |
378 | } | 377 | } |
379 | 378 | ||
380 | 379 | ||
381 | /** | 380 | /** |
382 | * Closure for the #client_tokenizer_callback(). | 381 | * Closure for the #client_tokenizer_callback(). |
383 | */ | 382 | */ |
384 | struct TokenizerContext | 383 | struct TokenizerContext { |
385 | { | ||
386 | |||
387 | /** | 384 | /** |
388 | * Active request handle for the message. | 385 | * Active request handle for the message. |
389 | */ | 386 | */ |
@@ -409,58 +406,58 @@ struct TokenizerContext | |||
409 | * #GNUNET_SYSERR to stop further processing with error | 406 | * #GNUNET_SYSERR to stop further processing with error |
410 | */ | 407 | */ |
411 | static int | 408 | static int |
412 | tokenized_cb (void *cls, const struct GNUNET_MessageHeader *message) | 409 | tokenized_cb(void *cls, const struct GNUNET_MessageHeader *message) |
413 | { | 410 | { |
414 | struct TokenizerContext *tc = cls; | 411 | struct TokenizerContext *tc = cls; |
415 | struct GSC_ClientActiveRequest *car = tc->car; | 412 | struct GSC_ClientActiveRequest *car = tc->car; |
416 | char buf[92]; | 413 | char buf[92]; |
417 | 414 | ||
418 | GNUNET_snprintf (buf, | 415 | GNUNET_snprintf(buf, |
419 | sizeof (buf), | 416 | sizeof(buf), |
420 | gettext_noop ("# bytes of messages of type %u received"), | 417 | gettext_noop("# bytes of messages of type %u received"), |
421 | (unsigned int) ntohs (message->type)); | 418 | (unsigned int)ntohs(message->type)); |
422 | GNUNET_STATISTICS_update (GSC_stats, buf, ntohs (message->size), GNUNET_NO); | 419 | GNUNET_STATISTICS_update(GSC_stats, buf, ntohs(message->size), GNUNET_NO); |
423 | if (0 == memcmp (&car->target, | 420 | if (0 == memcmp(&car->target, |
424 | &GSC_my_identity, | 421 | &GSC_my_identity, |
425 | sizeof (struct GNUNET_PeerIdentity))) | 422 | sizeof(struct GNUNET_PeerIdentity))) |
426 | { | 423 | { |
427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 424 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
428 | "Delivering message of type %u to myself\n", | 425 | "Delivering message of type %u to myself\n", |
429 | ntohs (message->type)); | 426 | ntohs(message->type)); |
430 | GSC_CLIENTS_deliver_message (&GSC_my_identity, | 427 | GSC_CLIENTS_deliver_message(&GSC_my_identity, |
431 | message, | 428 | message, |
432 | ntohs (message->size), | 429 | ntohs(message->size), |
433 | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); | 430 | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); |
434 | GSC_CLIENTS_deliver_message (&GSC_my_identity, | 431 | GSC_CLIENTS_deliver_message(&GSC_my_identity, |
435 | message, | 432 | message, |
436 | sizeof (struct GNUNET_MessageHeader), | 433 | sizeof(struct GNUNET_MessageHeader), |
437 | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); | 434 | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); |
438 | GSC_CLIENTS_deliver_message (&GSC_my_identity, | 435 | GSC_CLIENTS_deliver_message(&GSC_my_identity, |
439 | message, | 436 | message, |
440 | ntohs (message->size), | 437 | ntohs(message->size), |
441 | GNUNET_CORE_OPTION_SEND_FULL_INBOUND); | 438 | GNUNET_CORE_OPTION_SEND_FULL_INBOUND); |
442 | GSC_CLIENTS_deliver_message (&GSC_my_identity, | 439 | GSC_CLIENTS_deliver_message(&GSC_my_identity, |
443 | message, | 440 | message, |
444 | sizeof (struct GNUNET_MessageHeader), | 441 | sizeof(struct GNUNET_MessageHeader), |
445 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND); | 442 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND); |
446 | } | 443 | } |
447 | else | 444 | else |
448 | { | 445 | { |
449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 446 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
450 | "Delivering message of type %u and size %u to %s\n", | 447 | "Delivering message of type %u and size %u to %s\n", |
451 | ntohs (message->type), | 448 | ntohs(message->type), |
452 | ntohs (message->size), | 449 | ntohs(message->size), |
453 | GNUNET_i2s (&car->target)); | 450 | GNUNET_i2s(&car->target)); |
454 | GSC_CLIENTS_deliver_message (&car->target, | 451 | GSC_CLIENTS_deliver_message(&car->target, |
455 | message, | 452 | message, |
456 | ntohs (message->size), | 453 | ntohs(message->size), |
457 | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); | 454 | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); |
458 | GSC_CLIENTS_deliver_message (&car->target, | 455 | GSC_CLIENTS_deliver_message(&car->target, |
459 | message, | 456 | message, |
460 | sizeof (struct GNUNET_MessageHeader), | 457 | sizeof(struct GNUNET_MessageHeader), |
461 | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); | 458 | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); |
462 | GSC_SESSIONS_transmit (car, message, tc->priority); | 459 | GSC_SESSIONS_transmit(car, message, tc->priority); |
463 | } | 460 | } |
464 | return GNUNET_OK; | 461 | return GNUNET_OK; |
465 | } | 462 | } |
466 | 463 | ||
@@ -473,7 +470,7 @@ tokenized_cb (void *cls, const struct GNUNET_MessageHeader *message) | |||
473 | * @return #GNUNET_OK if @a sm is well-formed | 470 | * @return #GNUNET_OK if @a sm is well-formed |
474 | */ | 471 | */ |
475 | static int | 472 | static int |
476 | check_client_send (void *cls, const struct SendMessage *sm) | 473 | check_client_send(void *cls, const struct SendMessage *sm) |
477 | { | 474 | { |
478 | return GNUNET_OK; | 475 | return GNUNET_OK; |
479 | } | 476 | } |
@@ -486,7 +483,7 @@ check_client_send (void *cls, const struct SendMessage *sm) | |||
486 | * @param sm the `struct SendMessage` | 483 | * @param sm the `struct SendMessage` |
487 | */ | 484 | */ |
488 | static void | 485 | static void |
489 | handle_client_send (void *cls, const struct SendMessage *sm) | 486 | handle_client_send(void *cls, const struct SendMessage *sm) |
490 | { | 487 | { |
491 | struct GSC_Client *c = cls; | 488 | struct GSC_Client *c = cls; |
492 | struct TokenizerContext tc; | 489 | struct TokenizerContext tc; |
@@ -494,51 +491,51 @@ handle_client_send (void *cls, const struct SendMessage *sm) | |||
494 | struct GNUNET_TIME_Relative delay; | 491 | struct GNUNET_TIME_Relative delay; |
495 | struct GNUNET_MessageStreamTokenizer *mst; | 492 | struct GNUNET_MessageStreamTokenizer *mst; |
496 | 493 | ||
497 | msize = ntohs (sm->header.size) - sizeof (struct SendMessage); | 494 | msize = ntohs(sm->header.size) - sizeof(struct SendMessage); |
498 | tc.car = GNUNET_CONTAINER_multipeermap_get (c->requests, &sm->peer); | 495 | tc.car = GNUNET_CONTAINER_multipeermap_get(c->requests, &sm->peer); |
499 | if (NULL == tc.car) | 496 | if (NULL == tc.car) |
500 | { | 497 | { |
501 | /* Must have been that we first approved the request, then got disconnected | 498 | /* Must have been that we first approved the request, then got disconnected |
502 | * (which triggered removal of the 'car') and now the client gives us a message | 499 | * (which triggered removal of the 'car') and now the client gives us a message |
503 | * just *before* the client learns about the disconnect. Theoretically, we | 500 | * just *before* the client learns about the disconnect. Theoretically, we |
504 | * might also now be *again* connected. So this can happen (but should be | 501 | * might also now be *again* connected. So this can happen (but should be |
505 | * rare). If it does happen, the message is discarded. */ | 502 | * rare). If it does happen, the message is discarded. */ |
506 | GNUNET_STATISTICS_update (GSC_stats, | 503 | GNUNET_STATISTICS_update(GSC_stats, |
507 | gettext_noop ( | 504 | gettext_noop( |
508 | "# messages discarded (session disconnected)"), | 505 | "# messages discarded (session disconnected)"), |
509 | 1, | 506 | 1, |
510 | GNUNET_NO); | 507 | GNUNET_NO); |
511 | GNUNET_SERVICE_client_continue (c->client); | 508 | GNUNET_SERVICE_client_continue(c->client); |
512 | return; | 509 | return; |
513 | } | 510 | } |
514 | delay = GNUNET_TIME_absolute_get_duration (tc.car->received_time); | 511 | delay = GNUNET_TIME_absolute_get_duration(tc.car->received_time); |
515 | tc.priority = (enum GNUNET_MQ_PriorityPreferences) ntohl (sm->priority); | 512 | tc.priority = (enum GNUNET_MQ_PriorityPreferences)ntohl(sm->priority); |
516 | if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) | 513 | if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) |
517 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 514 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
518 | "Client waited %s for transmission of %u bytes to `%s'\n", | 515 | "Client waited %s for transmission of %u bytes to `%s'\n", |
519 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), | 516 | GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), |
520 | msize, | 517 | msize, |
521 | GNUNET_i2s (&sm->peer)); | 518 | GNUNET_i2s(&sm->peer)); |
522 | else | 519 | else |
523 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 520 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
524 | "Client waited %s for transmission of %u bytes to `%s'\n", | 521 | "Client waited %s for transmission of %u bytes to `%s'\n", |
525 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), | 522 | GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), |
526 | msize, | 523 | msize, |
527 | GNUNET_i2s (&sm->peer)); | 524 | GNUNET_i2s(&sm->peer)); |
528 | 525 | ||
529 | GNUNET_assert ( | 526 | GNUNET_assert( |
530 | GNUNET_YES == | 527 | GNUNET_YES == |
531 | GNUNET_CONTAINER_multipeermap_remove (c->requests, &sm->peer, tc.car)); | 528 | GNUNET_CONTAINER_multipeermap_remove(c->requests, &sm->peer, tc.car)); |
532 | mst = GNUNET_MST_create (&tokenized_cb, &tc); | 529 | mst = GNUNET_MST_create(&tokenized_cb, &tc); |
533 | GNUNET_MST_from_buffer (mst, | 530 | GNUNET_MST_from_buffer(mst, |
534 | (const char *) &sm[1], | 531 | (const char *)&sm[1], |
535 | msize, | 532 | msize, |
536 | GNUNET_YES, | 533 | GNUNET_YES, |
537 | GNUNET_NO); | 534 | GNUNET_NO); |
538 | GNUNET_MST_destroy (mst); | 535 | GNUNET_MST_destroy(mst); |
539 | GSC_SESSIONS_dequeue_request (tc.car); | 536 | GSC_SESSIONS_dequeue_request(tc.car); |
540 | GNUNET_free (tc.car); | 537 | GNUNET_free(tc.car); |
541 | GNUNET_SERVICE_client_continue (c->client); | 538 | GNUNET_SERVICE_client_continue(c->client); |
542 | } | 539 | } |
543 | 540 | ||
544 | 541 | ||
@@ -551,19 +548,19 @@ handle_client_send (void *cls, const struct SendMessage *sm) | |||
551 | * @return #GNUNET_YES (continue iteration) | 548 | * @return #GNUNET_YES (continue iteration) |
552 | */ | 549 | */ |
553 | static int | 550 | static int |
554 | destroy_active_client_request (void *cls, | 551 | destroy_active_client_request(void *cls, |
555 | const struct GNUNET_PeerIdentity *key, | 552 | const struct GNUNET_PeerIdentity *key, |
556 | void *value) | 553 | void *value) |
557 | { | 554 | { |
558 | struct GSC_ClientActiveRequest *car = value; | 555 | struct GSC_ClientActiveRequest *car = value; |
559 | 556 | ||
560 | GNUNET_assert ( | 557 | GNUNET_assert( |
561 | GNUNET_YES == | 558 | GNUNET_YES == |
562 | GNUNET_CONTAINER_multipeermap_remove (car->client_handle->requests, | 559 | GNUNET_CONTAINER_multipeermap_remove(car->client_handle->requests, |
563 | &car->target, | 560 | &car->target, |
564 | car)); | 561 | car)); |
565 | GSC_SESSIONS_dequeue_request (car); | 562 | GSC_SESSIONS_dequeue_request(car); |
566 | GNUNET_free (car); | 563 | GNUNET_free(car); |
567 | return GNUNET_YES; | 564 | return GNUNET_YES; |
568 | } | 565 | } |
569 | 566 | ||
@@ -577,17 +574,17 @@ destroy_active_client_request (void *cls, | |||
577 | * @return our client handle | 574 | * @return our client handle |
578 | */ | 575 | */ |
579 | static void * | 576 | static void * |
580 | client_connect_cb (void *cls, | 577 | client_connect_cb(void *cls, |
581 | struct GNUNET_SERVICE_Client *client, | 578 | struct GNUNET_SERVICE_Client *client, |
582 | struct GNUNET_MQ_Handle *mq) | 579 | struct GNUNET_MQ_Handle *mq) |
583 | { | 580 | { |
584 | struct GSC_Client *c; | 581 | struct GSC_Client *c; |
585 | 582 | ||
586 | c = GNUNET_new (struct GSC_Client); | 583 | c = GNUNET_new(struct GSC_Client); |
587 | c->client = client; | 584 | c->client = client; |
588 | c->mq = mq; | 585 | c->mq = mq; |
589 | c->connectmap = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO); | 586 | c->connectmap = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_NO); |
590 | GNUNET_CONTAINER_DLL_insert (client_head, client_tail, c); | 587 | GNUNET_CONTAINER_DLL_insert(client_head, client_tail, c); |
591 | return c; | 588 | return c; |
592 | } | 589 | } |
593 | 590 | ||
@@ -600,31 +597,31 @@ client_connect_cb (void *cls, | |||
600 | * @param app_ctx our `struct GST_Client` for @a client | 597 | * @param app_ctx our `struct GST_Client` for @a client |
601 | */ | 598 | */ |
602 | static void | 599 | static void |
603 | client_disconnect_cb (void *cls, | 600 | client_disconnect_cb(void *cls, |
604 | struct GNUNET_SERVICE_Client *client, | 601 | struct GNUNET_SERVICE_Client *client, |
605 | void *app_ctx) | 602 | void *app_ctx) |
606 | { | 603 | { |
607 | struct GSC_Client *c = app_ctx; | 604 | struct GSC_Client *c = app_ctx; |
608 | 605 | ||
609 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 606 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
610 | "Client %p has disconnected from core service.\n", | 607 | "Client %p has disconnected from core service.\n", |
611 | client); | 608 | client); |
612 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, c); | 609 | GNUNET_CONTAINER_DLL_remove(client_head, client_tail, c); |
613 | if (NULL != c->requests) | 610 | if (NULL != c->requests) |
614 | { | 611 | { |
615 | GNUNET_CONTAINER_multipeermap_iterate (c->requests, | 612 | GNUNET_CONTAINER_multipeermap_iterate(c->requests, |
616 | &destroy_active_client_request, | 613 | &destroy_active_client_request, |
617 | NULL); | 614 | NULL); |
618 | GNUNET_CONTAINER_multipeermap_destroy (c->requests); | 615 | GNUNET_CONTAINER_multipeermap_destroy(c->requests); |
619 | } | 616 | } |
620 | GNUNET_CONTAINER_multipeermap_destroy (c->connectmap); | 617 | GNUNET_CONTAINER_multipeermap_destroy(c->connectmap); |
621 | c->connectmap = NULL; | 618 | c->connectmap = NULL; |
622 | if (NULL != c->types) | 619 | if (NULL != c->types) |
623 | { | 620 | { |
624 | GSC_TYPEMAP_remove (c->types, c->tcnt); | 621 | GSC_TYPEMAP_remove(c->types, c->tcnt); |
625 | GNUNET_free (c->types); | 622 | GNUNET_free(c->types); |
626 | } | 623 | } |
627 | GNUNET_free (c); | 624 | GNUNET_free(c); |
628 | 625 | ||
629 | /* recalculate 'all_client_options' */ | 626 | /* recalculate 'all_client_options' */ |
630 | all_client_options = 0; | 627 | all_client_options = 0; |
@@ -644,7 +641,7 @@ client_disconnect_cb (void *cls, | |||
644 | * @param tmap_new updated type map for the neighbour, NULL for disconnect | 641 | * @param tmap_new updated type map for the neighbour, NULL for disconnect |
645 | */ | 642 | */ |
646 | void | 643 | void |
647 | GSC_CLIENTS_notify_client_about_neighbour ( | 644 | GSC_CLIENTS_notify_client_about_neighbour( |
648 | struct GSC_Client *client, | 645 | struct GSC_Client *client, |
649 | const struct GNUNET_PeerIdentity *neighbour, | 646 | const struct GNUNET_PeerIdentity *neighbour, |
650 | const struct GSC_TypeMap *tmap_old, | 647 | const struct GSC_TypeMap *tmap_old, |
@@ -656,62 +653,62 @@ GSC_CLIENTS_notify_client_about_neighbour ( | |||
656 | 653 | ||
657 | if (GNUNET_YES != client->got_init) | 654 | if (GNUNET_YES != client->got_init) |
658 | return; | 655 | return; |
659 | old_match = GSC_TYPEMAP_test_match (tmap_old, client->types, client->tcnt); | 656 | old_match = GSC_TYPEMAP_test_match(tmap_old, client->types, client->tcnt); |
660 | new_match = GSC_TYPEMAP_test_match (tmap_new, client->types, client->tcnt); | 657 | new_match = GSC_TYPEMAP_test_match(tmap_new, client->types, client->tcnt); |
661 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 658 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
662 | "Notifying client about neighbour %s (%d/%d)\n", | 659 | "Notifying client about neighbour %s (%d/%d)\n", |
663 | GNUNET_i2s (neighbour), | 660 | GNUNET_i2s(neighbour), |
664 | old_match, | 661 | old_match, |
665 | new_match); | 662 | new_match); |
666 | if (old_match == new_match) | 663 | if (old_match == new_match) |
667 | { | 664 | { |
668 | GNUNET_assert ( | 665 | GNUNET_assert( |
669 | old_match == | 666 | old_match == |
670 | GNUNET_CONTAINER_multipeermap_contains (client->connectmap, neighbour)); | 667 | GNUNET_CONTAINER_multipeermap_contains(client->connectmap, neighbour)); |
671 | return; /* no change */ | 668 | return; /* no change */ |
672 | } | 669 | } |
673 | if (GNUNET_NO == old_match) | 670 | if (GNUNET_NO == old_match) |
674 | { | 671 | { |
675 | struct ConnectNotifyMessage *cnm; | 672 | struct ConnectNotifyMessage *cnm; |
676 | 673 | ||
677 | /* send connect */ | 674 | /* send connect */ |
678 | GNUNET_assert ( | 675 | GNUNET_assert( |
679 | GNUNET_NO == | 676 | GNUNET_NO == |
680 | GNUNET_CONTAINER_multipeermap_contains (client->connectmap, neighbour)); | 677 | GNUNET_CONTAINER_multipeermap_contains(client->connectmap, neighbour)); |
681 | GNUNET_assert (GNUNET_YES == | 678 | GNUNET_assert(GNUNET_YES == |
682 | GNUNET_CONTAINER_multipeermap_put ( | 679 | GNUNET_CONTAINER_multipeermap_put( |
683 | client->connectmap, | 680 | client->connectmap, |
684 | neighbour, | 681 | neighbour, |
685 | NULL, | 682 | NULL, |
686 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 683 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
687 | env = GNUNET_MQ_msg (cnm, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); | 684 | env = GNUNET_MQ_msg(cnm, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); |
688 | cnm->reserved = htonl (0); | 685 | cnm->reserved = htonl(0); |
689 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 686 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
690 | "Sending NOTIFY_CONNECT message about peer %s to client.\n", | 687 | "Sending NOTIFY_CONNECT message about peer %s to client.\n", |
691 | GNUNET_i2s (neighbour)); | 688 | GNUNET_i2s(neighbour)); |
692 | cnm->peer = *neighbour; | 689 | cnm->peer = *neighbour; |
693 | GNUNET_MQ_send (client->mq, env); | 690 | GNUNET_MQ_send(client->mq, env); |
694 | } | 691 | } |
695 | else | 692 | else |
696 | { | 693 | { |
697 | struct DisconnectNotifyMessage *dcm; | 694 | struct DisconnectNotifyMessage *dcm; |
698 | 695 | ||
699 | /* send disconnect */ | 696 | /* send disconnect */ |
700 | GNUNET_assert ( | 697 | GNUNET_assert( |
701 | GNUNET_YES == | 698 | GNUNET_YES == |
702 | GNUNET_CONTAINER_multipeermap_contains (client->connectmap, neighbour)); | 699 | GNUNET_CONTAINER_multipeermap_contains(client->connectmap, neighbour)); |
703 | GNUNET_assert (GNUNET_YES == | 700 | GNUNET_assert(GNUNET_YES == |
704 | GNUNET_CONTAINER_multipeermap_remove (client->connectmap, | 701 | GNUNET_CONTAINER_multipeermap_remove(client->connectmap, |
705 | neighbour, | 702 | neighbour, |
706 | NULL)); | 703 | NULL)); |
707 | env = GNUNET_MQ_msg (dcm, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT); | 704 | env = GNUNET_MQ_msg(dcm, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT); |
708 | dcm->reserved = htonl (0); | 705 | dcm->reserved = htonl(0); |
709 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 706 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
710 | "Sending NOTIFY_DISCONNECT message about peer %s to client.\n", | 707 | "Sending NOTIFY_DISCONNECT message about peer %s to client.\n", |
711 | GNUNET_i2s (neighbour)); | 708 | GNUNET_i2s(neighbour)); |
712 | dcm->peer = *neighbour; | 709 | dcm->peer = *neighbour; |
713 | GNUNET_MQ_send (client->mq, env); | 710 | GNUNET_MQ_send(client->mq, env); |
714 | } | 711 | } |
715 | } | 712 | } |
716 | 713 | ||
717 | 714 | ||
@@ -725,7 +722,7 @@ GSC_CLIENTS_notify_client_about_neighbour ( | |||
725 | * @param tmap_new updated type map for the neighbour, NULL for disconnect | 722 | * @param tmap_new updated type map for the neighbour, NULL for disconnect |
726 | */ | 723 | */ |
727 | void | 724 | void |
728 | GSC_CLIENTS_notify_clients_about_neighbour ( | 725 | GSC_CLIENTS_notify_clients_about_neighbour( |
729 | const struct GNUNET_PeerIdentity *neighbour, | 726 | const struct GNUNET_PeerIdentity *neighbour, |
730 | const struct GSC_TypeMap *tmap_old, | 727 | const struct GSC_TypeMap *tmap_old, |
731 | const struct GSC_TypeMap *tmap_new) | 728 | const struct GSC_TypeMap *tmap_new) |
@@ -733,10 +730,10 @@ GSC_CLIENTS_notify_clients_about_neighbour ( | |||
733 | struct GSC_Client *c; | 730 | struct GSC_Client *c; |
734 | 731 | ||
735 | for (c = client_head; NULL != c; c = c->next) | 732 | for (c = client_head; NULL != c; c = c->next) |
736 | GSC_CLIENTS_notify_client_about_neighbour (c, | 733 | GSC_CLIENTS_notify_client_about_neighbour(c, |
737 | neighbour, | 734 | neighbour, |
738 | tmap_old, | 735 | tmap_old, |
739 | tmap_new); | 736 | tmap_new); |
740 | } | 737 | } |
741 | 738 | ||
742 | 739 | ||
@@ -752,108 +749,108 @@ GSC_CLIENTS_notify_clients_about_neighbour ( | |||
752 | * receive the message | 749 | * receive the message |
753 | */ | 750 | */ |
754 | void | 751 | void |
755 | GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, | 752 | GSC_CLIENTS_deliver_message(const struct GNUNET_PeerIdentity *sender, |
756 | const struct GNUNET_MessageHeader *msg, | 753 | const struct GNUNET_MessageHeader *msg, |
757 | uint16_t msize, | 754 | uint16_t msize, |
758 | uint32_t options) | 755 | uint32_t options) |
759 | { | 756 | { |
760 | size_t size = msize + sizeof (struct NotifyTrafficMessage); | 757 | size_t size = msize + sizeof(struct NotifyTrafficMessage); |
761 | 758 | ||
762 | if (size >= GNUNET_MAX_MESSAGE_SIZE) | 759 | if (size >= GNUNET_MAX_MESSAGE_SIZE) |
763 | { | 760 | { |
764 | GNUNET_break (0); | 761 | GNUNET_break(0); |
765 | return; | 762 | return; |
766 | } | 763 | } |
767 | if (! ((0 != (all_client_options & options)) || | 764 | if (!((0 != (all_client_options & options)) || |
768 | (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)))) | 765 | (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)))) |
769 | return; /* no client cares about this message notification */ | 766 | return; /* no client cares about this message notification */ |
770 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 767 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
771 | "Core service passes message from `%s' of type %u to client.\n", | 768 | "Core service passes message from `%s' of type %u to client.\n", |
772 | GNUNET_i2s (sender), | 769 | GNUNET_i2s(sender), |
773 | (unsigned int) ntohs (msg->type)); | 770 | (unsigned int)ntohs(msg->type)); |
774 | GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type)); | 771 | GSC_SESSIONS_add_to_typemap(sender, ntohs(msg->type)); |
775 | 772 | ||
776 | for (struct GSC_Client *c = client_head; NULL != c; c = c->next) | 773 | for (struct GSC_Client *c = client_head; NULL != c; c = c->next) |
777 | { | ||
778 | struct GNUNET_MQ_Envelope *env; | ||
779 | struct NotifyTrafficMessage *ntm; | ||
780 | uint16_t mtype; | ||
781 | unsigned int qlen; | ||
782 | int tm; | ||
783 | |||
784 | tm = type_match (ntohs (msg->type), c); | ||
785 | if (! ((0 != (c->options & options)) || | ||
786 | ((0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) && | ||
787 | (GNUNET_YES == tm)))) | ||
788 | continue; /* neither options nor type match permit the message */ | ||
789 | if ((0 != (options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)) && | ||
790 | ((0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) || | ||
791 | (GNUNET_YES == tm))) | ||
792 | continue; | ||
793 | if ((0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) && | ||
794 | (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND))) | ||
795 | continue; | ||
796 | |||
797 | /* Drop messages if: | ||
798 | 1) We are above the hard limit, or | ||
799 | 2) We are above the soft limit, and a coin toss limited | ||
800 | to the message size (giving larger messages a | ||
801 | proportionally higher chance of being queued) falls | ||
802 | below the threshold. The threshold is based on where | ||
803 | we are between the soft and the hard limit, scaled | ||
804 | to match the range of message sizes we usually encounter | ||
805 | (i.e. up to 32k); so a 64k message has a 50% chance of | ||
806 | being kept if we are just barely below the hard max, | ||
807 | and a 99% chance of being kept if we are at the soft max. | ||
808 | The reason is to make it more likely to drop control traffic | ||
809 | (ACK, queries) which may be cummulative or highly redundant, | ||
810 | and cheap to drop than data traffic. */ | ||
811 | qlen = GNUNET_MQ_get_length (c->mq); | ||
812 | if ((qlen >= HARD_MAX_QUEUE) || | ||
813 | ((qlen > SOFT_MAX_QUEUE) && | ||
814 | ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
815 | ntohs (msg->size))) < | ||
816 | (qlen - SOFT_MAX_QUEUE) * 0x8000 / | ||
817 | (HARD_MAX_QUEUE - SOFT_MAX_QUEUE)))) | ||
818 | { | 774 | { |
819 | char buf[1024]; | 775 | struct GNUNET_MQ_Envelope *env; |
820 | 776 | struct NotifyTrafficMessage *ntm; | |
821 | GNUNET_log ( | 777 | uint16_t mtype; |
822 | GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 778 | unsigned int qlen; |
823 | "Dropping decrypted message of type %u as client is too busy (queue full)\n", | 779 | int tm; |
824 | (unsigned int) ntohs (msg->type)); | 780 | |
825 | GNUNET_snprintf (buf, | 781 | tm = type_match(ntohs(msg->type), c); |
826 | sizeof (buf), | 782 | if (!((0 != (c->options & options)) || |
827 | gettext_noop ( | 783 | ((0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) && |
828 | "# messages of type %u discarded (client busy)"), | 784 | (GNUNET_YES == tm)))) |
829 | (unsigned int) ntohs (msg->type)); | 785 | continue; /* neither options nor type match permit the message */ |
830 | GNUNET_STATISTICS_update (GSC_stats, buf, 1, GNUNET_NO); | 786 | if ((0 != (options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)) && |
831 | continue; | 787 | ((0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) || |
788 | (GNUNET_YES == tm))) | ||
789 | continue; | ||
790 | if ((0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) && | ||
791 | (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND))) | ||
792 | continue; | ||
793 | |||
794 | /* Drop messages if: | ||
795 | 1) We are above the hard limit, or | ||
796 | 2) We are above the soft limit, and a coin toss limited | ||
797 | to the message size (giving larger messages a | ||
798 | proportionally higher chance of being queued) falls | ||
799 | below the threshold. The threshold is based on where | ||
800 | we are between the soft and the hard limit, scaled | ||
801 | to match the range of message sizes we usually encounter | ||
802 | (i.e. up to 32k); so a 64k message has a 50% chance of | ||
803 | being kept if we are just barely below the hard max, | ||
804 | and a 99% chance of being kept if we are at the soft max. | ||
805 | The reason is to make it more likely to drop control traffic | ||
806 | (ACK, queries) which may be cummulative or highly redundant, | ||
807 | and cheap to drop than data traffic. */ | ||
808 | qlen = GNUNET_MQ_get_length(c->mq); | ||
809 | if ((qlen >= HARD_MAX_QUEUE) || | ||
810 | ((qlen > SOFT_MAX_QUEUE) && | ||
811 | ((GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | ||
812 | ntohs(msg->size))) < | ||
813 | (qlen - SOFT_MAX_QUEUE) * 0x8000 / | ||
814 | (HARD_MAX_QUEUE - SOFT_MAX_QUEUE)))) | ||
815 | { | ||
816 | char buf[1024]; | ||
817 | |||
818 | GNUNET_log( | ||
819 | GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | ||
820 | "Dropping decrypted message of type %u as client is too busy (queue full)\n", | ||
821 | (unsigned int)ntohs(msg->type)); | ||
822 | GNUNET_snprintf(buf, | ||
823 | sizeof(buf), | ||
824 | gettext_noop( | ||
825 | "# messages of type %u discarded (client busy)"), | ||
826 | (unsigned int)ntohs(msg->type)); | ||
827 | GNUNET_STATISTICS_update(GSC_stats, buf, 1, GNUNET_NO); | ||
828 | continue; | ||
829 | } | ||
830 | |||
831 | GNUNET_log( | ||
832 | GNUNET_ERROR_TYPE_DEBUG, | ||
833 | "Sending %u message with %u bytes to client interested in messages of type %u.\n", | ||
834 | options, | ||
835 | ntohs(msg->size), | ||
836 | (unsigned int)ntohs(msg->type)); | ||
837 | |||
838 | if (0 != (options & (GNUNET_CORE_OPTION_SEND_FULL_INBOUND | | ||
839 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND))) | ||
840 | mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND; | ||
841 | else | ||
842 | mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND; | ||
843 | env = GNUNET_MQ_msg_extra(ntm, msize, mtype); | ||
844 | ntm->peer = *sender; | ||
845 | GNUNET_memcpy(&ntm[1], msg, msize); | ||
846 | |||
847 | GNUNET_assert( | ||
848 | (0 == (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) || | ||
849 | (GNUNET_YES != tm) || | ||
850 | (GNUNET_YES == | ||
851 | GNUNET_CONTAINER_multipeermap_contains(c->connectmap, sender))); | ||
852 | GNUNET_MQ_send(c->mq, env); | ||
832 | } | 853 | } |
833 | |||
834 | GNUNET_log ( | ||
835 | GNUNET_ERROR_TYPE_DEBUG, | ||
836 | "Sending %u message with %u bytes to client interested in messages of type %u.\n", | ||
837 | options, | ||
838 | ntohs (msg->size), | ||
839 | (unsigned int) ntohs (msg->type)); | ||
840 | |||
841 | if (0 != (options & (GNUNET_CORE_OPTION_SEND_FULL_INBOUND | | ||
842 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND))) | ||
843 | mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND; | ||
844 | else | ||
845 | mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND; | ||
846 | env = GNUNET_MQ_msg_extra (ntm, msize, mtype); | ||
847 | ntm->peer = *sender; | ||
848 | GNUNET_memcpy (&ntm[1], msg, msize); | ||
849 | |||
850 | GNUNET_assert ( | ||
851 | (0 == (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) || | ||
852 | (GNUNET_YES != tm) || | ||
853 | (GNUNET_YES == | ||
854 | GNUNET_CONTAINER_multipeermap_contains (c->connectmap, sender))); | ||
855 | GNUNET_MQ_send (c->mq, env); | ||
856 | } | ||
857 | } | 854 | } |
858 | 855 | ||
859 | 856 | ||
@@ -864,21 +861,21 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, | |||
864 | * @param cls NULL, unused | 861 | * @param cls NULL, unused |
865 | */ | 862 | */ |
866 | static void | 863 | static void |
867 | shutdown_task (void *cls) | 864 | shutdown_task(void *cls) |
868 | { | 865 | { |
869 | struct GSC_Client *c; | 866 | struct GSC_Client *c; |
870 | 867 | ||
871 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n"); | 868 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n"); |
872 | while (NULL != (c = client_head)) | 869 | while (NULL != (c = client_head)) |
873 | GNUNET_SERVICE_client_drop (c->client); | 870 | GNUNET_SERVICE_client_drop(c->client); |
874 | GSC_SESSIONS_done (); | 871 | GSC_SESSIONS_done(); |
875 | GSC_KX_done (); | 872 | GSC_KX_done(); |
876 | GSC_TYPEMAP_done (); | 873 | GSC_TYPEMAP_done(); |
877 | if (NULL != GSC_stats) | 874 | if (NULL != GSC_stats) |
878 | { | 875 | { |
879 | GNUNET_STATISTICS_destroy (GSC_stats, GNUNET_NO); | 876 | GNUNET_STATISTICS_destroy(GSC_stats, GNUNET_NO); |
880 | GSC_stats = NULL; | 877 | GSC_stats = NULL; |
881 | } | 878 | } |
882 | GSC_cfg = NULL; | 879 | GSC_cfg = NULL; |
883 | } | 880 | } |
884 | 881 | ||
@@ -893,13 +890,13 @@ shutdown_task (void *cls) | |||
893 | * @param message iteration request message | 890 | * @param message iteration request message |
894 | */ | 891 | */ |
895 | static void | 892 | static void |
896 | handle_client_monitor_peers (void *cls, | 893 | handle_client_monitor_peers(void *cls, |
897 | const struct GNUNET_MessageHeader *message) | 894 | const struct GNUNET_MessageHeader *message) |
898 | { | 895 | { |
899 | struct GSC_Client *c = cls; | 896 | struct GSC_Client *c = cls; |
900 | 897 | ||
901 | GNUNET_SERVICE_client_continue (c->client); | 898 | GNUNET_SERVICE_client_continue(c->client); |
902 | GSC_KX_handle_client_monitor_peers (c->mq); | 899 | GSC_KX_handle_client_monitor_peers(c->mq); |
903 | } | 900 | } |
904 | 901 | ||
905 | 902 | ||
@@ -911,72 +908,72 @@ handle_client_monitor_peers (void *cls, | |||
911 | * @param service the initialized service | 908 | * @param service the initialized service |
912 | */ | 909 | */ |
913 | static void | 910 | static void |
914 | run (void *cls, | 911 | run(void *cls, |
915 | const struct GNUNET_CONFIGURATION_Handle *c, | 912 | const struct GNUNET_CONFIGURATION_Handle *c, |
916 | struct GNUNET_SERVICE_Handle *service) | 913 | struct GNUNET_SERVICE_Handle *service) |
917 | { | 914 | { |
918 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 915 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; |
919 | char *keyfile; | 916 | char *keyfile; |
920 | 917 | ||
921 | GSC_cfg = c; | 918 | GSC_cfg = c; |
922 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, | 919 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(GSC_cfg, |
923 | "PEER", | 920 | "PEER", |
924 | "PRIVATE_KEY", | 921 | "PRIVATE_KEY", |
925 | &keyfile)) | 922 | &keyfile)) |
926 | { | 923 | { |
927 | GNUNET_log ( | 924 | GNUNET_log( |
928 | GNUNET_ERROR_TYPE_ERROR, | 925 | GNUNET_ERROR_TYPE_ERROR, |
929 | _ ("Core service is lacking HOSTKEY configuration setting. Exiting.\n")); | 926 | _("Core service is lacking HOSTKEY configuration setting. Exiting.\n")); |
930 | GNUNET_SCHEDULER_shutdown (); | 927 | GNUNET_SCHEDULER_shutdown(); |
931 | return; | 928 | return; |
932 | } | 929 | } |
933 | GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg); | 930 | GSC_stats = GNUNET_STATISTICS_create("core", GSC_cfg); |
934 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 931 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
935 | GNUNET_SERVICE_suspend (service); | 932 | GNUNET_SERVICE_suspend(service); |
936 | GSC_TYPEMAP_init (); | 933 | GSC_TYPEMAP_init(); |
937 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); | 934 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile); |
938 | GNUNET_free (keyfile); | 935 | GNUNET_free(keyfile); |
939 | GNUNET_assert (NULL != pk); | 936 | GNUNET_assert(NULL != pk); |
940 | if (GNUNET_OK != GSC_KX_init (pk)) | 937 | if (GNUNET_OK != GSC_KX_init(pk)) |
941 | { | 938 | { |
942 | GNUNET_SCHEDULER_shutdown (); | 939 | GNUNET_SCHEDULER_shutdown(); |
943 | return; | 940 | return; |
944 | } | 941 | } |
945 | GSC_SESSIONS_init (); | 942 | GSC_SESSIONS_init(); |
946 | GNUNET_SERVICE_resume (service); | 943 | GNUNET_SERVICE_resume(service); |
947 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 944 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
948 | _ ("Core service of `%s' ready.\n"), | 945 | _("Core service of `%s' ready.\n"), |
949 | GNUNET_i2s (&GSC_my_identity)); | 946 | GNUNET_i2s(&GSC_my_identity)); |
950 | } | 947 | } |
951 | 948 | ||
952 | 949 | ||
953 | /** | 950 | /** |
954 | * Define "main" method using service macro. | 951 | * Define "main" method using service macro. |
955 | */ | 952 | */ |
956 | GNUNET_SERVICE_MAIN ( | 953 | GNUNET_SERVICE_MAIN( |
957 | "core", | 954 | "core", |
958 | GNUNET_SERVICE_OPTION_NONE, | 955 | GNUNET_SERVICE_OPTION_NONE, |
959 | &run, | 956 | &run, |
960 | &client_connect_cb, | 957 | &client_connect_cb, |
961 | &client_disconnect_cb, | 958 | &client_disconnect_cb, |
962 | NULL, | 959 | NULL, |
963 | GNUNET_MQ_hd_var_size (client_init, | 960 | GNUNET_MQ_hd_var_size(client_init, |
964 | GNUNET_MESSAGE_TYPE_CORE_INIT, | 961 | GNUNET_MESSAGE_TYPE_CORE_INIT, |
965 | struct InitMessage, | 962 | struct InitMessage, |
966 | NULL), | 963 | NULL), |
967 | GNUNET_MQ_hd_fixed_size (client_monitor_peers, | 964 | GNUNET_MQ_hd_fixed_size(client_monitor_peers, |
968 | GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS, | 965 | GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS, |
969 | struct GNUNET_MessageHeader, | 966 | struct GNUNET_MessageHeader, |
970 | NULL), | 967 | NULL), |
971 | GNUNET_MQ_hd_fixed_size (client_send_request, | 968 | GNUNET_MQ_hd_fixed_size(client_send_request, |
972 | GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST, | 969 | GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST, |
973 | struct SendMessageRequest, | 970 | struct SendMessageRequest, |
974 | NULL), | 971 | NULL), |
975 | GNUNET_MQ_hd_var_size (client_send, | 972 | GNUNET_MQ_hd_var_size(client_send, |
976 | GNUNET_MESSAGE_TYPE_CORE_SEND, | 973 | GNUNET_MESSAGE_TYPE_CORE_SEND, |
977 | struct SendMessage, | 974 | struct SendMessage, |
978 | NULL), | 975 | NULL), |
979 | GNUNET_MQ_handler_end ()); | 976 | GNUNET_MQ_handler_end()); |
980 | 977 | ||
981 | 978 | ||
982 | /* end of gnunet-service-core.c */ | 979 | /* end of gnunet-service-core.c */ |