aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-04-16 09:10:58 +0000
committerChristian Grothoff <christian@grothoff.org>2014-04-16 09:10:58 +0000
commit07dd8e7624cdc8fb02fe69fdd20ed83691d355fc (patch)
treed0840aaf5f44d634a5381297cc276259b047afa7 /src
parent2cf8e99766e1102658075923a1dfbe691fcdc54e (diff)
downloadgnunet-07dd8e7624cdc8fb02fe69fdd20ed83691d355fc.tar.gz
gnunet-07dd8e7624cdc8fb02fe69fdd20ed83691d355fc.zip
-signal monitor disconnect via callback
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-transport.c99
-rw-r--r--src/transport/transport_api_monitoring.c34
2 files changed, 83 insertions, 50 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, 313static int
314 const struct GNUNET_PeerIdentity *key, 314destroy_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
568static void 571static void
569resolve_validation_address (const struct GNUNET_PeerIdentity *id, 572resolve_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
576static void 581static void
577process_validation_string (void *cls, const char *address) 582process_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
688void process_validation_cb (void *cls, 693static void
689 const struct GNUNET_PeerIdentity *peer, 694process_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
719static void 726static void
720run_nat_test () 727run_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
1012static void 1021static void
1013resolve_peer_address (const struct GNUNET_PeerIdentity *id, 1022resolve_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
1018static void 1029static void
1019print_info (const struct GNUNET_PeerIdentity *id, const char *transport, 1030print_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
1042static void 1056static void
1043process_peer_string (void *cls, const char *address) 1057process_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
1093static void 1108static void
1094resolve_peer_address (const struct GNUNET_PeerIdentity *id, 1109resolve_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 */
1128static void 1145static void
1129process_peer_iteration_cb (void *cls, const struct GNUNET_PeerIdentity *peer, 1146process_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);
diff --git a/src/transport/transport_api_monitoring.c b/src/transport/transport_api_monitoring.c
index f8dfc9ead..624ed4f74 100644
--- a/src/transport/transport_api_monitoring.c
+++ b/src/transport/transport_api_monitoring.c
@@ -375,6 +375,10 @@ reconnect_val_ctx (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx)
375 GNUNET_assert (GNUNET_NO == val_ctx->one_shot); 375 GNUNET_assert (GNUNET_NO == val_ctx->one_shot);
376 GNUNET_CLIENT_disconnect (val_ctx->client); 376 GNUNET_CLIENT_disconnect (val_ctx->client);
377 val_ctx->client = NULL; 377 val_ctx->client = NULL;
378 /* notify clients about (re)connect */
379 val_ctx->cb (val_ctx->cb_cls, NULL, NULL,
380 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS,
381 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_TIMEOUT);
378 val_ctx->backoff = GNUNET_TIME_STD_BACKOFF (val_ctx->backoff); 382 val_ctx->backoff = GNUNET_TIME_STD_BACKOFF (val_ctx->backoff);
379 val_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (val_ctx->backoff, 383 val_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (val_ctx->backoff,
380 &do_val_connect, 384 &do_val_connect,
@@ -384,7 +388,7 @@ reconnect_val_ctx (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx)
384/** 388/**
385 * Function called with responses from the service. 389 * Function called with responses from the service.
386 * 390 *
387 * @param cls our 'struct GNUNET_TRANSPORT_PeerMonitoringContext*' 391 * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *`
388 * @param msg NULL on timeout or error, otherwise presumably a 392 * @param msg NULL on timeout or error, otherwise presumably a
389 * message with the human-readable address 393 * message with the human-readable address
390 */ 394 */
@@ -400,7 +404,7 @@ val_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
400 size_t tlen; 404 size_t tlen;
401 size_t alen; 405 size_t alen;
402 406
403 if (msg == NULL) 407 if (NULL == msg)
404 { 408 {
405 if (val_ctx->one_shot) 409 if (val_ctx->one_shot)
406 { 410 {
@@ -530,15 +534,17 @@ val_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
530 GNUNET_HELLO_address_free (address); 534 GNUNET_HELLO_address_free (address);
531 } 535 }
532 /* expect more replies */ 536 /* expect more replies */
533 GNUNET_CLIENT_receive (val_ctx->client, &val_response_processor, 537 GNUNET_CLIENT_receive (val_ctx->client,
534 val_ctx, GNUNET_TIME_absolute_get_remaining (val_ctx->timeout)); 538 &val_response_processor,
539 val_ctx,
540 GNUNET_TIME_absolute_get_remaining (val_ctx->timeout));
535} 541}
536 542
537 543
538/** 544/**
539 * Function called with responses from the service. 545 * Function called with responses from the service.
540 * 546 *
541 * @param cls our 'struct GNUNET_TRANSPORT_PeerMonitoringContext*' 547 * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *`
542 * @param msg NULL on timeout or error, otherwise presumably a 548 * @param msg NULL on timeout or error, otherwise presumably a
543 * message with the human-readable address 549 * message with the human-readable address
544 */ 550 */
@@ -577,6 +583,7 @@ peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
577 /* Done! */ 583 /* Done! */
578 if (pal_ctx->one_shot) 584 if (pal_ctx->one_shot)
579 { 585 {
586 /* iteration finished */
580 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL, 587 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
581 GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS); 588 GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
582 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx); 589 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
@@ -594,6 +601,7 @@ peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
594 GNUNET_break (0); 601 GNUNET_break (0);
595 if (pal_ctx->one_shot) 602 if (pal_ctx->one_shot)
596 { 603 {
604 /* iteration finished (with error) */
597 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL, 605 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
598 GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS); 606 GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
599 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx); 607 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
@@ -697,19 +705,19 @@ peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
697 * @param cfg configuration to use 705 * @param cfg configuration to use
698 * @param peer a specific peer identity to obtain information for, 706 * @param peer a specific peer identity to obtain information for,
699 * NULL for all peers 707 * NULL for all peers
700 * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL), 708 * @param one_shot #GNUNET_YES to return the current state and then end (with NULL+NULL),
701 * GNUNET_NO to monitor peers continuously 709 * #GNUNET_NO to monitor peers continuously
702 * @param timeout how long is the lookup allowed to take at most 710 * @param timeout how long is the lookup allowed to take at most
703 * @param peer_callback function to call with the results 711 * @param peer_callback function to call with the results
704 * @param peer_callback_cls closure for peer_address_callback 712 * @param peer_callback_cls closure for @a peer_address_callback
705 */ 713 */
706struct GNUNET_TRANSPORT_PeerMonitoringContext * 714struct GNUNET_TRANSPORT_PeerMonitoringContext *
707GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, 715GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
708 const struct GNUNET_PeerIdentity *peer, 716 const struct GNUNET_PeerIdentity *peer,
709 int one_shot, 717 int one_shot,
710 struct GNUNET_TIME_Relative timeout, 718 struct GNUNET_TIME_Relative timeout,
711 GNUNET_TRANSPORT_PeerIterateCallback peer_callback, 719 GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
712 void *peer_callback_cls) 720 void *peer_callback_cls)
713{ 721{
714 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx; 722 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx;
715 struct GNUNET_CLIENT_Connection *client; 723 struct GNUNET_CLIENT_Connection *client;