diff options
Diffstat (limited to 'src/peerinfo/gnunet-peerinfo-gtk.c')
-rw-r--r-- | src/peerinfo/gnunet-peerinfo-gtk.c | 611 |
1 files changed, 430 insertions, 181 deletions
diff --git a/src/peerinfo/gnunet-peerinfo-gtk.c b/src/peerinfo/gnunet-peerinfo-gtk.c index b81a7ce2..d0e752db 100644 --- a/src/peerinfo/gnunet-peerinfo-gtk.c +++ b/src/peerinfo/gnunet-peerinfo-gtk.c | |||
@@ -147,7 +147,7 @@ enum PEERINFO_ModelColumns | |||
147 | PEERINFO_MC_VALIDATION_TIMEOUT_AS_STRING = 20, | 147 | PEERINFO_MC_VALIDATION_TIMEOUT_AS_STRING = 20, |
148 | 148 | ||
149 | /** | 149 | /** |
150 | * A gboolean | 150 | * A GdkPixbuf |
151 | */ | 151 | */ |
152 | PEERINFO_MC_PLUGIN_CONNECTIVITY_LED = 21, | 152 | PEERINFO_MC_PLUGIN_CONNECTIVITY_LED = 21, |
153 | 153 | ||
@@ -164,7 +164,12 @@ enum PEERINFO_ModelColumns | |||
164 | /** | 164 | /** |
165 | * A gboolean | 165 | * A gboolean |
166 | */ | 166 | */ |
167 | PEERINFO_MC_SHOW_FRIEND = 24 | 167 | PEERINFO_MC_SHOW_FRIEND = 24, |
168 | |||
169 | /** | ||
170 | * A gchararray | ||
171 | */ | ||
172 | PEERINFO_MC_PEERINFO_ADDRESS_EXPIRATION = 25 | ||
168 | 173 | ||
169 | }; | 174 | }; |
170 | 175 | ||
@@ -201,10 +206,40 @@ struct PeerAddress | |||
201 | const void *addr; | 206 | const void *addr; |
202 | 207 | ||
203 | /** | 208 | /** |
209 | * Name of the plugin. | ||
210 | */ | ||
211 | char *plugin; | ||
212 | |||
213 | /** | ||
214 | * Timeout for the current state in the state machine. | ||
215 | */ | ||
216 | struct GNUNET_TIME_Absolute state_timeout; | ||
217 | |||
218 | /** | ||
219 | * State of this address in the transport state machine. | ||
220 | */ | ||
221 | enum GNUNET_TRANSPORT_PeerState state; | ||
222 | |||
223 | /** | ||
204 | * Number of bytes in @e addr. | 224 | * Number of bytes in @e addr. |
205 | */ | 225 | */ |
206 | size_t addr_len; | 226 | size_t addr_len; |
207 | 227 | ||
228 | /** | ||
229 | * ATS bandwidth in for this address. | ||
230 | */ | ||
231 | guint ats_in; | ||
232 | |||
233 | /** | ||
234 | * ATS bandwidth out for this address. | ||
235 | */ | ||
236 | guint ats_out; | ||
237 | |||
238 | /** | ||
239 | * Is this address active in ATS? | ||
240 | */ | ||
241 | gboolean address_ats_active; | ||
242 | |||
208 | }; | 243 | }; |
209 | 244 | ||
210 | 245 | ||
@@ -292,9 +327,9 @@ static GdkPixbuf *led_green; | |||
292 | static GdkPixbuf *led_red; | 327 | static GdkPixbuf *led_red; |
293 | 328 | ||
294 | /** | 329 | /** |
295 | * Main window list store. | 330 | * Main window tree store. |
296 | */ | 331 | */ |
297 | static GtkListStore *ls; | 332 | static GtkTreeStore *ts; |
298 | 333 | ||
299 | /** | 334 | /** |
300 | * Map of all of our friends. | 335 | * Map of all of our friends. |
@@ -334,13 +369,13 @@ get_object (const char *name) | |||
334 | * Function called on each entry in the #peer2info map | 369 | * Function called on each entry in the #peer2info map |
335 | * to free the associated path. | 370 | * to free the associated path. |
336 | * | 371 | * |
337 | * @param cls unused | 372 | * @param cts unused |
338 | * @param key peer identity | 373 | * @param key peer identity |
339 | * @param value the `struct PeerInfo` | 374 | * @param value the `struct PeerInfo` |
340 | * @return #GNUNET_OK (continue to iterate) | 375 | * @return #GNUNET_OK (continue to iterate) |
341 | */ | 376 | */ |
342 | static int | 377 | static int |
343 | free_paths (void *cls, | 378 | free_paths (void *cts, |
344 | const struct GNUNET_PeerIdentity *key, | 379 | const struct GNUNET_PeerIdentity *key, |
345 | void *value) | 380 | void *value) |
346 | { | 381 | { |
@@ -358,6 +393,7 @@ free_paths (void *cls, | |||
358 | pa->tos = NULL; | 393 | pa->tos = NULL; |
359 | } | 394 | } |
360 | gtk_tree_row_reference_free (pa->rr); | 395 | gtk_tree_row_reference_free (pa->rr); |
396 | GNUNET_free_non_null (pa->plugin); | ||
361 | GNUNET_free (pa); | 397 | GNUNET_free (pa); |
362 | } | 398 | } |
363 | gtk_tree_row_reference_free (info->rr); | 399 | gtk_tree_row_reference_free (info->rr); |
@@ -369,11 +405,11 @@ free_paths (void *cls, | |||
369 | /** | 405 | /** |
370 | * Task run on shutdown. | 406 | * Task run on shutdown. |
371 | * | 407 | * |
372 | * @param cls unused | 408 | * @param cts unused |
373 | * @param tc scheduler context, unused | 409 | * @param tc scheduler context, unused |
374 | */ | 410 | */ |
375 | static void | 411 | static void |
376 | shutdown_task (void *cls, | 412 | shutdown_task (void *cts, |
377 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 413 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
378 | { | 414 | { |
379 | GNUNET_GTK_tray_icon_destroy (); | 415 | GNUNET_GTK_tray_icon_destroy (); |
@@ -412,18 +448,36 @@ shutdown_task (void *cls, | |||
412 | 448 | ||
413 | 449 | ||
414 | /** | 450 | /** |
451 | * Convert a row reference to an iter. | ||
452 | * | ||
453 | * @param rr reference to a row (in our #ts) | ||
454 | * @param iter set to the iter corresponding to @a rr | ||
455 | */ | ||
456 | static void | ||
457 | get_iter_from_rr (GtkTreeRowReference *rr, | ||
458 | GtkTreeIter *iter) | ||
459 | { | ||
460 | GtkTreePath *path; | ||
461 | |||
462 | path = gtk_tree_row_reference_get_path (rr); | ||
463 | GNUNET_assert (NULL != path); | ||
464 | GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), iter, path)); | ||
465 | gtk_tree_path_free (path); | ||
466 | } | ||
467 | |||
468 | |||
469 | /** | ||
415 | * Function to call with the text format of an address | 470 | * Function to call with the text format of an address |
416 | * | 471 | * |
417 | * @param cls the `struct PeerAddress` for the address | 472 | * @param cts the `struct PeerAddress` for the address |
418 | * @param address address as a string, NULL on error | 473 | * @param address address as a string, NULL on error |
419 | */ | 474 | */ |
420 | static void | 475 | static void |
421 | peer_address_string_cb (void *cls, | 476 | peer_address_string_cb (void *cts, |
422 | const char *address) | 477 | const char *address) |
423 | { | 478 | { |
424 | struct PeerAddress *pa = cls; | 479 | struct PeerAddress *pa = cts; |
425 | GtkTreeIter iter; | 480 | GtkTreeIter iter; |
426 | GtkTreePath *path; | ||
427 | char *country; | 481 | char *country; |
428 | const char *colon; | 482 | const char *colon; |
429 | const char *dot; | 483 | const char *dot; |
@@ -433,10 +487,7 @@ peer_address_string_cb (void *cls, | |||
433 | pa->tos = NULL; | 487 | pa->tos = NULL; |
434 | return; | 488 | return; |
435 | } | 489 | } |
436 | path = gtk_tree_row_reference_get_path (pa->rr); | 490 | get_iter_from_rr (pa->rr, &iter); |
437 | GNUNET_assert (NULL != path); | ||
438 | GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (ls), &iter, path)); | ||
439 | gtk_tree_path_free (path); | ||
440 | country = NULL; | 491 | country = NULL; |
441 | colon = strstr (address, ":"); | 492 | colon = strstr (address, ":"); |
442 | if (NULL != colon) | 493 | if (NULL != colon) |
@@ -447,7 +498,7 @@ peer_address_string_cb (void *cls, | |||
447 | if ('.' == *dot) | 498 | if ('.' == *dot) |
448 | country = GNUNET_strndup (&dot[1], (colon - dot) - 1); | 499 | country = GNUNET_strndup (&dot[1], (colon - dot) - 1); |
449 | } | 500 | } |
450 | gtk_list_store_set (ls, &iter, | 501 | gtk_tree_store_set (ts, &iter, |
451 | PEERINFO_MC_COUNTRY_NAME, country, | 502 | PEERINFO_MC_COUNTRY_NAME, country, |
452 | PEERINFO_MC_COUNTRY_FLAG, GNUNET_PEERINFO_GTK_get_flag (country), | 503 | PEERINFO_MC_COUNTRY_FLAG, GNUNET_PEERINFO_GTK_get_flag (country), |
453 | PEERINFO_MC_ADDRESS_AS_STRING, address, | 504 | PEERINFO_MC_ADDRESS_AS_STRING, address, |
@@ -456,100 +507,154 @@ peer_address_string_cb (void *cls, | |||
456 | } | 507 | } |
457 | 508 | ||
458 | 509 | ||
510 | |||
511 | /** | ||
512 | * Obtain the address entry for the given address at the given | ||
513 | * peer. If the address entry does not yet exist, create it. | ||
514 | * | ||
515 | * @param pi peer info of the peer | ||
516 | * @param addr peer's address | ||
517 | * @return address entry for the given address | ||
518 | */ | ||
519 | static struct PeerAddress * | ||
520 | get_address (struct PeerInfo *pi, | ||
521 | const struct GNUNET_HELLO_Address *addr) | ||
522 | { | ||
523 | static struct PeerAddress *pa; | ||
524 | GtkTreeIter iter; | ||
525 | GtkTreeIter aiter; | ||
526 | GtkTreePath *path; | ||
527 | |||
528 | for (pa = pi->pa_head; NULL != pa; pa = pa->next) | ||
529 | if ( (addr->address_length == pa->addr_len) && | ||
530 | (0 == memcmp (addr, | ||
531 | pa->addr, | ||
532 | addr->address_length)) && | ||
533 | (0 == strcmp (addr->transport_name, | ||
534 | pa->plugin)) ) | ||
535 | return pa; | ||
536 | pa = GNUNET_malloc (sizeof (struct PeerAddress) + addr->address_length); | ||
537 | pa->plugin = GNUNET_strdup (addr->transport_name); | ||
538 | pa->addr = &pa[1]; | ||
539 | memcpy (&pa[1], addr->address, addr->address_length); | ||
540 | pa->addr_len = addr->address_length; | ||
541 | GNUNET_CONTAINER_DLL_insert (pi->pa_head, | ||
542 | pi->pa_tail, | ||
543 | pa); | ||
544 | path = gtk_tree_row_reference_get_path (pi->rr); | ||
545 | GNUNET_assert (NULL != path); | ||
546 | GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &iter, path)); | ||
547 | gtk_tree_path_free (path); | ||
548 | gtk_tree_store_append (ts, &aiter, &iter); | ||
549 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), &aiter); | ||
550 | pa->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), path); | ||
551 | GNUNET_assert (NULL != pa->rr); | ||
552 | gtk_tree_path_free (path); | ||
553 | pa->tos = GNUNET_TRANSPORT_address_to_string (get_configuration (), addr, | ||
554 | GNUNET_NO, | ||
555 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
556 | &peer_address_string_cb, pa); | ||
557 | |||
558 | return pa; | ||
559 | } | ||
560 | |||
561 | |||
459 | /** | 562 | /** |
460 | * Function to call with a binary format of an address | 563 | * Function to call with a binary format of an address |
461 | * | 564 | * |
462 | * @param cls the `struct PeerInfo` for which this is a valid address | 565 | * @param cts the `struct PeerInfo` for which this is a valid address |
463 | * @param peer peer the update is about | 566 | * @param address an address of the peer |
464 | * @param address NULL on disconnect, otherwise 0-terminated printable UTF-8 string | 567 | * @param expiration expiration time for that address |
568 | * @return #GNUNET_OK (keep iterating) | ||
465 | */ | 569 | */ |
466 | static void | 570 | static int |
467 | peer_address_cb (void *cls, | 571 | peer_address_cb (void *cts, |
468 | const struct GNUNET_PeerIdentity *peer, | 572 | const struct GNUNET_HELLO_Address *address, |
469 | const struct GNUNET_HELLO_Address *address) | 573 | struct GNUNET_TIME_Absolute expiration) |
470 | { | 574 | { |
471 | struct PeerInfo *info = cls; | 575 | struct PeerInfo *info = cts; |
472 | struct PeerAddress *pa; | 576 | struct PeerAddress *pa; |
473 | GtkTreeIter iter; | 577 | GtkTreeIter iter; |
474 | GtkTreePath *path; | 578 | GtkTreePath *path; |
475 | 579 | ||
476 | path = gtk_tree_row_reference_get_path (info->rr); | 580 | path = gtk_tree_row_reference_get_path (info->rr); |
477 | GNUNET_assert (NULL != path); | 581 | GNUNET_assert (NULL != path); |
478 | GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (ls), &iter, path)); | 582 | GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &iter, path)); |
479 | gtk_tree_path_free (path); | 583 | gtk_tree_path_free (path); |
480 | if (NULL == address) | 584 | pa = get_address (info, address); |
481 | { | 585 | get_iter_from_rr (pa->rr, &iter); |
482 | /* disconnect */ | 586 | gtk_tree_store_set (ts, &iter, |
483 | gtk_list_store_set (ls, &iter, | 587 | PEERINFO_MC_PEERINFO_ADDRESS_EXPIRATION, GNUNET_STRINGS_absolute_time_to_string (expiration), |
484 | // PEERINFO_MC_CONNECTIVITY_LED, led_red, | 588 | -1); |
485 | // PEERINFO_MC_CONNECTED_STATUS, FALSE, | 589 | return GNUNET_OK; |
486 | -1); | 590 | } |
487 | return; | 591 | |
488 | } | 592 | |
489 | gtk_list_store_set (ls, &iter, | 593 | /** |
490 | // PEERINFO_MC_CONNECTIVITY_LED, led_green, | 594 | * Obtain the `struct PeerInfo` for the given peer; if it does |
491 | // PEERINFO_MC_CONNECTED_STATUS, TRUE, | 595 | * not yet exist, add it. |
492 | -1); | 596 | * |
493 | #if 0 | 597 | * @param peer peer identity to get the `struct PeerInfo` for |
494 | if (NULL != info->tos) | 598 | * @return the corresponding struct |
495 | GNUNET_TRANSPORT_address_to_string_cancel (info->tos); | 599 | */ |
496 | pa->tos = | 600 | static struct PeerInfo * |
497 | GNUNET_TRANSPORT_address_to_string (get_configuration (), address, | 601 | get_peer_info (const struct GNUNET_PeerIdentity *peer) |
498 | GNUNET_NO, | 602 | { |
499 | GNUNET_TIME_UNIT_FOREVER_REL, | 603 | GtkTreeIter iter; |
500 | &peer_address_string_cb, pa); | 604 | GtkTreePath *path; |
501 | #endif | 605 | struct PeerInfo *info; |
606 | |||
607 | info = GNUNET_CONTAINER_multipeermap_get (peer2info, peer); | ||
608 | if (NULL != info) | ||
609 | return info; | ||
610 | info = GNUNET_new (struct PeerInfo); | ||
611 | info->pid = *peer; | ||
612 | gtk_tree_store_append (ts, &iter, NULL); | ||
613 | gtk_tree_store_set (ts, &iter, | ||
614 | PEERINFO_MC_PEER_IDENTITY_STRING, GNUNET_i2s (peer), | ||
615 | PEERINFO_MC_IS_FRIEND, GNUNET_CONTAINER_multipeermap_contains (friends, | ||
616 | peer), | ||
617 | PEERINFO_MC_PEERINFO, info, | ||
618 | PEERINFO_MC_SHOW_FRIEND, TRUE, | ||
619 | PEERINFO_MC_CORE_CONNECTIVITY_LED, led_red, | ||
620 | -1); | ||
621 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), &iter); | ||
622 | info->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), path); | ||
623 | GNUNET_assert (NULL != info->rr); | ||
624 | gtk_tree_path_free (path); | ||
625 | GNUNET_assert (GNUNET_OK == | ||
626 | GNUNET_CONTAINER_multipeermap_put (peer2info, peer, info, | ||
627 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
628 | return info; | ||
502 | } | 629 | } |
503 | 630 | ||
504 | 631 | ||
505 | /** | 632 | /** |
506 | * Function called for peers that we know about. | 633 | * Function called for peers that we know about. |
507 | * | 634 | * |
508 | * @param cls closure | 635 | * @param cts closure |
509 | * @param peer id of the peer, NULL for last call | 636 | * @param peer id of the peer, NULL for last call |
510 | * @param hello hello message for the peer (can be NULL) | 637 | * @param hello hello message for the peer (can be NULL) |
511 | * @param err_msg NULL if successful, otherwise contains error message | 638 | * @param err_msg NULL if successful, otherwise contains error message |
512 | */ | 639 | */ |
513 | static void | 640 | static void |
514 | peerinfo_processor (void *cls, | 641 | peerinfo_processor (void *cts, |
515 | const struct GNUNET_PeerIdentity *peer, | 642 | const struct GNUNET_PeerIdentity *peer, |
516 | const struct GNUNET_HELLO_Message *hello, | 643 | const struct GNUNET_HELLO_Message *hello, |
517 | const char *err_msg) | 644 | const char *err_msg) |
518 | { | 645 | { |
519 | GtkTreeIter iter; | ||
520 | struct PeerInfo *info; | 646 | struct PeerInfo *info; |
521 | GtkTreePath *path; | ||
522 | 647 | ||
523 | info = GNUNET_CONTAINER_multipeermap_get (peer2info, peer); | 648 | info = get_peer_info (peer); |
524 | if (NULL == info) | 649 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, |
525 | { | 650 | &peer_address_cb, info); |
526 | info = GNUNET_new (struct PeerInfo); | ||
527 | info->pid = *peer; | ||
528 | gtk_list_store_append (ls, &iter); | ||
529 | gtk_list_store_set (ls, &iter, | ||
530 | PEERINFO_MC_PEER_IDENTITY_STRING, GNUNET_i2s (peer), | ||
531 | PEERINFO_MC_COUNTRY_NAME, "", | ||
532 | PEERINFO_MC_COUNTRY_FLAG, NULL, | ||
533 | PEERINFO_MC_BANDWIDTH_IN, (guint) 0, | ||
534 | PEERINFO_MC_BANDWIDTH_OUT, (guint) 0, | ||
535 | PEERINFO_MC_IS_FRIEND, GNUNET_CONTAINER_multipeermap_contains (friends, | ||
536 | peer), | ||
537 | PEERINFO_MC_PEERINFO, info, | ||
538 | -1); | ||
539 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (ls), &iter); | ||
540 | info->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ls), path); | ||
541 | GNUNET_assert (NULL != info->rr); | ||
542 | gtk_tree_path_free (path); | ||
543 | GNUNET_CONTAINER_multipeermap_put (peer2info, peer, info, | ||
544 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
545 | } | ||
546 | } | 651 | } |
547 | 652 | ||
548 | 653 | ||
549 | /** | 654 | /** |
550 | * Method called whenever a given peer has a QoS status change. | 655 | * Method called whenever a given peer has a QoS status change. |
551 | * | 656 | * |
552 | * @param cls closure | 657 | * @param cts closure |
553 | * @param address the address | 658 | * @param address the address |
554 | * @param address_active is this address actively used to maintain a connection | 659 | * @param address_active is this address actively used to maintain a connection |
555 | * to a peer | 660 | * to a peer |
@@ -559,7 +664,7 @@ peerinfo_processor (void *cls, | |||
559 | * @param ats_count number of performance records in @a ats | 664 | * @param ats_count number of performance records in @a ats |
560 | */ | 665 | */ |
561 | static void | 666 | static void |
562 | status_cb (void *cls, | 667 | status_cb (void *cts, |
563 | const struct GNUNET_HELLO_Address *address, | 668 | const struct GNUNET_HELLO_Address *address, |
564 | int address_active, | 669 | int address_active, |
565 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 670 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
@@ -568,45 +673,262 @@ status_cb (void *cls, | |||
568 | uint32_t ats_count) | 673 | uint32_t ats_count) |
569 | { | 674 | { |
570 | struct PeerInfo *info; | 675 | struct PeerInfo *info; |
676 | struct PeerAddress *pa; | ||
677 | struct PeerAddress *act; | ||
571 | GtkTreeIter iter; | 678 | GtkTreeIter iter; |
572 | GtkTreePath *path; | ||
573 | 679 | ||
574 | if (0 == address_active) | 680 | info = get_peer_info (&address->peer); |
681 | pa = get_address (info, address); | ||
682 | pa->address_ats_active = address_active; | ||
683 | pa->ats_in = (guint) ntohl (bandwidth_in.value__); | ||
684 | pa->ats_out = (guint) ntohl (bandwidth_out.value__); | ||
685 | get_iter_from_rr (pa->rr, &iter); | ||
686 | gtk_tree_store_set (ts, &iter, | ||
687 | PEERINFO_MC_ATS_CONNECTIVITY_LED, (pa->address_ats_active) ? led_green : led_red, | ||
688 | PEERINFO_MC_ATS_SELECTED_STATUS, pa->address_ats_active, | ||
689 | PEERINFO_MC_BANDWIDTH_IN, pa->ats_in, | ||
690 | PEERINFO_MC_BANDWIDTH_OUT, pa->ats_out, | ||
691 | -1); | ||
692 | act = NULL; | ||
693 | for (pa = info->pa_head; NULL != pa; pa = pa->next) | ||
694 | if (pa->address_ats_active) | ||
695 | { | ||
696 | GNUNET_break (NULL == act); | ||
697 | act = pa; | ||
698 | } | ||
699 | get_iter_from_rr (info->rr, &iter); | ||
700 | if (NULL == act) | ||
701 | { | ||
702 | gtk_tree_store_set (ts, &iter, | ||
703 | PEERINFO_MC_ATS_CONNECTIVITY_LED, led_red, | ||
704 | PEERINFO_MC_ATS_SELECTED_STATUS, FALSE, | ||
705 | PEERINFO_MC_BANDWIDTH_IN, (guint) 0, | ||
706 | PEERINFO_MC_BANDWIDTH_OUT, (guint) 0, | ||
707 | -1); | ||
708 | } | ||
709 | else | ||
710 | { | ||
711 | gtk_tree_store_set (ts, &iter, | ||
712 | PEERINFO_MC_ATS_CONNECTIVITY_LED, led_green, | ||
713 | PEERINFO_MC_ATS_SELECTED_STATUS, TRUE, | ||
714 | PEERINFO_MC_BANDWIDTH_IN, act->ats_in, | ||
715 | PEERINFO_MC_BANDWIDTH_OUT, act->ats_out, | ||
716 | -1); | ||
717 | } | ||
718 | } | ||
719 | |||
720 | |||
721 | /** | ||
722 | * Function to call with information about a peer | ||
723 | * | ||
724 | * @param cts closure | ||
725 | * @param peer peer this update is about, | ||
726 | * NULL if this is the final last callback for a iteration operation | ||
727 | * @param address address, NULL for disconnect notification in monitor mode | ||
728 | * @param state current state this peer is in | ||
729 | * @param state_timeout timeout for the current state of the peer | ||
730 | */ | ||
731 | static void | ||
732 | transport_peer_cb (void *cts, | ||
733 | const struct GNUNET_PeerIdentity *peer, | ||
734 | const struct GNUNET_HELLO_Address *address, | ||
735 | enum GNUNET_TRANSPORT_PeerState state, | ||
736 | struct GNUNET_TIME_Absolute state_timeout) | ||
737 | { | ||
738 | struct PeerInfo *info; | ||
739 | struct PeerAddress *pa; | ||
740 | struct PeerAddress *act; | ||
741 | struct PeerAddress *pre; | ||
742 | GtkTreeIter iter; | ||
743 | gboolean con; | ||
744 | const char *tos; | ||
745 | |||
746 | info = get_peer_info (peer); | ||
747 | if (NULL == address) | ||
748 | { | ||
749 | GNUNET_break (0); | ||
575 | return; | 750 | return; |
576 | info = GNUNET_CONTAINER_multipeermap_get (peer2info, &address->peer); | 751 | } |
577 | if (NULL == info) | 752 | pa = get_address (info, address); |
753 | pa->state = state; | ||
754 | pa->state_timeout = state_timeout; | ||
755 | con = (GNUNET_YES == GNUNET_TRANSPORT_is_connected (state)); | ||
756 | get_iter_from_rr (pa->rr, &iter); | ||
757 | tos = GNUNET_STRINGS_absolute_time_to_string (state_timeout); | ||
758 | gtk_tree_store_set (ts, &iter, | ||
759 | PEERINFO_MC_NEIGHBOUR_CONNECTED_STATUS, con, | ||
760 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_TIMEOUT_AS_STRING, con ? tos : NULL, | ||
761 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_LED, (con ? led_green : led_red), | ||
762 | PEERINFO_MC_NEIGHBOUR_STATE_AS_STRING, GNUNET_TRANSPORT_p2s (state), | ||
763 | PEERINFO_MC_NEIGHBOUR_STATE_TIMEOUT_AS_STRING, tos, | ||
764 | -1); | ||
765 | act = NULL; | ||
766 | pre = NULL; | ||
767 | for (pa = info->pa_head; NULL != pa; pa = pa->next) | ||
578 | { | 768 | { |
579 | /* should rarely happen... */ | 769 | if (GNUNET_YES == GNUNET_TRANSPORT_is_connected (pa->state)) |
580 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 770 | { |
581 | "Entry for peer %s not found\n", | 771 | GNUNET_break (NULL == act); |
582 | GNUNET_i2s (&address->peer)); | 772 | act = pa; |
773 | } | ||
774 | else if (GNUNET_TRANSPORT_DISCONNECT_FINISHED != pa->state) | ||
775 | { | ||
776 | /* remember that we're at least still in the neighbours table */ | ||
777 | pre = pa; | ||
778 | } | ||
779 | } | ||
780 | |||
781 | get_iter_from_rr (info->rr, &iter); | ||
782 | if (NULL == act) | ||
783 | { | ||
784 | if (NULL == pre) | ||
785 | { | ||
786 | /* peer is not even in neighbours table; remove the LED entirely */ | ||
787 | gtk_tree_store_set (ts, &iter, | ||
788 | PEERINFO_MC_NEIGHBOUR_CONNECTED_STATUS, FALSE, | ||
789 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_TIMEOUT_AS_STRING, NULL, | ||
790 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_LED, NULL, | ||
791 | PEERINFO_MC_NEIGHBOUR_STATE_AS_STRING, NULL, | ||
792 | PEERINFO_MC_NEIGHBOUR_STATE_TIMEOUT_AS_STRING, NULL, | ||
793 | -1); | ||
794 | } | ||
795 | else | ||
796 | { | ||
797 | /* mark peer as down with red LED */ | ||
798 | gtk_tree_store_set (ts, &iter, | ||
799 | PEERINFO_MC_NEIGHBOUR_CONNECTED_STATUS, FALSE, | ||
800 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_TIMEOUT_AS_STRING, NULL, | ||
801 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_LED, led_red, | ||
802 | PEERINFO_MC_NEIGHBOUR_STATE_AS_STRING, NULL, | ||
803 | PEERINFO_MC_NEIGHBOUR_STATE_TIMEOUT_AS_STRING, NULL, | ||
804 | -1); | ||
805 | } | ||
806 | } | ||
807 | else | ||
808 | { | ||
809 | /* mark peer as up, show details on top-level */ | ||
810 | tos = GNUNET_STRINGS_absolute_time_to_string (state_timeout); | ||
811 | gtk_tree_store_set (ts, &iter, | ||
812 | PEERINFO_MC_NEIGHBOUR_CONNECTED_STATUS, TRUE, | ||
813 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_TIMEOUT_AS_STRING, tos, | ||
814 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_LED, led_green, | ||
815 | PEERINFO_MC_NEIGHBOUR_STATE_AS_STRING, GNUNET_TRANSPORT_p2s (act->state), | ||
816 | PEERINFO_MC_NEIGHBOUR_STATE_TIMEOUT_AS_STRING, tos, | ||
817 | -1); | ||
818 | } | ||
819 | } | ||
820 | |||
821 | |||
822 | /** | ||
823 | * Function to call with validation information about a peer | ||
824 | * | ||
825 | * @param cts closure | ||
826 | * @param peer peer this update is about, | ||
827 | * NULL if this is the final last callback for a iteration operation | ||
828 | * @param address address, NULL for disconnect notification in monitor mode | ||
829 | * @param valid_until when does this address expire | ||
830 | * @param next_validation time of the next validation operation | ||
831 | * | ||
832 | */ | ||
833 | static void | ||
834 | validation_monitor_cb (void *cts, | ||
835 | const struct GNUNET_PeerIdentity *peer, | ||
836 | const struct GNUNET_HELLO_Address *address, | ||
837 | struct GNUNET_TIME_Absolute valid_until, | ||
838 | struct GNUNET_TIME_Absolute next_validation) | ||
839 | { | ||
840 | struct PeerInfo *info; | ||
841 | struct PeerAddress *pa; | ||
842 | GtkTreeIter iter; | ||
843 | const char *tos; | ||
844 | gboolean valid; | ||
845 | |||
846 | GNUNET_assert (NULL != peer); | ||
847 | info = get_peer_info (peer); | ||
848 | if (NULL == address) | ||
849 | { | ||
850 | /* disconnect, mark all as down */ | ||
851 | for (pa = info->pa_head; NULL != pa; pa = pa->next) | ||
852 | { | ||
853 | get_iter_from_rr (pa->rr, &iter); | ||
854 | gtk_tree_store_set (ts, &iter, | ||
855 | PEERINFO_MC_VALIDATION_IS_VALID, FALSE, | ||
856 | PEERINFO_MC_VALIDATION_TIMEOUT_AS_STRING, NULL, | ||
857 | PEERINFO_MC_VALIDATION_STATE_LED, NULL, | ||
858 | -1); | ||
859 | } | ||
583 | return; | 860 | return; |
584 | } | 861 | } |
585 | path = gtk_tree_row_reference_get_path (info->rr); | 862 | valid = GNUNET_TIME_absolute_get_remaining (valid_until).rel_value_us > 0; |
586 | GNUNET_assert (NULL != path); | 863 | pa = get_address (info, address); |
587 | GNUNET_assert (TRUE == gtk_tree_model_get_iter (GTK_TREE_MODEL (ls), &iter, path)); | 864 | get_iter_from_rr (pa->rr, &iter); |
588 | gtk_tree_path_free (path); | 865 | tos = GNUNET_STRINGS_absolute_time_to_string (valid_until); |
589 | gtk_list_store_set (ls, &iter, | 866 | gtk_tree_store_set (ts, &iter, |
590 | PEERINFO_MC_BANDWIDTH_IN, (guint) ntohl (bandwidth_in.value__), | 867 | PEERINFO_MC_VALIDATION_IS_VALID, valid, |
591 | PEERINFO_MC_BANDWIDTH_OUT, (guint) ntohl (bandwidth_out.value__), | 868 | PEERINFO_MC_VALIDATION_TIMEOUT_AS_STRING, tos, |
592 | -1); | 869 | PEERINFO_MC_VALIDATION_STATE_LED, (valid ? led_green : led_red), |
870 | -1); | ||
871 | } | ||
872 | |||
873 | |||
874 | /** | ||
875 | * Method called whenever a given peer connects. | ||
876 | * | ||
877 | * @param cts closure | ||
878 | * @param peer peer identity this notification is about | ||
879 | */ | ||
880 | static void | ||
881 | handle_core_connect (void *cts, | ||
882 | const struct GNUNET_PeerIdentity *peer) | ||
883 | { | ||
884 | struct PeerInfo *info; | ||
885 | GtkTreeIter iter; | ||
886 | |||
887 | info = get_peer_info (peer); | ||
888 | get_iter_from_rr (info->rr, &iter); | ||
889 | gtk_tree_store_set (ts, &iter, | ||
890 | PEERINFO_MC_CORE_CONNECTIVITY_LED, led_green, | ||
891 | PEERINFO_MC_CORE_CONNECTED_STATUS, TRUE, | ||
892 | -1); | ||
893 | } | ||
894 | |||
895 | |||
896 | /** | ||
897 | * Method called whenever a peer disconnects. | ||
898 | * | ||
899 | * @param cts closure | ||
900 | * @param peer peer identity this notification is about | ||
901 | */ | ||
902 | static void | ||
903 | handle_core_disconnect (void *cts, | ||
904 | const struct GNUNET_PeerIdentity *peer) | ||
905 | { | ||
906 | struct PeerInfo *info; | ||
907 | GtkTreeIter iter; | ||
908 | |||
909 | info = get_peer_info (peer); | ||
910 | get_iter_from_rr (info->rr, &iter); | ||
911 | gtk_tree_store_set (ts, &iter, | ||
912 | PEERINFO_MC_CORE_CONNECTIVITY_LED, led_red, | ||
913 | PEERINFO_MC_CORE_CONNECTED_STATUS, FALSE, | ||
914 | -1); | ||
593 | } | 915 | } |
594 | 916 | ||
595 | 917 | ||
596 | /** | 918 | /** |
597 | * Write a friend to the friends file. | 919 | * Write a friend to the friends file. |
598 | * | 920 | * |
599 | * @param cls the `struct GNUNET_FRIENDS_Writer` | 921 | * @param cts the `struct GNUNET_FRIENDS_Writer` |
600 | * @param friend friend to write to file | 922 | * @param friend friend to write to file |
601 | * @param value unused | 923 | * @param value unused |
602 | * @return #GNUNET_OK if the writing succeeded | 924 | * @return #GNUNET_OK if the writing succeeded |
603 | */ | 925 | */ |
604 | static int | 926 | static int |
605 | write_friend (void *cls, | 927 | write_friend (void *cts, |
606 | const struct GNUNET_PeerIdentity *friend, | 928 | const struct GNUNET_PeerIdentity *friend, |
607 | void *value) | 929 | void *value) |
608 | { | 930 | { |
609 | struct GNUNET_FRIENDS_Writer *w = cls; | 931 | struct GNUNET_FRIENDS_Writer *w = cts; |
610 | 932 | ||
611 | return GNUNET_FRIENDS_write (w, friend); | 933 | return GNUNET_FRIENDS_write (w, friend); |
612 | } | 934 | } |
@@ -651,27 +973,20 @@ GNUNET_PEERINFO_GTK_main_window_friends_cellrenderertoggle_toggled_cb (GtkCellRe | |||
651 | gchar *path, | 973 | gchar *path, |
652 | gpointer user_data) | 974 | gpointer user_data) |
653 | { | 975 | { |
654 | GtkListStore *ls; | ||
655 | GtkTreeIter old; | 976 | GtkTreeIter old; |
656 | struct PeerInfo *info; | 977 | struct PeerInfo *info; |
657 | gboolean oldvalue; | 978 | gboolean oldvalue; |
658 | 979 | ||
659 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); | 980 | if (! gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (ts), &old, path)) |
660 | if (NULL == ls) | ||
661 | { | 981 | { |
662 | GNUNET_break (0); | 982 | GNUNET_break (0); |
663 | return; | 983 | return; |
664 | } | 984 | } |
665 | if (! gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (ls), &old, path)) | 985 | gtk_tree_model_get (GTK_TREE_MODEL (ts), &old, |
666 | { | ||
667 | GNUNET_break (0); | ||
668 | return; | ||
669 | } | ||
670 | gtk_tree_model_get (GTK_TREE_MODEL (ls), &old, | ||
671 | PEERINFO_MC_PEERINFO, &info, | 986 | PEERINFO_MC_PEERINFO, &info, |
672 | PEERINFO_MC_IS_FRIEND, &oldvalue, | 987 | PEERINFO_MC_IS_FRIEND, &oldvalue, |
673 | -1); | 988 | -1); |
674 | gtk_list_store_set (ls, &old, | 989 | gtk_tree_store_set (ts, &old, |
675 | PEERINFO_MC_IS_FRIEND, ! oldvalue, | 990 | PEERINFO_MC_IS_FRIEND, ! oldvalue, |
676 | -1); | 991 | -1); |
677 | if (oldvalue) | 992 | if (oldvalue) |
@@ -732,11 +1047,11 @@ load_led (const char *color) | |||
732 | /** | 1047 | /** |
733 | * Add a friend to our friends peer map. | 1048 | * Add a friend to our friends peer map. |
734 | * | 1049 | * |
735 | * @param cls NULL | 1050 | * @param cts NULL |
736 | * @param friend the friend to add | 1051 | * @param friend the friend to add |
737 | */ | 1052 | */ |
738 | static void | 1053 | static void |
739 | add_friend (void *cls, | 1054 | add_friend (void *cts, |
740 | const struct GNUNET_PeerIdentity *friend) | 1055 | const struct GNUNET_PeerIdentity *friend) |
741 | { | 1056 | { |
742 | GNUNET_break (GNUNET_YES == | 1057 | GNUNET_break (GNUNET_YES == |
@@ -748,86 +1063,19 @@ add_friend (void *cls, | |||
748 | 1063 | ||
749 | 1064 | ||
750 | /** | 1065 | /** |
751 | * Function to call with information about a peer | ||
752 | * | ||
753 | * @param cls closure | ||
754 | * @param peer peer this update is about, | ||
755 | * NULL if this is the final last callback for a iteration operation | ||
756 | * @param address address, NULL for disconnect notification in monitor mode | ||
757 | * @param state current state this peer is in | ||
758 | * @param state_timeout timeout for the current state of the peer | ||
759 | */ | ||
760 | static void | ||
761 | transport_peer_cb (void *cls, | ||
762 | const struct GNUNET_PeerIdentity *peer, | ||
763 | const struct GNUNET_HELLO_Address *address, | ||
764 | enum GNUNET_TRANSPORT_PeerState state, | ||
765 | struct GNUNET_TIME_Absolute state_timeout) | ||
766 | { | ||
767 | } | ||
768 | |||
769 | |||
770 | /** | ||
771 | * Function to call with validation information about a peer | ||
772 | * | ||
773 | * @param cls closure | ||
774 | * @param peer peer this update is about, | ||
775 | * NULL if this is the final last callback for a iteration operation | ||
776 | * @param address address, NULL for disconnect notification in monitor mode | ||
777 | * @param valid_until when does this address expire | ||
778 | * @param next_validation time of the next validation operation | ||
779 | * | ||
780 | */ | ||
781 | static void | ||
782 | validation_monitor_cb (void *cls, | ||
783 | const struct GNUNET_PeerIdentity *peer, | ||
784 | const struct GNUNET_HELLO_Address *address, | ||
785 | struct GNUNET_TIME_Absolute valid_until, | ||
786 | struct GNUNET_TIME_Absolute next_validation) | ||
787 | { | ||
788 | } | ||
789 | |||
790 | |||
791 | /** | ||
792 | * Method called whenever a given peer connects. | ||
793 | * | ||
794 | * @param cls closure | ||
795 | * @param peer peer identity this notification is about | ||
796 | */ | ||
797 | static void | ||
798 | handle_core_connect (void *cls, | ||
799 | const struct GNUNET_PeerIdentity *peer) | ||
800 | { | ||
801 | } | ||
802 | |||
803 | |||
804 | /** | ||
805 | * Method called whenever a peer disconnects. | ||
806 | * | ||
807 | * @param cls closure | ||
808 | * @param peer peer identity this notification is about | ||
809 | */ | ||
810 | static void | ||
811 | handle_core_disconnect (void *cls, | ||
812 | const struct GNUNET_PeerIdentity *peer) | ||
813 | { | ||
814 | } | ||
815 | |||
816 | |||
817 | /** | ||
818 | * Actual main function run right after GNUnet's scheduler | 1066 | * Actual main function run right after GNUnet's scheduler |
819 | * is initialized. Initializes up GTK and Glade. | 1067 | * is initialized. Initializes up GTK and Glade. |
820 | * | 1068 | * |
821 | * @param cls NULL | 1069 | * @param cts NULL |
822 | * @param tc schedule context | 1070 | * @param tc schedule context |
823 | */ | 1071 | */ |
824 | static void | 1072 | static void |
825 | run (void *cls, | 1073 | run (void *cts, |
826 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1074 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
827 | { | 1075 | { |
828 | GtkWidget *main_window; | 1076 | GtkWidget *main_window; |
829 | 1077 | ||
830 | ml = cls; | 1078 | ml = cts; |
831 | if (GNUNET_OK != | 1079 | if (GNUNET_OK != |
832 | GNUNET_GTK_main_loop_build_window (ml, NULL)) | 1080 | GNUNET_GTK_main_loop_build_window (ml, NULL)) |
833 | return; | 1081 | return; |
@@ -866,13 +1114,14 @@ run (void *cls, | |||
866 | GNUNET_TIME_UNIT_FOREVER_REL, | 1114 | GNUNET_TIME_UNIT_FOREVER_REL, |
867 | &validation_monitor_cb, | 1115 | &validation_monitor_cb, |
868 | NULL); | 1116 | NULL); |
869 | ats = GNUNET_ATS_performance_init (get_configuration (), &status_cb, NULL); | 1117 | ats = GNUNET_ATS_performance_init (get_configuration (), |
1118 | &status_cb, NULL); | ||
870 | /* setup main window */ | 1119 | /* setup main window */ |
871 | main_window = GTK_WIDGET (get_object ("GNUNET_PEERINFO_GTK_main_window")); | 1120 | main_window = GTK_WIDGET (get_object ("GNUNET_PEERINFO_GTK_main_window")); |
872 | main_window = GNUNET_GTK_plug_me ("GNUNET_PEERINFO_GTK_PLUG", | 1121 | main_window = GNUNET_GTK_plug_me ("GNUNET_PEERINFO_GTK_PLUG", |
873 | main_window); | 1122 | main_window); |
874 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); | 1123 | ts = GTK_TREE_STORE (get_object ("GNUNET_PEERINFO_GTK_tree_store")); |
875 | GNUNET_assert (NULL != ls); | 1124 | GNUNET_assert (NULL != ts); |
876 | gtk_window_maximize (GTK_WINDOW (main_window)); | 1125 | gtk_window_maximize (GTK_WINDOW (main_window)); |
877 | if (NULL == getenv ("GNUNET_PEERINFO_GTK_PLUG")) | 1126 | if (NULL == getenv ("GNUNET_PEERINFO_GTK_PLUG")) |
878 | GNUNET_GTK_tray_icon_create (ml, | 1127 | GNUNET_GTK_tray_icon_create (ml, |