diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-01-10 08:33:20 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-01-10 08:33:20 +0000 |
commit | 7820c4bb7a6c30c7ed4760769a950181a47a9cf8 (patch) | |
tree | 54d609bf395a999c73e3ab8be33cc58196709210 | |
parent | cd8c843794230fc02907cf75078e48da1d3a6ae9 (diff) | |
download | gnunet-gtk-7820c4bb7a6c30c7ed4760769a950181a47a9cf8.tar.gz gnunet-gtk-7820c4bb7a6c30c7ed4760769a950181a47a9cf8.zip |
misc improvements and fixes to peerinfo GUI
-rw-r--r-- | src/peerinfo/gnunet-peerinfo-gtk.c | 139 |
1 files changed, 73 insertions, 66 deletions
diff --git a/src/peerinfo/gnunet-peerinfo-gtk.c b/src/peerinfo/gnunet-peerinfo-gtk.c index c8704358..e9d5b8e9 100644 --- a/src/peerinfo/gnunet-peerinfo-gtk.c +++ b/src/peerinfo/gnunet-peerinfo-gtk.c | |||
@@ -175,6 +175,11 @@ enum PEERINFO_ModelColumns | |||
175 | 175 | ||
176 | 176 | ||
177 | /** | 177 | /** |
178 | * Information we track for each peer outside of the model. | ||
179 | */ | ||
180 | struct PeerInfo; | ||
181 | |||
182 | /** | ||
178 | * Information about an address of the peer. | 183 | * Information about an address of the peer. |
179 | */ | 184 | */ |
180 | struct PeerAddress | 185 | struct PeerAddress |
@@ -191,6 +196,11 @@ struct PeerAddress | |||
191 | struct PeerAddress *prev; | 196 | struct PeerAddress *prev; |
192 | 197 | ||
193 | /** | 198 | /** |
199 | * Peer this address belongs to. | ||
200 | */ | ||
201 | struct PeerInfo *pi; | ||
202 | |||
203 | /** | ||
194 | * Reference to the peer in the view. | 204 | * Reference to the peer in the view. |
195 | */ | 205 | */ |
196 | GtkTreeRowReference *rr; | 206 | GtkTreeRowReference *rr; |
@@ -211,14 +221,14 @@ struct PeerAddress | |||
211 | char *plugin; | 221 | char *plugin; |
212 | 222 | ||
213 | /** | 223 | /** |
214 | * Timeout for the current state in the state machine. | 224 | * Address in string format. |
215 | */ | 225 | */ |
216 | struct GNUNET_TIME_Absolute state_timeout; | 226 | char *address_as_string; |
217 | 227 | ||
218 | /** | 228 | /** |
219 | * State of this address in the transport state machine. | 229 | * ccTLD. |
220 | */ | 230 | */ |
221 | enum GNUNET_TRANSPORT_PeerState state; | 231 | char *country_name; |
222 | 232 | ||
223 | /** | 233 | /** |
224 | * Number of bytes in @e addr. | 234 | * Number of bytes in @e addr. |
@@ -273,6 +283,16 @@ struct PeerInfo | |||
273 | */ | 283 | */ |
274 | struct PeerAddress *pa_tail; | 284 | struct PeerAddress *pa_tail; |
275 | 285 | ||
286 | /** | ||
287 | * Timeout for the current state in the state machine. | ||
288 | */ | ||
289 | struct GNUNET_TIME_Absolute state_timeout; | ||
290 | |||
291 | /** | ||
292 | * State of this address in the transport state machine. | ||
293 | */ | ||
294 | enum GNUNET_TRANSPORT_PeerState state; | ||
295 | |||
276 | }; | 296 | }; |
277 | 297 | ||
278 | 298 | ||
@@ -394,6 +414,8 @@ free_paths (void *cts, | |||
394 | } | 414 | } |
395 | gtk_tree_row_reference_free (pa->rr); | 415 | gtk_tree_row_reference_free (pa->rr); |
396 | GNUNET_free_non_null (pa->plugin); | 416 | GNUNET_free_non_null (pa->plugin); |
417 | GNUNET_free_non_null (pa->address_as_string); | ||
418 | GNUNET_free_non_null (pa->country_name); | ||
397 | GNUNET_free (pa); | 419 | GNUNET_free (pa); |
398 | } | 420 | } |
399 | gtk_tree_row_reference_free (info->rr); | 421 | gtk_tree_row_reference_free (info->rr); |
@@ -503,7 +525,18 @@ peer_address_string_cb (void *cts, | |||
503 | PEERINFO_MC_COUNTRY_FLAG, GNUNET_PEERINFO_GTK_get_flag (country), | 525 | PEERINFO_MC_COUNTRY_FLAG, GNUNET_PEERINFO_GTK_get_flag (country), |
504 | PEERINFO_MC_ADDRESS_AS_STRING, address, | 526 | PEERINFO_MC_ADDRESS_AS_STRING, address, |
505 | -1); | 527 | -1); |
506 | GNUNET_free_non_null (country); | 528 | if (pa->address_ats_active) |
529 | { | ||
530 | get_iter_from_rr (pa->pi->rr, &iter); | ||
531 | gtk_tree_store_set (ts, &iter, | ||
532 | PEERINFO_MC_COUNTRY_NAME, country, | ||
533 | PEERINFO_MC_COUNTRY_FLAG, GNUNET_PEERINFO_GTK_get_flag (country), | ||
534 | PEERINFO_MC_ADDRESS_AS_STRING, address, | ||
535 | PEERINFO_MC_PLUGIN_NAME, pa->plugin, | ||
536 | -1); | ||
537 | } | ||
538 | pa->address_as_string = GNUNET_strdup (address); | ||
539 | pa->country_name = country; | ||
507 | } | 540 | } |
508 | 541 | ||
509 | 542 | ||
@@ -536,6 +569,7 @@ get_address (struct PeerInfo *pi, | |||
536 | pa = GNUNET_malloc (sizeof (struct PeerAddress) + addr->address_length); | 569 | pa = GNUNET_malloc (sizeof (struct PeerAddress) + addr->address_length); |
537 | pa->plugin = GNUNET_strdup (addr->transport_name); | 570 | pa->plugin = GNUNET_strdup (addr->transport_name); |
538 | pa->addr = &pa[1]; | 571 | pa->addr = &pa[1]; |
572 | pa->pi = pi; | ||
539 | memcpy (&pa[1], addr->address, addr->address_length); | 573 | memcpy (&pa[1], addr->address, addr->address_length); |
540 | pa->addr_len = addr->address_length; | 574 | pa->addr_len = addr->address_length; |
541 | GNUNET_CONTAINER_DLL_insert (pi->pa_head, | 575 | GNUNET_CONTAINER_DLL_insert (pi->pa_head, |
@@ -546,6 +580,9 @@ get_address (struct PeerInfo *pi, | |||
546 | GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &iter, path)); | 580 | GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &iter, path)); |
547 | gtk_tree_path_free (path); | 581 | gtk_tree_path_free (path); |
548 | gtk_tree_store_append (ts, &aiter, &iter); | 582 | gtk_tree_store_append (ts, &aiter, &iter); |
583 | gtk_tree_store_set (ts, &iter, | ||
584 | PEERINFO_MC_PLUGIN_NAME, addr->transport_name, | ||
585 | -1); | ||
549 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), &aiter); | 586 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), &aiter); |
550 | pa->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), path); | 587 | pa->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), path); |
551 | GNUNET_assert (NULL != pa->rr); | 588 | GNUNET_assert (NULL != pa->rr); |
@@ -646,6 +683,8 @@ peerinfo_processor (void *cts, | |||
646 | struct PeerInfo *info; | 683 | struct PeerInfo *info; |
647 | 684 | ||
648 | info = get_peer_info (peer); | 685 | info = get_peer_info (peer); |
686 | if (NULL == hello) | ||
687 | return; | ||
649 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, | 688 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, |
650 | &peer_address_cb, info); | 689 | &peer_address_cb, info); |
651 | } | 690 | } |
@@ -704,6 +743,10 @@ status_cb (void *cts, | |||
704 | PEERINFO_MC_ATS_SELECTED_STATUS, FALSE, | 743 | PEERINFO_MC_ATS_SELECTED_STATUS, FALSE, |
705 | PEERINFO_MC_BANDWIDTH_IN, (guint) 0, | 744 | PEERINFO_MC_BANDWIDTH_IN, (guint) 0, |
706 | PEERINFO_MC_BANDWIDTH_OUT, (guint) 0, | 745 | PEERINFO_MC_BANDWIDTH_OUT, (guint) 0, |
746 | PEERINFO_MC_COUNTRY_NAME, NULL, | ||
747 | PEERINFO_MC_COUNTRY_FLAG, NULL, | ||
748 | PEERINFO_MC_ADDRESS_AS_STRING, NULL, | ||
749 | PEERINFO_MC_PLUGIN_NAME, NULL, | ||
707 | -1); | 750 | -1); |
708 | } | 751 | } |
709 | else | 752 | else |
@@ -713,6 +756,10 @@ status_cb (void *cts, | |||
713 | PEERINFO_MC_ATS_SELECTED_STATUS, TRUE, | 756 | PEERINFO_MC_ATS_SELECTED_STATUS, TRUE, |
714 | PEERINFO_MC_BANDWIDTH_IN, act->ats_in, | 757 | PEERINFO_MC_BANDWIDTH_IN, act->ats_in, |
715 | PEERINFO_MC_BANDWIDTH_OUT, act->ats_out, | 758 | PEERINFO_MC_BANDWIDTH_OUT, act->ats_out, |
759 | PEERINFO_MC_COUNTRY_NAME, act->country_name, | ||
760 | PEERINFO_MC_COUNTRY_FLAG, GNUNET_PEERINFO_GTK_get_flag (act->country_name), | ||
761 | PEERINFO_MC_ADDRESS_AS_STRING, act->address_as_string, | ||
762 | PEERINFO_MC_PLUGIN_NAME, act->plugin, | ||
716 | -1); | 763 | -1); |
717 | } | 764 | } |
718 | } | 765 | } |
@@ -736,24 +783,16 @@ transport_peer_cb (void *cts, | |||
736 | struct GNUNET_TIME_Absolute state_timeout) | 783 | struct GNUNET_TIME_Absolute state_timeout) |
737 | { | 784 | { |
738 | struct PeerInfo *info; | 785 | struct PeerInfo *info; |
739 | struct PeerAddress *pa; | ||
740 | struct PeerAddress *act; | ||
741 | struct PeerAddress *pre; | ||
742 | GtkTreeIter iter; | 786 | GtkTreeIter iter; |
743 | gboolean con; | 787 | gboolean con; |
744 | const char *tos; | 788 | const char *tos; |
789 | struct PeerAddress *pa; | ||
745 | 790 | ||
746 | info = get_peer_info (peer); | 791 | info = get_peer_info (peer); |
747 | if (NULL == address) | 792 | info->state = state; |
748 | { | 793 | info->state_timeout = state_timeout; |
749 | GNUNET_break (0); | ||
750 | return; | ||
751 | } | ||
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)); | 794 | con = (GNUNET_YES == GNUNET_TRANSPORT_is_connected (state)); |
756 | get_iter_from_rr (pa->rr, &iter); | 795 | get_iter_from_rr (info->rr, &iter); |
757 | tos = GNUNET_STRINGS_absolute_time_to_string (state_timeout); | 796 | tos = GNUNET_STRINGS_absolute_time_to_string (state_timeout); |
758 | gtk_tree_store_set (ts, &iter, | 797 | gtk_tree_store_set (ts, &iter, |
759 | PEERINFO_MC_NEIGHBOUR_CONNECTED_STATUS, con, | 798 | PEERINFO_MC_NEIGHBOUR_CONNECTED_STATUS, con, |
@@ -762,60 +801,28 @@ transport_peer_cb (void *cts, | |||
762 | PEERINFO_MC_NEIGHBOUR_STATE_AS_STRING, GNUNET_TRANSPORT_p2s (state), | 801 | PEERINFO_MC_NEIGHBOUR_STATE_AS_STRING, GNUNET_TRANSPORT_p2s (state), |
763 | PEERINFO_MC_NEIGHBOUR_STATE_TIMEOUT_AS_STRING, tos, | 802 | PEERINFO_MC_NEIGHBOUR_STATE_TIMEOUT_AS_STRING, tos, |
764 | -1); | 803 | -1); |
765 | act = NULL; | ||
766 | pre = NULL; | ||
767 | for (pa = info->pa_head; NULL != pa; pa = pa->next) | 804 | for (pa = info->pa_head; NULL != pa; pa = pa->next) |
768 | { | 805 | { |
769 | if (GNUNET_YES == GNUNET_TRANSPORT_is_connected (pa->state)) | 806 | get_iter_from_rr (pa->rr, &iter); |
770 | { | ||
771 | GNUNET_break (NULL == act); | ||
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, | 807 | gtk_tree_store_set (ts, &iter, |
812 | PEERINFO_MC_NEIGHBOUR_CONNECTED_STATUS, TRUE, | 808 | PEERINFO_MC_NEIGHBOUR_CONNECTED_STATUS, FALSE, |
813 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_TIMEOUT_AS_STRING, tos, | 809 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_TIMEOUT_AS_STRING, NULL, |
814 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_LED, led_green, | 810 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_LED, led_red, |
815 | PEERINFO_MC_NEIGHBOUR_STATE_AS_STRING, GNUNET_TRANSPORT_p2s (act->state), | 811 | PEERINFO_MC_NEIGHBOUR_STATE_AS_STRING, NULL, |
816 | PEERINFO_MC_NEIGHBOUR_STATE_TIMEOUT_AS_STRING, tos, | 812 | PEERINFO_MC_NEIGHBOUR_STATE_TIMEOUT_AS_STRING, NULL, |
817 | -1); | 813 | -1); |
818 | } | 814 | } |
815 | if (NULL == address) | ||
816 | return; | ||
817 | pa = get_address (info, address); | ||
818 | get_iter_from_rr (pa->rr, &iter); | ||
819 | gtk_tree_store_set (ts, &iter, | ||
820 | PEERINFO_MC_NEIGHBOUR_CONNECTED_STATUS, con, | ||
821 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_TIMEOUT_AS_STRING, con ? tos : NULL, | ||
822 | PEERINFO_MC_NEIGHBOUR_CONNECTIVITY_LED, (con ? led_green : led_red), | ||
823 | PEERINFO_MC_NEIGHBOUR_STATE_AS_STRING, GNUNET_TRANSPORT_p2s (state), | ||
824 | PEERINFO_MC_NEIGHBOUR_STATE_TIMEOUT_AS_STRING, tos, | ||
825 | -1); | ||
819 | } | 826 | } |
820 | 827 | ||
821 | 828 | ||