diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-04-16 09:10:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-04-16 09:10:58 +0000 |
commit | 07dd8e7624cdc8fb02fe69fdd20ed83691d355fc (patch) | |
tree | d0840aaf5f44d634a5381297cc276259b047afa7 /src/transport/gnunet-transport.c | |
parent | 2cf8e99766e1102658075923a1dfbe691fcdc54e (diff) | |
download | gnunet-07dd8e7624cdc8fb02fe69fdd20ed83691d355fc.tar.gz gnunet-07dd8e7624cdc8fb02fe69fdd20ed83691d355fc.zip |
-signal monitor disconnect via callback
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r-- | src/transport/gnunet-transport.c | 99 |
1 files changed, 62 insertions, 37 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 707b796dd..c701970d1 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -310,18 +310,21 @@ struct MonitoredPeer | |||
310 | }; | 310 | }; |
311 | 311 | ||
312 | 312 | ||
313 | int destroy_it (void *cls, | 313 | static int |
314 | const struct GNUNET_PeerIdentity *key, | 314 | destroy_it (void *cls, |
315 | void *value) | 315 | const struct GNUNET_PeerIdentity *key, |
316 | void *value) | ||
316 | { | 317 | { |
317 | struct MonitoredPeer *m = value; | 318 | struct MonitoredPeer *m = value; |
318 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (monitored_peers, | 319 | |
319 | key, value)); | 320 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (monitored_peers, |
320 | GNUNET_free_non_null (m->address); | 321 | key, value)); |
321 | GNUNET_free (value); | 322 | GNUNET_free_non_null (m->address); |
322 | return GNUNET_OK; | 323 | GNUNET_free (value); |
324 | return GNUNET_OK; | ||
323 | } | 325 | } |
324 | 326 | ||
327 | |||
325 | /** | 328 | /** |
326 | * Task run in monitor mode when the user presses CTRL-C to abort. | 329 | * Task run in monitor mode when the user presses CTRL-C to abort. |
327 | * Stops monitoring activity. | 330 | * Stops monitoring activity. |
@@ -567,11 +570,13 @@ fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
567 | 570 | ||
568 | static void | 571 | static void |
569 | resolve_validation_address (const struct GNUNET_PeerIdentity *id, | 572 | resolve_validation_address (const struct GNUNET_PeerIdentity *id, |
570 | const struct GNUNET_HELLO_Address *address, int numeric, | 573 | const struct GNUNET_HELLO_Address *address, |
571 | struct GNUNET_TIME_Absolute last_validation, | 574 | int numeric, |
572 | struct GNUNET_TIME_Absolute valid_until, | 575 | struct GNUNET_TIME_Absolute last_validation, |
573 | struct GNUNET_TIME_Absolute next_validation, | 576 | struct GNUNET_TIME_Absolute valid_until, |
574 | enum GNUNET_TRANSPORT_ValidationState state); | 577 | struct GNUNET_TIME_Absolute next_validation, |
578 | enum GNUNET_TRANSPORT_ValidationState state); | ||
579 | |||
575 | 580 | ||
576 | static void | 581 | static void |
577 | process_validation_string (void *cls, const char *address) | 582 | process_validation_string (void *cls, const char *address) |
@@ -685,13 +690,14 @@ resolve_validation_address (const struct GNUNET_PeerIdentity *id, | |||
685 | } | 690 | } |
686 | 691 | ||
687 | 692 | ||
688 | void process_validation_cb (void *cls, | 693 | static void |
689 | const struct GNUNET_PeerIdentity *peer, | 694 | process_validation_cb (void *cls, |
690 | const struct GNUNET_HELLO_Address *address, | 695 | const struct GNUNET_PeerIdentity *peer, |
691 | struct GNUNET_TIME_Absolute last_validation, | 696 | const struct GNUNET_HELLO_Address *address, |
692 | struct GNUNET_TIME_Absolute valid_until, | 697 | struct GNUNET_TIME_Absolute last_validation, |
693 | struct GNUNET_TIME_Absolute next_validation, | 698 | struct GNUNET_TIME_Absolute valid_until, |
694 | enum GNUNET_TRANSPORT_ValidationState state) | 699 | struct GNUNET_TIME_Absolute next_validation, |
700 | enum GNUNET_TRANSPORT_ValidationState state) | ||
695 | { | 701 | { |
696 | if ((NULL == peer) && (NULL == address)) | 702 | if ((NULL == peer) && (NULL == address)) |
697 | { | 703 | { |
@@ -716,6 +722,7 @@ void process_validation_cb (void *cls, | |||
716 | valid_until, next_validation, state); | 722 | valid_until, next_validation, state); |
717 | } | 723 | } |
718 | 724 | ||
725 | |||
719 | static void | 726 | static void |
720 | run_nat_test () | 727 | run_nat_test () |
721 | { | 728 | { |
@@ -736,6 +743,7 @@ run_nat_test () | |||
736 | head->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, head); | 743 | head->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, head); |
737 | } | 744 | } |
738 | 745 | ||
746 | |||
739 | /** | 747 | /** |
740 | * Test our plugin's configuration (NAT traversal, etc.). | 748 | * Test our plugin's configuration (NAT traversal, etc.). |
741 | * | 749 | * |
@@ -1009,16 +1017,21 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1009 | } | 1017 | } |
1010 | } | 1018 | } |
1011 | 1019 | ||
1020 | |||
1012 | static void | 1021 | static void |
1013 | resolve_peer_address (const struct GNUNET_PeerIdentity *id, | 1022 | resolve_peer_address (const struct GNUNET_PeerIdentity *id, |
1014 | const struct GNUNET_HELLO_Address *address, int numeric, | 1023 | const struct GNUNET_HELLO_Address *address, |
1015 | enum GNUNET_TRANSPORT_PeerState state, | 1024 | int numeric, |
1016 | struct GNUNET_TIME_Absolute state_timeout); | 1025 | enum GNUNET_TRANSPORT_PeerState state, |
1026 | struct GNUNET_TIME_Absolute state_timeout); | ||
1027 | |||
1017 | 1028 | ||
1018 | static void | 1029 | static void |
1019 | print_info (const struct GNUNET_PeerIdentity *id, const char *transport, | 1030 | print_info (const struct GNUNET_PeerIdentity *id, |
1020 | const char *addr, enum GNUNET_TRANSPORT_PeerState state, | 1031 | const char *transport, |
1021 | struct GNUNET_TIME_Absolute state_timeout) | 1032 | const char *addr, |
1033 | enum GNUNET_TRANSPORT_PeerState state, | ||
1034 | struct GNUNET_TIME_Absolute state_timeout) | ||
1022 | { | 1035 | { |
1023 | 1036 | ||
1024 | if ( ((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) || | 1037 | if ( ((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) || |
@@ -1039,6 +1052,7 @@ print_info (const struct GNUNET_PeerIdentity *id, const char *transport, | |||
1039 | } | 1052 | } |
1040 | } | 1053 | } |
1041 | 1054 | ||
1055 | |||
1042 | static void | 1056 | static void |
1043 | process_peer_string (void *cls, const char *address) | 1057 | process_peer_string (void *cls, const char *address) |
1044 | { | 1058 | { |
@@ -1090,11 +1104,13 @@ process_peer_string (void *cls, const char *address) | |||
1090 | } | 1104 | } |
1091 | } | 1105 | } |
1092 | 1106 | ||
1107 | |||
1093 | static void | 1108 | static void |
1094 | resolve_peer_address (const struct GNUNET_PeerIdentity *id, | 1109 | resolve_peer_address (const struct GNUNET_PeerIdentity *id, |
1095 | const struct GNUNET_HELLO_Address *address, int numeric, | 1110 | const struct GNUNET_HELLO_Address *address, |
1096 | enum GNUNET_TRANSPORT_PeerState state, | 1111 | int numeric, |
1097 | struct GNUNET_TIME_Absolute state_timeout) | 1112 | enum GNUNET_TRANSPORT_PeerState state, |
1113 | struct GNUNET_TIME_Absolute state_timeout) | ||
1098 | { | 1114 | { |
1099 | struct PeerResolutionContext *rc; | 1115 | struct PeerResolutionContext *rc; |
1100 | 1116 | ||
@@ -1114,6 +1130,7 @@ resolve_peer_address (const struct GNUNET_PeerIdentity *id, | |||
1114 | RESOLUTION_TIMEOUT, &process_peer_string, rc); | 1130 | RESOLUTION_TIMEOUT, &process_peer_string, rc); |
1115 | } | 1131 | } |
1116 | 1132 | ||
1133 | |||
1117 | /** | 1134 | /** |
1118 | * Function called with information about a peers during a one shot iteration | 1135 | * Function called with information about a peers during a one shot iteration |
1119 | * | 1136 | * |
@@ -1126,13 +1143,20 @@ resolve_peer_address (const struct GNUNET_PeerIdentity *id, | |||
1126 | * | 1143 | * |
1127 | */ | 1144 | */ |
1128 | static void | 1145 | static void |
1129 | process_peer_iteration_cb (void *cls, const struct GNUNET_PeerIdentity *peer, | 1146 | process_peer_iteration_cb (void *cls, |
1130 | const struct GNUNET_HELLO_Address *address, | 1147 | const struct GNUNET_PeerIdentity *peer, |
1131 | enum GNUNET_TRANSPORT_PeerState state, | 1148 | const struct GNUNET_HELLO_Address *address, |
1132 | struct GNUNET_TIME_Absolute state_timeout) | 1149 | enum GNUNET_TRANSPORT_PeerState state, |
1150 | struct GNUNET_TIME_Absolute state_timeout) | ||
1133 | { | 1151 | { |
1134 | if (peer == NULL ) | 1152 | if (NULL == peer) |
1135 | { | 1153 | { |
1154 | if (monitor_connections) | ||
1155 | { | ||
1156 | FPRINTF (stdout, | ||
1157 | _("Monitor disconnected from transport service. Reconnecting.\n")); | ||
1158 | return; | ||
1159 | } | ||
1136 | /* done */ | 1160 | /* done */ |
1137 | address_resolution_in_progress = GNUNET_NO; | 1161 | address_resolution_in_progress = GNUNET_NO; |
1138 | pic = NULL; | 1162 | pic = NULL; |
@@ -1150,8 +1174,9 @@ process_peer_iteration_cb (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1150 | op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, | 1174 | op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, |
1151 | NULL ); | 1175 | NULL ); |
1152 | 1176 | ||
1153 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received address for peer `%s': %s\n", | 1177 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1154 | GNUNET_i2s (peer), address->transport_name); | 1178 | "Received address for peer `%s': %s\n", |
1179 | GNUNET_i2s (peer), address->transport_name); | ||
1155 | 1180 | ||
1156 | if (NULL != address) | 1181 | if (NULL != address) |
1157 | resolve_peer_address (peer, address, numeric, state, state_timeout); | 1182 | resolve_peer_address (peer, address, numeric, state, state_timeout); |