diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-11-23 19:24:08 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-11-23 19:24:08 +0000 |
commit | e5d9d0d24bc32dcebcd5d2f86ca5cca579bc5dbb (patch) | |
tree | 892b7997407e9705e7a4072ffe8397f03c40adb5 | |
parent | b3db692279aec4f8e016ee3ebd83a18ce182bd35 (diff) | |
download | gnunet-e5d9d0d24bc32dcebcd5d2f86ca5cca579bc5dbb.tar.gz gnunet-e5d9d0d24bc32dcebcd5d2f86ca5cca579bc5dbb.zip |
-fix sync signalling for plugin monitoring
-rw-r--r-- | src/include/gnunet_protocols.h | 8 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 74 | ||||
-rw-r--r-- | src/transport/gnunet-transport.c | 19 | ||||
-rw-r--r-- | src/transport/transport_api_monitor_plugins.c | 11 |
4 files changed, 81 insertions, 31 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index a1bc09492..18dc5d33b 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -1348,6 +1348,12 @@ extern "C" | |||
1348 | */ | 1348 | */ |
1349 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT 389 | 1349 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT 389 |
1350 | 1350 | ||
1351 | /** | ||
1352 | * Monitoring event notifying client that the initial iteration | ||
1353 | * is now completed and we are in sync with the state of the subsystem. | ||
1354 | */ | ||
1355 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC 390 | ||
1356 | |||
1351 | /******************************************************************************* | 1357 | /******************************************************************************* |
1352 | * FS-PUBLISH-HELPER IPC Messages | 1358 | * FS-PUBLISH-HELPER IPC Messages |
1353 | ******************************************************************************/ | 1359 | ******************************************************************************/ |
@@ -2607,7 +2613,7 @@ extern "C" | |||
2607 | 2613 | ||
2608 | /** | 2614 | /** |
2609 | * Send back peer that considers you are its successor, a confirmation | 2615 | * Send back peer that considers you are its successor, a confirmation |
2610 | * that you got the notify successor message. | 2616 | * that you got the notify successor message. |
2611 | */ | 2617 | */ |
2612 | #define GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION 892 | 2618 | #define GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION 892 |
2613 | 2619 | ||
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index b50aab6af..96b3e0bf3 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -299,26 +299,32 @@ lookup_monitoring_client (struct MonitoringClient *head, | |||
299 | */ | 299 | */ |
300 | static struct MonitoringClient * | 300 | static struct MonitoringClient * |
301 | setup_peer_monitoring_client (struct GNUNET_SERVER_Client *client, | 301 | setup_peer_monitoring_client (struct GNUNET_SERVER_Client *client, |
302 | struct GNUNET_PeerIdentity *peer) | 302 | const struct GNUNET_PeerIdentity *peer) |
303 | { | 303 | { |
304 | struct MonitoringClient *mc; | 304 | struct MonitoringClient *mc; |
305 | static struct GNUNET_PeerIdentity all_zeros; | 305 | static struct GNUNET_PeerIdentity all_zeros; |
306 | 306 | ||
307 | GNUNET_assert (lookup_monitoring_client (peer_monitoring_clients_head, client) == NULL); | 307 | GNUNET_assert (NULL == |
308 | lookup_monitoring_client (peer_monitoring_clients_head, | ||
309 | client)); | ||
308 | mc = GNUNET_new (struct MonitoringClient); | 310 | mc = GNUNET_new (struct MonitoringClient); |
309 | mc->client = client; | 311 | mc->client = client; |
310 | mc->peer = *peer; | 312 | mc->peer = *peer; |
311 | GNUNET_CONTAINER_DLL_insert (peer_monitoring_clients_head, peer_monitoring_clients_tail, mc); | 313 | GNUNET_CONTAINER_DLL_insert (peer_monitoring_clients_head, |
314 | peer_monitoring_clients_tail, | ||
315 | mc); | ||
312 | GNUNET_SERVER_client_mark_monitor (client); | 316 | GNUNET_SERVER_client_mark_monitor (client); |
313 | GNUNET_SERVER_notification_context_add (peer_nc, client); | 317 | GNUNET_SERVER_notification_context_add (peer_nc, client); |
314 | 318 | ||
315 | if (0 != memcmp (peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) | 319 | if (0 != memcmp (peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) |
316 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 320 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
317 | "Client %p started monitoring of the peer `%s'\n", | 321 | "Client %p started monitoring of the peer `%s'\n", |
318 | mc, GNUNET_i2s (peer)); | 322 | mc, |
323 | GNUNET_i2s (peer)); | ||
319 | else | 324 | else |
320 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 325 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
321 | "Client %p started monitoring all peers\n", mc); | 326 | "Client %p started monitoring all peers\n", |
327 | mc); | ||
322 | return mc; | 328 | return mc; |
323 | } | 329 | } |
324 | 330 | ||
@@ -339,14 +345,20 @@ setup_val_monitoring_client (struct GNUNET_SERVER_Client *client, | |||
339 | struct MonitoringClient *mc; | 345 | struct MonitoringClient *mc; |
340 | static struct GNUNET_PeerIdentity all_zeros; | 346 | static struct GNUNET_PeerIdentity all_zeros; |
341 | 347 | ||
342 | GNUNET_assert (lookup_monitoring_client (val_monitoring_clients_head, client) == NULL); | 348 | GNUNET_assert (NULL == |
349 | lookup_monitoring_client (val_monitoring_clients_head, | ||
350 | client)); | ||
343 | mc = GNUNET_new (struct MonitoringClient); | 351 | mc = GNUNET_new (struct MonitoringClient); |
344 | mc->client = client; | 352 | mc->client = client; |
345 | mc->peer = *peer; | 353 | mc->peer = *peer; |
346 | GNUNET_CONTAINER_DLL_insert (val_monitoring_clients_head, val_monitoring_clients_tail, mc); | 354 | GNUNET_CONTAINER_DLL_insert (val_monitoring_clients_head, |
355 | val_monitoring_clients_tail, | ||
356 | mc); | ||
347 | GNUNET_SERVER_notification_context_add (val_nc, client); | 357 | GNUNET_SERVER_notification_context_add (val_nc, client); |
348 | 358 | ||
349 | if (0 != memcmp (peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) | 359 | if (0 != memcmp (peer, |
360 | &all_zeros, | ||
361 | sizeof (struct GNUNET_PeerIdentity))) | ||
350 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 362 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
351 | "Client %p started monitoring of the peer `%s'\n", | 363 | "Client %p started monitoring of the peer `%s'\n", |
352 | mc, GNUNET_i2s (peer)); | 364 | mc, GNUNET_i2s (peer)); |
@@ -487,7 +499,8 @@ client_disconnect_notification (void *cls, | |||
487 | 499 | ||
488 | if (client == NULL) | 500 | if (client == NULL) |
489 | return; | 501 | return; |
490 | mc = lookup_monitoring_client (peer_monitoring_clients_head, client); | 502 | mc = lookup_monitoring_client (peer_monitoring_clients_head, |
503 | client); | ||
491 | if (mc != NULL) | 504 | if (mc != NULL) |
492 | { | 505 | { |
493 | GNUNET_CONTAINER_DLL_remove (peer_monitoring_clients_head, | 506 | GNUNET_CONTAINER_DLL_remove (peer_monitoring_clients_head, |
@@ -495,7 +508,8 @@ client_disconnect_notification (void *cls, | |||
495 | mc); | 508 | mc); |
496 | GNUNET_free (mc); | 509 | GNUNET_free (mc); |
497 | } | 510 | } |
498 | mc = lookup_monitoring_client (val_monitoring_clients_head, client); | 511 | mc = lookup_monitoring_client (val_monitoring_clients_head, |
512 | client); | ||
499 | if (mc != NULL) | 513 | if (mc != NULL) |
500 | { | 514 | { |
501 | GNUNET_CONTAINER_DLL_remove (val_monitoring_clients_head, | 515 | GNUNET_CONTAINER_DLL_remove (val_monitoring_clients_head, |
@@ -607,8 +621,7 @@ clients_handle_start (void *cls, | |||
607 | { | 621 | { |
608 | /* client thinks this is a different peer, reject */ | 622 | /* client thinks this is a different peer, reject */ |
609 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 623 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
610 | _ | 624 | _("Rejecting control connection from peer `%s', which is not me!\n"), |
611 | ("Rejecting control connection from peer `%s', which is not me!\n"), | ||
612 | GNUNET_i2s (&start->self)); | 625 | GNUNET_i2s (&start->self)); |
613 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 626 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
614 | return; | 627 | return; |
@@ -1232,27 +1245,16 @@ send_peer_information (void *cls, | |||
1232 | * @param message the peer address information request | 1245 | * @param message the peer address information request |
1233 | */ | 1246 | */ |
1234 | static void | 1247 | static void |
1235 | clients_handle_monitor_peers (void *cls, struct GNUNET_SERVER_Client *client, | 1248 | clients_handle_monitor_peers (void *cls, |
1236 | const struct GNUNET_MessageHeader *message) | 1249 | struct GNUNET_SERVER_Client *client, |
1250 | const struct GNUNET_MessageHeader *message) | ||
1237 | { | 1251 | { |
1238 | static struct GNUNET_PeerIdentity all_zeros; | 1252 | static struct GNUNET_PeerIdentity all_zeros; |
1239 | struct GNUNET_SERVER_TransmitContext *tc; | 1253 | struct GNUNET_SERVER_TransmitContext *tc; |
1240 | struct PeerMonitorMessage *msg; | 1254 | const struct PeerMonitorMessage *msg; |
1241 | struct IterationContext pc; | 1255 | struct IterationContext pc; |
1242 | 1256 | ||
1243 | if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST) | 1257 | msg = (const struct PeerMonitorMessage *) message; |
1244 | { | ||
1245 | GNUNET_break (0); | ||
1246 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1247 | return; | ||
1248 | } | ||
1249 | if (ntohs (message->size) != sizeof (struct PeerMonitorMessage)) | ||
1250 | { | ||
1251 | GNUNET_break (0); | ||
1252 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1253 | return; | ||
1254 | } | ||
1255 | msg = (struct PeerMonitorMessage *) message; | ||
1256 | if ( (GNUNET_YES != ntohl (msg->one_shot)) && | 1258 | if ( (GNUNET_YES != ntohl (msg->one_shot)) && |
1257 | (NULL != lookup_monitoring_client (peer_monitoring_clients_head, client)) ) | 1259 | (NULL != lookup_monitoring_client (peer_monitoring_clients_head, client)) ) |
1258 | { | 1260 | { |
@@ -1388,6 +1390,7 @@ plugin_session_info_cb (void *cls, | |||
1388 | const struct GNUNET_TRANSPORT_SessionInfo *info) | 1390 | const struct GNUNET_TRANSPORT_SessionInfo *info) |
1389 | { | 1391 | { |
1390 | struct TransportPluginMonitorMessage *msg; | 1392 | struct TransportPluginMonitorMessage *msg; |
1393 | struct GNUNET_MessageHeader sync; | ||
1391 | size_t size; | 1394 | size_t size; |
1392 | size_t slen; | 1395 | size_t slen; |
1393 | uint16_t alen; | 1396 | uint16_t alen; |
@@ -1399,6 +1402,21 @@ plugin_session_info_cb (void *cls, | |||
1399 | GST_plugins_monitor_subscribe (NULL, NULL); | 1402 | GST_plugins_monitor_subscribe (NULL, NULL); |
1400 | return; | 1403 | return; |
1401 | } | 1404 | } |
1405 | if ( (NULL == info) && | ||
1406 | (NULL == session) ) | ||
1407 | { | ||
1408 | /* end of initial iteration */ | ||
1409 | sync.size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
1410 | sync.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC); | ||
1411 | GNUNET_SERVER_notification_context_broadcast (plugin_nc, | ||
1412 | &sync, | ||
1413 | GNUNET_NO); | ||
1414 | return; | ||
1415 | } | ||
1416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1417 | "Plugin event for peer %s on transport %s\n", | ||
1418 | GNUNET_i2s (&info->address->peer), | ||
1419 | info->address->transport_name); | ||
1402 | slen = strlen (info->address->transport_name) + 1; | 1420 | slen = strlen (info->address->transport_name) + 1; |
1403 | alen = info->address->address_length; | 1421 | alen = info->address->address_length; |
1404 | size = sizeof (struct TransportPluginMonitorMessage) + slen + alen; | 1422 | size = sizeof (struct TransportPluginMonitorMessage) + slen + alen; |
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 109622567..24be066bc 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -1599,6 +1599,9 @@ plugin_monitoring_cb (void *cls, | |||
1599 | const char *state; | 1599 | const char *state; |
1600 | struct PluginMonitorAddress *addr; | 1600 | struct PluginMonitorAddress *addr; |
1601 | 1601 | ||
1602 | if ( (NULL == info) && | ||
1603 | (NULL == session) ) | ||
1604 | return; /* in sync with transport service */ | ||
1602 | if ( (NULL != cpid) && | 1605 | if ( (NULL != cpid) && |
1603 | (0 != memcmp (&info->address->peer, | 1606 | (0 != memcmp (&info->address->peer, |
1604 | cpid, | 1607 | cpid, |
@@ -1740,6 +1743,14 @@ process_peer_monitoring_cb (void *cls, | |||
1740 | } | 1743 | } |
1741 | 1744 | ||
1742 | 1745 | ||
1746 | /** | ||
1747 | * Function called with our result of trying to connect to the | ||
1748 | * transport service. Will retry 10 times, and if we still | ||
1749 | * fail to connect terminate with an error message. | ||
1750 | * | ||
1751 | * @param cls NULL | ||
1752 | * @param result #GNUNET_OK if we connected to the service | ||
1753 | */ | ||
1743 | static void | 1754 | static void |
1744 | try_connect_cb (void *cls, | 1755 | try_connect_cb (void *cls, |
1745 | const int result) | 1756 | const int result) |
@@ -1753,8 +1764,12 @@ try_connect_cb (void *cls, | |||
1753 | } | 1764 | } |
1754 | retries++; | 1765 | retries++; |
1755 | if (retries < 10) | 1766 | if (retries < 10) |
1756 | tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb, | 1767 | { |
1757 | NULL); | 1768 | tc_handle = GNUNET_TRANSPORT_try_connect (handle, |
1769 | &pid, | ||
1770 | &try_connect_cb, | ||
1771 | NULL); | ||
1772 | } | ||
1758 | else | 1773 | else |
1759 | { | 1774 | { |
1760 | FPRINTF (stderr, | 1775 | FPRINTF (stderr, |
diff --git a/src/transport/transport_api_monitor_plugins.c b/src/transport/transport_api_monitor_plugins.c index 818530c84..1bbb4c102 100644 --- a/src/transport/transport_api_monitor_plugins.c +++ b/src/transport/transport_api_monitor_plugins.c | |||
@@ -296,6 +296,17 @@ response_processor (void *cls, | |||
296 | reconnect_plugin_ctx (pm); | 296 | reconnect_plugin_ctx (pm); |
297 | return; | 297 | return; |
298 | } | 298 | } |
299 | if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC == ntohs (msg->type)) && | ||
300 | (sizeof (struct GNUNET_MessageHeader) == ntohs (msg->size)) ) | ||
301 | { | ||
302 | /* we are in sync */ | ||
303 | pm->cb (pm->cb_cls, | ||
304 | NULL, | ||
305 | NULL, | ||
306 | NULL); | ||
307 | return; | ||
308 | } | ||
309 | |||
299 | if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT != ntohs (msg->type)) || | 310 | if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT != ntohs (msg->type)) || |
300 | (sizeof (struct TransportPluginMonitorMessage) > ntohs (msg->size)) ) | 311 | (sizeof (struct TransportPluginMonitorMessage) > ntohs (msg->size)) ) |
301 | { | 312 | { |