diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-12-15 18:09:16 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-12-15 18:09:16 +0000 |
commit | d80d181ca46d0804af85bb33f16caa4c8eb00f9a (patch) | |
tree | 887188d35de602da8793241bae716a998f5702d6 /src/ats/gnunet-service-ats_performance.c | |
parent | 8978db474d26bef8fd7b023baeb5b8e3cb5224c6 (diff) | |
download | gnunet-d80d181ca46d0804af85bb33f16caa4c8eb00f9a.tar.gz gnunet-d80d181ca46d0804af85bb33f16caa4c8eb00f9a.zip |
removing dead code, improving comments, simplifying iteration logic, making iteration over all addresses also faster
Diffstat (limited to 'src/ats/gnunet-service-ats_performance.c')
-rw-r--r-- | src/ats/gnunet-service-ats_performance.c | 236 |
1 files changed, 77 insertions, 159 deletions
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index 71e176a60..3f90802fe 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c | |||
@@ -60,23 +60,6 @@ struct PerformanceClient | |||
60 | 60 | ||
61 | 61 | ||
62 | /** | 62 | /** |
63 | * We keep clients that are interested in performance in a linked list. | ||
64 | */ | ||
65 | struct AddressIteration | ||
66 | { | ||
67 | /** | ||
68 | * Actual handle to the client. | ||
69 | */ | ||
70 | struct PerformanceClient *pc; | ||
71 | |||
72 | int all; | ||
73 | |||
74 | uint32_t id; | ||
75 | |||
76 | unsigned int msg_type; | ||
77 | }; | ||
78 | |||
79 | /** | ||
80 | * Address handle | 63 | * Address handle |
81 | */ | 64 | */ |
82 | static struct GAS_Addresses_Handle *GSA_addresses; | 65 | static struct GAS_Addresses_Handle *GSA_addresses; |
@@ -294,37 +277,15 @@ peerinfo_it (void *cls, | |||
294 | plugin_name, | 277 | plugin_name, |
295 | (unsigned int) ntohl (bandwidth_out.value__), | 278 | (unsigned int) ntohl (bandwidth_out.value__), |
296 | (unsigned int) ntohl (bandwidth_in.value__)); | 279 | (unsigned int) ntohl (bandwidth_in.value__)); |
297 | GAS_performance_notify_client(pc, | 280 | GAS_performance_notify_client (pc, |
298 | id, | 281 | id, |
299 | plugin_name, | 282 | plugin_name, |
300 | plugin_addr, | 283 | plugin_addr, |
301 | plugin_addr_len, | 284 | plugin_addr_len, |
302 | active, | 285 | active, |
303 | atsi, atsi_count, | 286 | atsi, atsi_count, |
304 | bandwidth_out, bandwidth_in); | 287 | bandwidth_out, |
305 | } | 288 | bandwidth_in); |
306 | |||
307 | |||
308 | /** | ||
309 | * Iterator for #GAS_performance_add_client() | ||
310 | * | ||
311 | * @param cls the client requesting information | ||
312 | * @param id result | ||
313 | */ | ||
314 | static void | ||
315 | peer_it (void *cls, | ||
316 | const struct GNUNET_PeerIdentity *id) | ||
317 | { | ||
318 | struct PerformanceClient *pc = cls; | ||
319 | |||
320 | if (NULL != id) | ||
321 | { | ||
322 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
323 | "Callback for peer `%s'\n", | ||
324 | GNUNET_i2s (id)); | ||
325 | GAS_addresses_get_peer_info (GSA_addresses, id, | ||
326 | &peerinfo_it, pc); | ||
327 | } | ||
328 | } | 289 | } |
329 | 290 | ||
330 | 291 | ||
@@ -339,8 +300,8 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client, | |||
339 | enum StartFlag flag) | 300 | enum StartFlag flag) |
340 | { | 301 | { |
341 | struct PerformanceClient *pc; | 302 | struct PerformanceClient *pc; |
342 | GNUNET_break (NULL == find_client (client)); | ||
343 | 303 | ||
304 | GNUNET_break (NULL == find_client (client)); | ||
344 | pc = GNUNET_new (struct PerformanceClient); | 305 | pc = GNUNET_new (struct PerformanceClient); |
345 | pc->client = client; | 306 | pc->client = client; |
346 | pc->flag = flag; | 307 | pc->flag = flag; |
@@ -349,17 +310,43 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client, | |||
349 | "Adding performance client %s PIC\n", | 310 | "Adding performance client %s PIC\n", |
350 | (flag == START_FLAG_PERFORMANCE_WITH_PIC) ? "with" : "without"); | 311 | (flag == START_FLAG_PERFORMANCE_WITH_PIC) ? "with" : "without"); |
351 | 312 | ||
352 | GNUNET_SERVER_notification_context_add (nc, client); | 313 | GNUNET_SERVER_notification_context_add (nc, |
353 | GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc); | 314 | client); |
354 | 315 | GNUNET_CONTAINER_DLL_insert (pc_head, | |
355 | /* Send information about clients */ | 316 | pc_tail, |
356 | GAS_addresses_iterate_peers (GSA_addresses, | 317 | pc); |
357 | &peer_it, | 318 | GAS_addresses_get_peer_info (GSA_addresses, |
319 | NULL, | ||
320 | &peerinfo_it, | ||
358 | pc); | 321 | pc); |
359 | } | 322 | } |
360 | 323 | ||
361 | 324 | ||
362 | /** | 325 | /** |
326 | * Information we need for the callbacks to return a list of addresses | ||
327 | * back to the client. | ||
328 | */ | ||
329 | struct AddressIteration | ||
330 | { | ||
331 | /** | ||
332 | * Actual handle to the client. | ||
333 | */ | ||
334 | struct PerformanceClient *pc; | ||
335 | |||
336 | /** | ||
337 | * Are we sending all addresses, or only those that are active? | ||
338 | */ | ||
339 | int all; | ||
340 | |||
341 | /** | ||
342 | * Which ID should be included in the response? | ||
343 | */ | ||
344 | uint32_t id; | ||
345 | |||
346 | }; | ||
347 | |||
348 | |||
349 | /** | ||
363 | * Send a #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE with the | 350 | * Send a #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE with the |
364 | * given address details to the client identified in @a ai. | 351 | * given address details to the client identified in @a ai. |
365 | * | 352 | * |
@@ -427,13 +414,16 @@ transmit_req_addr (struct AddressIteration *ai, | |||
427 | memcpy (addrp, plugin_addr, plugin_addr_len); | 414 | memcpy (addrp, plugin_addr, plugin_addr_len); |
428 | if (NULL != plugin_name) | 415 | if (NULL != plugin_name) |
429 | strcpy (&addrp[plugin_addr_len], plugin_name); | 416 | strcpy (&addrp[plugin_addr_len], plugin_name); |
430 | GNUNET_SERVER_notification_context_unicast (nc, ai->pc->client, &msg->header, | 417 | GNUNET_SERVER_notification_context_unicast (nc, |
418 | ai->pc->client, | ||
419 | &msg->header, | ||
431 | GNUNET_NO); | 420 | GNUNET_NO); |
432 | } | 421 | } |
433 | 422 | ||
434 | 423 | ||
435 | /** | 424 | /** |
436 | * Iterator for #GAS_addresses_get_peer_info() | 425 | * Iterator for #GAS_addresses_get_peer_info(), called with peer-specific |
426 | * information to be passed back to the client. | ||
437 | * | 427 | * |
438 | * @param cls closure with our `struct AddressIteration *` | 428 | * @param cls closure with our `struct AddressIteration *` |
439 | * @param id the peer id | 429 | * @param id the peer id |
@@ -450,7 +440,8 @@ static void | |||
450 | req_addr_peerinfo_it (void *cls, | 440 | req_addr_peerinfo_it (void *cls, |
451 | const struct GNUNET_PeerIdentity *id, | 441 | const struct GNUNET_PeerIdentity *id, |
452 | const char *plugin_name, | 442 | const char *plugin_name, |
453 | const void *plugin_addr, size_t plugin_addr_len, | 443 | const void *plugin_addr, |
444 | size_t plugin_addr_len, | ||
454 | int active, | 445 | int active, |
455 | const struct GNUNET_ATS_Information *atsi, | 446 | const struct GNUNET_ATS_Information *atsi, |
456 | uint32_t atsi_count, | 447 | uint32_t atsi_count, |
@@ -459,30 +450,29 @@ req_addr_peerinfo_it (void *cls, | |||
459 | { | 450 | { |
460 | struct AddressIteration *ai = cls; | 451 | struct AddressIteration *ai = cls; |
461 | 452 | ||
462 | GNUNET_assert (NULL != ai); | 453 | if ( (NULL == id) && |
463 | GNUNET_assert (NULL != ai->pc); | 454 | (NULL == plugin_name) && |
464 | if (NULL == find_client (ai->pc->client)) | 455 | (NULL == plugin_addr) ) |
465 | return; /* Client disconnected */ | ||
466 | |||
467 | if ((NULL == id) && (NULL == plugin_name) && (NULL == plugin_addr)) | ||
468 | { | 456 | { |
469 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 457 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
470 | "Address iteration done\n"); | 458 | "Address iteration done for one peer\n"); |
471 | return; | 459 | return; |
472 | } | 460 | } |
473 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 461 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
474 | "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n", | 462 | "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n", |
475 | (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", | 463 | (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", |
476 | GNUNET_i2s (id), | 464 | GNUNET_i2s (id), |
477 | plugin_name, | 465 | plugin_name, |
478 | (unsigned int) ntohl (bandwidth_out.value__), | 466 | (unsigned int) ntohl (bandwidth_out.value__), |
479 | (unsigned int) ntohl (bandwidth_in.value__)); | 467 | (unsigned int) ntohl (bandwidth_in.value__)); |
480 | 468 | ||
481 | /* Transmit result */ | 469 | /* Transmit result (either if address is active, or if |
482 | if ((GNUNET_YES == ai->all) || (GNUNET_YES == active)) | 470 | client wanted all addresses) */ |
471 | if ( (GNUNET_YES == ai->all) || | ||
472 | (GNUNET_YES == active)) | ||
483 | { | 473 | { |
484 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
485 | "Sending result for %s peer `%s' plugin `%s' BW out %u, BW in %u\n", | 475 | "Sending result for %s peer `%s' plugin `%s' BW out %u, BW in %u\n", |
486 | (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", | 476 | (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", |
487 | GNUNET_i2s (id), | 477 | GNUNET_i2s (id), |
488 | plugin_name, | 478 | plugin_name, |
@@ -495,34 +485,9 @@ req_addr_peerinfo_it (void *cls, | |||
495 | active, | 485 | active, |
496 | atsi, | 486 | atsi, |
497 | atsi_count, | 487 | atsi_count, |
498 | bandwidth_out, bandwidth_in); | 488 | bandwidth_out, |
499 | } | 489 | bandwidth_in); |
500 | } | ||
501 | |||
502 | |||
503 | /** | ||
504 | * Iterator for GAS_handle_request_address_list | ||
505 | * | ||
506 | * @param cls the client requesting information, a `struct AddressIteration *` | ||
507 | * @param id result | ||
508 | */ | ||
509 | static void | ||
510 | req_addr_peer_it (void *cls, | ||
511 | const struct GNUNET_PeerIdentity *id) | ||
512 | { | ||
513 | struct AddressIteration *ai = cls; | ||
514 | |||
515 | if (NULL == id) | ||
516 | { | ||
517 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
518 | "Peer iteration done\n"); | ||
519 | return; | ||
520 | } | 490 | } |
521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
522 | "Callback for peer `%s'\n", | ||
523 | GNUNET_i2s (id)); | ||
524 | GAS_addresses_get_peer_info (GSA_addresses, id, | ||
525 | &req_addr_peerinfo_it, ai); | ||
526 | } | 491 | } |
527 | 492 | ||
528 | 493 | ||
@@ -540,7 +505,7 @@ GAS_handle_request_address_list (void *cls, | |||
540 | { | 505 | { |
541 | struct PerformanceClient *pc; | 506 | struct PerformanceClient *pc; |
542 | struct AddressIteration ai; | 507 | struct AddressIteration ai; |
543 | struct AddressListRequestMessage * alrm = (struct AddressListRequestMessage *) message; | 508 | const struct AddressListRequestMessage *alrm; |
544 | struct GNUNET_PeerIdentity allzeros; | 509 | struct GNUNET_PeerIdentity allzeros; |
545 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; | 510 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; |
546 | 511 | ||
@@ -552,7 +517,7 @@ GAS_handle_request_address_list (void *cls, | |||
552 | GNUNET_break (0); | 517 | GNUNET_break (0); |
553 | return; | 518 | return; |
554 | } | 519 | } |
555 | 520 | alrm = (const struct AddressListRequestMessage *) message; | |
556 | ai.all = ntohl (alrm->all); | 521 | ai.all = ntohl (alrm->all); |
557 | ai.id = ntohl (alrm->id); | 522 | ai.id = ntohl (alrm->id); |
558 | ai.pc = pc; | 523 | ai.pc = pc; |
@@ -564,74 +529,27 @@ GAS_handle_request_address_list (void *cls, | |||
564 | sizeof (struct GNUNET_PeerIdentity))) | 529 | sizeof (struct GNUNET_PeerIdentity))) |
565 | { | 530 | { |
566 | /* Return addresses for all peers */ | 531 | /* Return addresses for all peers */ |
567 | GAS_addresses_iterate_peers (GSA_addresses, &req_addr_peer_it, &ai); | 532 | GAS_addresses_get_peer_info (GSA_addresses, |
568 | transmit_req_addr (&ai, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, | 533 | NULL, |
569 | bandwidth_zero, bandwidth_zero); | 534 | &req_addr_peerinfo_it, |
535 | &ai); | ||
570 | } | 536 | } |
571 | else | 537 | else |
572 | { | 538 | { |
573 | /* Return addresses for a specific peer */ | 539 | /* Return addresses for a specific peer */ |
574 | GAS_addresses_get_peer_info (GSA_addresses, | 540 | GAS_addresses_get_peer_info (GSA_addresses, |
575 | &alrm->peer, | 541 | &alrm->peer, |
576 | &req_addr_peerinfo_it, &ai); | 542 | &req_addr_peerinfo_it, |
577 | transmit_req_addr (&ai, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, | 543 | &ai); |
578 | bandwidth_zero, bandwidth_zero); | ||
579 | } | ||
580 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
581 | } | ||
582 | |||
583 | |||
584 | /** | ||
585 | * FIXME. | ||
586 | */ | ||
587 | void | ||
588 | GAS_handle_performance_update (struct GNUNET_PeerIdentity *peer, | ||
589 | const char *plugin_name, | ||
590 | const void *plugin_addr, size_t plugin_addr_len, | ||
591 | int active, | ||
592 | struct GNUNET_ATS_Information *ats, | ||
593 | uint32_t ats_count, | ||
594 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
595 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
596 | { | ||
597 | /* Notify here */ | ||
598 | GAS_performance_notify_all_clients (peer, | ||
599 | plugin_name, | ||
600 | plugin_addr, | ||
601 | plugin_addr_len, | ||
602 | active, | ||
603 | ats, ats_count, | ||
604 | bandwidth_out, | ||
605 | bandwidth_in); | ||
606 | |||
607 | #if 0 | ||
608 | struct PerformanceClient *cur; | ||
609 | struct PerformanceMonitorClient *curm; | ||
610 | struct MonitorResponseMessage *mrm; | ||
611 | size_t msglen; | ||
612 | |||
613 | msglen = sizeof (struct MonitorResponseMessage) + | ||
614 | ats_count * sizeof (struct GNUNET_ATS_Information); | ||
615 | mrm = GNUNET_malloc (msglen); | ||
616 | |||
617 | mrm->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR_RESPONSE); | ||
618 | mrm->header.size = htons (msglen); | ||
619 | mrm->ats_count = htonl (ats_count); | ||
620 | mrm->peer = *peer; | ||
621 | memcpy (&mrm[1], ats, ats_count * sizeof (struct GNUNET_ATS_Information)); | ||
622 | |||
623 | for (cur = pc_head; NULL != cur; cur = cur->next) | ||
624 | for (curm = cur->pm_head; NULL != curm; curm = curm->next) | ||
625 | { | ||
626 | /* Notify client about update */ | ||
627 | mrm->id = htonl (curm->id); | ||
628 | GNUNET_SERVER_notification_context_unicast (nc, | ||
629 | cur->client, | ||
630 | (struct GNUNET_MessageHeader *) mrm, | ||
631 | GNUNET_YES); | ||
632 | } | 544 | } |
633 | GNUNET_free (mrm); | 545 | transmit_req_addr (&ai, |
634 | #endif | 546 | NULL, NULL, NULL, |
547 | 0, GNUNET_NO, | ||
548 | NULL, 0, | ||
549 | bandwidth_zero, | ||
550 | bandwidth_zero); | ||
551 | GNUNET_SERVER_receive_done (client, | ||
552 | GNUNET_OK); | ||
635 | } | 553 | } |
636 | 554 | ||
637 | 555 | ||