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