aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-04-16 09:18:29 +0000
committerChristian Grothoff <christian@grothoff.org>2014-04-16 09:18:29 +0000
commit6355da1d20a93f99645494c2096e695a22c4ad7f (patch)
treedce700ac9419097822ac3d2a0391c060eda69fab /src
parent07dd8e7624cdc8fb02fe69fdd20ed83691d355fc (diff)
downloadgnunet-6355da1d20a93f99645494c2096e695a22c4ad7f.tar.gz
gnunet-6355da1d20a93f99645494c2096e695a22c4ad7f.zip
-signal monitor disconnect via callback
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-transport.c53
-rw-r--r--src/transport/transport_api_monitoring.c8
2 files changed, 35 insertions, 26 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index c701970d1..28c4c84fb 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -701,6 +701,14 @@ process_validation_cb (void *cls,
701{ 701{
702 if ((NULL == peer) && (NULL == address)) 702 if ((NULL == peer) && (NULL == address))
703 { 703 {
704 if (monitor_validation)
705 {
706 FPRINTF (stdout,
707 "%s",
708 _("Monitor disconnected from transport service. Reconnecting.\n"));
709 return;
710 }
711
704 /* done */ 712 /* done */
705 vic = NULL; 713 vic = NULL;
706 if (GNUNET_SCHEDULER_NO_TASK != end) 714 if (GNUNET_SCHEDULER_NO_TASK != end)
@@ -851,6 +859,7 @@ transmit_data (void *cls, size_t size, void *buf)
851 return size; 859 return size;
852} 860}
853 861
862
854/** 863/**
855 * Function called to notify transport users that another 864 * Function called to notify transport users that another
856 * peer connected to us. 865 * peer connected to us.
@@ -971,6 +980,7 @@ monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
971 _("Connected to"), GNUNET_i2s (peer), monitor_connect_counter); 980 _("Connected to"), GNUNET_i2s (peer), monitor_connect_counter);
972} 981}
973 982
983
974/** 984/**
975 * Function called to notify transport users that another 985 * Function called to notify transport users that another
976 * peer disconnected from us. 986 * peer disconnected from us.
@@ -991,6 +1001,7 @@ monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
991 _("Disconnected from"), GNUNET_i2s (peer), monitor_connect_counter); 1001 _("Disconnected from"), GNUNET_i2s (peer), monitor_connect_counter);
992} 1002}
993 1003
1004
994/** 1005/**
995 * Function called by the transport for each received message. 1006 * Function called by the transport for each received message.
996 * 1007 *
@@ -999,8 +1010,9 @@ monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
999 * @param message the message 1010 * @param message the message
1000 */ 1011 */
1001static void 1012static void
1002notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 1013notify_receive (void *cls,
1003 const struct GNUNET_MessageHeader *message) 1014 const struct GNUNET_PeerIdentity *peer,
1015 const struct GNUNET_MessageHeader *message)
1004{ 1016{
1005 if (benchmark_receive) 1017 if (benchmark_receive)
1006 { 1018 {
@@ -1140,7 +1152,6 @@ resolve_peer_address (const struct GNUNET_PeerIdentity *id,
1140 * NULL on disconnect or when done 1152 * NULL on disconnect or when done
1141 * @param state current state this peer is in 1153 * @param state current state this peer is in
1142 * @param state_timeout time out for the current state 1154 * @param state_timeout time out for the current state
1143 *
1144 */ 1155 */
1145static void 1156static void
1146process_peer_iteration_cb (void *cls, 1157process_peer_iteration_cb (void *cls,
@@ -1151,12 +1162,6 @@ process_peer_iteration_cb (void *cls,
1151{ 1162{
1152 if (NULL == peer) 1163 if (NULL == peer)
1153 { 1164 {
1154 if (monitor_connections)
1155 {
1156 FPRINTF (stdout,
1157 _("Monitor disconnected from transport service. Reconnecting.\n"));
1158 return;
1159 }
1160 /* done */ 1165 /* done */
1161 address_resolution_in_progress = GNUNET_NO; 1166 address_resolution_in_progress = GNUNET_NO;
1162 pic = NULL; 1167 pic = NULL;
@@ -1166,13 +1171,14 @@ process_peer_iteration_cb (void *cls,
1166 return; 1171 return;
1167 } 1172 }
1168 1173
1169 if ((GNUNET_NO == iterate_all) && (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state)) ) 1174 if ( (GNUNET_NO == iterate_all) &&
1175 (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state)) )
1170 return; /* Display only connected peers */ 1176 return; /* Display only connected peers */
1171 1177
1172 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 1178 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
1173 GNUNET_SCHEDULER_cancel (op_timeout); 1179 GNUNET_SCHEDULER_cancel (op_timeout);
1174 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, 1180 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
1175 NULL ); 1181 NULL);
1176 1182
1177 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1183 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1178 "Received address for peer `%s': %s\n", 1184 "Received address for peer `%s': %s\n",
@@ -1197,28 +1203,26 @@ process_peer_iteration_cb (void *cls,
1197 * 1203 *
1198 */ 1204 */
1199static void 1205static void
1200process_peer_monitoring_cb (void *cls, const struct GNUNET_PeerIdentity *peer, 1206process_peer_monitoring_cb (void *cls,
1201 const struct GNUNET_HELLO_Address *address, 1207 const struct GNUNET_PeerIdentity *peer,
1202 enum GNUNET_TRANSPORT_PeerState state, 1208 const struct GNUNET_HELLO_Address *address,
1203 struct GNUNET_TIME_Absolute state_timeout) 1209 enum GNUNET_TRANSPORT_PeerState state,
1210 struct GNUNET_TIME_Absolute state_timeout)
1204{ 1211{
1205 struct MonitoredPeer *m; 1212 struct MonitoredPeer *m;
1206 1213
1207 if (peer == NULL ) 1214 if (NULL == peer)
1208 { 1215 {
1209 /* done */ 1216 FPRINTF (stdout,
1210 address_resolution_in_progress = GNUNET_NO; 1217 "%s",
1211 pic = NULL; 1218 _("Monitor disconnected from transport service. Reconnecting.\n"));
1212 if (GNUNET_SCHEDULER_NO_TASK != end)
1213 GNUNET_SCHEDULER_cancel (end);
1214 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
1215 return; 1219 return;
1216 } 1220 }
1217 1221
1218 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 1222 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
1219 GNUNET_SCHEDULER_cancel (op_timeout); 1223 GNUNET_SCHEDULER_cancel (op_timeout);
1220 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, 1224 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
1221 NULL ); 1225 NULL);
1222 1226
1223 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer))) 1227 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer)))
1224 { 1228 {
@@ -1490,7 +1494,8 @@ testservice_task (void *cls, int result)
1490 { 1494 {
1491 monitor_connect_counter = 0; 1495 monitor_connect_counter = 0;
1492 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, 1496 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL,
1493 &monitor_notify_connect, &monitor_notify_disconnect); 1497 &monitor_notify_connect,
1498 &monitor_notify_disconnect);
1494 if (NULL == handle) 1499 if (NULL == handle)
1495 { 1500 {
1496 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") ); 1501 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
diff --git a/src/transport/transport_api_monitoring.c b/src/transport/transport_api_monitoring.c
index 624ed4f74..371a5f568 100644
--- a/src/transport/transport_api_monitoring.c
+++ b/src/transport/transport_api_monitoring.c
@@ -339,6 +339,9 @@ reconnect_peer_ctx (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
339 GNUNET_assert (GNUNET_NO == pal_ctx->one_shot); 339 GNUNET_assert (GNUNET_NO == pal_ctx->one_shot);
340 GNUNET_CLIENT_disconnect (pal_ctx->client); 340 GNUNET_CLIENT_disconnect (pal_ctx->client);
341 pal_ctx->client = NULL; 341 pal_ctx->client = NULL;
342 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
343 GNUNET_TRANSPORT_PS_NOT_CONNECTED,
344 GNUNET_TIME_UNIT_ZERO_ABS);
342 pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF (pal_ctx->backoff); 345 pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF (pal_ctx->backoff);
343 pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (pal_ctx->backoff, 346 pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (pal_ctx->backoff,
344 &do_peer_connect, 347 &do_peer_connect,
@@ -549,7 +552,8 @@ val_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
549 * message with the human-readable address 552 * message with the human-readable address
550 */ 553 */
551static void 554static void
552peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) 555peer_response_processor (void *cls,
556 const struct GNUNET_MessageHeader *msg)
553{ 557{
554 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; 558 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
555 struct PeerIterateResponseMessage *pir_msg; 559 struct PeerIterateResponseMessage *pir_msg;
@@ -560,7 +564,7 @@ peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
560 size_t alen; 564 size_t alen;
561 size_t tlen; 565 size_t tlen;
562 566
563 if (msg == NULL) 567 if (NULL == msg)
564 { 568 {
565 if (pal_ctx->one_shot) 569 if (pal_ctx->one_shot)
566 { 570 {