From 5c862712d9c389fced47fde9abdc9458da319aef Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 6 Jul 2016 22:10:48 +0000 Subject: removing GNUNET_TRANSPORT_monitor_validation-API --- src/transport/Makefile.am | 4 +- src/transport/gnunet-service-transport_clients.c | 265 -------------- src/transport/gnunet-service-transport_clients.h | 19 - .../gnunet-service-transport_validation.c | 123 +++---- .../gnunet-service-transport_validation.h | 30 -- src/transport/gnunet-transport.c | 258 +------------ src/transport/transport_api_monitor_validation.c | 402 --------------------- 7 files changed, 50 insertions(+), 1051 deletions(-) delete mode 100644 src/transport/transport_api_monitor_validation.c (limited to 'src/transport') 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 = \ transport_api_blacklist.c \ transport_api_address_to_string.c \ transport_api_monitor_peers.c \ - transport_api_monitor_plugins.c \ - transport_api_monitor_validation.c + transport_api_monitor_plugins.c + libgnunettransport_la_LIBADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(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 @@ -243,16 +243,6 @@ static struct MonitoringClient *peer_monitoring_clients_head; */ static struct MonitoringClient *peer_monitoring_clients_tail; -/** - * Head of linked list of validation monitoring clients. - */ -static struct MonitoringClient *val_monitoring_clients_head; - -/** - * Tail of linked list of validation monitoring clients. - */ -static struct MonitoringClient *val_monitoring_clients_tail; - /** * Notification context, to send updates on changes to active addresses * of our neighbours. @@ -386,47 +376,6 @@ setup_peer_monitoring_client (struct GNUNET_SERVER_Client *client, } -/** - * Setup a new monitoring client using the given server client handle and - * the peer identity. - * - * @param client server's client handle to create our internal handle for - * @param peer identity of the peer to monitor the addresses of, - * zero to monitor all neighrours. - * @return handle to the new monitoring client - */ -static struct MonitoringClient * -setup_val_monitoring_client (struct GNUNET_SERVER_Client *client, - struct GNUNET_PeerIdentity *peer) -{ - struct MonitoringClient *mc; - - GNUNET_assert (NULL == - lookup_monitoring_client (val_monitoring_clients_head, - client)); - mc = GNUNET_new (struct MonitoringClient); - mc->client = client; - mc->peer = *peer; - GNUNET_CONTAINER_DLL_insert (val_monitoring_clients_head, - val_monitoring_clients_tail, - mc); - GNUNET_SERVER_notification_context_add (val_nc, client); - - if (0 != memcmp (peer, - &all_zeros, - sizeof (struct GNUNET_PeerIdentity))) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client %p started monitoring of the peer `%s'\n", - mc, - GNUNET_i2s (peer)); - else - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client %p started monitoring all peers\n", - mc); - return mc; -} - - /** * Function called to notify a client about the socket being ready to * queue more data. @a buf will be NULL and @a size zero if the socket @@ -568,15 +517,6 @@ client_disconnect_notification (void *cls, mc); GNUNET_free (mc); } - mc = lookup_monitoring_client (val_monitoring_clients_head, - client); - if (NULL != mc) - { - GNUNET_CONTAINER_DLL_remove (val_monitoring_clients_head, - val_monitoring_clients_tail, - mc); - GNUNET_free (mc); - } tc = lookup_client (client); if (NULL == tc) return; @@ -1090,55 +1030,6 @@ compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer } -/** - * Compose #PeerIterateResponseMessage using the given peer and address. - * - * @param peer identity of the peer - * @param address the address, NULL on disconnect - * @return composed message - */ -static struct ValidationIterateResponseMessage * -compose_validation_iterate_response_message (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address) -{ - struct ValidationIterateResponseMessage *msg; - size_t size; - size_t tlen; - size_t alen; - char *addr; - - GNUNET_assert (NULL != peer); - if (NULL != address) - { - tlen = strlen (address->transport_name) + 1; - alen = address->address_length; - } - else - { - tlen = 0; - alen = 0; - } - size = (sizeof (struct ValidationIterateResponseMessage) + alen + tlen); - msg = GNUNET_malloc (size); - msg->header.size = htons (size); - msg->header.type = - htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE); - msg->reserved = htonl (0); - msg->peer = *peer; - msg->addrlen = htonl (alen); - msg->pluginlen = htonl (tlen); - - if (NULL != address) - { - msg->local_address_info = htonl((uint32_t) address->local_info); - addr = (char *) &msg[1]; - memcpy (addr, address->address, alen); - memcpy (&addr[alen], address->transport_name, tlen); - } - return msg; -} - - /** * Context for #send_validation_information() and * #send_peer_information(). @@ -1162,44 +1053,6 @@ struct IterationContext }; -/** - * Output information of validation entries to the given client. - * - * @param cls the `struct IterationContext *` - * @param address the address - * @param last_validation point in time when last validation was performed - * @param valid_until point in time how long address is valid - * @param next_validation point in time when next validation will be performed - * @param state state of validation notification - */ -static void -send_validation_information (void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Absolute last_validation, - struct GNUNET_TIME_Absolute valid_until, - struct GNUNET_TIME_Absolute next_validation, - enum GNUNET_TRANSPORT_ValidationState state) -{ - struct IterationContext *pc = cls; - struct ValidationIterateResponseMessage *msg; - - if ( (GNUNET_YES != pc->all) && - (0 != memcmp (&address->peer, &pc->id, sizeof (pc->id))) ) - return; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending information about for validation entry for peer `%s' using address `%s'\n", - GNUNET_i2s (&address->peer), - (NULL != address) ? GST_plugins_a2s (address) : ""); - msg = compose_validation_iterate_response_message (&address->peer, address); - msg->last_validation = GNUNET_TIME_absolute_hton(last_validation); - msg->valid_until = GNUNET_TIME_absolute_hton(valid_until); - msg->next_validation = GNUNET_TIME_absolute_hton(next_validation); - msg->state = htonl ((uint32_t) state); - GNUNET_SERVER_transmit_context_append_message (pc->tc, &msg->header); - GNUNET_free (msg); -} - - /** * Output information of neighbours to the given client. * @@ -1305,78 +1158,6 @@ clients_handle_monitor_peers (void *cls, } -/** - * Client asked to obtain information about a specific or all validation - * processes - * - * @param cls unused - * @param client the client - * @param message the peer address information request - */ -static void -clients_handle_monitor_validation (void *cls, - struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) -{ - struct GNUNET_SERVER_TransmitContext *tc; - struct PeerMonitorMessage *msg; - struct IterationContext pc; - - if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - if (ntohs (message->size) != sizeof (struct ValidationMonitorMessage)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - msg = (struct PeerMonitorMessage *) message; - if ( (GNUNET_YES != ntohl (msg->one_shot)) && - (NULL != lookup_monitoring_client (val_monitoring_clients_head, client)) ) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } - GNUNET_SERVER_disable_receive_done_warning (client); - GNUNET_SERVER_client_mark_monitor (client); - pc.tc = tc = GNUNET_SERVER_transmit_context_create (client); - - /* Send initial list */ - if (0 == memcmp (&msg->peer, - &all_zeros, - sizeof (struct GNUNET_PeerIdentity))) - { - /* iterate over all neighbours */ - pc.all = GNUNET_YES; - pc.id = msg->peer; - } - else - { - /* just return one neighbour */ - pc.all = GNUNET_NO; - pc.id = msg->peer; - } - GST_validation_iterate (&send_validation_information, - &pc); - - if (GNUNET_YES != ntohl (msg->one_shot)) - { - setup_val_monitoring_client (client, &msg->peer); - } - else - { - GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE); - } - GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); -} - - /** * Function called by the plugin with information about the * current sessions managed by the plugin (for monitoring). @@ -1514,9 +1295,6 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server) {&clients_handle_monitor_peers, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, sizeof (struct PeerMonitorMessage)}, - {&clients_handle_monitor_validation, NULL, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST, - sizeof (struct ValidationMonitorMessage)}, {&GST_blacklist_handle_init, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, sizeof (struct GNUNET_MessageHeader)}, @@ -1657,49 +1435,6 @@ GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer, } -/** - * Broadcast the new validation changes to all clients monitoring the peer. - * - * @param peer peer this update is about (never NULL) - * @param address address, NULL on disconnect - * @param last_validation point in time when last validation was performed - * @param valid_until point in time how long address is valid - * @param next_validation point in time when next validation will be performed - * @param state state of validation notification - */ -void -GST_clients_broadcast_validation_notification (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Absolute last_validation, - struct GNUNET_TIME_Absolute valid_until, - struct GNUNET_TIME_Absolute next_validation, - enum GNUNET_TRANSPORT_ValidationState state) -{ - struct ValidationIterateResponseMessage *msg; - struct MonitoringClient *mc; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending information about for validation entry for peer `%s' using address `%s'\n", - GNUNET_i2s(peer), - (address != NULL) ? GST_plugins_a2s (address) : ""); - msg = compose_validation_iterate_response_message (peer, address); - msg->last_validation = GNUNET_TIME_absolute_hton(last_validation); - msg->valid_until = GNUNET_TIME_absolute_hton(valid_until); - msg->next_validation = GNUNET_TIME_absolute_hton(next_validation); - msg->state = htonl ((uint32_t) state); - for (mc = val_monitoring_clients_head; NULL != mc; mc = mc->next) - if ((0 == memcmp (&mc->peer, &all_zeros, - sizeof (struct GNUNET_PeerIdentity))) || - (0 == memcmp (&mc->peer, peer, - sizeof (struct GNUNET_PeerIdentity)))) - GNUNET_SERVER_notification_context_unicast (val_nc, - mc->client, - &msg->header, - GNUNET_NO); - GNUNET_free (msg); -} - - /** * Mark the peer as down so we don't call the continuation * context in the future. 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 GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer); -/** - * Broadcast the new validation changes to all clients monitoring the peer. - * - * @param peer peer this update is about (never NULL) - * @param address address, NULL on disconnect - * @param last_validation point in time when last validation was performed - * @param valid_until point in time how long address is valid - * @param next_validation point in time when next validation will be performed - * @param state state of validation notification - */ -void -GST_clients_broadcast_validation_notification (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Absolute last_validation, - struct GNUNET_TIME_Absolute valid_until, - struct GNUNET_TIME_Absolute next_validation, - enum GNUNET_TRANSPORT_ValidationState state); - - #endif /* 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 @@ #include "gnunet_peerinfo_service.h" #include "gnunet_signatures.h" +/** + * Current state of a validation process. + * + * FIXME: what state is used to indicate that a validation + * was successful? If that is clarified/determined, "UGH" in + * ~gnunetpeerinfogtk.c:1103 should be resolved. + */ +enum GNUNET_TRANSPORT_ValidationState +{ + /** + * Undefined state + * + * Used for final callback indicating operation done + */ + GNUNET_TRANSPORT_VS_NONE, + + /** + * Fresh validation entry + * + * Entry was just created, no validation process was executed + */ + GNUNET_TRANSPORT_VS_NEW, + + /** + * Updated validation entry + * + * This is an update for an existing validation entry + */ + GNUNET_TRANSPORT_VS_UPDATE, + + /** + * Timeout for validation entry + * + * A timeout occured during the validation process + */ + GNUNET_TRANSPORT_VS_TIMEOUT, + + /** + * Validation entry is removed + * + * The validation entry is getting removed due to a failed validation + */ + GNUNET_TRANSPORT_VS_REMOVE +}; + + + /** * How long is a PONG signature valid? We'll recycle a signature until @@ -385,12 +432,6 @@ validation_entry_changed (struct ValidationEntry *ve, enum GNUNET_TRANSPORT_ValidationState state) { ve->state = state; - GST_clients_broadcast_validation_notification (&ve->address->peer, - ve->address, - ve->send_time, - ve->valid_until, - ve->next_validation, - state); } @@ -1733,74 +1774,4 @@ GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address, } -/** - * Closure for the validation_entries_iterate function. - */ -struct ValidationIteratorContext -{ - /** - * Function to call on each validation entry - */ - GST_ValidationChangedCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; -}; - - -/** - * Function called on each entry in the validation map. - * Passes the information from the validation entry to - * the callback given in the closure. - * - * @param cls the `struct ValidationIteratorContext` - * @param key peer this is about - * @param value the `struct ValidationEntry` - * @return #GNUNET_OK (continue to iterate) - */ -static int -validation_entries_iterate (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) -{ - struct ValidationIteratorContext *ic = cls; - struct ValidationEntry *ve = value; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Notifying about validation entry for peer `%s' address `%s' \n", - GNUNET_i2s (&ve->address->peer), - GST_plugins_a2s (ve->address)); - ic->cb (ic->cb_cls, - ve->address, - ve->send_time, - ve->valid_until, - ve->next_validation, - ve->state); - return GNUNET_OK; -} - - -/** - * Iterate over all iteration entries - * - * @param cb function to call - * @param cb_cls closure for @a cb - */ -void -GST_validation_iterate (GST_ValidationChangedCallback cb, - void *cb_cls) -{ - struct ValidationIteratorContext ic; - - if (NULL == validation_map) - return; /* can happen during shutdown */ - ic.cb = cb; - ic.cb_cls = cb_cls; - GNUNET_CONTAINER_multipeermap_iterate (validation_map, - &validation_entries_iterate, - &ic); -} - /* 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 @@ -61,36 +61,6 @@ GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address, int in_use); -/** - * Function called to notify transport users that a neighbour peer changed its - * active address. - * - * @param cls closure - * @param address address (never NULL) - * @param last_validation point in time when last validation was performed - * @param valid_until point in time how long address is valid - * @param next_validation point in time when next validation will be performed - * @param state state of validation notification - */ -typedef void -(*GST_ValidationChangedCallback) (void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Absolute last_validation, - struct GNUNET_TIME_Absolute valid_until, - struct GNUNET_TIME_Absolute next_validation, - enum GNUNET_TRANSPORT_ValidationState state); - - -/** - * Iterate over all iteration entries - * - * @param cb function to call - * @param cb_cls closure for @a cb - */ -void -GST_validation_iterate (GST_ValidationChangedCallback cb, void *cb_cls); - - /** * We've received a PING. If appropriate, generate a PONG. * 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 @@ -86,11 +86,6 @@ struct ValidationResolutionContext */ struct GNUNET_TIME_Absolute next_validation; - /** - * state of validation process - */ - enum GNUNET_TRANSPORT_ValidationState state; - /** * Tranport conversion handle */ @@ -295,11 +290,6 @@ static int benchmark_receive; */ static int iterate_connections; -/** - * Option -d. - */ -static int iterate_validation; - /** * Option -a. */ @@ -320,11 +310,6 @@ static int monitor_connects; */ static int monitor_connections; -/** - * Option -f. - */ -static int monitor_validation; - /** * Option -P. */ @@ -385,11 +370,6 @@ static struct GNUNET_CONTAINER_MultiPeerMap *monitored_plugins; */ static struct GNUNET_TRANSPORT_PeerMonitoringContext *pic; -/** - * Handle if we are monitoring transport validation activity. - */ -static struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic; - /** * Handle if we are monitoring plugin session activity. */ @@ -507,11 +487,6 @@ shutdown_task (void *cls) GNUNET_TRANSPORT_monitor_peers_cancel (pic); pic = NULL; } - if (NULL != vic) - { - GNUNET_TRANSPORT_monitor_validation_entries_cancel (vic); - vic = NULL; - } if (NULL != pm) { GNUNET_TRANSPORT_monitor_plugins_cancel (pm); @@ -729,217 +704,6 @@ result_callback (void *cls, } -/** - * Resolve address we got a validation state for to a string. - * - * @param address the address itself - * @param numeric #GNUNET_YES to disable DNS, #GNUNET_NO to try reverse lookup - * @param last_validation when was the address validated last - * @param valid_until until when is the address valid - * @param next_validation when will we try to revalidate the address next - * @param state where are we in the validation state machine - */ -static void -resolve_validation_address (const struct GNUNET_HELLO_Address *address, - int numeric, - struct GNUNET_TIME_Absolute last_validation, - struct GNUNET_TIME_Absolute valid_until, - struct GNUNET_TIME_Absolute next_validation, - enum GNUNET_TRANSPORT_ValidationState state); - - -/** - * Function to call with a textual representation of an address. This - * function will be called several times with different possible - * textual representations, and a last time with @a address being NULL - * to signal the end of the iteration. Note that @a address NULL - * always is the last call, regardless of the value in @a res. - * - * @param cls closure - * @param address NULL on end of iteration, - * otherwise 0-terminated printable UTF-8 string, - * in particular an empty string if @a res is #GNUNET_NO - * @param res result of the address to string conversion: - * if #GNUNET_OK: conversion successful - * if #GNUNET_NO: address was invalid (or not supported) - * if #GNUNET_SYSERR: communication error (IPC error) - */ -static void -process_validation_string (void *cls, - const char *address, - int res) -{ - struct ValidationResolutionContext *vc = cls; - char *s_valid; - char *s_last; - char *s_next; - - if (NULL != address) - { - if (GNUNET_SYSERR == res) - { - FPRINTF (stderr, - "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", - GNUNET_i2s (&vc->addrcp->peer), - vc->addrcp->transport_name, - (unsigned int) vc->addrcp->address_length); - } - if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->valid_until.abs_value_us) - s_valid = GNUNET_strdup ("never"); - else - s_valid = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->valid_until)); - - if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->last_validation.abs_value_us) - s_last = GNUNET_strdup ("never"); - else - s_last = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->last_validation)); - - if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->next_validation.abs_value_us) - s_next = GNUNET_strdup ("never"); - else - s_next = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->next_validation)); - - FPRINTF (stdout, - _("Peer `%s' %s %s\n\t%s%s\n\t%s%s\n\t%s%s\n"), - GNUNET_i2s (&vc->addrcp->peer), - (GNUNET_OK == res) ? address : "", - (monitor_validation) ? GNUNET_TRANSPORT_vs2s (vc->state) : "", - "Valid until : ", s_valid, - "Last validation: ",s_last, - "Next validation: ", s_next); - GNUNET_free (s_valid); - GNUNET_free (s_last); - GNUNET_free (s_next); - vc->printed = GNUNET_YES; - return; - } - /* last call, we are done */ - GNUNET_assert (address_resolutions > 0); - address_resolutions--; - if ( (GNUNET_SYSERR == res) && - (GNUNET_NO == vc->printed)) - { - if (numeric == GNUNET_NO) - { - /* Failed to resolve address, try numeric lookup - (note: this should be unnecessary, as - transport should fallback to numeric lookup - internally if DNS takes too long anyway) */ - resolve_validation_address (vc->addrcp, - GNUNET_NO, - vc->last_validation, - vc->valid_until, - vc->next_validation, - vc->state); - } - else - { - FPRINTF (stdout, - _("Peer `%s' %s `%s' \n"), - GNUNET_i2s (&vc->addrcp->peer), - "", - GNUNET_TRANSPORT_vs2s (vc->state)); - } - } - GNUNET_free (vc->transport); - GNUNET_free (vc->addrcp); - GNUNET_CONTAINER_DLL_remove (vc_head, vc_tail, vc); - GNUNET_free (vc); - if ((0 == address_resolutions) && (iterate_validation)) - { - if (NULL != op_timeout) - { - GNUNET_SCHEDULER_cancel (op_timeout); - op_timeout = NULL; - } - ret = 0; - GNUNET_SCHEDULER_shutdown (); - } -} - - -/** - * Resolve address we got a validation state for to a string. - * - * @param address the address itself - * @param numeric #GNUNET_YES to disable DNS, #GNUNET_NO to try reverse lookup - * @param last_validation when was the address validated last - * @param valid_until until when is the address valid - * @param next_validation when will we try to revalidate the address next - * @param state where are we in the validation state machine - */ -static void -resolve_validation_address (const struct GNUNET_HELLO_Address *address, - int numeric, - struct GNUNET_TIME_Absolute last_validation, - struct GNUNET_TIME_Absolute valid_until, - struct GNUNET_TIME_Absolute next_validation, - enum GNUNET_TRANSPORT_ValidationState state) -{ - struct ValidationResolutionContext *vc; - - vc = GNUNET_new (struct ValidationResolutionContext); - GNUNET_assert(NULL != vc); - GNUNET_CONTAINER_DLL_insert(vc_head, vc_tail, vc); - address_resolutions++; - - vc->transport = GNUNET_strdup(address->transport_name); - vc->addrcp = GNUNET_HELLO_address_copy (address); - vc->printed = GNUNET_NO; - vc->state = state; - vc->last_validation = last_validation; - vc->valid_until = valid_until; - vc->next_validation = next_validation; - - /* Resolve address to string */ - vc->asc = GNUNET_TRANSPORT_address_to_string (cfg, - address, - numeric, - RESOLUTION_TIMEOUT, - &process_validation_string, vc); -} - - -/** - * Resolve address we got a validation state for to a string. - * - * @param cls NULL - * @param address the address itself - * @param last_validation when was the address validated last - * @param valid_until until when is the address valid - * @param next_validation when will we try to revalidate the address next - * @param state where are we in the validation state machine - */ -static void -process_validation_cb (void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Absolute last_validation, - struct GNUNET_TIME_Absolute valid_until, - struct GNUNET_TIME_Absolute next_validation, - enum GNUNET_TRANSPORT_ValidationState state) -{ - if (NULL == address) - { - if (monitor_validation) - { - FPRINTF (stdout, - "%s", - _("Monitor disconnected from transport service. Reconnecting.\n")); - return; - } - vic = NULL; - GNUNET_SCHEDULER_shutdown (); - return; - } - resolve_validation_address (address, - numeric, - last_validation, - valid_until, - next_validation, - state); -} - - static void run_nat_test () { @@ -1784,7 +1548,7 @@ testservice_task (void *cls, counter = benchmark_send + benchmark_receive + iterate_connections + monitor_connections + monitor_connects + do_disconnect + - + iterate_validation + monitor_validation + monitor_plugins; + monitor_plugins; if (1 < counter) { @@ -1901,20 +1665,6 @@ testservice_task (void *cls, &plugin_monitoring_cb, NULL); } - else if (iterate_validation) /* -d: Print information about validations */ - { - vic = GNUNET_TRANSPORT_monitor_validation_entries (cfg, - (NULL == cpid) ? NULL : &pid, - GNUNET_YES, TIMEOUT, - &process_validation_cb, (void *) cfg); - } - else if (monitor_validation) /* -f: Print information about validations continuously */ - { - vic = GNUNET_TRANSPORT_monitor_validation_entries (cfg, - (NULL == cpid) ? NULL : &pid, - GNUNET_NO, TIMEOUT, - &process_validation_cb, (void *) cfg); - } else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */ { monitor_connect_counter = 0; @@ -1985,12 +1735,6 @@ main (int argc, { 'D', "disconnect", NULL, gettext_noop ("disconnect from a peer"), 0, &GNUNET_GETOPT_set_one, &do_disconnect }, - { 'd', "validation", NULL, - gettext_noop ("print information for all pending validations "), - 0, &GNUNET_GETOPT_set_one, &iterate_validation }, - { 'f', "monitorvalidation", NULL, - gettext_noop ("print information for all pending validations continuously"), - 0, &GNUNET_GETOPT_set_one, &monitor_validation }, { 'i', "information", NULL, gettext_noop ("provide information about all current connections (once)"), 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 @@ -/* - This file is part of GNUnet. - Copyright (C) 2009, 2010 GNUnet e.V. - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -/** - * @file transport/transport_api_monitor_validation.c - * @brief montoring api for validation status - * - * This api provides the ability to query the transport service about - * the status of address validation. - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_arm_service.h" -#include "gnunet_hello_lib.h" -#include "gnunet_protocols.h" -#include "gnunet_transport_service.h" -#include "transport.h" - - -/** - * Context for the address lookup. - */ -struct GNUNET_TRANSPORT_ValidationMonitoringContext -{ - /** - * Function to call with the binary address. - */ - GNUNET_TRANSPORT_ValidationIterateCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Connection to the service. - */ - struct GNUNET_CLIENT_Connection *client; - - /** - * Configuration we use. - */ - const struct GNUNET_CONFIGURATION_Handle *cfg; - - /** - * When should this operation time out? - */ - struct GNUNET_TIME_Absolute timeout; - - /** - * Backoff for reconnect. - */ - struct GNUNET_TIME_Relative backoff; - - /** - * Task ID for reconnect. - */ - struct GNUNET_SCHEDULER_Task * reconnect_task; - - /** - * Identity of the peer to monitor. - */ - struct GNUNET_PeerIdentity peer; - - /** - * Was this a one-shot request? - */ - int one_shot; -}; - - -/** - * Convert validation state to human-readable string. - * - * @param state the state value - * @return corresponding string - */ -const char * -GNUNET_TRANSPORT_vs2s (enum GNUNET_TRANSPORT_ValidationState state) -{ - switch (state) - { - case GNUNET_TRANSPORT_VS_NONE: - return "NONE"; - case GNUNET_TRANSPORT_VS_NEW: - return "NEW"; - case GNUNET_TRANSPORT_VS_REMOVE: - return "REMOVE"; - case GNUNET_TRANSPORT_VS_TIMEOUT: - return "TIMEOUT"; - case GNUNET_TRANSPORT_VS_UPDATE: - return "UPDATE"; - default: - GNUNET_break (0); - return "UNDEFINED"; - } -} - - -/** - * Function called with responses from the service. - * - * @param cls our `struct GNUNET_TRANSPORT_ValidationMonitoringContext *` - * @param msg NULL on timeout or error, otherwise presumably a - * message with the human-readable address - */ -static void -val_response_processor (void *cls, - const struct GNUNET_MessageHeader *msg); - - -/** - * Send our subscription request to the service. - * - * @param val_ctx our context - */ -static void -send_val_mon_request (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx) -{ - struct ValidationMonitorMessage msg; - - msg.header.size = htons (sizeof (struct ValidationMonitorMessage)); - msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST); - msg.one_shot = htonl (val_ctx->one_shot); - msg.peer = val_ctx->peer; - GNUNET_assert (GNUNET_OK == - GNUNET_CLIENT_transmit_and_get_response (val_ctx->client, - &msg.header, - GNUNET_TIME_absolute_get_remaining (val_ctx->timeout), - GNUNET_YES, - &val_response_processor, - val_ctx)); -} - - -/** - * Task run to re-establish the connection. - * - * @param cls our `struct GNUNET_TRANSPORT_ValidationMonitoringContext *` - */ -static void -do_val_connect (void *cls) -{ - struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx = cls; - - val_ctx->reconnect_task = NULL; - val_ctx->client = GNUNET_CLIENT_connect ("transport", val_ctx->cfg); - GNUNET_assert (NULL != val_ctx->client); - send_val_mon_request (val_ctx); -} - - -/** - * Cut the existing connection and reconnect. - * - * @param val_ctx our context - */ -static void -reconnect_val_ctx (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx) -{ - GNUNET_assert (GNUNET_NO == val_ctx->one_shot); - GNUNET_CLIENT_disconnect (val_ctx->client); - val_ctx->client = NULL; - /* notify clients about (re)connect */ - val_ctx->cb (val_ctx->cb_cls, NULL, - GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS, - GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_TIMEOUT); - val_ctx->backoff = GNUNET_TIME_STD_BACKOFF (val_ctx->backoff); - val_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (val_ctx->backoff, - &do_val_connect, - val_ctx); -} - - -/** - * Function called with responses from the service. - * - * @param cls our `struct GNUNET_TRANSPORT_ValidationMonitoringContext *` - * @param msg NULL on timeout or error, otherwise presumably a - * message with the human-readable address - */ -static void -val_response_processor (void *cls, - const struct GNUNET_MessageHeader *msg) -{ - struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx = cls; - struct ValidationIterateResponseMessage *vr_msg; - struct GNUNET_HELLO_Address *address; - const char *addr; - const char *transport_name; - size_t size; - size_t tlen; - size_t alen; - - if (NULL == msg) - { - if (val_ctx->one_shot) - { - /* Disconnect */ - val_ctx->cb (val_ctx->cb_cls, NULL, - GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS, - GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_TIMEOUT); - GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx); - } - else - { - reconnect_val_ctx (val_ctx); - } - return; - } - size = ntohs (msg->size); - GNUNET_break (ntohs (msg->type) == - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE); - - if (size == sizeof (struct GNUNET_MessageHeader)) - { - /* Done! */ - if (val_ctx->one_shot) - { - val_ctx->cb (val_ctx->cb_cls, NULL, - GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS, - GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_NONE); - GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx); - } - else - { - reconnect_val_ctx (val_ctx); - } - return; - } - - if ((size < sizeof (struct ValidationIterateResponseMessage)) || - (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE)) - { - GNUNET_break (0); - if (val_ctx->one_shot) - { - val_ctx->cb (val_ctx->cb_cls, NULL, - GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS, - GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_NONE); - GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx); - } - else - { - reconnect_val_ctx (val_ctx); - } - return; - } - - vr_msg = (struct ValidationIterateResponseMessage *) msg; - tlen = ntohl (vr_msg->pluginlen); - alen = ntohl (vr_msg->addrlen); - - if (size != sizeof (struct ValidationIterateResponseMessage) + tlen + alen) - { - GNUNET_break (0); - if (val_ctx->one_shot) - { - val_ctx->cb (val_ctx->cb_cls, NULL, - GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS, - GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_NONE); - GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx); - } - else - { - reconnect_val_ctx (val_ctx); - } - return; - } - if (0 == tlen) - { - GNUNET_break (0); /* This must not happen: address without plugin */ - return; - } - addr = (const char *) &vr_msg[1]; - transport_name = &addr[alen]; - - if (transport_name[tlen - 1] != '\0') - { - /* Corrupt plugin name */ - GNUNET_break (0); - if (val_ctx->one_shot) - { - val_ctx->cb (val_ctx->cb_cls, - NULL, - GNUNET_TIME_UNIT_ZERO_ABS, - GNUNET_TIME_UNIT_ZERO_ABS, - GNUNET_TIME_UNIT_ZERO_ABS, - GNUNET_TRANSPORT_VS_NONE); - GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx); - } - else - { - reconnect_val_ctx (val_ctx); - } - return; - } - - /* notify client */ - address = GNUNET_HELLO_address_allocate (&vr_msg->peer, - transport_name, - addr, alen, - ntohl (vr_msg->local_address_info)); - val_ctx->cb (val_ctx->cb_cls, - address, - GNUNET_TIME_absolute_ntoh (vr_msg->last_validation), - GNUNET_TIME_absolute_ntoh (vr_msg->valid_until), - GNUNET_TIME_absolute_ntoh (vr_msg->next_validation), - ntohl(vr_msg->state)); - GNUNET_HELLO_address_free (address); - /* expect more replies */ - GNUNET_CLIENT_receive (val_ctx->client, - &val_response_processor, - val_ctx, - GNUNET_TIME_absolute_get_remaining (val_ctx->timeout)); -} - - -/** - * Return information about pending address validation operations for a specific - * or all peers - * - * @param cfg configuration to use - * @param peer a specific peer identity to obtain validation entries for, - * NULL for all peers - * @param one_shot #GNUNET_YES to return all entries and then end (with NULL+NULL), - * #GNUNET_NO to monitor validation entries continuously - * @param timeout how long is the lookup allowed to take at most - * @param validation_callback function to call with the results - * @param validation_callback_cls closure for peer_address_callback - */ -struct GNUNET_TRANSPORT_ValidationMonitoringContext * -GNUNET_TRANSPORT_monitor_validation_entries (const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_PeerIdentity *peer, - int one_shot, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_ValidationIterateCallback validation_callback, - void *validation_callback_cls) -{ - struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx; - struct GNUNET_CLIENT_Connection *client; - - client = GNUNET_CLIENT_connect ("transport", cfg); - if (NULL == client) - return NULL; - if (GNUNET_YES != one_shot) - timeout = GNUNET_TIME_UNIT_FOREVER_REL; - val_ctx = GNUNET_new (struct GNUNET_TRANSPORT_ValidationMonitoringContext); - val_ctx->cb = validation_callback; - val_ctx->cb_cls = validation_callback_cls; - val_ctx->cfg = cfg; - val_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); - if (NULL != peer) - val_ctx->peer = *peer; - val_ctx->one_shot = one_shot; - val_ctx->client = client; - send_val_mon_request (val_ctx); - - return val_ctx; -} - - -/** - * Return information about all current pending validation operations - * - * @param vic handle for the request to cancel - */ -void -GNUNET_TRANSPORT_monitor_validation_entries_cancel (struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic) -{ - if (NULL != vic->client) - { - GNUNET_CLIENT_disconnect (vic->client); - vic->client = NULL; - } - if (NULL != vic->reconnect_task) - { - GNUNET_SCHEDULER_cancel (vic->reconnect_task); - vic->reconnect_task = NULL; - } - GNUNET_free (vic); -} - - -/* end of transport_api_monitor_validation.c */ -- cgit v1.2.3