diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-06 22:10:48 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-06 22:10:48 +0000 |
commit | 5c862712d9c389fced47fde9abdc9458da319aef (patch) | |
tree | 3d17ba8b4fc5ef821882b65aaf6c3d1a798c6ed3 | |
parent | 55c16b6ab6a83a594303efccff1e59a022470982 (diff) | |
download | gnunet-5c862712d9c389fced47fde9abdc9458da319aef.tar.gz gnunet-5c862712d9c389fced47fde9abdc9458da319aef.zip |
removing GNUNET_TRANSPORT_monitor_validation-API
-rw-r--r-- | src/include/gnunet_protocols.h | 11 | ||||
-rw-r--r-- | src/include/gnunet_transport_service.h | 120 | ||||
-rw-r--r-- | src/transport/Makefile.am | 4 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 265 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_clients.h | 19 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_validation.c | 123 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_validation.h | 30 | ||||
-rw-r--r-- | src/transport/gnunet-transport.c | 258 | ||||
-rw-r--r-- | src/transport/transport_api_monitor_validation.c | 402 |
9 files changed, 50 insertions, 1182 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index eeceb545d..7852a94e3 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -1341,17 +1341,6 @@ extern "C" | |||
1341 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC 385 | 1341 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC 385 |
1342 | 1342 | ||
1343 | /** | 1343 | /** |
1344 | * Request to monitor address validations by a peer or all peers. | ||
1345 | */ | ||
1346 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST 386 | ||
1347 | |||
1348 | /** | ||
1349 | * Response to #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST | ||
1350 | * request to iterate over all known addresses. | ||
1351 | */ | ||
1352 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE 387 | ||
1353 | |||
1354 | /** | ||
1355 | * Request to start monitoring the connection state of plugins. | 1344 | * Request to start monitoring the connection state of plugins. |
1356 | */ | 1345 | */ |
1357 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START 388 | 1346 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START 388 |
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index 3683286a5..0ff6c185a 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h | |||
@@ -628,126 +628,6 @@ void | |||
628 | GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringContext *pic); | 628 | GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringContext *pic); |
629 | 629 | ||
630 | 630 | ||
631 | /** | ||
632 | * Handle for a #GNUNET_TRANSPORT_monitor_validation_entries() operation. | ||
633 | */ | ||
634 | struct GNUNET_TRANSPORT_ValidationMonitoringContext; | ||
635 | |||
636 | |||
637 | /** | ||
638 | * Current state of a validation process. | ||
639 | * | ||
640 | * FIXME: what state is used to indicate that a validation | ||
641 | * was successful? If that is clarified/determined, "UGH" in | ||
642 | * ~gnunet-peerinfo-gtk.c:1103 should be resolved. | ||
643 | */ | ||
644 | enum GNUNET_TRANSPORT_ValidationState | ||
645 | { | ||
646 | /** | ||
647 | * Undefined state | ||
648 | * | ||
649 | * Used for final callback indicating operation done | ||
650 | */ | ||
651 | GNUNET_TRANSPORT_VS_NONE, | ||
652 | |||
653 | /** | ||
654 | * Fresh validation entry | ||
655 | * | ||
656 | * Entry was just created, no validation process was executed | ||
657 | */ | ||
658 | GNUNET_TRANSPORT_VS_NEW, | ||
659 | |||
660 | /** | ||
661 | * Updated validation entry | ||
662 | * | ||
663 | * This is an update for an existing validation entry | ||
664 | */ | ||
665 | GNUNET_TRANSPORT_VS_UPDATE, | ||
666 | |||
667 | /** | ||
668 | * Timeout for validation entry | ||
669 | * | ||
670 | * A timeout occured during the validation process | ||
671 | */ | ||
672 | GNUNET_TRANSPORT_VS_TIMEOUT, | ||
673 | |||
674 | /** | ||
675 | * Validation entry is removed | ||
676 | * | ||
677 | * The validation entry is getting removed due to a failed validation | ||
678 | */ | ||
679 | GNUNET_TRANSPORT_VS_REMOVE | ||
680 | }; | ||
681 | |||
682 | |||
683 | /** | ||
684 | * Function to call with validation information about a peer | ||
685 | * | ||
686 | * This function is called by the transport validation monitoring api to | ||
687 | * indicate a change to a validation entry. The information included represent | ||
688 | * the current state of the validation entry, | ||
689 | * | ||
690 | * If the monitoring was called with `one_shot==GNUNET_YES`, a final callback | ||
691 | * with `address==NULL` is executed. | ||
692 | * | ||
693 | * @param cls closure | ||
694 | * @param address address this update is about, | ||
695 | * NULL if this is the final last callback for a iteration operation | ||
696 | * @param last_validation when was this address last validated | ||
697 | * @param valid_until when does this address expire | ||
698 | * @param next_validation time of the next validation operation | ||
699 | * @param state state in the validation state machine | ||
700 | */ | ||
701 | typedef void | ||
702 | (*GNUNET_TRANSPORT_ValidationIterateCallback) (void *cls, | ||
703 | const struct GNUNET_HELLO_Address *address, | ||
704 | struct GNUNET_TIME_Absolute last_validation, | ||
705 | struct GNUNET_TIME_Absolute valid_until, | ||
706 | struct GNUNET_TIME_Absolute next_validation, | ||
707 | enum GNUNET_TRANSPORT_ValidationState state); | ||
708 | |||
709 | |||
710 | /** | ||
711 | * Convert validation state to human-readable string. | ||
712 | * | ||
713 | * @param state the state value | ||
714 | * @return corresponding string | ||
715 | */ | ||
716 | const char * | ||
717 | GNUNET_TRANSPORT_vs2s (enum GNUNET_TRANSPORT_ValidationState state); | ||
718 | |||
719 | |||
720 | /** | ||
721 | * Return information about pending address validation operations for a specific | ||
722 | * or all peers | ||
723 | * | ||
724 | * @param cfg configuration to use | ||
725 | * @param peer a specific peer identity to obtain validation entries for, | ||
726 | * NULL for all peers | ||
727 | * @param one_shot #GNUNET_YES to return all entries and then end (with NULL+NULL), | ||
728 | * #GNUNET_NO to monitor validation entries continuously | ||
729 | * @param timeout how long is the lookup allowed to take at most | ||
730 | * @param validation_callback function to call with the results | ||
731 | * @param validation_callback_cls closure for @a validation_callback | ||
732 | */ | ||
733 | struct GNUNET_TRANSPORT_ValidationMonitoringContext * | ||
734 | GNUNET_TRANSPORT_monitor_validation_entries (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
735 | const struct GNUNET_PeerIdentity *peer, | ||
736 | int one_shot, | ||
737 | struct GNUNET_TIME_Relative timeout, | ||
738 | GNUNET_TRANSPORT_ValidationIterateCallback validation_callback, | ||
739 | void *validation_callback_cls); | ||
740 | |||
741 | |||
742 | /** | ||
743 | * Return information about all current pending validation operations | ||
744 | * | ||
745 | * @param vic handle for the request to cancel | ||
746 | */ | ||
747 | void | ||
748 | GNUNET_TRANSPORT_monitor_validation_entries_cancel (struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic); | ||
749 | |||
750 | |||
751 | /* *********************** Blacklisting ************************ */ | 631 | /* *********************** Blacklisting ************************ */ |
752 | 632 | ||
753 | /** | 633 | /** |
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index c4ce03bee..5b18c8793 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -166,8 +166,8 @@ libgnunettransport_la_SOURCES = \ | |||
166 | transport_api_blacklist.c \ | 166 | transport_api_blacklist.c \ |
167 | transport_api_address_to_string.c \ | 167 | transport_api_address_to_string.c \ |
168 | transport_api_monitor_peers.c \ | 168 | transport_api_monitor_peers.c \ |
169 | transport_api_monitor_plugins.c \ | 169 | transport_api_monitor_plugins.c |
170 | transport_api_monitor_validation.c | 170 | |
171 | libgnunettransport_la_LIBADD = \ | 171 | libgnunettransport_la_LIBADD = \ |
172 | $(top_builddir)/src/hello/libgnunethello.la \ | 172 | $(top_builddir)/src/hello/libgnunethello.la \ |
173 | $(top_builddir)/src/ats/libgnunetats.la \ | 173 | $(top_builddir)/src/ats/libgnunetats.la \ |
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index b9bccc08b..3df62011c 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -244,16 +244,6 @@ static struct MonitoringClient *peer_monitoring_clients_head; | |||
244 | static struct MonitoringClient *peer_monitoring_clients_tail; | 244 | static struct MonitoringClient *peer_monitoring_clients_tail; |
245 | 245 | ||
246 | /** | 246 | /** |
247 | * Head of linked list of validation monitoring clients. | ||
248 | */ | ||
249 | static struct MonitoringClient *val_monitoring_clients_head; | ||
250 | |||
251 | /** | ||
252 | * Tail of linked list of validation monitoring clients. | ||
253 | */ | ||
254 | static struct MonitoringClient *val_monitoring_clients_tail; | ||
255 | |||
256 | /** | ||
257 | * Notification context, to send updates on changes to active addresses | 247 | * Notification context, to send updates on changes to active addresses |
258 | * of our neighbours. | 248 | * of our neighbours. |
259 | */ | 249 | */ |
@@ -387,47 +377,6 @@ setup_peer_monitoring_client (struct GNUNET_SERVER_Client *client, | |||
387 | 377 | ||
388 | 378 | ||
389 | /** | 379 | /** |
390 | * Setup a new monitoring client using the given server client handle and | ||
391 | * the peer identity. | ||
392 | * | ||
393 | * @param client server's client handle to create our internal handle for | ||
394 | * @param peer identity of the peer to monitor the addresses of, | ||
395 | * zero to monitor all neighrours. | ||
396 | * @return handle to the new monitoring client | ||
397 | */ | ||
398 | static struct MonitoringClient * | ||
399 | setup_val_monitoring_client (struct GNUNET_SERVER_Client *client, | ||
400 | struct GNUNET_PeerIdentity *peer) | ||
401 | { | ||
402 | struct MonitoringClient *mc; | ||
403 | |||
404 | GNUNET_assert (NULL == | ||
405 | lookup_monitoring_client (val_monitoring_clients_head, | ||
406 | client)); | ||
407 | mc = GNUNET_new (struct MonitoringClient); | ||
408 | mc->client = client; | ||
409 | mc->peer = *peer; | ||
410 | GNUNET_CONTAINER_DLL_insert (val_monitoring_clients_head, | ||
411 | val_monitoring_clients_tail, | ||
412 | mc); | ||
413 | GNUNET_SERVER_notification_context_add (val_nc, client); | ||
414 | |||
415 | if (0 != memcmp (peer, | ||
416 | &all_zeros, | ||
417 | sizeof (struct GNUNET_PeerIdentity))) | ||
418 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
419 | "Client %p started monitoring of the peer `%s'\n", | ||
420 | mc, | ||
421 | GNUNET_i2s (peer)); | ||
422 | else | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
424 | "Client %p started monitoring all peers\n", | ||
425 | mc); | ||
426 | return mc; | ||
427 | } | ||
428 | |||
429 | |||
430 | /** | ||
431 | * Function called to notify a client about the socket being ready to | 380 | * Function called to notify a client about the socket being ready to |
432 | * queue more data. @a buf will be NULL and @a size zero if the socket | 381 | * queue more data. @a buf will be NULL and @a size zero if the socket |
433 | * was closed for writing in the meantime. | 382 | * was closed for writing in the meantime. |
@@ -568,15 +517,6 @@ client_disconnect_notification (void *cls, | |||
568 | mc); | 517 | mc); |
569 | GNUNET_free (mc); | 518 | GNUNET_free (mc); |
570 | } | 519 | } |
571 | mc = lookup_monitoring_client (val_monitoring_clients_head, | ||
572 | client); | ||
573 | if (NULL != mc) | ||
574 | { | ||
575 | GNUNET_CONTAINER_DLL_remove (val_monitoring_clients_head, | ||
576 | val_monitoring_clients_tail, | ||
577 | mc); | ||
578 | GNUNET_free (mc); | ||
579 | } | ||
580 | tc = lookup_client (client); | 520 | tc = lookup_client (client); |
581 | if (NULL == tc) | 521 | if (NULL == tc) |
582 | return; | 522 | return; |
@@ -1091,55 +1031,6 @@ compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer | |||
1091 | 1031 | ||
1092 | 1032 | ||
1093 | /** | 1033 | /** |
1094 | * Compose #PeerIterateResponseMessage using the given peer and address. | ||
1095 | * | ||
1096 | * @param peer identity of the peer | ||
1097 | * @param address the address, NULL on disconnect | ||
1098 | * @return composed message | ||
1099 | */ | ||
1100 | static struct ValidationIterateResponseMessage * | ||
1101 | compose_validation_iterate_response_message (const struct GNUNET_PeerIdentity *peer, | ||
1102 | const struct GNUNET_HELLO_Address *address) | ||
1103 | { | ||
1104 | struct ValidationIterateResponseMessage *msg; | ||
1105 | size_t size; | ||
1106 | size_t tlen; | ||
1107 | size_t alen; | ||
1108 | char *addr; | ||
1109 | |||
1110 | GNUNET_assert (NULL != peer); | ||
1111 | if (NULL != address) | ||
1112 | { | ||
1113 | tlen = strlen (address->transport_name) + 1; | ||
1114 | alen = address->address_length; | ||
1115 | } | ||
1116 | else | ||
1117 | { | ||
1118 | tlen = 0; | ||
1119 | alen = 0; | ||
1120 | } | ||
1121 | size = (sizeof (struct ValidationIterateResponseMessage) + alen + tlen); | ||
1122 | msg = GNUNET_malloc (size); | ||
1123 | msg->header.size = htons (size); | ||
1124 | msg->header.type = | ||
1125 | htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE); | ||
1126 | msg->reserved = htonl (0); | ||
1127 | msg->peer = *peer; | ||
1128 | msg->addrlen = htonl (alen); | ||
1129 | msg->pluginlen = htonl (tlen); | ||
1130 | |||
1131 | if (NULL != address) | ||
1132 | { | ||
1133 | msg->local_address_info = htonl((uint32_t) address->local_info); | ||
1134 | addr = (char *) &msg[1]; | ||
1135 | memcpy (addr, address->address, alen); | ||
1136 | memcpy (&addr[alen], address->transport_name, tlen); | ||
1137 | } | ||
1138 | return msg; | ||
1139 | } | ||
1140 | |||
1141 | |||
1142 | /** | ||
1143 | * Context for #send_validation_information() and | 1034 | * Context for #send_validation_information() and |
1144 | * #send_peer_information(). | 1035 | * #send_peer_information(). |
1145 | */ | 1036 | */ |
@@ -1163,44 +1054,6 @@ struct IterationContext | |||
1163 | 1054 | ||
1164 | 1055 | ||
1165 | /** | 1056 | /** |
1166 | * Output information of validation entries to the given client. | ||
1167 | * | ||
1168 | * @param cls the `struct IterationContext *` | ||
1169 | * @param address the address | ||
1170 | * @param last_validation point in time when last validation was performed | ||
1171 | * @param valid_until point in time how long address is valid | ||
1172 | * @param next_validation point in time when next validation will be performed | ||
1173 | * @param state state of validation notification | ||
1174 | */ | ||
1175 | static void | ||
1176 | send_validation_information (void *cls, | ||
1177 | const struct GNUNET_HELLO_Address *address, | ||
1178 | struct GNUNET_TIME_Absolute last_validation, | ||
1179 | struct GNUNET_TIME_Absolute valid_until, | ||
1180 | struct GNUNET_TIME_Absolute next_validation, | ||
1181 | enum GNUNET_TRANSPORT_ValidationState state) | ||
1182 | { | ||
1183 | struct IterationContext *pc = cls; | ||
1184 | struct ValidationIterateResponseMessage *msg; | ||
1185 | |||
1186 | if ( (GNUNET_YES != pc->all) && | ||
1187 | (0 != memcmp (&address->peer, &pc->id, sizeof (pc->id))) ) | ||
1188 | return; | ||
1189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1190 | "Sending information about for validation entry for peer `%s' using address `%s'\n", | ||
1191 | GNUNET_i2s (&address->peer), | ||
1192 | (NULL != address) ? GST_plugins_a2s (address) : "<none>"); | ||
1193 | msg = compose_validation_iterate_response_message (&address->peer, address); | ||
1194 | msg->last_validation = GNUNET_TIME_absolute_hton(last_validation); | ||
1195 | msg->valid_until = GNUNET_TIME_absolute_hton(valid_until); | ||
1196 | msg->next_validation = GNUNET_TIME_absolute_hton(next_validation); | ||
1197 | msg->state = htonl ((uint32_t) state); | ||
1198 | GNUNET_SERVER_transmit_context_append_message (pc->tc, &msg->header); | ||
1199 | GNUNET_free (msg); | ||
1200 | } | ||
1201 | |||
1202 | |||
1203 | /** | ||
1204 | * Output information of neighbours to the given client. | 1057 | * Output information of neighbours to the given client. |
1205 | * | 1058 | * |
1206 | * @param cls the `struct PeerIterationContext *` | 1059 | * @param cls the `struct PeerIterationContext *` |
@@ -1306,78 +1159,6 @@ clients_handle_monitor_peers (void *cls, | |||
1306 | 1159 | ||
1307 | 1160 | ||
1308 | /** | 1161 | /** |
1309 | * Client asked to obtain information about a specific or all validation | ||
1310 | * processes | ||
1311 | * | ||
1312 | * @param cls unused | ||
1313 | * @param client the client | ||
1314 | * @param message the peer address information request | ||
1315 | */ | ||
1316 | static void | ||
1317 | clients_handle_monitor_validation (void *cls, | ||
1318 | struct GNUNET_SERVER_Client *client, | ||
1319 | const struct GNUNET_MessageHeader *message) | ||
1320 | { | ||
1321 | struct GNUNET_SERVER_TransmitContext *tc; | ||
1322 | struct PeerMonitorMessage *msg; | ||
1323 | struct IterationContext pc; | ||
1324 | |||
1325 | if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST) | ||
1326 | { | ||
1327 | GNUNET_break (0); | ||
1328 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1329 | return; | ||
1330 | } | ||
1331 | if (ntohs (message->size) != sizeof (struct ValidationMonitorMessage)) | ||
1332 | { | ||
1333 | GNUNET_break (0); | ||
1334 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1335 | return; | ||
1336 | } | ||
1337 | msg = (struct PeerMonitorMessage *) message; | ||
1338 | if ( (GNUNET_YES != ntohl (msg->one_shot)) && | ||
1339 | (NULL != lookup_monitoring_client (val_monitoring_clients_head, client)) ) | ||
1340 | { | ||
1341 | GNUNET_break (0); | ||
1342 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1343 | return; | ||
1344 | } | ||
1345 | GNUNET_SERVER_disable_receive_done_warning (client); | ||
1346 | GNUNET_SERVER_client_mark_monitor (client); | ||
1347 | pc.tc = tc = GNUNET_SERVER_transmit_context_create (client); | ||
1348 | |||
1349 | /* Send initial list */ | ||
1350 | if (0 == memcmp (&msg->peer, | ||
1351 | &all_zeros, | ||
1352 | sizeof (struct GNUNET_PeerIdentity))) | ||
1353 | { | ||
1354 | /* iterate over all neighbours */ | ||
1355 | pc.all = GNUNET_YES; | ||
1356 | pc.id = msg->peer; | ||
1357 | } | ||
1358 | else | ||
1359 | { | ||
1360 | /* just return one neighbour */ | ||
1361 | pc.all = GNUNET_NO; | ||
1362 | pc.id = msg->peer; | ||
1363 | } | ||
1364 | GST_validation_iterate (&send_validation_information, | ||
1365 | &pc); | ||
1366 | |||
1367 | if (GNUNET_YES != ntohl (msg->one_shot)) | ||
1368 | { | ||
1369 | setup_val_monitoring_client (client, &msg->peer); | ||
1370 | } | ||
1371 | else | ||
1372 | { | ||
1373 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | ||
1374 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE); | ||
1375 | } | ||
1376 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | ||
1377 | } | ||
1378 | |||
1379 | |||
1380 | /** | ||
1381 | * Function called by the plugin with information about the | 1162 | * Function called by the plugin with information about the |
1382 | * current sessions managed by the plugin (for monitoring). | 1163 | * current sessions managed by the plugin (for monitoring). |
1383 | * | 1164 | * |
@@ -1514,9 +1295,6 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server) | |||
1514 | {&clients_handle_monitor_peers, NULL, | 1295 | {&clients_handle_monitor_peers, NULL, |
1515 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, | 1296 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, |
1516 | sizeof (struct PeerMonitorMessage)}, | 1297 | sizeof (struct PeerMonitorMessage)}, |
1517 | {&clients_handle_monitor_validation, NULL, | ||
1518 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST, | ||
1519 | sizeof (struct ValidationMonitorMessage)}, | ||
1520 | {&GST_blacklist_handle_init, NULL, | 1298 | {&GST_blacklist_handle_init, NULL, |
1521 | GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, | 1299 | GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, |
1522 | sizeof (struct GNUNET_MessageHeader)}, | 1300 | sizeof (struct GNUNET_MessageHeader)}, |
@@ -1658,49 +1436,6 @@ GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer, | |||
1658 | 1436 | ||
1659 | 1437 | ||
1660 | /** | 1438 | /** |
1661 | * Broadcast the new validation changes to all clients monitoring the peer. | ||
1662 | * | ||
1663 | * @param peer peer this update is about (never NULL) | ||
1664 | * @param address address, NULL on disconnect | ||
1665 | * @param last_validation point in time when last validation was performed | ||
1666 | * @param valid_until point in time how long address is valid | ||
1667 | * @param next_validation point in time when next validation will be performed | ||
1668 | * @param state state of validation notification | ||
1669 | */ | ||
1670 | void | ||
1671 | GST_clients_broadcast_validation_notification (const struct GNUNET_PeerIdentity *peer, | ||
1672 | const struct GNUNET_HELLO_Address *address, | ||
1673 | struct GNUNET_TIME_Absolute last_validation, | ||
1674 | struct GNUNET_TIME_Absolute valid_until, | ||
1675 | struct GNUNET_TIME_Absolute next_validation, | ||
1676 | enum GNUNET_TRANSPORT_ValidationState state) | ||
1677 | { | ||
1678 | struct ValidationIterateResponseMessage *msg; | ||
1679 | struct MonitoringClient *mc; | ||
1680 | |||
1681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1682 | "Sending information about for validation entry for peer `%s' using address `%s'\n", | ||
1683 | GNUNET_i2s(peer), | ||
1684 | (address != NULL) ? GST_plugins_a2s (address) : "<none>"); | ||
1685 | msg = compose_validation_iterate_response_message (peer, address); | ||
1686 | msg->last_validation = GNUNET_TIME_absolute_hton(last_validation); | ||
1687 | msg->valid_until = GNUNET_TIME_absolute_hton(valid_until); | ||
1688 | msg->next_validation = GNUNET_TIME_absolute_hton(next_validation); | ||
1689 | msg->state = htonl ((uint32_t) state); | ||
1690 | for (mc = val_monitoring_clients_head; NULL != mc; mc = mc->next) | ||
1691 | if ((0 == memcmp (&mc->peer, &all_zeros, | ||
1692 | sizeof (struct GNUNET_PeerIdentity))) || | ||
1693 | (0 == memcmp (&mc->peer, peer, | ||
1694 | sizeof (struct GNUNET_PeerIdentity)))) | ||
1695 | GNUNET_SERVER_notification_context_unicast (val_nc, | ||
1696 | mc->client, | ||
1697 | &msg->header, | ||
1698 | GNUNET_NO); | ||
1699 | GNUNET_free (msg); | ||
1700 | } | ||
1701 | |||
1702 | |||
1703 | /** | ||
1704 | * Mark the peer as down so we don't call the continuation | 1439 | * Mark the peer as down so we don't call the continuation |
1705 | * context in the future. | 1440 | * context in the future. |
1706 | * | 1441 | * |
diff --git a/src/transport/gnunet-service-transport_clients.h b/src/transport/gnunet-service-transport_clients.h index 9eee3699a..d85e1e340 100644 --- a/src/transport/gnunet-service-transport_clients.h +++ b/src/transport/gnunet-service-transport_clients.h | |||
@@ -97,24 +97,5 @@ void | |||
97 | GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer); | 97 | GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer); |
98 | 98 | ||
99 | 99 | ||
100 | /** | ||
101 | * Broadcast the new validation changes to all clients monitoring the peer. | ||
102 | * | ||
103 | * @param peer peer this update is about (never NULL) | ||
104 | * @param address address, NULL on disconnect | ||
105 | * @param last_validation point in time when last validation was performed | ||
106 | * @param valid_until point in time how long address is valid | ||
107 | * @param next_validation point in time when next validation will be performed | ||
108 | * @param state state of validation notification | ||
109 | */ | ||
110 | void | ||
111 | GST_clients_broadcast_validation_notification (const struct GNUNET_PeerIdentity *peer, | ||
112 | const struct GNUNET_HELLO_Address *address, | ||
113 | struct GNUNET_TIME_Absolute last_validation, | ||
114 | struct GNUNET_TIME_Absolute valid_until, | ||
115 | struct GNUNET_TIME_Absolute next_validation, | ||
116 | enum GNUNET_TRANSPORT_ValidationState state); | ||
117 | |||
118 | |||
119 | #endif | 100 | #endif |
120 | /* end of file gnunet-service-transport_clients.h */ | 101 | /* end of file gnunet-service-transport_clients.h */ |
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index 6ea5394bf..624e3b93c 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c | |||
@@ -37,6 +37,53 @@ | |||
37 | #include "gnunet_peerinfo_service.h" | 37 | #include "gnunet_peerinfo_service.h" |
38 | #include "gnunet_signatures.h" | 38 | #include "gnunet_signatures.h" |
39 | 39 | ||
40 | /** | ||
41 | * Current state of a validation process. | ||
42 | * | ||
43 | * FIXME: what state is used to indicate that a validation | ||
44 | * was successful? If that is clarified/determined, "UGH" in | ||
45 | * ~gnunetpeerinfogtk.c:1103 should be resolved. | ||
46 | */ | ||
47 | enum GNUNET_TRANSPORT_ValidationState | ||
48 | { | ||
49 | /** | ||
50 | * Undefined state | ||
51 | * | ||
52 | * Used for final callback indicating operation done | ||
53 | */ | ||
54 | GNUNET_TRANSPORT_VS_NONE, | ||
55 | |||
56 | /** | ||
57 | * Fresh validation entry | ||
58 | * | ||
59 | * Entry was just created, no validation process was executed | ||
60 | */ | ||
61 | GNUNET_TRANSPORT_VS_NEW, | ||
62 | |||
63 | /** | ||
64 | * Updated validation entry | ||
65 | * | ||
66 | * This is an update for an existing validation entry | ||
67 | */ | ||
68 | GNUNET_TRANSPORT_VS_UPDATE, | ||
69 | |||
70 | /** | ||
71 | * Timeout for validation entry | ||
72 | * | ||
73 | * A timeout occured during the validation process | ||
74 | */ | ||
75 | GNUNET_TRANSPORT_VS_TIMEOUT, | ||
76 | |||
77 | /** | ||
78 | * Validation entry is removed | ||
79 | * | ||
80 | * The validation entry is getting removed due to a failed validation | ||
81 | */ | ||
82 | GNUNET_TRANSPORT_VS_REMOVE | ||
83 | }; | ||
84 | |||
85 | |||
86 | |||
40 | 87 | ||
41 | /** | 88 | /** |
42 | * How long is a PONG signature valid? We'll recycle a signature until | 89 | * How long is a PONG signature valid? We'll recycle a signature until |
@@ -385,12 +432,6 @@ validation_entry_changed (struct ValidationEntry *ve, | |||
385 | enum GNUNET_TRANSPORT_ValidationState state) | 432 | enum GNUNET_TRANSPORT_ValidationState state) |
386 | { | 433 | { |
387 | ve->state = state; | 434 | ve->state = state; |
388 | GST_clients_broadcast_validation_notification (&ve->address->peer, | ||
389 | ve->address, | ||
390 | ve->send_time, | ||
391 | ve->valid_until, | ||
392 | ve->next_validation, | ||
393 | state); | ||
394 | } | 435 | } |
395 | 436 | ||
396 | 437 | ||
@@ -1733,74 +1774,4 @@ GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address, | |||
1733 | } | 1774 | } |
1734 | 1775 | ||
1735 | 1776 | ||
1736 | /** | ||
1737 | * Closure for the validation_entries_iterate function. | ||
1738 | */ | ||
1739 | struct ValidationIteratorContext | ||
1740 | { | ||
1741 | /** | ||
1742 | * Function to call on each validation entry | ||
1743 | */ | ||
1744 | GST_ValidationChangedCallback cb; | ||
1745 | |||
1746 | /** | ||
1747 | * Closure for @e cb. | ||
1748 | */ | ||
1749 | void *cb_cls; | ||
1750 | }; | ||
1751 | |||
1752 | |||
1753 | /** | ||
1754 | * Function called on each entry in the validation map. | ||
1755 | * Passes the information from the validation entry to | ||
1756 | * the callback given in the closure. | ||
1757 | * | ||
1758 | * @param cls the `struct ValidationIteratorContext` | ||
1759 | * @param key peer this is about | ||
1760 | * @param value the `struct ValidationEntry` | ||
1761 | * @return #GNUNET_OK (continue to iterate) | ||
1762 | */ | ||
1763 | static int | ||
1764 | validation_entries_iterate (void *cls, | ||
1765 | const struct GNUNET_PeerIdentity *key, | ||
1766 | void *value) | ||
1767 | { | ||
1768 | struct ValidationIteratorContext *ic = cls; | ||
1769 | struct ValidationEntry *ve = value; | ||
1770 | |||
1771 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1772 | "Notifying about validation entry for peer `%s' address `%s' \n", | ||
1773 | GNUNET_i2s (&ve->address->peer), | ||
1774 | GST_plugins_a2s (ve->address)); | ||
1775 | ic->cb (ic->cb_cls, | ||
1776 | ve->address, | ||
1777 | ve->send_time, | ||
1778 | ve->valid_until, | ||
1779 | ve->next_validation, | ||
1780 | ve->state); | ||
1781 | return GNUNET_OK; | ||
1782 | } | ||
1783 | |||
1784 | |||
1785 | /** | ||
1786 | * Iterate over all iteration entries | ||
1787 | * | ||
1788 | * @param cb function to call | ||
1789 | * @param cb_cls closure for @a cb | ||
1790 | */ | ||
1791 | void | ||
1792 | GST_validation_iterate (GST_ValidationChangedCallback cb, | ||
1793 | void *cb_cls) | ||
1794 | { | ||
1795 | struct ValidationIteratorContext ic; | ||
1796 | |||
1797 | if (NULL == validation_map) | ||
1798 | return; /* can happen during shutdown */ | ||
1799 | ic.cb = cb; | ||
1800 | ic.cb_cls = cb_cls; | ||
1801 | GNUNET_CONTAINER_multipeermap_iterate (validation_map, | ||
1802 | &validation_entries_iterate, | ||
1803 | &ic); | ||
1804 | } | ||
1805 | |||
1806 | /* end of file gnunet-service-transport_validation.c */ | 1777 | /* end of file gnunet-service-transport_validation.c */ |
diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h index ec516b3a9..53528437a 100644 --- a/src/transport/gnunet-service-transport_validation.h +++ b/src/transport/gnunet-service-transport_validation.h | |||
@@ -62,36 +62,6 @@ GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address, | |||
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Function called to notify transport users that a neighbour peer changed its | ||
66 | * active address. | ||
67 | * | ||
68 | * @param cls closure | ||
69 | * @param address address (never NULL) | ||
70 | * @param last_validation point in time when last validation was performed | ||
71 | * @param valid_until point in time how long address is valid | ||
72 | * @param next_validation point in time when next validation will be performed | ||
73 | * @param state state of validation notification | ||
74 | */ | ||
75 | typedef void | ||
76 | (*GST_ValidationChangedCallback) (void *cls, | ||
77 | const struct GNUNET_HELLO_Address *address, | ||
78 | struct GNUNET_TIME_Absolute last_validation, | ||
79 | struct GNUNET_TIME_Absolute valid_until, | ||
80 | struct GNUNET_TIME_Absolute next_validation, | ||
81 | enum GNUNET_TRANSPORT_ValidationState state); | ||
82 | |||
83 | |||
84 | /** | ||
85 | * Iterate over all iteration entries | ||
86 | * | ||
87 | * @param cb function to call | ||
88 | * @param cb_cls closure for @a cb | ||
89 | */ | ||
90 | void | ||
91 | GST_validation_iterate (GST_ValidationChangedCallback cb, void *cb_cls); | ||
92 | |||
93 | |||
94 | /** | ||
95 | * We've received a PING. If appropriate, generate a PONG. | 65 | * We've received a PING. If appropriate, generate a PONG. |
96 | * | 66 | * |
97 | * @param sender peer sending the PING | 67 | * @param sender peer sending the PING |
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 85f22a7f2..994dd0111 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -87,11 +87,6 @@ struct ValidationResolutionContext | |||
87 | struct GNUNET_TIME_Absolute next_validation; | 87 | struct GNUNET_TIME_Absolute next_validation; |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * state of validation process | ||
91 | */ | ||
92 | enum GNUNET_TRANSPORT_ValidationState state; | ||
93 | |||
94 | /** | ||
95 | * Tranport conversion handle | 90 | * Tranport conversion handle |
96 | */ | 91 | */ |
97 | struct GNUNET_TRANSPORT_AddressToStringContext *asc; | 92 | struct GNUNET_TRANSPORT_AddressToStringContext *asc; |
@@ -296,11 +291,6 @@ static int benchmark_receive; | |||
296 | static int iterate_connections; | 291 | static int iterate_connections; |
297 | 292 | ||
298 | /** | 293 | /** |
299 | * Option -d. | ||
300 | */ | ||
301 | static int iterate_validation; | ||
302 | |||
303 | /** | ||
304 | * Option -a. | 294 | * Option -a. |
305 | */ | 295 | */ |
306 | static int iterate_all; | 296 | static int iterate_all; |
@@ -321,11 +311,6 @@ static int monitor_connects; | |||
321 | static int monitor_connections; | 311 | static int monitor_connections; |
322 | 312 | ||
323 | /** | 313 | /** |
324 | * Option -f. | ||
325 | */ | ||
326 | static int monitor_validation; | ||
327 | |||
328 | /** | ||
329 | * Option -P. | 314 | * Option -P. |
330 | */ | 315 | */ |
331 | static int monitor_plugins; | 316 | static int monitor_plugins; |
@@ -386,11 +371,6 @@ static struct GNUNET_CONTAINER_MultiPeerMap *monitored_plugins; | |||
386 | static struct GNUNET_TRANSPORT_PeerMonitoringContext *pic; | 371 | static struct GNUNET_TRANSPORT_PeerMonitoringContext *pic; |
387 | 372 | ||
388 | /** | 373 | /** |
389 | * Handle if we are monitoring transport validation activity. | ||
390 | */ | ||
391 | static struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic; | ||
392 | |||
393 | /** | ||
394 | * Handle if we are monitoring plugin session activity. | 374 | * Handle if we are monitoring plugin session activity. |
395 | */ | 375 | */ |
396 | static struct GNUNET_TRANSPORT_PluginMonitor *pm; | 376 | static struct GNUNET_TRANSPORT_PluginMonitor *pm; |
@@ -507,11 +487,6 @@ shutdown_task (void *cls) | |||
507 | GNUNET_TRANSPORT_monitor_peers_cancel (pic); | 487 | GNUNET_TRANSPORT_monitor_peers_cancel (pic); |
508 | pic = NULL; | 488 | pic = NULL; |
509 | } | 489 | } |
510 | if (NULL != vic) | ||
511 | { | ||
512 | GNUNET_TRANSPORT_monitor_validation_entries_cancel (vic); | ||
513 | vic = NULL; | ||
514 | } | ||
515 | if (NULL != pm) | 490 | if (NULL != pm) |
516 | { | 491 | { |
517 | GNUNET_TRANSPORT_monitor_plugins_cancel (pm); | 492 | GNUNET_TRANSPORT_monitor_plugins_cancel (pm); |
@@ -729,217 +704,6 @@ result_callback (void *cls, | |||
729 | } | 704 | } |
730 | 705 | ||
731 | 706 | ||
732 | /** | ||
733 | * Resolve address we got a validation state for to a string. | ||
734 | * | ||
735 | * @param address the address itself | ||
736 | * @param numeric #GNUNET_YES to disable DNS, #GNUNET_NO to try reverse lookup | ||
737 | * @param last_validation when was the address validated last | ||
738 | * @param valid_until until when is the address valid | ||
739 | * @param next_validation when will we try to revalidate the address next | ||
740 | * @param state where are we in the validation state machine | ||
741 | */ | ||
742 | static void | ||
743 | resolve_validation_address (const struct GNUNET_HELLO_Address *address, | ||
744 | int numeric, | ||
745 | struct GNUNET_TIME_Absolute last_validation, | ||
746 | struct GNUNET_TIME_Absolute valid_until, | ||
747 | struct GNUNET_TIME_Absolute next_validation, | ||
748 | enum GNUNET_TRANSPORT_ValidationState state); | ||
749 | |||
750 | |||
751 | /** | ||
752 | * Function to call with a textual representation of an address. This | ||
753 | * function will be called several times with different possible | ||
754 | * textual representations, and a last time with @a address being NULL | ||
755 | * to signal the end of the iteration. Note that @a address NULL | ||
756 | * always is the last call, regardless of the value in @a res. | ||
757 | * | ||
758 | * @param cls closure | ||
759 | * @param address NULL on end of iteration, | ||
760 | * otherwise 0-terminated printable UTF-8 string, | ||
761 | * in particular an empty string if @a res is #GNUNET_NO | ||
762 | * @param res result of the address to string conversion: | ||
763 | * if #GNUNET_OK: conversion successful | ||
764 | * if #GNUNET_NO: address was invalid (or not supported) | ||
765 | * if #GNUNET_SYSERR: communication error (IPC error) | ||
766 | */ | ||
767 | static void | ||
768 | process_validation_string (void *cls, | ||
769 | const char *address, | ||
770 | int res) | ||
771 | { | ||
772 | struct ValidationResolutionContext *vc = cls; | ||
773 | char *s_valid; | ||
774 | char *s_last; | ||
775 | char *s_next; | ||
776 | |||
777 | if (NULL != address) | ||
778 | { | ||
779 | if (GNUNET_SYSERR == res) | ||
780 | { | ||
781 | FPRINTF (stderr, | ||
782 | "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", | ||
783 | GNUNET_i2s (&vc->addrcp->peer), | ||
784 | vc->addrcp->transport_name, | ||
785 | (unsigned int) vc->addrcp->address_length); | ||
786 | } | ||
787 | if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->valid_until.abs_value_us) | ||
788 | s_valid = GNUNET_strdup ("never"); | ||
789 | else | ||
790 | s_valid = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->valid_until)); | ||
791 | |||
792 | if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->last_validation.abs_value_us) | ||
793 | s_last = GNUNET_strdup ("never"); | ||
794 | else | ||
795 | s_last = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->last_validation)); | ||
796 | |||
797 | if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->next_validation.abs_value_us) | ||
798 | s_next = GNUNET_strdup ("never"); | ||
799 | else | ||
800 | s_next = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->next_validation)); | ||
801 | |||
802 | FPRINTF (stdout, | ||
803 | _("Peer `%s' %s %s\n\t%s%s\n\t%s%s\n\t%s%s\n"), | ||
804 | GNUNET_i2s (&vc->addrcp->peer), | ||
805 | (GNUNET_OK == res) ? address : "<invalid address>", | ||
806 | (monitor_validation) ? GNUNET_TRANSPORT_vs2s (vc->state) : "", | ||
807 | "Valid until : ", s_valid, | ||
808 | "Last validation: ",s_last, | ||
809 | "Next validation: ", s_next); | ||
810 | GNUNET_free (s_valid); | ||
811 | GNUNET_free (s_last); | ||
812 | GNUNET_free (s_next); | ||
813 | vc->printed = GNUNET_YES; | ||
814 | return; | ||
815 | } | ||
816 | /* last call, we are done */ | ||
817 | GNUNET_assert (address_resolutions > 0); | ||
818 | address_resolutions--; | ||
819 | if ( (GNUNET_SYSERR == res) && | ||
820 | (GNUNET_NO == vc->printed)) | ||
821 | { | ||
822 | if (numeric == GNUNET_NO) | ||
823 | { | ||
824 | /* Failed to resolve address, try numeric lookup | ||
825 | (note: this should be unnecessary, as | ||
826 | transport should fallback to numeric lookup | ||
827 | internally if DNS takes too long anyway) */ | ||
828 | resolve_validation_address (vc->addrcp, | ||
829 | GNUNET_NO, | ||
830 | vc->last_validation, | ||
831 | vc->valid_until, | ||
832 | vc->next_validation, | ||
833 | vc->state); | ||
834 | } | ||
835 | else | ||
836 | { | ||
837 | FPRINTF (stdout, | ||
838 | _("Peer `%s' %s `%s' \n"), | ||
839 | GNUNET_i2s (&vc->addrcp->peer), | ||
840 | "<unable to resolve address>", | ||
841 | GNUNET_TRANSPORT_vs2s (vc->state)); | ||
842 | } | ||
843 | } | ||
844 | GNUNET_free (vc->transport); | ||
845 | GNUNET_free (vc->addrcp); | ||
846 | GNUNET_CONTAINER_DLL_remove (vc_head, vc_tail, vc); | ||
847 | GNUNET_free (vc); | ||
848 | if ((0 == address_resolutions) && (iterate_validation)) | ||
849 | { | ||
850 | if (NULL != op_timeout) | ||
851 | { | ||
852 | GNUNET_SCHEDULER_cancel (op_timeout); | ||
853 | op_timeout = NULL; | ||
854 | } | ||
855 | ret = 0; | ||
856 | GNUNET_SCHEDULER_shutdown (); | ||
857 | } | ||
858 | } | ||
859 | |||
860 | |||
861 | /** | ||
862 | * Resolve address we got a validation state for to a string. | ||
863 | * | ||
864 | * @param address the address itself | ||
865 | * @param numeric #GNUNET_YES to disable DNS, #GNUNET_NO to try reverse lookup | ||
866 | * @param last_validation when was the address validated last | ||
867 | * @param valid_until until when is the address valid | ||
868 | * @param next_validation when will we try to revalidate the address next | ||
869 | * @param state where are we in the validation state machine | ||
870 | */ | ||
871 | static void | ||
872 | resolve_validation_address (const struct GNUNET_HELLO_Address *address, | ||
873 | int numeric, | ||
874 | struct GNUNET_TIME_Absolute last_validation, | ||
875 | struct GNUNET_TIME_Absolute valid_until, | ||
876 | struct GNUNET_TIME_Absolute next_validation, | ||
877 | enum GNUNET_TRANSPORT_ValidationState state) | ||
878 | { | ||
879 | struct ValidationResolutionContext *vc; | ||
880 | |||
881 | vc = GNUNET_new (struct ValidationResolutionContext); | ||
882 | GNUNET_assert(NULL != vc); | ||
883 | GNUNET_CONTAINER_DLL_insert(vc_head, vc_tail, vc); | ||
884 | address_resolutions++; | ||
885 | |||
886 | vc->transport = GNUNET_strdup(address->transport_name); | ||
887 | vc->addrcp = GNUNET_HELLO_address_copy (address); | ||
888 | vc->printed = GNUNET_NO; | ||
889 | vc->state = state; | ||
890 | vc->last_validation = last_validation; | ||
891 | vc->valid_until = valid_until; | ||
892 | vc->next_validation = next_validation; | ||
893 | |||
894 | /* Resolve address to string */ | ||
895 | vc->asc = GNUNET_TRANSPORT_address_to_string (cfg, | ||
896 | address, | ||
897 | numeric, | ||
898 | RESOLUTION_TIMEOUT, | ||
899 | &process_validation_string, vc); | ||
900 | } | ||
901 | |||
902 | |||
903 | /** | ||
904 | * Resolve address we got a validation state for to a string. | ||
905 | * | ||
906 | * @param cls NULL | ||
907 | * @param address the address itself | ||
908 | * @param last_validation when was the address validated last | ||
909 | * @param valid_until until when is the address valid | ||
910 | * @param next_validation when will we try to revalidate the address next | ||
911 | * @param state where are we in the validation state machine | ||
912 | */ | ||
913 | static void | ||
914 | process_validation_cb (void *cls, | ||
915 | const struct GNUNET_HELLO_Address *address, | ||
916 | struct GNUNET_TIME_Absolute last_validation, | ||
917 | struct GNUNET_TIME_Absolute valid_until, | ||
918 | struct GNUNET_TIME_Absolute next_validation, | ||
919 | enum GNUNET_TRANSPORT_ValidationState state) | ||
920 | { | ||
921 | if (NULL == address) | ||
922 | { | ||
923 | if (monitor_validation) | ||
924 | { | ||
925 | FPRINTF (stdout, | ||
926 | "%s", | ||
927 | _("Monitor disconnected from transport service. Reconnecting.\n")); | ||
928 | return; | ||
929 | } | ||
930 | vic = NULL; | ||
931 | GNUNET_SCHEDULER_shutdown (); | ||
932 | return; | ||
933 | } | ||
934 | resolve_validation_address (address, | ||
935 | numeric, | ||
936 | last_validation, | ||
937 | valid_until, | ||
938 | next_validation, | ||
939 | state); | ||
940 | } | ||
941 | |||
942 | |||
943 | static void | 707 | static void |
944 | run_nat_test () | 708 | run_nat_test () |
945 | { | 709 | { |
@@ -1784,7 +1548,7 @@ testservice_task (void *cls, | |||
1784 | 1548 | ||
1785 | counter = benchmark_send + benchmark_receive + iterate_connections | 1549 | counter = benchmark_send + benchmark_receive + iterate_connections |
1786 | + monitor_connections + monitor_connects + do_disconnect + | 1550 | + monitor_connections + monitor_connects + do_disconnect + |
1787 | + iterate_validation + monitor_validation + monitor_plugins; | 1551 | monitor_plugins; |
1788 | 1552 | ||
1789 | if (1 < counter) | 1553 | if (1 < counter) |
1790 | { | 1554 | { |
@@ -1901,20 +1665,6 @@ testservice_task (void *cls, | |||
1901 | &plugin_monitoring_cb, | 1665 | &plugin_monitoring_cb, |
1902 | NULL); | 1666 | NULL); |
1903 | } | 1667 | } |
1904 | else if (iterate_validation) /* -d: Print information about validations */ | ||
1905 | { | ||
1906 | vic = GNUNET_TRANSPORT_monitor_validation_entries (cfg, | ||
1907 | (NULL == cpid) ? NULL : &pid, | ||
1908 | GNUNET_YES, TIMEOUT, | ||
1909 | &process_validation_cb, (void *) cfg); | ||
1910 | } | ||
1911 | else if (monitor_validation) /* -f: Print information about validations continuously */ | ||
1912 | { | ||
1913 | vic = GNUNET_TRANSPORT_monitor_validation_entries (cfg, | ||
1914 | (NULL == cpid) ? NULL : &pid, | ||
1915 | GNUNET_NO, TIMEOUT, | ||
1916 | &process_validation_cb, (void *) cfg); | ||
1917 | } | ||
1918 | else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */ | 1668 | else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */ |
1919 | { | 1669 | { |
1920 | monitor_connect_counter = 0; | 1670 | monitor_connect_counter = 0; |
@@ -1985,12 +1735,6 @@ main (int argc, | |||
1985 | { 'D', "disconnect", | 1735 | { 'D', "disconnect", |
1986 | NULL, gettext_noop ("disconnect from a peer"), 0, | 1736 | NULL, gettext_noop ("disconnect from a peer"), 0, |
1987 | &GNUNET_GETOPT_set_one, &do_disconnect }, | 1737 | &GNUNET_GETOPT_set_one, &do_disconnect }, |
1988 | { 'd', "validation", NULL, | ||
1989 | gettext_noop ("print information for all pending validations "), | ||
1990 | 0, &GNUNET_GETOPT_set_one, &iterate_validation }, | ||
1991 | { 'f', "monitorvalidation", NULL, | ||
1992 | gettext_noop ("print information for all pending validations continuously"), | ||
1993 | 0, &GNUNET_GETOPT_set_one, &monitor_validation }, | ||
1994 | { 'i', "information", NULL, | 1738 | { 'i', "information", NULL, |
1995 | gettext_noop ("provide information about all current connections (once)"), | 1739 | gettext_noop ("provide information about all current connections (once)"), |
1996 | 0, &GNUNET_GETOPT_set_one, &iterate_connections }, | 1740 | 0, &GNUNET_GETOPT_set_one, &iterate_connections }, |
diff --git a/src/transport/transport_api_monitor_validation.c b/src/transport/transport_api_monitor_validation.c deleted file mode 100644 index fa76645dd..000000000 --- a/src/transport/transport_api_monitor_validation.c +++ /dev/null | |||
@@ -1,402 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2010 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file transport/transport_api_monitor_validation.c | ||
23 | * @brief montoring api for validation status | ||
24 | * | ||
25 | * This api provides the ability to query the transport service about | ||
26 | * the status of address validation. | ||
27 | */ | ||
28 | #include "platform.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_arm_service.h" | ||
31 | #include "gnunet_hello_lib.h" | ||
32 | #include "gnunet_protocols.h" | ||
33 | #include "gnunet_transport_service.h" | ||
34 | #include "transport.h" | ||
35 | |||
36 | |||
37 | /** | ||
38 | * Context for the address lookup. | ||
39 | */ | ||
40 | struct GNUNET_TRANSPORT_ValidationMonitoringContext | ||
41 | { | ||
42 | /** | ||
43 | * Function to call with the binary address. | ||
44 | */ | ||
45 | GNUNET_TRANSPORT_ValidationIterateCallback cb; | ||
46 | |||
47 | /** | ||
48 | * Closure for @e cb. | ||
49 | */ | ||
50 | void *cb_cls; | ||
51 | |||
52 | /** | ||
53 | * Connection to the service. | ||
54 | */ | ||
55 | struct GNUNET_CLIENT_Connection *client; | ||
56 | |||
57 | /** | ||
58 | * Configuration we use. | ||
59 | */ | ||
60 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
61 | |||
62 | /** | ||
63 | * When should this operation time out? | ||
64 | */ | ||
65 | struct GNUNET_TIME_Absolute timeout; | ||
66 | |||
67 | /** | ||
68 | * Backoff for reconnect. | ||
69 | */ | ||
70 | struct GNUNET_TIME_Relative backoff; | ||
71 | |||
72 | /** | ||
73 | * Task ID for reconnect. | ||
74 | */ | ||
75 | struct GNUNET_SCHEDULER_Task * reconnect_task; | ||
76 | |||
77 | /** | ||
78 | * Identity of the peer to monitor. | ||
79 | */ | ||
80 | struct GNUNET_PeerIdentity peer; | ||
81 | |||
82 | /** | ||
83 | * Was this a one-shot request? | ||
84 | */ | ||
85 | int one_shot; | ||
86 | }; | ||
87 | |||
88 | |||
89 | /** | ||
90 | * Convert validation state to human-readable string. | ||
91 | * | ||
92 | * @param state the state value | ||
93 | * @return corresponding string | ||
94 | */ | ||
95 | const char * | ||
96 | GNUNET_TRANSPORT_vs2s (enum GNUNET_TRANSPORT_ValidationState state) | ||
97 | { | ||
98 | switch (state) | ||
99 | { | ||
100 | case GNUNET_TRANSPORT_VS_NONE: | ||
101 | return "NONE"; | ||
102 | case GNUNET_TRANSPORT_VS_NEW: | ||
103 | return "NEW"; | ||
104 | case GNUNET_TRANSPORT_VS_REMOVE: | ||
105 | return "REMOVE"; | ||
106 | case GNUNET_TRANSPORT_VS_TIMEOUT: | ||
107 | return "TIMEOUT"; | ||
108 | case GNUNET_TRANSPORT_VS_UPDATE: | ||
109 | return "UPDATE"; | ||
110 | default: | ||
111 | GNUNET_break (0); | ||
112 | return "UNDEFINED"; | ||
113 | } | ||
114 | } | ||
115 | |||
116 | |||
117 | /** | ||
118 | * Function called with responses from the service. | ||
119 | * | ||
120 | * @param cls our `struct GNUNET_TRANSPORT_ValidationMonitoringContext *` | ||
121 | * @param msg NULL on timeout or error, otherwise presumably a | ||
122 | * message with the human-readable address | ||
123 | */ | ||
124 | static void | ||
125 | val_response_processor (void *cls, | ||
126 | const struct GNUNET_MessageHeader *msg); | ||
127 | |||
128 | |||
129 | /** | ||
130 | * Send our subscription request to the service. | ||
131 | * | ||
132 | * @param val_ctx our context | ||
133 | */ | ||
134 | static void | ||
135 | send_val_mon_request (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx) | ||
136 | { | ||
137 | struct ValidationMonitorMessage msg; | ||
138 | |||
139 | msg.header.size = htons (sizeof (struct ValidationMonitorMessage)); | ||
140 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST); | ||
141 | msg.one_shot = htonl (val_ctx->one_shot); | ||
142 | msg.peer = val_ctx->peer; | ||
143 | GNUNET_assert (GNUNET_OK == | ||
144 | GNUNET_CLIENT_transmit_and_get_response (val_ctx->client, | ||
145 | &msg.header, | ||
146 | GNUNET_TIME_absolute_get_remaining (val_ctx->timeout), | ||
147 | GNUNET_YES, | ||
148 | &val_response_processor, | ||
149 | val_ctx)); | ||
150 | } | ||
151 | |||
152 | |||
153 | /** | ||
154 | * Task run to re-establish the connection. | ||
155 | * | ||
156 | * @param cls our `struct GNUNET_TRANSPORT_ValidationMonitoringContext *` | ||
157 | */ | ||
158 | static void | ||
159 | do_val_connect (void *cls) | ||
160 | { | ||
161 | struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx = cls; | ||
162 | |||
163 | val_ctx->reconnect_task = NULL; | ||
164 | val_ctx->client = GNUNET_CLIENT_connect ("transport", val_ctx->cfg); | ||
165 | GNUNET_assert (NULL != val_ctx->client); | ||
166 | send_val_mon_request (val_ctx); | ||
167 | } | ||
168 | |||
169 | |||
170 | /** | ||
171 | * Cut the existing connection and reconnect. | ||
172 | * | ||
173 | * @param val_ctx our context | ||
174 | */ | ||
175 | static void | ||
176 | reconnect_val_ctx (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx) | ||
177 | { | ||
178 | GNUNET_assert (GNUNET_NO == val_ctx->one_shot); | ||
179 | GNUNET_CLIENT_disconnect (val_ctx->client); | ||
180 | val_ctx->client = NULL; | ||
181 | /* notify clients about (re)connect */ | ||
182 | val_ctx->cb (val_ctx->cb_cls, NULL, | ||
183 | GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS, | ||
184 | GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_TIMEOUT); | ||
185 | val_ctx->backoff = GNUNET_TIME_STD_BACKOFF (val_ctx->backoff); | ||
186 | val_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (val_ctx->backoff, | ||
187 | &do_val_connect, | ||
188 | val_ctx); | ||
189 | } | ||
190 | |||
191 | |||
192 | /** | ||
193 | * Function called with responses from the service. | ||
194 | * | ||
195 | * @param cls our `struct GNUNET_TRANSPORT_ValidationMonitoringContext *` | ||
196 | * @param msg NULL on timeout or error, otherwise presumably a | ||
197 | * message with the human-readable address | ||
198 | */ | ||
199 | static void | ||
200 | val_response_processor (void *cls, | ||
201 | const struct GNUNET_MessageHeader *msg) | ||
202 | { | ||
203 | struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx = cls; | ||
204 | struct ValidationIterateResponseMessage *vr_msg; | ||
205 | struct GNUNET_HELLO_Address *address; | ||
206 | const char *addr; | ||
207 | const char *transport_name; | ||
208 | size_t size; | ||
209 | size_t tlen; | ||
210 | size_t alen; | ||
211 | |||
212 | if (NULL == msg) | ||
213 | { | ||
214 | if (val_ctx->one_shot) | ||
215 | { | ||
216 | /* Disconnect */ | ||
217 | val_ctx->cb (val_ctx->cb_cls, NULL, | ||
218 | GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS, | ||
219 | GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_TIMEOUT); | ||
220 | GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx); | ||
221 | } | ||
222 | else | ||
223 | { | ||
224 | reconnect_val_ctx (val_ctx); | ||
225 | } | ||
226 | return; | ||
227 | } | ||
228 | size = ntohs (msg->size); | ||
229 | GNUNET_break (ntohs (msg->type) == | ||
230 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE); | ||
231 | |||
232 | if (size == sizeof (struct GNUNET_MessageHeader)) | ||
233 | { | ||
234 | /* Done! */ | ||
235 | if (val_ctx->one_shot) | ||
236 | { | ||
237 | val_ctx->cb (val_ctx->cb_cls, NULL, | ||
238 | GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS, | ||
239 | GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_NONE); | ||
240 | GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx); | ||
241 | } | ||
242 | else | ||
243 | { | ||
244 | reconnect_val_ctx (val_ctx); | ||
245 | } | ||
246 | return; | ||
247 | } | ||
248 | |||
249 | if ((size < sizeof (struct ValidationIterateResponseMessage)) || | ||
250 | (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE)) | ||
251 | { | ||
252 | GNUNET_break (0); | ||
253 | if (val_ctx->one_shot) | ||
254 | { | ||
255 | val_ctx->cb (val_ctx->cb_cls, NULL, | ||
256 | GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS, | ||
257 | GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_NONE); | ||
258 | GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx); | ||
259 | } | ||
260 | else | ||
261 | { | ||
262 | reconnect_val_ctx (val_ctx); | ||
263 | } | ||
264 | return; | ||
265 | } | ||
266 | |||
267 | vr_msg = (struct ValidationIterateResponseMessage *) msg; | ||
268 | tlen = ntohl (vr_msg->pluginlen); | ||
269 | alen = ntohl (vr_msg->addrlen); | ||
270 | |||
271 | if (size != sizeof (struct ValidationIterateResponseMessage) + tlen + alen) | ||
272 | { | ||
273 | GNUNET_break (0); | ||
274 | if (val_ctx->one_shot) | ||
275 | { | ||
276 | val_ctx->cb (val_ctx->cb_cls, NULL, | ||
277 | GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS, | ||
278 | GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_NONE); | ||
279 | GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx); | ||
280 | } | ||
281 | else | ||
282 | { | ||
283 | reconnect_val_ctx (val_ctx); | ||
284 | } | ||
285 | return; | ||
286 | } | ||
287 | if (0 == tlen) | ||
288 | { | ||
289 | GNUNET_break (0); /* This must not happen: address without plugin */ | ||
290 | return; | ||
291 | } | ||
292 | addr = (const char *) &vr_msg[1]; | ||
293 | transport_name = &addr[alen]; | ||
294 | |||
295 | if (transport_name[tlen - 1] != '\0') | ||
296 | { | ||
297 | /* Corrupt plugin name */ | ||
298 | GNUNET_break (0); | ||
299 | if (val_ctx->one_shot) | ||
300 | { | ||
301 | val_ctx->cb (val_ctx->cb_cls, | ||
302 | NULL, | ||
303 | GNUNET_TIME_UNIT_ZERO_ABS, | ||
304 | GNUNET_TIME_UNIT_ZERO_ABS, | ||
305 | GNUNET_TIME_UNIT_ZERO_ABS, | ||
306 | GNUNET_TRANSPORT_VS_NONE); | ||
307 | GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx); | ||
308 | } | ||
309 | else | ||
310 | { | ||
311 | reconnect_val_ctx (val_ctx); | ||
312 | } | ||
313 | return; | ||
314 | } | ||
315 | |||
316 | /* notify client */ | ||
317 | address = GNUNET_HELLO_address_allocate (&vr_msg->peer, | ||
318 | transport_name, | ||
319 | addr, alen, | ||
320 | ntohl (vr_msg->local_address_info)); | ||
321 | val_ctx->cb (val_ctx->cb_cls, | ||
322 | address, | ||
323 | GNUNET_TIME_absolute_ntoh (vr_msg->last_validation), | ||
324 | GNUNET_TIME_absolute_ntoh (vr_msg->valid_until), | ||
325 | GNUNET_TIME_absolute_ntoh (vr_msg->next_validation), | ||
326 | ntohl(vr_msg->state)); | ||
327 | GNUNET_HELLO_address_free (address); | ||
328 | /* expect more replies */ | ||
329 | GNUNET_CLIENT_receive (val_ctx->client, | ||
330 | &val_response_processor, | ||
331 | val_ctx, | ||
332 | GNUNET_TIME_absolute_get_remaining (val_ctx->timeout)); | ||
333 | } | ||
334 | |||
335 | |||
336 | /** | ||
337 | * Return information about pending address validation operations for a specific | ||
338 | * or all peers | ||
339 | * | ||
340 | * @param cfg configuration to use | ||
341 | * @param peer a specific peer identity to obtain validation entries for, | ||
342 | * NULL for all peers | ||
343 | * @param one_shot #GNUNET_YES to return all entries and then end (with NULL+NULL), | ||
344 | * #GNUNET_NO to monitor validation entries continuously | ||
345 | * @param timeout how long is the lookup allowed to take at most | ||
346 | * @param validation_callback function to call with the results | ||
347 | * @param validation_callback_cls closure for peer_address_callback | ||
348 | */ | ||
349 | struct GNUNET_TRANSPORT_ValidationMonitoringContext * | ||
350 | GNUNET_TRANSPORT_monitor_validation_entries (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
351 | const struct GNUNET_PeerIdentity *peer, | ||
352 | int one_shot, | ||
353 | struct GNUNET_TIME_Relative timeout, | ||
354 | GNUNET_TRANSPORT_ValidationIterateCallback validation_callback, | ||
355 | void *validation_callback_cls) | ||
356 | { | ||
357 | struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx; | ||
358 | struct GNUNET_CLIENT_Connection *client; | ||
359 | |||
360 | client = GNUNET_CLIENT_connect ("transport", cfg); | ||
361 | if (NULL == client) | ||
362 | return NULL; | ||
363 | if (GNUNET_YES != one_shot) | ||
364 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; | ||
365 | val_ctx = GNUNET_new (struct GNUNET_TRANSPORT_ValidationMonitoringContext); | ||
366 | val_ctx->cb = validation_callback; | ||
367 | val_ctx->cb_cls = validation_callback_cls; | ||
368 | val_ctx->cfg = cfg; | ||
369 | val_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); | ||
370 | if (NULL != peer) | ||
371 | val_ctx->peer = *peer; | ||
372 | val_ctx->one_shot = one_shot; | ||
373 | val_ctx->client = client; | ||
374 | send_val_mon_request (val_ctx); | ||
375 | |||
376 | return val_ctx; | ||
377 | } | ||
378 | |||
379 | |||
380 | /** | ||
381 | * Return information about all current pending validation operations | ||
382 | * | ||
383 | * @param vic handle for the request to cancel | ||
384 | */ | ||
385 | void | ||
386 | GNUNET_TRANSPORT_monitor_validation_entries_cancel (struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic) | ||
387 | { | ||
388 | if (NULL != vic->client) | ||
389 | { | ||
390 | GNUNET_CLIENT_disconnect (vic->client); | ||
391 | vic->client = NULL; | ||
392 | } | ||
393 | if (NULL != vic->reconnect_task) | ||
394 | { | ||
395 | GNUNET_SCHEDULER_cancel (vic->reconnect_task); | ||
396 | vic->reconnect_task = NULL; | ||
397 | } | ||
398 | GNUNET_free (vic); | ||
399 | } | ||
400 | |||
401 | |||
402 | /* end of transport_api_monitor_validation.c */ | ||