*/
#define GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC 385
-/**
- * Request to monitor address validations by a peer or all peers.
- */
-#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST 386
-
-/**
- * Response to #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST
- * request to iterate over all known addresses.
- */
-#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE 387
-
/**
* Request to start monitoring the connection state of plugins.
*/
GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringContext *pic);
-/**
- * Handle for a #GNUNET_TRANSPORT_monitor_validation_entries() operation.
- */
-struct GNUNET_TRANSPORT_ValidationMonitoringContext;
-
-
-/**
- * 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
- * ~gnunet-peerinfo-gtk.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
-};
-
-
-/**
- * Function to call with validation information about a peer
- *
- * This function is called by the transport validation monitoring api to
- * indicate a change to a validation entry. The information included represent
- * the current state of the validation entry,
- *
- * If the monitoring was called with `one_shot==GNUNET_YES`, a final callback
- * with `address==NULL` is executed.
- *
- * @param cls closure
- * @param address address this update is about,
- * NULL if this is the final last callback for a iteration operation
- * @param last_validation when was this address last validated
- * @param valid_until when does this address expire
- * @param next_validation time of the next validation operation
- * @param state state in the validation state machine
- */
-typedef void
-(*GNUNET_TRANSPORT_ValidationIterateCallback) (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);
-
-
-/**
- * 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);
-
-
-/**
- * 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 @a validation_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);
-
-
-/**
- * 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);
-
-
/* *********************** Blacklisting ************************ */
/**
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 \
*/
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.
}
-/**
- * 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
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;
}
-/**
- * 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().
};
-/**
- * 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) : "<none>");
- 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.
*
}
-/**
- * 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).
{&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)},
}
-/**
- * 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) : "<none>");
- 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.
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 */
#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
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);
}
}
-/**
- * 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 */
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.
*
*/
struct GNUNET_TIME_Absolute next_validation;
- /**
- * state of validation process
- */
- enum GNUNET_TRANSPORT_ValidationState state;
-
/**
* Tranport conversion handle
*/
*/
static int iterate_connections;
-/**
- * Option -d.
- */
-static int iterate_validation;
-
/**
* Option -a.
*/
*/
static int monitor_connections;
-/**
- * Option -f.
- */
-static int monitor_validation;
-
/**
* Option -P.
*/
*/
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.
*/
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);
}
-/**
- * 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 : "<invalid 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),
- "<unable to resolve address>",
- 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 ()
{
counter = benchmark_send + benchmark_receive + iterate_connections
+ monitor_connections + monitor_connects + do_disconnect +
- + iterate_validation + monitor_validation + monitor_plugins;
+ monitor_plugins;
if (1 < counter)
{
&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;
{ '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 },
+++ /dev/null
-/*
- 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 */