summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transport/Makefile.am2
-rw-r--r--src/transport/gnunet-service-transport.c2103
-rw-r--r--src/transport/gnunet-service-transport.h112
-rw-r--r--src/transport/gnunet-service-transport_blacklist.c933
-rw-r--r--src/transport/gnunet-service-transport_blacklist.h159
-rw-r--r--src/transport/gnunet-service-transport_clients.c1491
-rw-r--r--src/transport/gnunet-service-transport_clients.h101
-rw-r--r--src/transport/gnunet-service-transport_manipulation.c20
-rw-r--r--src/transport/gnunet-service-transport_manipulation.h8
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c2
-rw-r--r--src/transport/gnunet-service-transport_validation.c2
-rw-r--r--src/transport/test_transport_api_manipulation_recv_tcp.c16
-rw-r--r--src/transport/test_transport_api_manipulation_send_tcp.c22
13 files changed, 2195 insertions, 2776 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 2d79ae534..9fb451383 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -253,8 +253,6 @@ gnunet_transport_LDADD = \
gnunet_service_transport_SOURCES = \
gnunet-service-transport.c gnunet-service-transport.h \
gnunet-service-transport_ats.h gnunet-service-transport_ats.c \
- gnunet-service-transport_blacklist.h gnunet-service-transport_blacklist.c \
- gnunet-service-transport_clients.h gnunet-service-transport_clients.c \
gnunet-service-transport_hello.h gnunet-service-transport_hello.c \
gnunet-service-transport_neighbours.h gnunet-service-transport_neighbours.c \
gnunet-service-transport_plugins.h gnunet-service-transport_plugins.c \
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index a21ddabd6..e7b221344 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2010-2015 GNUnet e.V.
+ Copyright (C) 2010-2016 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
@@ -31,8 +31,6 @@
#include "gnunet_ats_service.h"
#include "gnunet-service-transport.h"
#include "gnunet-service-transport_ats.h"
-#include "gnunet-service-transport_blacklist.h"
-#include "gnunet-service-transport_clients.h"
#include "gnunet-service-transport_hello.h"
#include "gnunet-service-transport_neighbours.h"
#include "gnunet-service-transport_plugins.h"
@@ -40,6 +38,25 @@
#include "gnunet-service-transport_manipulation.h"
#include "transport.h"
+/**
+ * Size of the blacklist hash map.
+ */
+#define TRANSPORT_BLACKLIST_HT_SIZE 64
+
+/**
+ * How many messages can we have pending for a given client process
+ * before we start to drop incoming messages? We typically should
+ * have only one client and so this would be the primary buffer for
+ * messages, so the number should be chosen rather generously.
+ *
+ * The expectation here is that most of the time the queue is large
+ * enough so that a drop is virtually never required. Note that
+ * this value must be about as large as 'TOTAL_MSGS' in the
+ * 'test_transport_api_reliability.c', otherwise that testcase may
+ * fail.
+ */
+#define MAX_PENDING (128 * 1024)
+
/**
* Information we need for an asynchronous session kill.
@@ -73,7 +90,279 @@ struct GNUNET_ATS_SessionKiller
};
-/* globals */
+/**
+ * What type of client is the `struct TransportClient` about?
+ */
+enum ClientType
+{
+ /**
+ * We do not know yet (client is fresh).
+ */
+ CT_NONE = 0,
+
+ /**
+ * Is the CORE service, we need to forward traffic to it.
+ */
+ CT_CORE = 1,
+
+ /**
+ * It is a monitor, forward monitor data.
+ */
+ CT_MONITOR = 2,
+
+ /**
+ * It is a blacklist, query about allowed connections.
+ */
+ CT_BLACKLIST = 3
+};
+
+
+/**
+ * Context we use when performing a blacklist check.
+ */
+struct GST_BlacklistCheck;
+
+/**
+ * Client connected to the transport service.
+ */
+struct TransportClient
+{
+
+ /**
+ * This is a doubly-linked list.
+ */
+ struct TransportClient *next;
+
+ /**
+ * This is a doubly-linked list.
+ */
+ struct TransportClient *prev;
+
+ /**
+ * Handle to the client.
+ */
+ struct GNUNET_SERVICE_Client *client;
+
+ /**
+ * Message queue to the client.
+ */
+ struct GNUNET_MQ_Handle *mq;
+
+ /**
+ * What type of client is this?
+ */
+ enum ClientType type;
+
+ union {
+
+ /**
+ * Peer identity to monitor the addresses of.
+ * Zero to monitor all neighbours. Valid if
+ * @e type is CT_MONITOR.
+ */
+ struct GNUNET_PeerIdentity monitor_peer;
+
+ /**
+ * Additional details if @e type is CT_BLACKLIST.
+ */
+ struct {
+
+ /**
+ * Blacklist check that we're currently performing (or NULL
+ * if we're performing one that has been cancelled).
+ */
+ struct GST_BlacklistCheck *bc;
+
+ /**
+ * Set to #GNUNET_YES if we're currently waiting for a reply.
+ */
+ int waiting_for_reply;
+
+ /**
+ * #GNUNET_YES if we have to call receive_done for this client
+ */
+ int call_receive_done;
+
+ } blacklist;
+
+ } details;
+
+};
+
+
+
+/**
+ * Context we use when performing a blacklist check.
+ */
+struct GST_BlacklistCheck
+{
+
+ /**
+ * This is a linked list.
+ */
+ struct GST_BlacklistCheck *next;
+
+ /**
+ * This is a linked list.
+ */
+ struct GST_BlacklistCheck *prev;
+
+ /**
+ * Peer being checked.
+ */
+ struct GNUNET_PeerIdentity peer;
+
+ /**
+ * Continuation to call with the result.
+ */
+ GST_BlacklistTestContinuation cont;
+
+ /**
+ * Closure for @e cont.
+ */
+ void *cont_cls;
+
+ /**
+ * Address for #GST_blacklist_abort_matching(), can be NULL.
+ */
+ struct GNUNET_HELLO_Address *address;
+
+ /**
+ * Session for #GST_blacklist_abort_matching(), can be NULL.
+ */
+ struct GNUNET_ATS_Session *session;
+
+ /**
+ * Our current position in the blacklisters list.
+ */
+ struct TransportClient *bl_pos;
+
+ /**
+ * Current task performing the check.
+ */
+ struct GNUNET_SCHEDULER_Task *task;
+
+};
+
+
+/**
+ * Context for address to string operations
+ */
+struct AddressToStringContext
+{
+ /**
+ * This is a doubly-linked list.
+ */
+ struct AddressToStringContext *next;
+
+ /**
+ * This is a doubly-linked list.
+ */
+ struct AddressToStringContext *prev;
+
+ /**
+ * Client that made the request.
+ */
+ struct TransportClient* tc;
+};
+
+
+/**
+ * Closure for #handle_send_transmit_continuation()
+ */
+struct SendTransmitContinuationContext
+{
+
+ /**
+ * Client that made the request.
+ */
+ struct TransportClient *tc;
+
+ /**
+ * Peer that was the target.
+ */
+ struct GNUNET_PeerIdentity target;
+
+ /**
+ * At what time did we receive the message?
+ */
+ struct GNUNET_TIME_Absolute send_time;
+
+ /**
+ * Unique ID, for logging.
+ */
+ unsigned long long uuid;
+
+ /**
+ * Set to #GNUNET_YES if the connection for @e target goes
+ * down and we thus must no longer send the
+ * #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK message.
+ */
+ int down;
+};
+
+
+/**
+ * Head of linked list of all clients to this service.
+ */
+static struct TransportClient *clients_head;
+
+/**
+ * Tail of linked list of all clients to this service.
+ */
+static struct TransportClient *clients_tail;
+
+/**
+ * Map of peer identities to active send transmit continuation
+ * contexts. Used to flag contexts as 'dead' when a connection goes
+ * down. Values are of type `struct SendTransmitContinuationContext
+ * *`.
+ */
+static struct GNUNET_CONTAINER_MultiPeerMap *active_stccs;
+
+/**
+ * Head of linked list of all pending address iterations
+ */
+static struct AddressToStringContext *a2s_head;
+
+/**
+ * Tail of linked list of all pending address iterations
+ */
+static struct AddressToStringContext *a2s_tail;
+
+/**
+ * Head of DLL of active blacklisting queries.
+ */
+static struct GST_BlacklistCheck *bc_head;
+
+/**
+ * Tail of DLL of active blacklisting queries.
+ */
+static struct GST_BlacklistCheck *bc_tail;
+
+/**
+ * Hashmap of blacklisted peers. Values are of type 'char *' (transport names),
+ * can be NULL if we have no static blacklist.
+ */
+static struct GNUNET_CONTAINER_MultiPeerMap *blacklist;
+
+/**
+ * Notification context, to send updates on changes to active plugin
+ * connections.
+ */
+static struct GNUNET_NotificationContext *plugin_nc;
+
+/**
+ * Plugin monitoring client we are currently syncing, NULL if all
+ * monitoring clients are in sync.
+ */
+static struct TransportClient *sync_client;
+
+/**
+ * Peer identity that is all zeros, used as a way to indicate
+ * "all peers". Used for comparissons.
+ */
+static struct GNUNET_PeerIdentity all_zeros;
/**
* Statistics handle.
@@ -96,11 +385,6 @@ struct GNUNET_PeerIdentity GST_my_identity;
struct GNUNET_PEERINFO_Handle *GST_peerinfo;
/**
- * Handle to our service's server.
- */
-static struct GNUNET_SERVER_Handle *GST_server;
-
-/**
* Our private key.
*/
struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key;
@@ -137,6 +421,1029 @@ struct GNUNET_ATS_InterfaceScanner *GST_is;
/**
+ * Queue the given message for transmission to the given client
+ *
+ * @param tc target of the message
+ * @param msg message to transmit
+ * @param may_drop #GNUNET_YES if the message can be dropped
+ */
+static void
+unicast (struct TransportClient *tc,
+ const struct GNUNET_MessageHeader *msg,
+ int may_drop)
+{
+ struct GNUNET_MQ_Envelope *env;
+
+ if ( (GNUNET_MQ_get_length (tc->mq) >= MAX_PENDING) &&
+ (GNUNET_YES == may_drop) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping message of type %u and size %u, have %u/%u messages pending\n",
+ ntohs (msg->type),
+ ntohs (msg->size),
+ GNUNET_MQ_get_length (tc->mq),
+ MAX_PENDING);
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop
+ ("# messages dropped due to slow client"), 1,
+ GNUNET_NO);
+ return;
+ }
+ env = GNUNET_MQ_msg_copy (msg);
+ GNUNET_MQ_send (tc->mq,
+ env);
+}
+
+
+/**
+ * Called whenever a client connects. Allocates our
+ * data structures associated with that client.
+ *
+ * @param cls closure, NULL
+ * @param client identification of the client
+ * @param mq message queue for the client
+ * @return our `struct TransportClient`
+ */
+static void *
+client_connect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *client,
+ struct GNUNET_MQ_Handle *mq)
+{
+ struct TransportClient *tc;
+
+ tc = GNUNET_new (struct TransportClient);
+ tc->client = client;
+ tc->mq = mq;
+ GNUNET_CONTAINER_DLL_insert (clients_head,
+ clients_tail,
+ tc);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client %p connected\n",
+ tc);
+ return tc;
+}
+
+
+/**
+ * Perform next action in the blacklist check.
+ *
+ * @param cls the `struct BlacklistCheck*`
+ */
+static void
+do_blacklist_check (void *cls);
+
+
+/**
+ * Mark the peer as down so we don't call the continuation
+ * context in the future.
+ *
+ * @param cls a `struct TransportClient`
+ * @param peer a peer we are sending to
+ * @param value a `struct SendTransmitContinuationContext` to mark
+ * @return #GNUNET_OK (continue to iterate)
+ */
+static int
+mark_match_down (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ void *value)
+{
+ struct TransportClient *tc = cls;
+ struct SendTransmitContinuationContext *stcc = value;
+
+ if (tc == stcc->tc)
+ {
+ stcc->down = GNUNET_YES;
+ stcc->tc = NULL;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Called whenever a client is disconnected. Frees our
+ * resources associated with that client.
+ *
+ * @param cls closure, NULL
+ * @param client identification of the client
+ * @param app_ctx our `struct TransportClient`
+ */
+static void
+client_disconnect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *client,
+ void *app_ctx)
+{
+ struct TransportClient *tc = app_ctx;
+ struct GST_BlacklistCheck *bc;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client %p disconnected, cleaning up.\n",
+ tc);
+ GNUNET_CONTAINER_multipeermap_iterate (active_stccs,
+ &mark_match_down,
+ tc);
+ GNUNET_CONTAINER_DLL_remove (clients_head,
+ clients_tail,
+ tc);
+ switch (tc->type)
+ {
+ case CT_NONE:
+ break;
+ case CT_CORE:
+ break;
+ case CT_MONITOR:
+ break;
+ case CT_BLACKLIST:
+ for (bc = bc_head; NULL != bc; bc = bc->next)
+ {
+ if (bc->bl_pos != tc)
+ continue;
+ bc->bl_pos = tc->next;
+ if (NULL == bc->task)
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
+ bc);
+ }
+ break;
+ }
+ GNUNET_free (tc);
+}
+
+
+/**
+ * Function called for each of our connected neighbours. Notify the
+ * client about the existing neighbour.
+ *
+ * @param cls the `struct TransportClient *` to notify
+ * @param peer identity of the neighbour
+ * @param address the address
+ * @param state the current state of the peer
+ * @param state_timeout the time out for the state
+ * @param bandwidth_in inbound bandwidth in NBO
+ * @param bandwidth_out outbound bandwidth in NBO
+ */
+static void
+notify_client_about_neighbour (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Address *address,
+ enum GNUNET_TRANSPORT_PeerState state,
+ struct GNUNET_TIME_Absolute state_timeout,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
+{
+ struct TransportClient *tc = cls;
+ struct ConnectInfoMessage cim;
+
+ if (GNUNET_NO == GST_neighbours_test_connected (peer))
+ return;
+ cim.header.size = htons (sizeof (struct ConnectInfoMessage));
+ cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
+ cim.id = *peer;
+ cim.quota_in = bandwidth_in;
+ cim.quota_out = bandwidth_out;
+ unicast (tc,
+ &cim.header,
+ GNUNET_NO);
+}
+
+
+/**
+ * Initialize a normal client. We got a start message from this
+ * client, add him to the list of clients for broadcasting of inbound
+ * messages.
+ *
+ * @param cls the client
+ * @param start the start message that was sent
+ */
+static void
+handle_client_start (void *cls,
+ const struct StartMessage *start)
+{
+ struct TransportClient *tc = cls;
+ const struct GNUNET_MessageHeader *hello;
+ uint32_t options;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client %p sent START\n",
+ tc);
+ options = ntohl (start->options);
+ if ((0 != (1 & options)) &&
+ (0 !=
+ memcmp (&start->self,
+ &GST_my_identity,
+ sizeof (struct GNUNET_PeerIdentity))))
+ {
+ /* client thinks this is a different peer, reject */
+ GNUNET_break (0);
+ GNUNET_SERVICE_client_drop (tc->client);
+ return;
+ }
+ if (CT_NONE != tc->type)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVICE_client_drop (tc->client);
+ return;
+ }
+ if (0 != (2 & options))
+ tc->type = CT_CORE;
+ hello = GST_hello_get ();
+ if (NULL != hello)
+ unicast (tc,
+ hello,
+ GNUNET_NO);
+ GST_neighbours_iterate (&notify_client_about_neighbour,
+ tc);
+ GNUNET_SERVICE_client_continue (tc->client);
+}
+
+
+/**
+ * Client sent us a HELLO. Check the request.
+ *
+ * @param cls the client
+ * @param message the HELLO message
+ */
+static int
+check_client_hello (void *cls,
+ const struct GNUNET_MessageHeader *message)
+{
+ return GNUNET_OK; /* FIXME: check here? */
+}
+
+
+/**
+ * Client sent us a HELLO. Process the request.
+ *
+ * @param cls the client
+ * @param message the HELLO message
+ */
+static void
+handle_client_hello (void *cls,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct TransportClient *tc = cls;
+
+ GST_validation_handle_hello (message);
+ GNUNET_SERVICE_client_continue (tc->client);
+}
+
+
+/**
+ * Function called after the transmission is done. Notify the client that it is
+ * OK to send the next message.
+ *
+ * @param cls closure
+ * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
+ * @param bytes_payload bytes payload sent
+ * @param bytes_on_wire bytes sent on wire
+ */
+static void
+handle_send_transmit_continuation (void *cls,
+ int success,
+ size_t bytes_payload,
+ size_t bytes_on_wire)
+{
+ struct SendTransmitContinuationContext *stcc = cls;
+ struct SendOkMessage send_ok_msg;
+ struct GNUNET_TIME_Relative delay;
+ const struct GNUNET_HELLO_Address *addr;
+
+ delay = GNUNET_TIME_absolute_get_duration (stcc->send_time);
+ addr = GST_neighbour_get_current_address (&stcc->target);
+ if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
+ GNUNET_STRINGS_relative_time_to_string (delay,
+ GNUNET_YES),
+ (unsigned int) bytes_payload,
+ (unsigned int) bytes_on_wire,
+ GNUNET_i2s (&stcc->target),
+ success,
+ (NULL != addr) ? addr->transport_name : "%");
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
+ GNUNET_STRINGS_relative_time_to_string (delay,
+ GNUNET_YES),
+ (unsigned int) bytes_payload,
+ (unsigned int) bytes_on_wire,
+ GNUNET_i2s (&stcc->target),
+ success,
+ (NULL != addr) ? addr->transport_name : "%");
+
+ if (GNUNET_NO == stcc->down)
+ {
+ /* Only send confirmation if we are still connected */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending SEND_OK for transmission request %llu\n",
+ stcc->uuid);
+ send_ok_msg.header.size = htons (sizeof (send_ok_msg));
+ send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
+ send_ok_msg.bytes_msg = htonl (bytes_payload);
+ send_ok_msg.bytes_physical = htonl (bytes_on_wire);
+ send_ok_msg.success = htonl (success);
+ send_ok_msg.peer = stcc->target;
+ unicast (stcc->tc,
+ &send_ok_msg.header,
+ GNUNET_NO);
+ }
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multipeermap_remove (active_stccs,
+ &stcc->target,
+ stcc));
+ GNUNET_free (stcc);
+}
+
+
+/**
+ * Client asked for transmission to a peer. Process the request.
+ *
+ * @param cls the client
+ * @param obm the send message that was sent
+ */
+static int
+check_client_send (void *cls,
+ const struct OutboundMessage *obm)
+{
+ uint16_t size;
+ const struct GNUNET_MessageHeader *obmm;
+
+ size = ntohs (obm->header.size) - sizeof (struct OutboundMessage);
+ if (size < sizeof (struct GNUNET_MessageHeader))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ obmm = (const struct GNUNET_MessageHeader *) &obm[1];
+ if (size != ntohs (obmm->size))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Client asked for transmission to a peer. Process the request.
+ *
+ * @param cls the client
+ * @param obm the send message that was sent
+ */
+static void
+handle_client_send (void *cls,
+ const struct OutboundMessage *obm)
+{
+ static unsigned long long uuid_gen;
+ struct TransportClient *tc = cls;
+ const struct GNUNET_MessageHeader *obmm;
+ struct SendTransmitContinuationContext *stcc;
+
+ obmm = (const struct GNUNET_MessageHeader *) &obm[1];
+ if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
+ {
+ /* not connected, not allowed to send; can happen due to asynchronous operations */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not send message to peer `%s': not connected\n",
+ GNUNET_i2s (&obm->peer));
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop
+ ("# bytes payload dropped (other peer was not connected)"),
+ ntohs (obmm->size),
+ GNUNET_NO);
+ GNUNET_SERVICE_client_continue (tc->client);
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received SEND request %llu for `%s' and first message of type %u and total size %u\n",
+ uuid_gen,
+ GNUNET_i2s (&obm->peer),
+ ntohs (obmm->type),
+ ntohs (obmm->size));
+ GNUNET_SERVICE_client_continue (tc->client);
+
+ stcc = GNUNET_new (struct SendTransmitContinuationContext);
+ stcc->target = obm->peer;
+ stcc->tc = tc;
+ stcc->send_time = GNUNET_TIME_absolute_get ();
+ stcc->uuid = uuid_gen++;
+ (void) GNUNET_CONTAINER_multipeermap_put (active_stccs,
+ &stcc->target,
+ stcc,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ GST_manipulation_send (&obm->peer,
+ obmm,
+ ntohs (obmm->size),
+ GNUNET_TIME_relative_ntoh (obm->timeout),
+ &handle_send_transmit_continuation,
+ stcc);
+}
+
+
+/**
+ * Take the given address and append it to the set of results sent back to
+ * the client. This function may be called serveral times for a single
+ * conversion. The last invocation will be with a @a address of
+ * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
+ * errors, the callback might be called first with @a address NULL and
+ * @a res being #GNUNET_SYSERR. In that case, there will still be a
+ * subsequent call later with @a address NULL and @a res #GNUNET_OK.
+ *
+ * @param cls the `struct AddressToStringContext`
+ * @param buf text to transmit (contains the human-readable address, or NULL)
+ * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on error,
+ * never #GNUNET_NO
+ */
+static void
+transmit_address_to_client (void *cls,
+ const char *buf,
+ int res)
+{
+ struct AddressToStringContext *actx = cls;
+ struct GNUNET_MQ_Envelope *env;
+ struct AddressToStringResultMessage *atsm;
+ size_t slen;
+
+ GNUNET_assert ( (GNUNET_OK == res) ||
+ (GNUNET_SYSERR == res) );
+ if (NULL == buf)
+ {
+ env = GNUNET_MQ_msg (atsm,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
+ if (GNUNET_OK == res)
+ {
+ /* this was the last call, transmit */
+ atsm->res = htonl (GNUNET_OK);
+ atsm->addr_len = htonl (0);
+ GNUNET_MQ_send (actx->tc->mq,
+ env);
+ GNUNET_CONTAINER_DLL_remove (a2s_head,
+ a2s_tail,
+ actx);
+ return;
+ }
+ if (GNUNET_SYSERR == res)
+ {
+ /* address conversion failed, but there will be more callbacks */
+ atsm->res = htonl (GNUNET_SYSERR);
+ atsm->addr_len = htonl (0);
+ GNUNET_MQ_send (actx->tc->mq,
+ env);
+ return;
+ }
+ }
+ GNUNET_assert (GNUNET_OK == res);
+ /* succesful conversion, append*/
+ slen = strlen (buf) + 1;
+ env = GNUNET_MQ_msg_extra (atsm,
+ slen,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
+ atsm->res = htonl (GNUNET_YES);
+ atsm->addr_len = htonl (slen);
+ GNUNET_memcpy (&atsm[1],
+ buf,
+ slen);
+ GNUNET_MQ_send (actx->tc->mq,
+ env);
+}
+
+
+/**
+ * Client asked to resolve an address. Check the request.
+ *
+ * @param cls the client
+ * @param alum the resolution request
+ * @return #GNUNET_OK if @a alum is well-formed
+ */
+static int
+check_client_address_to_string (void *cls,
+ const struct AddressLookupMessage *alum)
+{
+ const char *plugin_name;
+ const char *address;
+ uint32_t address_len;
+ uint16_t size;
+
+ size = ntohs (alum->header.size);
+ address_len = ntohs (alum->addrlen);
+ if (size <= sizeof (struct AddressLookupMessage) + address_len)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ address = (const char *) &alum[1];
+ plugin_name = (const char *) &address[address_len];
+ if ('\0' != plugin_name[size - sizeof (struct AddressLookupMessage) - address_len - 1])
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Client asked to resolve an address. Process the request.
+ *
+ * @param cls the client
+ * @param alum the resolution request
+ */
+static void
+handle_client_address_to_string (void *cls,
+ const struct AddressLookupMessage *alum)
+{
+ struct TransportClient *tc = cls;
+ struct GNUNET_TRANSPORT_PluginFunctions *papi;
+ const char *plugin_name;
+ const char *address;
+ uint32_t address_len;
+ struct AddressToStringContext *actx;
+ struct GNUNET_MQ_Envelope *env;
+ struct AddressToStringResultMessage *atsm;
+ struct GNUNET_TIME_Relative rtimeout;
+ int32_t numeric;
+
+ address_len = ntohs (alum->addrlen);
+ address = (const char *) &alum[1];
+ plugin_name = (const char *) &address[address_len];
+ rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
+ numeric = ntohs (alum->numeric_only);
+ papi = GST_plugins_printer_find (plugin_name);
+ if (NULL == papi)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to find plugin `%s'\n",
+ plugin_name);
+ env = GNUNET_MQ_msg (atsm,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
+ atsm->res = htonl (GNUNET_SYSERR);
+ atsm->addr_len = htonl (0);
+ GNUNET_MQ_send (tc->mq,
+ env);
+ env = GNUNET_MQ_msg (atsm,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
+ atsm->res = htonl (GNUNET_OK);
+ atsm->addr_len = htonl (0);
+ GNUNET_MQ_send (tc->mq,
+ env);
+ return;
+ }
+ actx = GNUNET_new (struct AddressToStringContext);
+ actx->tc = tc;
+ GNUNET_CONTAINER_DLL_insert (a2s_head,
+ a2s_tail,
+ actx);
+ GNUNET_SERVICE_client_disable_continue_warning (tc->client);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Pretty-printing address of %u bytes using plugin `%s'\n",
+ address_len,
+ plugin_name);
+ papi->address_pretty_printer (papi->cls,
+ plugin_name,
+ address,
+ address_len,
+ numeric,
+ rtimeout,
+ &transmit_address_to_client,
+ actx);
+}
+
+
+/**
+ * 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 PeerIterateResponseMessage *
+compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Address *address)
+{
+ struct PeerIterateResponseMessage *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 PeerIterateResponseMessage) + alen + tlen);
+ msg = GNUNET_malloc (size);
+ msg->header.size = htons (size);
+ msg->header.type
+ = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_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];
+ GNUNET_memcpy (addr,
+ address->address,
+ alen);
+ GNUNET_memcpy (&addr[alen],
+ address->transport_name,
+ tlen);
+ }
+ return msg;
+}
+
+
+/**
+ * Context for #send_validation_information() and
+ * #send_peer_information().
+ */
+struct IterationContext
+{
+ /**
+ * Context to use for the transmission.
+ */
+ struct TransportClient *tc;
+
+ /**
+ * Which peers do we care about?
+ */
+ struct GNUNET_PeerIdentity id;
+
+ /**
+ * #GNUNET_YES if @e id should be ignored because we want all peers.
+ */
+ int all;
+};
+
+
+/**
+ * Output information of neighbours to the given client.
+ *
+ * @param cls the `struct PeerIterationContext *`
+ * @param peer identity of the neighbour
+ * @param address the address
+ * @param state current state this peer is in
+ * @param state_timeout timeout for the current state of the peer
+ * @param bandwidth_in inbound quota in NBO
+ * @param bandwidth_out outbound quota in NBO
+ */
+static void
+send_peer_information (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Address *address,
+ enum GNUNET_TRANSPORT_PeerState state,
+ struct GNUNET_TIME_Absolute state_timeout,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
+{
+ struct IterationContext *pc = cls;
+ struct GNUNET_MQ_Envelope *env;
+ struct PeerIterateResponseMessage *msg;
+
+ if ( (GNUNET_YES != pc->all) &&
+ (0 != memcmp (peer,
+ &pc->id,
+ sizeof (pc->id))) )
+ return;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending information about `%s' using address `%s' in state `%s'\n",
+ GNUNET_i2s(peer),
+ (NULL != address) ? GST_plugins_a2s (address) : "<none>",
+ GNUNET_TRANSPORT_ps2s (state));
+ msg = compose_address_iterate_response_message (peer,
+ address);
+ msg->state = htonl (state);
+ msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout);
+ env = GNUNET_MQ_msg_copy (&msg->header);
+ GNUNET_free (msg);
+ GNUNET_MQ_send (pc->tc->mq,
+ env);
+}
+
+
+/**
+ * Client asked to obtain information about a specific or all peers
+ * Process the request.
+ *
+ * @param cls the client
+ * @param msg the peer address information request
+ */
+static void
+handle_client_monitor_peers (void *cls,
+ const struct PeerMonitorMessage *msg)
+{
+ struct TransportClient *tc = cls;
+ struct IterationContext pc;
+
+ if (CT_NONE != tc->type)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVICE_client_drop (tc->client);
+ return;
+ }
+ GNUNET_SERVICE_client_disable_continue_warning (tc->client);
+ GNUNET_SERVICE_client_mark_monitor (tc->client);
+
+ /* Send initial list */
+ pc.tc = tc;
+ 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_neighbours_iterate (&send_peer_information,
+ &pc);
+
+ if (GNUNET_YES != ntohl (msg->one_shot))
+ {
+ tc->details.monitor_peer = msg->peer;
+ tc->type = CT_MONITOR;
+ if (0 != memcmp (&msg->peer,
+ &all_zeros,
+ sizeof (struct GNUNET_PeerIdentity)))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client %p started monitoring of the peer `%s'\n",
+ tc,
+ GNUNET_i2s (&msg->peer));
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client %p started monitoring all peers\n",
+ tc);
+ }
+ else
+ {
+ struct GNUNET_MessageHeader *msg;
+ struct GNUNET_MQ_Envelope *env;
+
+ env = GNUNET_MQ_msg (msg,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END);
+ GNUNET_MQ_send (tc->mq,
+ env);
+ }
+}
+
+
+/**
+ * Function called by the plugin with information about the
+ * current sessions managed by the plugin (for monitoring).
+ *
+ * @param cls closure
+ * @param session session handle this information is about,
+ * NULL to indicate that we are "in sync" (initial
+ * iteration complete)
+ * @param info information about the state of the session,
+ * NULL if @a session is also NULL and we are
+ * merely signalling that the initial iteration is over
+ */
+static void
+plugin_session_info_cb (void *cls,
+ struct GNUNET_ATS_Session *session,
+ const struct GNUNET_TRANSPORT_SessionInfo *info)
+{
+ struct GNUNET_MQ_Envelope *env;
+ struct TransportPluginMonitorMessage *msg;
+ struct GNUNET_MessageHeader *sync;
+ size_t size;
+ size_t slen;
+ uint16_t alen;
+ char *name;
+ char *addr;
+
+ if (0 == GNUNET_notification_context_get_size (plugin_nc))
+ {
+ GST_plugins_monitor_subscribe (NULL,
+ NULL);
+ return;
+ }
+ if ( (NULL == info) &&
+ (NULL == session) )
+ {
+ /* end of initial iteration */
+ if (NULL != sync_client)
+ {
+ env = GNUNET_MQ_msg (sync,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC);
+ GNUNET_MQ_send (sync_client->mq,
+ env);
+ sync_client = NULL;
+ }
+ return;
+ }
+ GNUNET_assert (NULL != info);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Plugin event for peer %s on transport %s\n",
+ GNUNET_i2s (&info->address->peer),
+ info->address->transport_name);
+ slen = strlen (info->address->transport_name) + 1;
+ alen = info->address->address_length;
+ size = sizeof (struct TransportPluginMonitorMessage) + slen + alen;
+ if (size > UINT16_MAX)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ msg = GNUNET_malloc (size);
+ msg->header.size = htons (size);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT);
+ msg->session_state = htons ((uint16_t) info->state);
+ msg->is_inbound = htons ((int16_t) info->is_inbound);
+ msg->msgs_pending = htonl (info->num_msg_pending);
+ msg->bytes_pending = htonl (info->num_bytes_pending);
+ msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout);
+ msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay);
+ msg->peer = info->address->peer;
+ msg->session_id = (uint64_t) (intptr_t) session;
+ msg->plugin_name_len = htons (slen);
+ msg->plugin_address_len = htons (alen);
+ name = (char *) &msg[1];
+ GNUNET_memcpy (name,
+ info->address->transport_name,
+ slen);
+ addr = &name[slen];
+ GNUNET_memcpy (addr,
+ info->address->address,
+ alen);
+ if (NULL != sync_client)
+ {
+ struct GNUNET_MQ_Envelope *env;
+
+ env = GNUNET_MQ_msg_copy (&msg->header);
+ GNUNET_MQ_send (sync_client->mq,
+ env);
+ }
+ else
+ {
+ GNUNET_notification_context_broadcast (plugin_nc,
+ &msg->header,
+ GNUNET_NO);
+ }
+ GNUNET_free (msg);
+}
+
+
+/**
+ * Client asked to obtain information about all plugin connections.
+ *
+ * @param cls the client
+ * @param message the peer address information request
+ */
+static void
+handle_client_monitor_plugins (void *cls,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct TransportClient *tc = cls;
+
+ GNUNET_SERVICE_client_mark_monitor (tc->client);
+ GNUNET_SERVICE_client_disable_continue_warning (tc->client);
+ GNUNET_notification_context_add (plugin_nc,
+ tc->mq);
+ GNUNET_assert (NULL == sync_client);
+ sync_client = tc;
+ GST_plugins_monitor_subscribe (&plugin_session_info_cb,
+ NULL);
+}
+
+
+/**
+ * Broadcast the given message to all of our clients.
+ *
+ * @param msg message to broadcast
+ * @param may_drop #GNUNET_YES if the message can be dropped / is payload
+ */
+void
+GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
+ int may_drop)
+{
+ struct TransportClient *tc;
+ int done;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asked to broadcast message of type %u with %u bytes\n",
+ (unsigned int) ntohs (msg->type),
+ (unsigned int) ntohs (msg->size));
+ done = GNUNET_NO;
+ for (tc = clients_head; NULL != tc; tc = tc->next)
+ {
+ if ( (GNUNET_YES == may_drop) &&
+ (CT_CORE != tc->type) )
+ continue; /* skip, this client does not care about payload */
+ unicast (tc,
+ msg,
+ may_drop);
+ done = GNUNET_YES;
+ }
+ if (GNUNET_NO == done)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Message of type %u not delivered, is CORE service up?\n",
+ ntohs (msg->type));
+}
+
+
+/**
+ * Broadcast the new active address to all clients monitoring the peer.
+ *
+ * @param peer peer this update is about (never NULL)
+ * @param address address, NULL on disconnect
+ * @param state the current state of the peer
+ * @param state_timeout the time out for the state
+ */
+void
+GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Address *address,
+ enum GNUNET_TRANSPORT_PeerState state,
+ struct GNUNET_TIME_Absolute state_timeout)
+{
+ struct GNUNET_MQ_Envelope *env;
+ struct PeerIterateResponseMessage *msg;
+ struct TransportClient *tc;
+
+ msg = compose_address_iterate_response_message (peer,
+ address);
+ msg->state = htonl (state);
+ msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
+ for (tc = clients_head; NULL != tc; tc = tc->next)
+ {
+ if (CT_MONITOR != tc->type)
+ continue;
+ if ((0 == memcmp (&tc->details.monitor_peer,
+ &all_zeros,
+ sizeof (struct GNUNET_PeerIdentity))) ||
+ (0 == memcmp (&tc->details.monitor_peer,
+ peer,
+ sizeof (struct GNUNET_PeerIdentity))))
+ {
+ env = GNUNET_MQ_msg_copy (&msg->header);
+ GNUNET_MQ_send (tc->mq,
+ env);
+ }
+ }
+ GNUNET_free (msg);
+}
+
+
+/**
+ * Mark the peer as down so we don't call the continuation
+ * context in the future.
+ *
+ * @param cls NULL
+ * @param peer peer that got disconnected
+ * @param value a `struct SendTransmitContinuationContext` to mark
+ * @return #GNUNET_OK (continue to iterate)
+ */
+static int
+mark_peer_down (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ void *value)
+{
+ struct SendTransmitContinuationContext *stcc = value;
+
+ stcc->down = GNUNET_YES;
+ return GNUNET_OK;
+}
+
+
+/**
+ * Notify all clients about a disconnect, and cancel
+ * pending SEND_OK messages for this peer.
+ *
+ * @param peer peer that disconnected
+ */
+void
+GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer)
+{
+ struct DisconnectInfoMessage disconnect_msg;
+
+ GNUNET_CONTAINER_multipeermap_get_multiple (active_stccs,
+ peer,
+ &mark_peer_down,
+ NULL);
+ disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
+ disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
+ disconnect_msg.reserved = htonl (0);
+ disconnect_msg.peer = *peer;
+ GST_clients_broadcast (&disconnect_msg.header,
+ GNUNET_NO);
+
+}
+
+
+/**
* Transmit our HELLO message to the given (connected) neighbour.
*
* @param cls the 'HELLO' message
@@ -170,7 +1477,8 @@ transmit_our_hello (void *cls,
hello,
ntohs (hello->size),
hello_expiration,
- NULL, NULL);
+ NULL,
+ NULL);
}
@@ -240,8 +1548,11 @@ process_payload (const struct GNUNET_HELLO_Address *address,
im->header.size = htons (size);
im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
im->peer = address->peer;
- GNUNET_memcpy (&im[1], message, ntohs (message->size));
- GST_clients_broadcast (&im->header, GNUNET_YES);
+ GNUNET_memcpy (&im[1],
+ message,
+ ntohs (message->size));
+ GST_clients_broadcast (&im->header,
+ GNUNET_YES);
return ret;
}
@@ -257,8 +1568,11 @@ kill_session_task (void *cls)
struct GNUNET_ATS_SessionKiller *sk = cls;
sk->task = NULL;
- GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
- sk->plugin->disconnect_session (sk->plugin->cls, sk->session);
+ GNUNET_CONTAINER_DLL_remove (sk_head,
+ sk_tail,
+ sk);
+ sk->plugin->disconnect_session (sk->plugin->cls,
+ sk->session);
GNUNET_free(sk);
}
@@ -290,7 +1604,8 @@ kill_session (const char *plugin_name,
sk = GNUNET_new (struct GNUNET_ATS_SessionKiller);
sk->session = session;
sk->plugin = plugin;
- sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, sk);
+ sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task,
+ sk);
GNUNET_CONTAINER_DLL_insert (sk_head,
sk_tail,
sk);
@@ -418,7 +1733,9 @@ GST_receive_callback (void *cls,
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Processing PONG from `%s'\n",
GST_plugins_a2s (address));
- if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message))
+ if (GNUNET_OK !=
+ GST_validation_handle_pong (&address->peer,
+ message))
{
GNUNET_break_op (0);
GST_blacklist_abort_matching (address,
@@ -508,12 +1825,11 @@ plugin_env_address_change_notification (void *cls,
const struct GNUNET_HELLO_Address *address)
{
static int addresses = 0;
- struct GNUNET_STATISTICS_Handle *cfg = GST_stats;
if (GNUNET_YES == add_remove)
{
addresses ++;
- GNUNET_STATISTICS_update (cfg,
+ GNUNET_STATISTICS_update (GST_stats,
"# transport addresses",
1,
GNUNET_NO);
@@ -527,7 +1843,7 @@ plugin_env_address_change_notification (void *cls,
else
{
addresses --;
- GNUNET_STATISTICS_update (cfg,
+ GNUNET_STATISTICS_update (GST_stats,
"# transport addresses",
-1,
GNUNET_NO);
@@ -579,16 +1895,20 @@ plugin_env_session_end (void *cls,
GNUNET_i2s (&address->peer),
GST_plugins_a2s (address));
- GST_neighbours_session_terminated (&address->peer, session);
+ GST_neighbours_session_terminated (&address->peer,
+ session);
GST_ats_del_session (address,
session);
- GST_blacklist_abort_matching (address, session);
+ GST_blacklist_abort_matching (address,
+ session);
for (sk = sk_head; NULL != sk; sk = sk->next)
{
if (sk->session == session)
{
- GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
+ GNUNET_CONTAINER_DLL_remove (sk_head,
+ sk_tail,
+ sk);
GNUNET_SCHEDULER_cancel (sk->task);
GNUNET_free(sk);
break;
@@ -672,7 +1992,9 @@ plugin_env_session_start (void *cls,
for example for UNIX, we have symmetric connections and thus we
may not know the address yet; add if necessary! */
/* FIXME: maybe change API here so we just pass scope? */
- memset (&prop, 0, sizeof (prop));
+ memset (&prop,
+ 0,
+ sizeof (prop));
GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != scope);
prop.scope = scope;
GST_ats_add_inbound_address (address,
@@ -750,6 +2072,167 @@ ats_request_address_change (void *cls,
/**
+ * Closure for #test_connection_ok().
+ */
+struct TestConnectionContext
+{
+ /**
+ * Is this the first neighbour we're checking?
+ */
+ int first;
+
+ /**
+ * Handle to the blacklisting client we need to ask.
+ */
+ struct TransportClient *tc;
+};
+
+
+/**
+ * Got the result about an existing connection from a new blacklister.
+ * Shutdown the neighbour if necessary.
+ *
+ * @param cls unused
+ * @param peer the neighbour that was investigated
+ * @param address address associated with the request
+ * @param session session associated with the request
+ * @param allowed #GNUNET_OK if we can keep it,
+ * #GNUNET_NO if we must shutdown the connection
+ */
+static void
+confirm_or_drop_neighbour (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Address *address,
+ struct GNUNET_ATS_Session *session,
+ int allowed)
+{
+ if (GNUNET_OK == allowed)
+ return; /* we're done */
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop ("# disconnects due to blacklist"),
+ 1,
+ GNUNET_NO);
+ GST_neighbours_force_disconnect (peer);
+}
+
+
+/**
+ * Test if an existing connection is still acceptable given a new
+ * blacklisting client.
+ *
+ * @param cls the `struct TestConnectionContext *`
+ * @param peer identity of the peer
+ * @param address the address
+ * @param state current state this peer is in
+ * @param state_timeout timeout for the current state of the peer
+ * @param bandwidth_in bandwidth assigned inbound
+ * @param bandwidth_out bandwidth assigned outbound
+ */
+static void
+test_connection_ok (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Address *address,
+ enum GNUNET_TRANSPORT_PeerState state,
+ struct GNUNET_TIME_Absolute state_timeout,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
+{
+ struct TestConnectionContext *tcc = cls;
+ struct GST_BlacklistCheck *bc;
+
+ bc = GNUNET_new (struct GST_BlacklistCheck);
+ GNUNET_CONTAINER_DLL_insert (bc_head,
+ bc_tail,
+ bc);
+ bc->peer = *peer;
+ bc->address = GNUNET_HELLO_address_copy (address);
+ bc->cont = &confirm_or_drop_neighbour;
+ bc->cont_cls = NULL;
+ bc->bl_pos = tcc->tc;
+ if (GNUNET_YES == tcc->first)
+ {
+ /* all would wait for the same client, no need to
+ * create more than just the first task right now */
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
+ bc);
+ tcc->first = GNUNET_NO;
+ }
+}
+
+
+/**
+ * Initialize a blacklisting client. We got a blacklist-init
+ * message from this client, add him to the list of clients
+ * to query for blacklisting.
+ *
+ * @param cls the client
+ * @param message the blacklist-init message that was sent
+ */
+static void
+handle_client_blacklist_init (void *cls,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct TransportClient *tc = cls;
+ struct TestConnectionContext tcc;
+
+ if (CT_NONE != tc->type)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVICE_client_drop (tc->client);
+ return;
+ }
+ GNUNET_SERVICE_client_mark_monitor (tc->client);
+ tc->type = CT_BLACKLIST;
+ tc->details.blacklist.call_receive_done = GNUNET_YES;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "New blacklist client %p\n",
+ tc);
+ /* confirm that all existing connections are OK! */
+ tcc.tc = tc;
+ tcc.first = GNUNET_YES;
+ GST_neighbours_iterate (&test_connection_ok,
+ &tcc);
+}
+
+
+/**
+ * Free the given entry in the blacklist.
+ *
+ * @param cls unused
+ * @param key host identity (unused)
+ * @param value the blacklist entry
+ * @return #GNUNET_OK (continue to iterate)
+ */
+static int
+free_blacklist_entry (void *cls,
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
+{
+ char *be = value;
+
+ GNUNET_free_non_null (be);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Set traffic metric to manipulate
+ *
+ * @param cls closure
+ * @param message containing information
+ */
+static void
+handle_client_set_metric (void *cls,
+ const struct TrafficMetricMessage *tm)
+{
+ struct TransportClient *tc = cls;
+
+ GST_manipulation_set_metric (tm);
+ GNUNET_SERVICE_client_continue (tc->client);
+}
+
+
+/**
* Function called when the service shuts down. Unloads our plugins
* and cancels pending validations.
*
@@ -758,6 +2241,8 @@ ats_request_address_change (void *cls,
static void
shutdown_task (void *cls)
{
+ struct AddressToStringContext *cur;
+
GST_neighbours_stop ();
GST_plugins_unload ();
GST_validation_stop ();
@@ -768,8 +2253,28 @@ shutdown_task (void *cls)
GST_ats_connect = NULL;
GNUNET_ATS_scanner_done (GST_is);
GST_is = NULL;
- GST_clients_stop ();
- GST_blacklist_stop ();
+ while (NULL != (cur = a2s_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (a2s_head,
+ a2s_tail,
+ cur);
+ GNUNET_free (cur);
+ }
+ if (NULL != plugin_nc)
+ {
+ GNUNET_notification_context_destroy (plugin_nc);
+ plugin_nc = NULL;
+ }
+ GNUNET_CONTAINER_multipeermap_destroy (active_stccs);
+ active_stccs = NULL;
+ if (NULL != blacklist)
+ {
+ GNUNET_CONTAINER_multipeermap_iterate (blacklist,
+ &free_blacklist_entry,
+ NULL);
+ GNUNET_CONTAINER_multipeermap_destroy (blacklist);
+ blacklist = NULL;
+ }
GST_hello_stop ();
GST_manipulation_stop ();
@@ -785,10 +2290,452 @@ shutdown_task (void *cls)
}
if (NULL != GST_my_private_key)
{
- GNUNET_free(GST_my_private_key);
+ GNUNET_free (GST_my_private_key);
GST_my_private_key = NULL;
}
- GST_server = NULL;
+}
+
+
+/**
+ * Perform next action in the blacklist check.
+ *
+ * @param cls the `struct GST_BlacklistCheck *`
+ */
+static void
+do_blacklist_check (void *cls)
+{
+ struct GST_BlacklistCheck *bc = cls;
+ struct TransportClient *tc;
+ struct GNUNET_MQ_Envelope *env;
+ struct BlacklistMessage *bm;
+
+ bc->task = NULL;
+ while (NULL != (tc = bc->bl_pos))
+ {
+ if (CT_BLACKLIST == tc->type)
+ break;
+ bc->bl_pos = tc->next;
+ }
+ if (NULL == tc)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No other blacklist clients active, will allow neighbour `%s'\n",
+ GNUNET_i2s (&bc->peer));
+
+ bc->cont (bc->cont_cls,
+ &bc->peer,
+ bc->address,
+ bc->session,
+ GNUNET_OK);
+ GST_blacklist_test_cancel (bc);
+ return;
+ }
+ if ( (NULL != tc->details.blacklist.bc) ||
+ (GNUNET_NO != tc->details.blacklist.waiting_for_reply) )
+ return; /* someone else busy with this client */
+ tc->details.blacklist.bc = bc;
+ env = GNUNET_MQ_msg (bm,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY);
+ bm->is_allowed = htonl (0);
+ bm->peer = bc->peer;
+ GNUNET_MQ_send (tc->mq,
+ env);
+ if (GNUNET_YES == tc->details.blacklist.call_receive_done)
+ {
+ tc->details.blacklist.call_receive_done = GNUNET_NO;
+ GNUNET_SERVICE_client_continue (tc->client);
+ }
+ tc->details.blacklist.waiting_for_reply = GNUNET_YES;
+}
+
+
+/**
+ * A blacklisting client has sent us reply. Process it.
+ *
+ * @param cls the client
+ * @param msg the blacklist-reply message that was sent
+ */
+static void
+handle_client_blacklist_reply (void *cls,
+ const struct BlacklistMessage *msg)
+{
+ struct TransportClient *tc = cls;
+ struct GST_BlacklistCheck *bc;
+
+ if (CT_BLACKLIST != tc->type)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVICE_client_drop (tc->client);
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Blacklist client %p sent reply for `%s'\n",
+ tc,
+ GNUNET_i2s (&msg->peer));
+ bc = tc->details.blacklist.bc;
+ tc->details.blacklist.bc = NULL;
+ tc->details.blacklist.waiting_for_reply = GNUNET_NO;
+ tc->details.blacklist.call_receive_done = GNUNET_YES;
+ if (NULL != bc)
+ {
+ /* only run this if the blacklist check has not been
+ * cancelled in the meantime... */
+ GNUNET_assert (bc->bl_pos == tc);
+ if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Blacklist check failed, peer not allowed\n");
+ /* For the duration of the continuation, make the ongoing
+ check invisible (to avoid double-cancellation); then
+ add it back again so we can re-use GST_blacklist_test_cancel() */
+ GNUNET_CONTAINER_DLL_remove (bc_head,
+ bc_tail,
+ bc);
+ bc->cont (bc->cont_cls,
+ &bc->peer,
+ bc->address,
+ bc->session,
+ GNUNET_NO);
+ GNUNET_CONTAINER_DLL_insert (bc_head,
+ bc_tail,
+ bc);
+ GST_blacklist_test_cancel (bc);
+ tc->details.blacklist.call_receive_done = GNUNET_NO;
+ GNUNET_SERVICE_client_continue (tc->client);
+ return;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Blacklist check succeeded, continuing with checks\n");
+ tc->details.blacklist.call_receive_done = GNUNET_NO;
+ GNUNET_SERVICE_client_continue (tc->client);
+ bc->bl_pos = tc->next;
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
+ bc);
+ }
+ }
+ /* check if any other blacklist checks are waiting for this blacklister */
+ for (bc = bc_head; bc != NULL; bc = bc->next)
+ if ( (bc->bl_pos == tc) &&
+ (NULL == bc->task) )
+ {
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
+ bc);
+ break;
+ }
+}
+
+
+/**
+ * Add the given peer to the blacklist (for the given transport).
+ *
+ * @param peer peer to blacklist
+ * @param transport_name transport to blacklist for this peer, NULL for all
+ */
+void
+GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
+ const char *transport_name)
+{
+ char *transport = NULL;
+
+ if (NULL != transport_name)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Adding peer `%s' with plugin `%s' to blacklist\n",
+ GNUNET_i2s (peer),
+ transport_name);
+ transport = GNUNET_strdup (transport_name);
+ }
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Adding peer `%s' with all plugins to blacklist\n",
+ GNUNET_i2s (peer));
+ if (NULL == blacklist)
+ blacklist =
+ GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE,
+ GNUNET_NO);
+
+ GNUNET_CONTAINER_multipeermap_put (blacklist,
+ peer,
+ transport,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+}
+
+
+/**
+ * Abort blacklist if @a address and @a session match.
+ *
+ * @param address address used to abort matching checks
+ * @param session session used to abort matching checks
+ */
+void
+GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
+ struct GNUNET_ATS_Session *session)
+{
+ struct GST_BlacklistCheck *bc;
+ struct GST_BlacklistCheck *n;
+
+ n = bc_head;
+ while (NULL != (bc = n))
+ {
+ n = bc->next;
+ if ( (bc->session == session) &&
+ (0 == GNUNET_HELLO_address_cmp (bc->address,
+ address)) )
+ {
+ bc->cont (bc->cont_cls,
+ &bc->peer,
+ bc->address,
+ bc->session,
+ GNUNET_SYSERR);
+ GST_blacklist_test_cancel (bc);
+ }
+ }
+}
+
+
+/**
+ * Test if the given blacklist entry matches. If so,
+ * abort the iteration.
+ *
+ * @param cls the transport name to match (const char*)
+ * @param key the key (unused)
+ * @param value the 'char *' (name of a blacklisted transport)
+ * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches
+ */
+static int
+test_blacklisted (void *cls,
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
+{
+ const char *transport_name = cls;
+ char *be = value;
+
+ /* Blacklist entry be:
+ * (NULL == be): peer is blacklisted with all plugins
+ * (NULL != be): peer is blacklisted for a specific plugin
+ *
+ * If (NULL != transport_name) we look for a transport specific entry:
+ * if (transport_name == be) forbidden
+ *
+ */
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n",
+ GNUNET_i2s (key),
+ (NULL == transport_name) ? "unspecified" : transport_name,
+ (NULL == be) ? "all plugins" : be);
+ /* all plugins for this peer were blacklisted: disallow */
+ if (NULL == value)
+ return GNUNET_NO;
+
+ /* blacklist check for specific transport */
+ if ( (NULL != transport_name) &&
+ (NULL != value) )
+ {
+ if (0 == strcmp (transport_name,
+ be))
+ return GNUNET_NO; /* plugin is blacklisted! */
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Test if a peer/transport combination is blacklisted.
+ *
+ * @param peer the identity of the peer to test
+ * @param transport_name name of the transport to test, never NULL
+ * @param cont function to call with result
+ * @param cont_cls closure for @a cont
+ * @param address address to pass back to @a cont, can be NULL
+ * @param session session to pass back to @a cont, can be NULL
+ * @return handle to the blacklist check, NULL if the decision
+ * was made instantly and @a cont was already called
+ */
+struct GST_BlacklistCheck *
+GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
+ const char *transport_name,
+ GST_BlacklistTestContinuation cont,
+ void *cont_cls,
+ const struct GNUNET_HELLO_Address *address,
+ struct GNUNET_ATS_Session *session)
+{
+ struct GST_BlacklistCheck *bc;
+ struct TransportClient *tc;
+
+ GNUNET_assert (NULL != peer);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Blacklist check for peer `%s':%s\n",
+ GNUNET_i2s (peer),
+ (NULL != transport_name) ? transport_name : "unspecified");
+
+ /* Check local blacklist by iterating over hashmap
+ * If iteration is aborted, we found a matching blacklist entry */
+ if ((NULL != blacklist) &&
+ (GNUNET_SYSERR ==
+ GNUNET_CONTAINER_multipeermap_get_multiple (blacklist, peer,
+ &test_blacklisted,
+ (void *) transport_name)))
+ {
+ /* Disallowed by config, disapprove instantly */
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop ("# disconnects due to blacklist"),
+ 1,
+ GNUNET_NO);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Disallowing connection to peer `%s' on transport %s\n"),
+ GNUNET_i2s (peer),
+ (NULL != transport_name) ? transport_name : "unspecified");
+ if (NULL != cont)
+ cont (cont_cls,
+ peer,
+ address,
+ session,
+ GNUNET_NO);
+ return NULL;
+ }
+
+ for (tc = clients_head; NULL != tc; tc = tc->next)
+ if (CT_BLACKLIST == tc->type)
+ break;
+ if (NULL == tc)
+ {
+ /* no blacklist clients, approve instantly */
+ if (NULL != cont)
+ cont (cont_cls,
+ peer,
+ address,
+ session,
+ GNUNET_OK);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Allowing connection to peer `%s' %s\n",
+ GNUNET_i2s (peer),
+ (NULL != transport_name) ? transport_name : "");
+ return NULL;
+ }
+
+ /* need to query blacklist clients */
+ bc = GNUNET_new (struct GST_BlacklistCheck);
+ GNUNET_CONTAINER_DLL_insert (bc_head,
+ bc_tail,
+ bc);
+ bc->peer = *peer;
+ bc->address = GNUNET_HELLO_address_copy (address);
+ bc->session = session;
+ bc->cont = cont;
+ bc->cont_cls = cont_cls;
+ bc->bl_pos = tc;
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
+ bc);
+ return bc;
+}
+
+
+/**
+ * Cancel a blacklist check.
+ *
+ * @param bc check to cancel
+ */
+void
+GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
+{
+ GNUNET_CONTAINER_DLL_remove (bc_head,
+ bc_tail,
+ bc);
+ if (NULL != bc->bl_pos)
+ {
+ if ( (CT_BLACKLIST == bc->bl_pos->type) &&
+ (bc->bl_pos->details.blacklist.bc == bc) )
+ {
+ /* we're at the head of the queue, remove us! */
+ bc->bl_pos->details.blacklist.bc = NULL;
+ }
+ }
+ if (NULL != bc->task)
+ {
+ GNUNET_SCHEDULER_cancel (bc->task);
+ bc->task = NULL;
+ }
+ GNUNET_free_non_null (bc->address);
+ GNUNET_free (bc);
+}
+
+
+/**
+ * Function to iterate over options in the blacklisting section for a peer.
+ *
+ * @param cls closure
+ * @param section name of the section
+ * @param option name of the option
+ * @param value value of the option
+ */
+static void
+blacklist_cfg_iter (void *cls,
+ const char *section,
+ const char *option,
+ const char *value)
+{
+ unsigned int *res = cls;
+ struct GNUNET_PeerIdentity peer;
+ char *plugs;
+ char *pos;
+
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_public_key_from_string (option,
+ strlen (option),
+ &peer.public_key))
+ return;
+
+ if ((NULL == value) || (0 == strcmp(value, "")))
+ {
+ /* Blacklist whole peer */
+ GST_blacklist_add_peer (&peer, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Adding blacklisting entry for peer `%s'\n"),
+ GNUNET_i2s (&peer));
+ }
+ else
+ {
+ plugs = GNUNET_strdup (value);
+ for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Adding blacklisting entry for peer `%s':`%s'\n"),
+ GNUNET_i2s (&peer), pos);
+ GST_blacklist_add_peer (&peer, pos);
+ }
+ GNUNET_free (plugs);
+ }
+ (*res)++;
+}
+
+
+/**
+ * Read blacklist configuration
+ *
+ * @param cfg the configuration handle
+ * @param my_id my peer identity
+ */
+static void
+read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const struct GNUNET_PeerIdentity *my_id)
+{
+ char cfg_sect[512];
+ unsigned int res = 0;
+
+ GNUNET_snprintf (cfg_sect,
+ sizeof (cfg_sect),
+ "transport-blacklist-%s",
+ GNUNET_i2s_full (my_id));
+ GNUNET_CONFIGURATION_iterate_section_values (cfg,
+ cfg_sect,
+ &blacklist_cfg_iter,
+ &res);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Loaded %u blacklisting entries from configuration\n",
+ res);
}
@@ -796,13 +2743,13 @@ shutdown_task (void *cls)
* Initiate transport service.
*
* @param cls closure
- * @param server the initialized server
* @param c configuration to use
+ * @param service the initialized service
*/
static void
run (void *cls,
- struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const struct GNUNET_CONFIGURATION_Handle *c,
+ struct GNUNET_SERVICE_Handle *service)
{
char *keyfile;
struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
@@ -832,7 +2779,6 @@ run (void *cls,
{
hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
}
- GST_server = server;
pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
GNUNET_free (keyfile);
GNUNET_assert (NULL != pk);
@@ -842,7 +2788,7 @@ run (void *cls,
GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
&GST_my_identity.public_key);
- GNUNET_assert(NULL != GST_my_private_key);
+ GNUNET_assert (NULL != GST_my_private_key);
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
"My identity is `%4s'\n",
@@ -852,24 +2798,28 @@ run (void *cls,
NULL);
if (NULL == GST_peerinfo)
{
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("Could not access PEERINFO service. Exiting.\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not access PEERINFO service. Exiting.\n"));
GNUNET_SCHEDULER_shutdown ();
return;
}
max_fd_rlimit = 0;
#if HAVE_GETRLIMIT
- struct rlimit r_file;
- if (0 == getrlimit (RLIMIT_NOFILE, &r_file))
{
- max_fd_rlimit = r_file.rlim_cur;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Maximum number of open files was: %u/%u\n",
- (unsigned int) r_file.rlim_cur,
- (unsigned int) r_file.rlim_max);
+ struct rlimit r_file;
+
+ if (0 == getrlimit (RLIMIT_NOFILE,
+ &r_file))
+ {
+ max_fd_rlimit = r_file.rlim_cur;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Maximum number of open files was: %u/%u\n",
+ (unsigned int) r_file.rlim_cur,
+ (unsigned int) r_file.rlim_max);
+ }
+ max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
}
- max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
#endif
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (GST_cfg,
@@ -897,9 +2847,8 @@ run (void *cls,
if (GNUNET_SYSERR == friend_only)
friend_only = GNUNET_NO; /* According to topology defaults */
/* start subsystems */
- GST_blacklist_start (GST_server,
- GST_cfg,
- &GST_my_identity);
+ read_blacklist_configuration (GST_cfg,
+ &GST_my_identity);
GST_is = GNUNET_ATS_scanner_init ();
GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg);
GST_ats = GNUNET_ATS_scheduling_init (GST_cfg,
@@ -915,26 +2864,60 @@ run (void *cls,
&process_hello_update,
NULL);
GST_neighbours_start ((max_fd / 3) * 2);
- GST_clients_start (GST_server);
+ active_stccs = GNUNET_CONTAINER_multipeermap_create (128,
+ GNUNET_YES);
+ plugin_nc = GNUNET_notification_context_create (0);
GST_validation_start ((max_fd / 3));
}
/**
- * The main function for the transport service.
- *
- * @param argc number of arguments from the command line
- * @param argv command line arguments
- * @return 0 ok, 1 on error
+ * Define "main" method using service macro.
*/
-int
-main (int argc,
- char * const *argv)
-{
- return
- (GNUNET_OK
- == GNUNET_SERVICE_run (argc, argv, "transport",
- GNUNET_SERVICE_OPTION_NONE, &run, NULL )) ? 0 : 1;
-}
+GNUNET_SERVICE_MAIN
+("transport",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_fixed_size (client_start,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_START,
+ struct StartMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (client_hello,
+ GNUNET_MESSAGE_TYPE_HELLO,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_hd_var_size (client_send,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
+ struct OutboundMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (client_address_to_string,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING,
+ struct AddressLookupMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (client_monitor_peers,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
+ struct PeerMonitorMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (client_blacklist_init,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (client_blacklist_reply,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
+ struct BlacklistMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (client_set_metric,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC,
+ struct TrafficMetricMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (client_monitor_plugins,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_handler_end ());
+
/* end of file gnunet-service-transport.c */
diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h
index 981996a00..2807afd79 100644
--- a/src/transport/gnunet-service-transport.h
+++ b/src/transport/gnunet-service-transport.h
@@ -92,6 +92,83 @@ typedef void
/**
+ * Continuation called from a blacklist test.
+ *
+ * @param cls closure
+ * @param peer identity of peer that was tested
+ * @param address address associated with the request
+ * @param session session associated with the request
+ * @param result #GNUNET_OK if the connection is allowed,
+ * #GNUNET_NO if not,
+ * #GNUNET_SYSERR if operation was aborted
+ */
+typedef void
+(*GST_BlacklistTestContinuation) (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Address *address,
+ struct GNUNET_ATS_Session *session,
+ int result);
+
+
+/**
+ * Add the given peer to the blacklist (for the given transport).
+ *
+ * @param peer peer to blacklist
+ * @param transport_name transport to blacklist for this peer, NULL for all
+ */
+void
+GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
+ const char *transport_name);
+
+
+/**
+ * Handle to an active blacklist check.
+ */
+struct GST_BlacklistCheck;
+
+
+
+/**
+ * Test if a peer/transport combination is blacklisted.
+ *
+ * @param peer the identity of the peer to test
+ * @param transport_name name of the transport to test, never NULL
+ * @param cont function to call with result
+ * @param cont_cls closure for @a cont
+ * @param address address to pass back to @a cont, can be NULL
+ * @param session session to pass back to @a cont, can be NULL
+ * @return handle to the blacklist check, NULL if the decision
+ * was made instantly and @a cont was already called
+ */
+struct GST_BlacklistCheck *
+GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
+ const char *transport_name,
+ GST_BlacklistTestContinuation cont,
+ void *cont_cls,
+ const struct GNUNET_HELLO_Address *address,
+ struct GNUNET_ATS_Session *session);
+
+
+/**
+ * Abort blacklist if @a address and @a session match.
+ *
+ * @param address address used to abort matching checks
+ * @param session session used to abort matching checks
+ */
+void
+GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
+ struct GNUNET_ATS_Session *session);
+
+/**
+ * Cancel a blacklist check.
+ *
+ * @param bc check to cancel
+ */
+void
+GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc);
+
+
+/**
* Function called by the transport for each received message.
*
* @param cls closure, const char* with the name of the plugin we received the message from
@@ -110,6 +187,41 @@ GST_receive_callback (void *cls,
struct GNUNET_ATS_Session *session,
const struct GNUNET_MessageHeader *message);
+/**
+ * Broadcast the given message to all of our clients.
+ *
+ * @param msg message to broadcast
+ * @param may_drop #GNUNET_YES if the message can be dropped / is payload
+ */
+void
+GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
+ int may_drop);
+
+
+/**
+ * Broadcast the new active address to all clients monitoring the peer.
+ *
+ * @param peer peer this update is about (never NULL)
+ * @param address address, NULL on disconnect
+ * @param state the current state of the peer
+ * @param state_timeout the time out for the state
+ */
+void
+GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Address *address,
+ enum GNUNET_TRANSPORT_PeerState state,
+ struct GNUNET_TIME_Absolute state_timeout);
+
+
+/**
+ * Notify all clients about a disconnect, and cancel
+ * pending SEND_OK messages for this peer.
+ *
+ * @param peer peer that disconnected
+ */
+void
+GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer);
+
diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c
deleted file mode 100644
index b6c36a6cd..000000000
--- a/src/transport/gnunet-service-transport_blacklist.c
+++ /dev/null
@@ -1,933 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010,2011 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/gnunet-service-transport_blacklist.c
- * @brief blacklisting implementation
- * @author Christian Grothoff
- * @author Matthias Wachs
- * @details This is the blacklisting component of transport service. With
- * blacklisting it is possible to deny connections to specific peers of
- * to use a specific plugin to a specific peer. Peers can be blacklisted using
- * the configuration or a blacklist client can be asked.
- *
- * To blacklist peers using the configuration you have to add a section to your
- * configuration containing the peer id of the peer to blacklist and the plugin
- * if required.
- *
- * Example:
- * To blacklist connections to P565... on peer AG2P... using tcp add:
- * [transport-blacklist-AG2PHES1BARB9IJCPAMJTFPVJ5V3A72S3F2A8SBUB8DAQ2V0O3V8G6G2JU56FHGFOHMQVKBSQFV98TCGTC3RJ1NINP82G0RC00N1520]
- * P565723JO1C2HSN6J29TAQ22MN6CI8HTMUU55T0FUQG4CMDGGEQ8UCNBKUMB94GC8R9G4FB2SF9LDOBAJ6AMINBP4JHHDD6L7VD801G = tcp
- *
- * To blacklist connections to P565... on peer AG2P... using all plugins add:
- * [transport-blacklist-AG2PHES1BARB9IJCPAMJTFPVJ5V3A72S3F2A8SBUB8DAQ2V0O3V8G6G2JU56FHGFOHMQVKBSQFV98TCGTC3RJ1NINP82G0RC00N1520]
- * P565723JO1C2HSN6J29TAQ22MN6CI8HTMUU55T0FUQG4CMDGGEQ8UCNBKUMB94GC8R9G4FB2SF9LDOBAJ6AMINBP4JHHDD6L7VD801G =
- *
- * You can also add a blacklist client usign the blacklist api. On a blacklist
- * check, blacklisting first checks internally if the peer is blacklisted and
- * if not, it asks the blacklisting clients. Clients are asked if it is OK to
- * connect to a peer ID, the plugin is omitted.
- *
- * On blacklist check for (peer, plugin)
- * - Do we have a local blacklist entry for this peer and this plugin?
- * - YES: disallow connection
- * - Do we have a local blacklist entry for this peer and all plugins?
- * - YES: disallow connection
- * - Does one of the clients disallow?
- * - YES: disallow connection
- *
- */
-#include "platform.h"
-#include "gnunet-service-transport.h"
-#include "gnunet-service-transport_blacklist.h"
-#include "gnunet-service-transport_neighbours.h"
-#include "transport.h"
-
-/**
- * Size of the blacklist hash map.
- */
-#define TRANSPORT_BLACKLIST_HT_SIZE 64
-
-
-/**
- * Context we use when performing a blacklist check.
- */
-struct GST_BlacklistCheck;
-
-
-/**
- * Information kept for each client registered to perform
- * blacklisting.
- */
-struct Blacklisters
-{
- /**
- * This is a linked list.
- */
- struct Blacklisters *next;
-
- /**
- * This is a linked list.
- */
- struct Blacklisters *prev;
-
- /**
- * Client responsible for this entry.
- */
- struct GNUNET_SERVER_Client *client;
-
- /**
- * Blacklist check that we're currently performing (or NULL
- * if we're performing one that has been cancelled).
- */
- struct GST_BlacklistCheck *bc;
-
- /**
- * Set to #GNUNET_YES if we're currently waiting for a reply.
- */
- int waiting_for_reply;
-
- /**
- * #GNUNET_YES if we have to call receive_done for this client
- */
- int call_receive_done;
-
-};
-
-
-
-/**
- * Context we use when performing a blacklist check.
- */
-struct GST_BlacklistCheck
-{
-
- /**
- * This is a linked list.
- */
- struct GST_BlacklistCheck *next;
-
- /**
- * This is a linked list.
- */
- struct GST_BlacklistCheck *prev;
-
- /**
- * Peer being checked.
- */
- struct GNUNET_PeerIdentity peer;
-
- /**
- * Continuation to call with the result.
- */
- GST_BlacklistTestContinuation cont;
-
- /**
- * Closure for @e cont.
- */
- void *cont_cls;
-
- /**
- * Address for #GST_blacklist_abort_matching(), can be NULL.
- */
- struct GNUNET_HELLO_Address *address;
-
- /**
- * Session for #GST_blacklist_abort_matching(), can be NULL.
- */
- struct GNUNET_ATS_Session *session;
-
- /**
- * Current transmission request handle for this client, or NULL if no
- * request is pending.
- */
- struct GNUNET_SERVER_TransmitHandle *th;
-
- /**
- * Our current position in the blacklisters list.
- */
- struct Blacklisters *bl_pos;
-
- /**
- * Current task performing the check.
- */
- struct GNUNET_SCHEDULER_Task *task;
-
-};
-
-
-/**
- * Head of DLL of active blacklisting queries.
- */
-static struct GST_BlacklistCheck *bc_head;
-
-/**
- * Tail of DLL of active blacklisting queries.
- */
-static struct GST_BlacklistCheck *bc_tail;
-
-/**
- * Head of DLL of blacklisting clients.
- */
-static struct Blacklisters *bl_head;
-
-/**
- * Tail of DLL of blacklisting clients.
- */
-static struct Blacklisters *bl_tail;
-
-/**
- * Hashmap of blacklisted peers. Values are of type 'char *' (transport names),
- * can be NULL if we have no static blacklist.
- */
-static struct GNUNET_CONTAINER_MultiPeerMap *blacklist;
-
-
-/**
- * Perform next action in the blacklist check.
- *
- * @param cls the `struct BlacklistCheck*`
- */
-static void
-do_blacklist_check (void *cls);
-
-
-/**
- * Called whenever a client is disconnected. Frees our
- * resources associated with that client.
- *
- * @param cls closure (unused)
- * @param client identification of the client
- */
-static void
-client_disconnect_notification (void *cls,
- struct GNUNET_SERVER_Client *client)
-{
- struct Blacklisters *bl;
- struct GST_BlacklistCheck *bc;
-
- if (NULL == client)
- return;
- for (bl = bl_head; bl != NULL; bl = bl->next)
- {
- if (bl->client != client)
- continue;
- for (bc = bc_head; NULL != bc; bc = bc->next)
- {
- if (bc->bl_pos != bl)
- continue;
- bc->bl_pos = bl->next;
- if (NULL != bc->th)
- {
- GNUNET_SERVER_notify_transmit_ready_cancel (bc->th);
- bc->th = NULL;
- }
- if (NULL == bc->task)
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
- }
- GNUNET_CONTAINER_DLL_remove (bl_head, bl_tail, bl);
- GNUNET_SERVER_client_drop (bl->client);
- GNUNET_free (bl);
- break;
- }
-}
-
-
-/**
- * Function to iterate over options in the blacklisting section for a peer.
- *
- * @param cls closure
- * @param section name of the section
- * @param option name of the option
- * @param value value of the option
- */
-static void
-blacklist_cfg_iter (void *cls,
- const char *section,
- const char *option,
- const char *value)
-{
- unsigned int *res = cls;
- struct GNUNET_PeerIdentity peer;
- char *plugs;
- char *pos;
-
- if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_public_key_from_string (option,
- strlen (option),
- &peer.public_key))
- return;
-
- if ((NULL == value) || (0 == strcmp(value, "")))
- {
- /* Blacklist whole peer */
- GST_blacklist_add_peer (&peer, NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Adding blacklisting entry for peer `%s'\n"),
- GNUNET_i2s (&peer));
- }
- else
- {
- plugs = GNUNET_strdup (value);
- for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Adding blacklisting entry for peer `%s':`%s'\n"),
- GNUNET_i2s (&peer), pos);
- GST_blacklist_add_peer (&peer, pos);
- }
- GNUNET_free (plugs);
- }
- (*res)++;
-}
-
-
-/**
- * Read blacklist configuration
- *
- * @param cfg the configuration handle
- * @param my_id my peer identity
- */
-static void
-read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const struct GNUNET_PeerIdentity *my_id)
-{
- char cfg_sect[512];
- unsigned int res = 0;
-
- GNUNET_snprintf (cfg_sect,
- sizeof (cfg_sect),
- "transport-blacklist-%s",
- GNUNET_i2s_full (my_id));
- GNUNET_CONFIGURATION_iterate_section_values (cfg,
- cfg_sect,
- &blacklist_cfg_iter,
- &res);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Loaded %u blacklisting entries from configuration\n",
- res);
-}
-
-
-/**
- * Start blacklist subsystem.
- *
- * @param server server used to accept clients from
- * @param cfg configuration handle
- * @param my_id my peer id
- */
-void
-GST_blacklist_start (struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- const struct GNUNET_PeerIdentity *my_id)
-{
- GNUNET_assert (NULL != cfg);
- GNUNET_assert (NULL != my_id);
- read_blacklist_configuration (cfg, my_id);
- GNUNET_SERVER_disconnect_notify (server,
- &client_disconnect_notification,
- NULL);
-}
-
-
-/**
- * Free the given entry in the blacklist.
- *
- * @param cls unused
- * @param key host identity (unused)
- * @param value the blacklist entry
- * @return #GNUNET_OK (continue to iterate)
- */
-static int
-free_blacklist_entry (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
-{
- char *be = value;
-
- GNUNET_free_non_null (be);
- return GNUNET_OK;
-}
-
-
-/**
- * Stop blacklist subsystem.
- */
-void
-GST_blacklist_stop ()
-{
- if (NULL == blacklist)
- return;
- GNUNET_CONTAINER_multipeermap_iterate (blacklist,
- &free_blacklist_entry,
- NULL);
- GNUNET_CONTAINER_multipeermap_destroy (blacklist);
- blacklist = NULL;
-}
-
-
-/**
- * Transmit blacklist query to the client.
- *
- * @param cls the `struct GST_BlacklistCheck`
- * @param size number of bytes allowed
- * @param buf where to copy the message
- * @return number of bytes copied to @a buf
- */
-static size_t
-transmit_blacklist_message (void *cls,
- size_t size,
- void *buf)
-{
- struct GST_BlacklistCheck *bc = cls;
- struct Blacklisters *bl;
- struct BlacklistMessage bm;
-
- bc->th = NULL;
- if (0 == size)
- {
- GNUNET_assert (NULL == bc->task);
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to send blacklist test for peer `%s' to client\n",
- GNUNET_i2s (&bc->peer));
- return 0;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending blacklist test for peer `%s' to client %p\n",
- GNUNET_i2s (&bc->peer),
- bc->bl_pos->client);
- bl = bc->bl_pos;
- bm.header.size = htons (sizeof (struct BlacklistMessage));
- bm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY);
- bm.is_allowed = htonl (0);
- bm.peer = bc->peer;
- GNUNET_memcpy (buf,
- &bm,
- sizeof (bm));
- if (GNUNET_YES == bl->call_receive_done)
- {
- GNUNET_SERVER_receive_done (bl->client,
- GNUNET_OK);
- bl->call_receive_done = GNUNET_NO;
- }
-
- bl->waiting_for_reply = GNUNET_YES;
- return sizeof (bm);
-}
-
-
-/**
- * Perform next action in the blacklist check.
- *
- * @param cls the `struct GST_BlacklistCheck *`
- */
-static void
-do_blacklist_check (void *cls)
-{
- struct GST_BlacklistCheck *bc = cls;
- struct Blacklisters *bl;
-
- bc->task = NULL;
- bl = bc->bl_pos;
- if (NULL == bl)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No other blacklist clients active, will allow neighbour `%s'\n",
- GNUNET_i2s (&bc->peer));
-
- bc->cont (bc->cont_cls,
- &bc->peer,
- bc->address,
- bc->session,
- GNUNET_OK);
- GST_blacklist_test_cancel (bc);
- return;
- }
- if ( (NULL != bl->bc) ||
- (GNUNET_NO != bl->waiting_for_reply) )
- return; /* someone else busy with this client */
- bl->bc = bc;
- bc->th =
- GNUNET_SERVER_notify_transmit_ready (bl->client,
- sizeof (struct BlacklistMessage),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_blacklist_message,
- bc);
-}
-
-
-/**
- * Got the result about an existing connection from a new blacklister.
- * Shutdown the neighbour if necessary.
- *
- * @param cls unused
- * @param peer the neighbour that was investigated
- * @param address address associated with the request
- * @param session session associated with the request
- * @param allowed #GNUNET_OK if we can keep it,
- * #GNUNET_NO if we must shutdown the connection
- */
-static void
-confirm_or_drop_neighbour (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- struct GNUNET_ATS_Session *session,
- int allowed)
-{
- if (GNUNET_OK == allowed)
- return; /* we're done */
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# disconnects due to blacklist"),
- 1,
- GNUNET_NO);
- GST_neighbours_force_disconnect (peer);
-}
-
-
-/**
- * Closure for #test_connection_ok().
- */
-struct TestConnectionContext
-{
- /**
- * Is this the first neighbour we're checking?
- */
- int first;
-
- /**
- * Handle to the blacklisting client we need to ask.
- */
- struct Blacklisters *bl;
-};
-
-
-/**
- * Test if an existing connection is still acceptable given a new
- * blacklisting client.
- *
- * @param cls the `struct TestConnectionContext *`
- * @param peer identity of the peer
- * @param address the address
- * @param state current state this peer is in
- * @param state_timeout timeout for the current state of the peer
- * @param bandwidth_in bandwidth assigned inbound
- * @param bandwidth_out bandwidth assigned outbound
- */
-static void
-test_connection_ok (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- enum GNUNET_TRANSPORT_PeerState state,
- struct GNUNET_TIME_Absolute state_timeout,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
-{
- struct TestConnectionContext *tcc = cls;
- struct GST_BlacklistCheck *bc;
-
- bc = GNUNET_new (struct GST_BlacklistCheck);
- GNUNET_CONTAINER_DLL_insert (bc_head,
- bc_tail,
- bc);
- bc->peer = *peer;
- bc->address = GNUNET_HELLO_address_copy (address);
- bc->cont = &confirm_or_drop_neighbour;
- bc->cont_cls = NULL;
- bc->bl_pos = tcc->bl;
- if (GNUNET_YES == tcc->first)
- {
- /* all would wait for the same client, no need to
- * create more than just the first task right now */
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
- tcc->first = GNUNET_NO;
- }
-}
-
-
-/**
- * Initialize a blacklisting client. We got a blacklist-init
- * message from this client, add him to the list of clients
- * to query for blacklisting.
- *
- * @param cls unused
- * @param client the client
- * @param message the blacklist-init message that was sent
- */
-void
-GST_blacklist_handle_init (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- struct Blacklisters *bl;
- struct TestConnectionContext tcc;
-
- for (bl = bl_head; NULL != bl; bl = bl->next)
- if (bl->client == client)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
-
- GNUNET_SERVER_client_mark_monitor (client);
- bl = GNUNET_new (struct Blacklisters);
- bl->client = client;
- bl->call_receive_done = GNUNET_YES;
- GNUNET_SERVER_client_keep (client);
- GNUNET_CONTAINER_DLL_insert_after (bl_head,
- bl_tail,
- bl_tail,
- bl);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "New blacklist client %p\n",
- client);
-
- /* confirm that all existing connections are OK! */
- tcc.bl = bl;
- tcc.first = GNUNET_YES;
- GST_neighbours_iterate (&test_connection_ok, &tcc);
-}
-
-
-/**
- * A blacklisting client has sent us reply. Process it.
- *
- * @param cls unused
- * @param client the client
- * @param message the blacklist-init message that was sent
- */
-void
-GST_blacklist_handle_reply (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- const struct BlacklistMessage *msg =
- (const struct BlacklistMessage *) message;
- struct Blacklisters *bl;
- struct GST_BlacklistCheck *bc;
-
- bl = bl_head;
- while ((bl != NULL) && (bl->client != client))
- bl = bl->next;
- if (NULL == bl)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist client disconnected\n");
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist client %p sent reply for `%s'\n",
- client,
- GNUNET_i2s (&msg->peer));
-
- bc = bl->bc;
- bl->bc = NULL;
- bl->waiting_for_reply = GNUNET_NO;
- bl->call_receive_done = GNUNET_YES; /* Remember to call receive_done */
- if (NULL != bc)
- {
- /* only run this if the blacklist check has not been
- * cancelled in the meantime... */
- GNUNET_assert (bc->bl_pos == bl);
- if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist check failed, peer not allowed\n");
- /* For the duration of the continuation, make the ongoing
- check invisible (to avoid double-cancellation); then
- add it back again so we can re-use GST_blacklist_test_cancel() */
- GNUNET_CONTAINER_DLL_remove (bc_head,
- bc_tail,
- bc);
- bc->cont (bc->cont_cls,
- &bc->peer,
- bc->address,
- bc->session,
- GNUNET_NO);
- GNUNET_CONTAINER_DLL_insert (bc_head,
- bc_tail,
- bc);
- GST_blacklist_test_cancel (bc);
- GNUNET_SERVER_receive_done (bl->client, GNUNET_OK);
- bl->call_receive_done = GNUNET_NO;
- return;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist check succeeded, continuing with checks\n");
- GNUNET_SERVER_receive_done (bl->client,
- GNUNET_OK);
- bl->call_receive_done = GNUNET_NO;
- bc->bl_pos = bl->next;
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
- }
- }
- /* check if any other blacklist checks are waiting for this blacklister */
- for (bc = bc_head; bc != NULL; bc = bc->next)
- if ((bc->bl_pos == bl) && (NULL == bc->task))
- {
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
- bc);
- break;
- }
-}
-
-
-/**
- * Add the given peer to the blacklist (for the given transport).
- *
- * @param peer peer to blacklist
- * @param transport_name transport to blacklist for this peer, NULL for all
- */
-void
-GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
- const char *transport_name)
-{
- char *transport = NULL;
-
- if (NULL != transport_name)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Adding peer `%s' with plugin `%s' to blacklist\n",
- GNUNET_i2s (peer), transport_name);
- transport = GNUNET_strdup (transport_name);
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Adding peer `%s' with all plugins to blacklist\n",
- GNUNET_i2s (peer));
- if (NULL == blacklist)
- blacklist =
- GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE,
- GNUNET_NO);
-
- GNUNET_CONTAINER_multipeermap_put (blacklist, peer,
- transport,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
-}
-
-
-/**
- * Abort blacklist if @a address and @a session match.
- *
- * @param address address used to abort matching checks
- * @param session session used to abort matching checks
- */
-void
-GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
- struct GNUNET_ATS_Session *session)
-{
- struct GST_BlacklistCheck *bc;
- struct GST_BlacklistCheck *n;
-
- n = bc_head;
- while (NULL != (bc = n))
- {
- n = bc->next;
- if ( (bc->session == session) &&
- (0 == GNUNET_HELLO_address_cmp (bc->address,
- address)) )
- {
- bc->cont (bc->cont_cls,
- &bc->peer,
- bc->address,
- bc->session,
- GNUNET_SYSERR);
- GST_blacklist_test_cancel (bc);
- }
- }
-}
-
-
-/**
- * Test if the given blacklist entry matches. If so,
- * abort the iteration.
- *
- * @param cls the transport name to match (const char*)
- * @param key the key (unused)
- * @param value the 'char *' (name of a blacklisted transport)
- * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches
- */
-static int
-test_blacklisted (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
-{
- const char *transport_name = cls;
- char *be = value;
-
- /* Blacklist entry be:
- * (NULL == be): peer is blacklisted with all plugins
- * (NULL != be): peer is blacklisted for a specific plugin
- *
- * If (NULL != transport_name) we look for a transport specific entry:
- * if (transport_name == be) forbidden
- *
- */
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n",
- GNUNET_i2s (key),
- (NULL == transport_name) ? "unspecified" : transport_name,
- (NULL == be) ? "all plugins" : be);
- /* all plugins for this peer were blacklisted: disallow */
- if (NULL == value)
- return GNUNET_NO;
-
- /* blacklist check for specific transport */
- if ((NULL != transport_name) && (NULL != value))
- {
- if (0 == strcmp (transport_name,
- be))
- return GNUNET_NO; /* plugin is blacklisted! */
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Test if a peer/transport combination is blacklisted.
- *
- * @param peer the identity of the peer to test
- * @param transport_name name of the transport to test, never NULL
- * @param cont function to call with result
- * @param cont_cls closure for @a cont
- * @param address address to pass back to @a cont, can be NULL
- * @param session session to pass back to @a cont, can be NULL
- * @return handle to the blacklist check, NULL if the decision
- * was made instantly and @a cont was already called
- */
-struct GST_BlacklistCheck *
-GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
- const char *transport_name,
- GST_BlacklistTestContinuation cont,
- void *cont_cls,
- const struct GNUNET_HELLO_Address *address,
- struct GNUNET_ATS_Session *session)
-{
- struct GST_BlacklistCheck *bc;
-
- GNUNET_assert (NULL != peer);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist check for peer `%s':%s\n",
- GNUNET_i2s (peer),
- (NULL != transport_name) ? transport_name : "unspecified");
-
- /* Check local blacklist by iterating over hashmap
- * If iteration is aborted, we found a matching blacklist entry */
- if ((NULL != blacklist) &&
- (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multipeermap_get_multiple (blacklist, peer,
- &test_blacklisted,
- (void *) transport_name)))
- {
- /* Disallowed by config, disapprove instantly */
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# disconnects due to blacklist"),
- 1,
- GNUNET_NO);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Disallowing connection to peer `%s' on transport %s\n"),
- GNUNET_i2s (peer),
- (NULL != transport_name) ? transport_name : "unspecified");
- if (NULL != cont)
- cont (cont_cls,
- peer,
- address,
- session,
- GNUNET_NO);
- return NULL;
- }
-
- if (NULL == bl_head)
- {
- /* no blacklist clients, approve instantly */
- if (NULL != cont)
- cont (cont_cls,
- peer,
- address,
- session,
- GNUNET_OK);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Allowing connection to peer `%s' %s\n",
- GNUNET_i2s (peer),
- (NULL != transport_name) ? transport_name : "");
- return NULL;
- }
-
- /* need to query blacklist clients */
- bc = GNUNET_new (struct GST_BlacklistCheck);
- GNUNET_CONTAINER_DLL_insert (bc_head,
- bc_tail,
- bc);
- bc->peer = *peer;
- bc->address = GNUNET_HELLO_address_copy (address);
- bc->session = session;
- bc->cont = cont;
- bc->cont_cls = cont_cls;
- bc->bl_pos = bl_head;
- bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
- return bc;
-}
-
-
-/**
- * Cancel a blacklist check.
- *
- * @param bc check to cancel
- */
-void
-GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
-{
- GNUNET_CONTAINER_DLL_remove (bc_head,
- bc_tail,
- bc);
- if (NULL != bc->bl_pos)
- {
- if (bc->bl_pos->bc == bc)
- {
- /* we're at the head of the queue, remove us! */
- bc->bl_pos->bc = NULL;
- }
- }
- if (NULL != bc->task)
- {
- GNUNET_SCHEDULER_cancel (bc->task);
- bc->task = NULL;
- }
- if (NULL != bc->th)
- {
- GNUNET_SERVER_notify_transmit_ready_cancel (bc->th);
- bc->th = NULL;
- }
- GNUNET_free_non_null (bc->address);
- GNUNET_free (bc);
-}
-
-
-/* end of file gnunet-service-transport_blacklist.c */
diff --git a/src/transport/gnunet-service-transport_blacklist.h b/src/transport/gnunet-service-transport_blacklist.h
deleted file mode 100644
index 3888d33d3..000000000
--- a/src/transport/gnunet-service-transport_blacklist.h
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010,2011 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/gnunet-service-transport_blacklist.h
- * @brief blacklisting API
- * @author Christian Grothoff
- */
-#ifndef GNUNET_SERVICE_TRANSPORT_BLACKLIST_H
-#define GNUNET_SERVICE_TRANSPORT_BLACKLIST_H
-
-#include "gnunet_statistics_service.h"
-#include "gnunet_ats_service.h"
-#include "gnunet_util_lib.h"
-
-/**
- * Start blacklist subsystem.
- *
- * @param server server used to accept clients from
- * @param cfg configuration handle
- * @param my_id my peer id
- */
-void
-GST_blacklist_start (struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- const struct GNUNET_PeerIdentity *my_id);
-
-
-/**
- * Stop blacklist subsystem.
- */
-void
-GST_blacklist_stop (void);
-
-
-/**
- * Initialize a blacklisting client. We got a blacklist-init
- * message from this client, add him to the list of clients
- * to query for blacklisting.
- *
- * @param cls unused
- * @param client the client
- * @param message the blacklist-init message that was sent
- */
-void
-GST_blacklist_handle_init (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
-
-
-/**
- * A blacklisting client has sent us reply. Process it.
- *
- * @param cls unused
- * @param client the client
- * @param message the blacklist-init message that was sent
- */
-void
-GST_blacklist_handle_reply (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
-
-
-/**
- * Add the given peer to the blacklist (for the given transport).
- *
- * @param peer peer to blacklist
- * @param transport_name transport to blacklist for this peer, NULL for all
- */
-void
-GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
- const char *transport_name);
-
-
-/**
- * Handle to an active blacklist check.
- */
-struct GST_BlacklistCheck;
-
-
-/**
- * Continuation called from a blacklist test.
- *
- * @param cls closure
- * @param peer identity of peer that was tested
- * @param address address associated with the request
- * @param session session associated with the request
- * @param result #GNUNET_OK if the connection is allowed,
- * #GNUNET_NO if not,
- * #GNUNET_SYSERR if operation was aborted
- */
-typedef void
-(*GST_BlacklistTestContinuation) (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- struct GNUNET_ATS_Session *session,
- int result);
-
-
-/**
- * Test if a peer/transport combination is blacklisted.
- *
- * @param peer the identity of the peer to test
- * @param transport_name name of the transport to test, never NULL
- * @param cont function to call with result
- * @param cont_cls closure for @a cont
- * @param address address to pass back to @a cont, can be NULL
- * @param session session to pass back to @a cont, can be NULL
- * @return handle to the blacklist check, NULL if the decision
- * was made instantly and @a cont was already called
- */
-struct GST_BlacklistCheck *
-GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
- const char *transport_name,
- GST_BlacklistTestContinuation cont,
- void *cont_cls,
- const struct GNUNET_HELLO_Address *address,
- struct GNUNET_ATS_Session *session);
-
-
-/**
- * Abort blacklist if @a address and @a session match.
- *
- * @param address address used to abort matching checks
- * @param session session used to abort matching checks
- */
-void
-GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
- struct GNUNET_ATS_Session *session);
-
-
-
-/**
- * Cancel a blacklist check.
- *
- * @param bc check to cancel
- */
-void
-GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc);
-
-#endif
-/* end of file gnunet-service-transport_blacklist.h */
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
deleted file mode 100644
index 036fc5637..000000000
--- a/src/transport/gnunet-service-transport_clients.c
+++ /dev/null
@@ -1,1491 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010-2015 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/gnunet-service-transport_clients.c
- * @brief communication with clients (core service and monitors)
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "gnunet-service-transport_blacklist.h"
-#include "gnunet-service-transport_clients.h"
-#include "gnunet-service-transport_hello.h"
-#include "gnunet-service-transport_neighbours.h"
-#include "gnunet-service-transport_plugins.h"
-#include "gnunet-service-transport_validation.h"
-#include "gnunet-service-transport_manipulation.h"
-#include "gnunet-service-transport.h"
-#include "transport.h"
-
-
-/**
- * How many messages can we have pending for a given client process
- * before we start to drop incoming messages? We typically should
- * have only one client and so this would be the primary buffer for
- * messages, so the number should be chosen rather generously.
- *
- * The expectation here is that most of the time the queue is large
- * enough so that a drop is virtually never required. Note that
- * this value must be about as large as 'TOTAL_MSGS' in the
- * 'test_transport_api_reliability.c', otherwise that testcase may
- * fail.
- */
-#define MAX_PENDING (128 * 1024)
-
-
-/**
- * Linked list of messages to be transmitted to the client. Each
- * entry is followed by the actual message.
- */
-struct ClientMessageQueueEntry
-{
- /**
- * This is a doubly-linked list.
- */
- struct ClientMessageQueueEntry *next;
-
- /**
- * This is a doubly-linked list.
- */
- struct ClientMessageQueueEntry *prev;
-};
-
-
-/**
- * Client connected to the transport service.
- */
-struct TransportClient
-{
-
- /**
- * This is a doubly-linked list.
- */
- struct TransportClient *next;
-
- /**
- * This is a doubly-linked list.
- */
- struct TransportClient *prev;
-
- /**
- * Handle to the client.
- */
- struct GNUNET_SERVER_Client *client;
-
- /**
- * Linked list of messages yet to be transmitted to
- * the client.
- */
- struct ClientMessageQueueEntry *message_queue_head;
-
- /**
- * Tail of linked list of messages yet to be transmitted to the
- * client.
- */
- struct ClientMessageQueueEntry *message_queue_tail;
-
- /**
- * Current transmit request handle.
- */
- struct GNUNET_SERVER_TransmitHandle *th;
-
- /**
- * Length of the list of messages pending for this client.
- */
- unsigned int message_count;
-
- /**
- * Is this client interested in payload messages?
- */
- int send_payload;
-};
-
-
-/**
- * Context for address to string operations
- */
-struct AddressToStringContext
-{
- /**
- * This is a doubly-linked list.
- */
- struct AddressToStringContext *next;
-
- /**
- * This is a doubly-linked list.
- */
- struct AddressToStringContext *prev;
-
- /**
- * Transmission context
- */
- struct GNUNET_SERVER_TransmitContext* tc;
-};
-
-
-/**
- * Client monitoring changes of active addresses or validations
- * of our neighbours. Which type is being monitored depends on the
- * DLL this struct is in.
- */
-struct MonitoringClient
-{
- /**
- * This is a doubly-linked list.
- */
- struct MonitoringClient *next;
-
- /**
- * This is a doubly-linked list.
- */
- struct MonitoringClient *prev;
-
- /**
- * Handle to the client.
- */
- struct GNUNET_SERVER_Client *client;
-
- /**
- * Peer identity to monitor the addresses of.
- * Zero to monitor all neighrours.
- */
- struct GNUNET_PeerIdentity peer;
-
-};
-
-
-/**
- * Closure for #handle_send_transmit_continuation()
- */
-struct SendTransmitContinuationContext
-{
- /**
- * Client that made the request.
- */
- struct GNUNET_SERVER_Client *client;
-
- /**
- * Peer that was the target.
- */
- struct GNUNET_PeerIdentity target;
-
- /**
- * At what time did we receive the message?
- */
- struct GNUNET_TIME_Absolute send_time;
-
- /**
- * Unique ID, for logging.
- */
- unsigned long long uuid;
-
- /**
- * Set to #GNUNET_YES if the connection for @e target goes
- * down and we thus must no longer send the
- * #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK message.
- */
- int down;
-};
-
-
-/**
- * Head of linked list of all clients to this service.
- */
-static struct TransportClient *clients_head;
-
-/**
- * Tail of linked list of all clients to this service.
- */
-static struct TransportClient *clients_tail;
-
-/**
- * Map of peer identities to active send transmit continuation
- * contexts. Used to flag contexts as 'dead' when a connection goes
- * down. Values are of type `struct SendTransmitContinuationContext
- * *`.
- */
-static struct GNUNET_CONTAINER_MultiPeerMap *active_stccs;
-
-/**
- * Head of linked list of all pending address iterations
- */
-static struct AddressToStringContext *a2s_head;
-
-/**
- * Tail of linked list of all pending address iterations
- */
-static struct AddressToStringContext *a2s_tail;
-
-/**
- * Head of linked list of monitoring clients.
- */
-static struct MonitoringClient *peer_monitoring_clients_head;
-
-/**
- * Tail of linked list of monitoring clients.
- */
-static struct MonitoringClient *peer_monitoring_clients_tail;
-
-/**
- * Notification context, to send updates on changes to active addresses
- * of our neighbours.
- */
-static struct GNUNET_SERVER_NotificationContext *peer_nc;
-
-/**
- * Notification context, to send updates on changes to active addresses
- * of our neighbours.
- */
-static struct GNUNET_SERVER_NotificationContext *val_nc;
-
-/**
- * Notification context, to send updates on changes to active plugin
- * connections.
- */
-static struct GNUNET_SERVER_NotificationContext *plugin_nc;
-
-/**
- * Plugin monitoring client we are currently syncing, NULL if all
- * monitoring clients are in sync.
- */
-static struct GNUNET_SERVER_Client *sync_client;
-
-/**
- * Peer identity that is all zeros, used as a way to indicate
- * "all peers". Used for comparissons.
- */
-static struct GNUNET_PeerIdentity all_zeros;
-
-
-/**
- * Find the internal handle associated with the given client handle.
- *
- * @param client server's client handle to look up
- * @return internal client handle
- */
-static struct TransportClient *
-lookup_client (struct GNUNET_SERVER_Client *client)
-{
- return GNUNET_SERVER_client_get_user_context (client,
- struct TransportClient);
-}
-
-
-/**
- * Create the internal handle for the given server client handle.
- *
- * @param client server's client handle to create our internal handle for
- * @return fresh internal client handle
- */
-static struct TransportClient *
-setup_client (struct GNUNET_SERVER_Client *client)
-{
- struct TransportClient *tc;
-
- GNUNET_assert (NULL == lookup_client (client));
- tc = GNUNET_new (struct TransportClient);
- tc->client = client;
- GNUNET_SERVER_client_set_user_context (client, tc);
- GNUNET_CONTAINER_DLL_insert (clients_head,
- clients_tail,
- tc);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p connected\n",
- tc);
- return tc;
-}
-
-
-/**
- * Find the handle to the monitoring client associated with the given
- * client handle.
- *
- * @param head the head of the client queue to look in
- * @param client server's client handle to look up
- * @return handle to the monitoring client
- */
-static struct MonitoringClient *
-lookup_monitoring_client (struct MonitoringClient *head,
- struct GNUNET_SERVER_Client *client)
-{
- struct MonitoringClient *mc;
-
- for (mc = head; NULL != mc; mc = mc->next)
- if (mc->client == client)
- return mc;
- return NULL;
-}
-
-
-/**
- * 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_peer_monitoring_client (struct GNUNET_SERVER_Client *client,
- const struct GNUNET_PeerIdentity *peer)
-{
- struct MonitoringClient *mc;
-
- GNUNET_assert (NULL ==
- lookup_monitoring_client (peer_monitoring_clients_head,
- client));
- mc = GNUNET_new (struct MonitoringClient);
- mc->client = client;
- mc->peer = *peer;
- GNUNET_CONTAINER_DLL_insert (peer_monitoring_clients_head,
- peer_monitoring_clients_tail,
- mc);
- GNUNET_SERVER_client_mark_monitor (client);
- GNUNET_SERVER_notification_context_add (peer_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
- * was closed for writing in the meantime.
- *
- * @param cls closure
- * @param size number of bytes available in @a buf
- * @param buf where the callee should write the message
- * @return number of bytes written to @a buf
- */
-static size_t
-transmit_to_client_callback (void *cls,
- size_t size,
- void *buf)
-{
- struct TransportClient *tc = cls;
- struct ClientMessageQueueEntry *q;
- const struct GNUNET_MessageHeader *msg;
- char *cbuf;
- uint16_t msize;
- size_t tsize;
-
- tc->th = NULL;
- if (NULL == buf)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission to client failed, closing connection.\n");
- return 0;
- }
- cbuf = buf;
- tsize = 0;
- while (NULL != (q = tc->message_queue_head))
- {
- msg = (const struct GNUNET_MessageHeader *) &q[1];
- msize = ntohs (msg->size);
- if (msize + tsize > size)
- break;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting message of type %u to client %p.\n",
- ntohs (msg->type),
- tc);
- GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
- tc->message_queue_tail,
- q);
- tc->message_count--;
- GNUNET_memcpy (&cbuf[tsize], msg, msize);
- GNUNET_free (q);
- tsize += msize;
- }
- if (NULL != q)
- {
- GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
- tc->th =
- GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_to_client_callback, tc);
- GNUNET_assert (NULL != tc->th);
- }
- return tsize;
-}
-
-
-/**
- * Queue the given message for transmission to the given client
- *
- * @param tc target of the message
- * @param msg message to transmit
- * @param may_drop #GNUNET_YES if the message can be dropped
- */
-static void
-unicast (struct TransportClient *tc,
- const struct GNUNET_MessageHeader *msg,
- int may_drop)
-{
- struct ClientMessageQueueEntry *q;
- uint16_t msize;
-
- if (NULL == msg)
- {
- GNUNET_break (0);
- return;
- }
- if ( (tc->message_count >= MAX_PENDING) &&
- (GNUNET_YES == may_drop) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dropping message of type %u and size %u, have %u/%u messages pending\n",
- ntohs (msg->type),
- ntohs (msg->size),
- tc->message_count,
- MAX_PENDING);
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop
- ("# messages dropped due to slow client"), 1,
- GNUNET_NO);
- return;
- }
- msize = ntohs (msg->size);
- GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
- q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
- GNUNET_memcpy (&q[1], msg, msize);
- GNUNET_CONTAINER_DLL_insert_tail (tc->message_queue_head,
- tc->message_queue_tail,
- q);
- tc->message_count++;
- if (NULL != tc->th)
- return;
- tc->th =
- GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_to_client_callback, tc);
- GNUNET_assert (NULL != tc->th);
-}
-
-
-/**
- * Called whenever a client is disconnected. Frees our
- * resources associated with that client.
- *
- * @param cls closure, NULL
- * @param client identification of the client
- */
-static void
-client_disconnect_notification (void *cls,
- struct GNUNET_SERVER_Client *client)
-{
- struct TransportClient *tc;
- struct MonitoringClient *mc;
- struct ClientMessageQueueEntry *mqe;
-
- if (NULL == client)
- return;
- mc = lookup_monitoring_client (peer_monitoring_clients_head,
- client);
- if (NULL != mc)
- {
- GNUNET_CONTAINER_DLL_remove (peer_monitoring_clients_head,
- peer_monitoring_clients_tail,
- mc);
- GNUNET_free (mc);
- }
- tc = lookup_client (client);
- if (NULL == tc)
- return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p disconnected, cleaning up.\n",
- tc);
- while (NULL != (mqe = tc->message_queue_head))
- {
- GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
- tc->message_queue_tail,
- mqe);
- tc->message_count--;
- GNUNET_free (mqe);
- }
- GNUNET_CONTAINER_DLL_remove (clients_head,
- clients_tail,
- tc);
- GNUNET_SERVER_client_set_user_context (client, NULL);
- if (NULL != tc->th)
- {
- GNUNET_SERVER_notify_transmit_ready_cancel (tc->th);
- tc->th = NULL;
- }
- GNUNET_break (0 == tc->message_count);
- GNUNET_free (tc);
-}
-
-
-/**
- * Function called for each of our connected neighbours. Notify the
- * client about the existing neighbour.
- *
- * @param cls the `struct TransportClient *` to notify
- * @param peer identity of the neighbour
- * @param address the address
- * @param state the current state of the peer
- * @param state_timeout the time out for the state
- * @param bandwidth_in inbound bandwidth in NBO
- * @param bandwidth_out outbound bandwidth in NBO
- */
-static void
-notify_client_about_neighbour (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- enum GNUNET_TRANSPORT_PeerState state,
- struct GNUNET_TIME_Absolute state_timeout,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
-{
- struct TransportClient *tc = cls;
- struct ConnectInfoMessage cim;
-
- if (GNUNET_NO == GST_neighbours_test_connected (peer))
- return;
- cim.header.size = htons (sizeof (struct ConnectInfoMessage));
- cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
- cim.id = *peer;
- cim.quota_in = bandwidth_in;
- cim.quota_out = bandwidth_out;
- unicast (tc, &cim.header, GNUNET_NO);
-}
-
-
-/**
- * Initialize a normal client. We got a start message from this
- * client, add him to the list of clients for broadcasting of inbound
- * messages.
- *
- * @param cls unused
- * @param client the client
- * @param message the start message that was sent
- */
-static void
-clients_handle_start (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- const struct StartMessage *start;
- const struct GNUNET_MessageHeader *hello;
- struct TransportClient *tc;
- uint32_t options;
-
- tc = lookup_client (client);
- if (NULL != tc)
- {
- /* got 'start' twice from the same client, not allowed */
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p sent START\n",
- client);
- start = (const struct StartMessage *) message;
- options = ntohl (start->options);
- if ((0 != (1 & options)) &&
- (0 !=
- memcmp (&start->self,
- &GST_my_identity,
- sizeof (struct GNUNET_PeerIdentity))))
- {
- /* client thinks this is a different peer, reject */
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return;
- }
- tc = setup_client (client);
- tc->send_payload = (0 != (2 & options));
- hello = GST_hello_get ();
- if (NULL != hello)
- unicast (tc,
- hello,
- GNUNET_NO);
- GST_neighbours_iterate (&notify_client_about_neighbour,
- tc);
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
-}
-
-
-/**
- * Client sent us a HELLO. Process the request.
- *
- * @param cls unused
- * @param client the client
- * @param message the HELLO message
- */
-static void
-clients_handle_hello (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- GST_validation_handle_hello (message);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
-}
-
-
-/**
- * Function called after the transmission is done. Notify the client that it is
- * OK to send the next message.
- *
- * @param cls closure
- * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
- * @param bytes_payload bytes payload sent
- * @param bytes_on_wire bytes sent on wire
- */
-static void
-handle_send_transmit_continuation (void *cls,
- int success,
- size_t bytes_payload,
- size_t bytes_on_wire)
-{
- struct SendTransmitContinuationContext *stcc = cls;
- struct SendOkMessage send_ok_msg;
- struct GNUNET_TIME_Relative delay;
- const struct GNUNET_HELLO_Address *addr;
-
- delay = GNUNET_TIME_absolute_get_duration (stcc->send_time);
- addr = GST_neighbour_get_current_address (&stcc->target);
- if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
- GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_YES),
- (unsigned int) bytes_payload,
- (unsigned int) bytes_on_wire,
- GNUNET_i2s (&stcc->target),
- success,
- (NULL != addr) ? addr->transport_name : "%");
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
- GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_YES),
- (unsigned int) bytes_payload,
- (unsigned int) bytes_on_wire,
- GNUNET_i2s (&stcc->target),
- success,
- (NULL != addr) ? addr->transport_name : "%");
-
- if (GNUNET_NO == stcc->down)
- {
- /* Only send confirmation if we are still connected */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending SEND_OK for transmission request %llu\n",
- stcc->uuid);
- send_ok_msg.header.size = htons (sizeof (send_ok_msg));
- send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
- send_ok_msg.bytes_msg = htonl (bytes_payload);
- send_ok_msg.bytes_physical = htonl (bytes_on_wire);
- send_ok_msg.success = htonl (success);
- send_ok_msg.peer = stcc->target;
- GST_clients_unicast (stcc->client,
- &send_ok_msg.header,
- GNUNET_NO);
- }
- GNUNET_SERVER_client_drop (stcc->client);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_remove (active_stccs,
- &stcc->target,
- stcc));
- GNUNET_free (stcc);
-}
-
-
-/**
- * Client asked for transmission to a peer. Process the request.
- *
- * @param cls unused
- * @param client the client
- * @param message the send message that was sent
- */
-static void
-clients_handle_send (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- static unsigned long long uuid_gen;
- const struct OutboundMessage *obm;
- const struct GNUNET_MessageHeader *obmm;
- struct SendTransmitContinuationContext *stcc;
- uint16_t size;
- uint16_t msize;
- struct TransportClient *tc;
-
- tc = lookup_client (client);
- if (NULL == tc)
- {
- /* client asked for transmission before 'START' */
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return;
- }
-
- size = ntohs (message->size);
- if (size <
- sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return;
- }
- obm = (const struct OutboundMessage *) message;
- obmm = (const struct GNUNET_MessageHeader *) &obm[1];
- msize = size - sizeof (struct OutboundMessage);
- if (msize < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return;
- }
-
- if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
- {
- /* not connected, not allowed to send; can happen due to asynchronous operations */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not send message to peer `%s': not connected\n",
- GNUNET_i2s (&obm->peer));
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop
- ("# bytes payload dropped (other peer was not connected)"),
- msize, GNUNET_NO);
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received SEND request %llu for `%s' and first message of type %u and total size %u\n",
- uuid_gen,
- GNUNET_i2s (&obm->peer),
- ntohs (obmm->type),
- msize);
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
- stcc = GNUNET_new (struct SendTransmitContinuationContext);
- stcc->target = obm->peer;
- stcc->client = client;
- stcc->send_time = GNUNET_TIME_absolute_get ();
- stcc->uuid = uuid_gen++;
- (void) GNUNET_CONTAINER_multipeermap_put (active_stccs,
- &stcc->target,
- stcc,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- GNUNET_SERVER_client_keep (client);
- GST_manipulation_send (&obm->peer,
- obmm,
- msize,
- GNUNET_TIME_relative_ntoh (obm->timeout),
- &handle_send_transmit_continuation,
- stcc);
-}
-
-
-/**
- * Take the given address and append it to the set of results sent back to
- * the client. This function may be called serveral times for a single
- * conversion. The last invocation will be with a @a address of
- * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
- * errors, the callback might be called first with @a address NULL and
- * @a res being #GNUNET_SYSERR. In that case, there will still be a
- * subsequent call later with @a address NULL and @a res #GNUNET_OK.
- *
- * @param cls the transmission context used (`struct GNUNET_SERVER_TransmitContext *`)
- * @param buf text to transmit (contains the human-readable address, or NULL)
- * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on error,
- * never #GNUNET_NO
- */
-static void
-transmit_address_to_client (void *cls,
- const char *buf,
- int res)
-{
- struct AddressToStringContext *actx = cls;
- struct AddressToStringResultMessage *atsm;
- size_t len;
- size_t slen;
-
- GNUNET_assert ( (GNUNET_OK == res) ||
- (GNUNET_SYSERR == res) );
- if (NULL == buf)
- {
- len = sizeof (struct AddressToStringResultMessage);
- atsm = GNUNET_malloc (len);
- atsm->header.size = ntohs (len);
- atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
- if (GNUNET_OK == res)
- {
- /* this was the last call, transmit */
- atsm->res = htonl (GNUNET_OK);
- atsm->addr_len = htonl (0);
- GNUNET_SERVER_transmit_context_append_message (actx->tc,
- (const struct GNUNET_MessageHeader *) atsm);
- GNUNET_SERVER_transmit_context_run (actx->tc,
- GNUNET_TIME_UNIT_FOREVER_REL);
- GNUNET_CONTAINER_DLL_remove (a2s_head,
- a2s_tail,
- actx);
- GNUNET_free (atsm);
- GNUNET_free (actx);
- return;
- }
- if (GNUNET_SYSERR == res)
- {
- /* address conversion failed, but there will be more callbacks */
- atsm->res = htonl (GNUNET_SYSERR);
- atsm->addr_len = htonl (0);
- GNUNET_SERVER_transmit_context_append_message (actx->tc,
- (const struct GNUNET_MessageHeader *) atsm);
- GNUNET_free (atsm);
- return;
- }
- }
- GNUNET_assert (GNUNET_OK == res);
- /* succesful conversion, append*/
- slen = strlen (buf) + 1;
- len = sizeof (struct AddressToStringResultMessage) + slen;
- atsm = GNUNET_malloc (len);
- atsm->header.size = ntohs (len);
- atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
- atsm->res = htonl (GNUNET_YES);
- atsm->addr_len = htonl (slen);
- GNUNET_memcpy (&atsm[1],
- buf,
- slen);
- GNUNET_SERVER_transmit_context_append_message (actx->tc,
- (const struct GNUNET_MessageHeader *) atsm);
- GNUNET_free (atsm);
-}
-
-
-/**
- * Client asked to resolve an address. Process the request.
- *
- * @param cls unused
- * @param client the client
- * @param message the resolution request
- */
-static void
-clients_handle_address_to_string (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- const struct AddressLookupMessage *alum;
- struct GNUNET_TRANSPORT_PluginFunctions *papi;
- const char *plugin_name;
- const char *address;
- uint32_t address_len;
- uint16_t size;
- struct GNUNET_SERVER_TransmitContext *tc;
- struct AddressToStringContext *actx;
- struct AddressToStringResultMessage atsm;
- struct GNUNET_TIME_Relative rtimeout;
- int32_t numeric;
-
- size = ntohs (message->size);
- if (size < sizeof (struct AddressLookupMessage))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- alum = (const struct AddressLookupMessage *) message;
- address_len = ntohs (alum->addrlen);
- if (size <= sizeof (struct AddressLookupMessage) + address_len)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- address = (const char *) &alum[1];
- plugin_name = (const char *) &address[address_len];
- if ('\0' != plugin_name[size - sizeof (struct AddressLookupMessage) - address_len - 1])
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
- numeric = ntohs (alum->numeric_only);
- tc = GNUNET_SERVER_transmit_context_create (client);
- papi = GST_plugins_printer_find (plugin_name);
- if (NULL == papi)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to find plugin `%s'\n",
- plugin_name);
- atsm.header.size = ntohs (sizeof (struct AddressToStringResultMessage));
- atsm.header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
- atsm.res = htonl (GNUNET_SYSERR);
- atsm.addr_len = htonl (0);
- GNUNET_SERVER_transmit_context_append_message (tc,
- &atsm.header);
- atsm.header.size = ntohs (sizeof (struct AddressToStringResultMessage));
- atsm.header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
- atsm.res = htonl (GNUNET_OK);
- atsm.addr_len = htonl (0);
- GNUNET_SERVER_transmit_context_append_message (tc,
- &atsm.header);
- GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
- return;
- }
- actx = GNUNET_new (struct AddressToStringContext);
- actx->tc = tc;
- GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx);
- GNUNET_SERVER_disable_receive_done_warning (client);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Pretty-printing address of %u bytes using plugin `%s'\n",
- address_len,
- plugin_name);
- papi->address_pretty_printer (papi->cls,
- plugin_name,
- address, address_len,
- numeric,
- rtimeout,
- &transmit_address_to_client,
- actx);
-}
-
-
-/**
- * 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 PeerIterateResponseMessage *
-compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address)
-{
- struct PeerIterateResponseMessage *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 PeerIterateResponseMessage) + alen + tlen);
- msg = GNUNET_malloc (size);
- msg->header.size = htons (size);
- msg->header.type =
- htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_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];
- GNUNET_memcpy (addr, address->address, alen);
- GNUNET_memcpy (&addr[alen], address->transport_name, tlen);
- }
- return msg;
-}
-
-
-/**
- * Context for #send_validation_information() and
- * #send_peer_information().
- */
-struct IterationContext
-{
- /**
- * Context to use for the transmission.
- */
- struct GNUNET_SERVER_TransmitContext *tc;
-
- /**
- * Which peers do we care about?
- */
- struct GNUNET_PeerIdentity id;
-
- /**
- * #GNUNET_YES if @e id should be ignored because we want all peers.
- */
- int all;
-};
-
-
-/**
- * Output information of neighbours to the given client.
- *
- * @param cls the `struct PeerIterationContext *`
- * @param peer identity of the neighbour
- * @param address the address
- * @param state current state this peer is in
- * @param state_timeout timeout for the current state of the peer
- * @param bandwidth_in inbound quota in NBO
- * @param bandwidth_out outbound quota in NBO
- */
-static void
-send_peer_information (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- enum GNUNET_TRANSPORT_PeerState state,
- struct GNUNET_TIME_Absolute state_timeout,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
-{
- struct IterationContext *pc = cls;
- struct PeerIterateResponseMessage *msg;
-
- if ( (GNUNET_YES != pc->all) &&
- (0 != memcmp (peer, &pc->id, sizeof (pc->id))) )
- return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending information about `%s' using address `%s' in state `%s'\n",
- GNUNET_i2s(peer),
- (NULL != address) ? GST_plugins_a2s (address) : "<none>",
- GNUNET_TRANSPORT_ps2s (state));
- msg = compose_address_iterate_response_message (peer, address);
- msg->state = htonl (state);
- msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout);
- GNUNET_SERVER_transmit_context_append_message (pc->tc, &msg->header);
- GNUNET_free (msg);
-}
-
-
-/**
- * Client asked to obtain information about a specific or all peers
- * Process the request.
- *
- * @param cls unused
- * @param client the client
- * @param message the peer address information request
- */
-static void
-clients_handle_monitor_peers (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- struct GNUNET_SERVER_TransmitContext *tc;
- const struct PeerMonitorMessage *msg;
- struct IterationContext pc;
-
- msg = (const struct PeerMonitorMessage *) message;
- if ( (GNUNET_YES != ntohl (msg->one_shot)) &&
- (NULL != lookup_monitoring_client (peer_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_neighbours_iterate (&send_peer_information,
- &pc);
-
- if (GNUNET_YES != ntohl (msg->one_shot))
- {
- setup_peer_monitoring_client (client,
- &msg->peer);
- }
- else
- {
- GNUNET_SERVER_transmit_context_append_data (tc,
- NULL,
- 0,
- GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END);
- }
- 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).
- *
- * @param cls closure
- * @param session session handle this information is about,
- * NULL to indicate that we are "in sync" (initial
- * iteration complete)
- * @param info information about the state of the session,
- * NULL if @a session is also NULL and we are
- * merely signalling that the initial iteration is over
- */
-static void
-plugin_session_info_cb (void *cls,
- struct GNUNET_ATS_Session *session,
- const struct GNUNET_TRANSPORT_SessionInfo *info)
-{
- struct TransportPluginMonitorMessage *msg;
- struct GNUNET_MessageHeader sync;
- size_t size;
- size_t slen;
- uint16_t alen;
- char *name;
- char *addr;
-
- if (0 == GNUNET_SERVER_notification_context_get_size (plugin_nc))
- {
- GST_plugins_monitor_subscribe (NULL,
- NULL);
- return;
- }
- if ( (NULL == info) &&
- (NULL == session) )
- {
- /* end of initial iteration */
- if (NULL != sync_client)
- {
- sync.size = htons (sizeof (struct GNUNET_MessageHeader));
- sync.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC);
- GNUNET_SERVER_notification_context_unicast (plugin_nc,
- sync_client,
- &sync,
- GNUNET_NO);
- sync_client = NULL;
- }
- return;
- }
- GNUNET_assert (NULL != info);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Plugin event for peer %s on transport %s\n",
- GNUNET_i2s (&info->address->peer),
- info->address->transport_name);
- slen = strlen (info->address->transport_name) + 1;
- alen = info->address->address_length;
- size = sizeof (struct TransportPluginMonitorMessage) + slen + alen;
- if (size > UINT16_MAX)
- {
- GNUNET_break (0);
- return;
- }
- msg = GNUNET_malloc (size);
- msg->header.size = htons (size);
- msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT);
- msg->session_state = htons ((uint16_t) info->state);
- msg->is_inbound = htons ((int16_t) info->is_inbound);
- msg->msgs_pending = htonl (info->num_msg_pending);
- msg->bytes_pending = htonl (info->num_bytes_pending);
- msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout);
- msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay);
- msg->peer = info->address->peer;
- msg->session_id = (uint64_t) (intptr_t) session;
- msg->plugin_name_len = htons (slen);
- msg->plugin_address_len = htons (alen);
- name = (char *) &msg[1];
- GNUNET_memcpy (name,
- info->address->transport_name,
- slen);
- addr = &name[slen];
- GNUNET_memcpy (addr,
- info->address->address,
- alen);
- if (NULL != sync_client)
- GNUNET_SERVER_notification_context_unicast (plugin_nc,
- sync_client,
- &msg->header,
- GNUNET_NO);
- else
- GNUNET_SERVER_notification_context_broadcast (plugin_nc,
- &msg->header,
- GNUNET_NO);
- GNUNET_free (msg);
-}
-
-
-/**
- * Client asked to obtain information about all plugin connections.
- *
- * @param cls unused
- * @param client the client
- * @param message the peer address information request
- */
-static void
-clients_handle_monitor_plugins (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- GNUNET_SERVER_client_mark_monitor (client);
- GNUNET_SERVER_disable_receive_done_warning (client);
- GNUNET_SERVER_notification_context_add (plugin_nc,
- client);
- GNUNET_assert (NULL == sync_client);
- sync_client = client;
- GST_plugins_monitor_subscribe (&plugin_session_info_cb,
- NULL);
-}
-
-
-/**
- * Start handling requests from clients.
- *
- * @param server server used to accept clients from.
- */
-void
-GST_clients_start (struct GNUNET_SERVER_Handle *server)
-{
- static const struct GNUNET_SERVER_MessageHandler handlers[] = {
- {&clients_handle_start, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)},
- {&clients_handle_hello, NULL,
- GNUNET_MESSAGE_TYPE_HELLO, 0},
- {&clients_handle_send, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
- {&clients_handle_address_to_string, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
- {&clients_handle_monitor_peers, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
- sizeof (struct PeerMonitorMessage)},
- {&GST_blacklist_handle_init, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
- sizeof (struct GNUNET_MessageHeader)},
- {&GST_blacklist_handle_reply, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
- sizeof (struct BlacklistMessage)},
- {&GST_manipulation_set_metric, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC,
- sizeof (struct TrafficMetricMessage) },
- {&clients_handle_monitor_plugins, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START,
- sizeof (struct GNUNET_MessageHeader) },
- {NULL, NULL, 0, 0}
- };
- active_stccs = GNUNET_CONTAINER_multipeermap_create (128,
- GNUNET_YES);
- peer_nc = GNUNET_SERVER_notification_context_create (server, 0);
- val_nc = GNUNET_SERVER_notification_context_create (server, 0);
- plugin_nc = GNUNET_SERVER_notification_context_create (server, 0);
- GNUNET_SERVER_add_handlers (server, handlers);
- GNUNET_SERVER_disconnect_notify (server,
- &client_disconnect_notification,
- NULL);
-}
-
-
-/**
- * Stop processing clients.
- */
-void
-GST_clients_stop ()
-{
- struct AddressToStringContext *cur;
-
- while (NULL != (cur = a2s_head))
- {
- GNUNET_SERVER_transmit_context_destroy (cur->tc, GNUNET_NO);
- GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, cur);
- GNUNET_free (cur);
- }
- if (NULL != peer_nc)
- {
- GNUNET_SERVER_notification_context_destroy (peer_nc);
- peer_nc = NULL;
- }
- if (NULL != val_nc)
- {
- GNUNET_SERVER_notification_context_destroy (val_nc);
- val_nc = NULL;
- }
- if (NULL != plugin_nc)
- {
- GNUNET_SERVER_notification_context_destroy (plugin_nc);
- plugin_nc = NULL;
- }
- GNUNET_CONTAINER_multipeermap_destroy (active_stccs);
- active_stccs = NULL;
-}
-
-
-/**
- * Broadcast the given message to all of our clients.
- *
- * @param msg message to broadcast
- * @param may_drop #GNUNET_YES if the message can be dropped / is payload
- */
-void
-GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
- int may_drop)
-{
- struct TransportClient *tc;
- int done;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to broadcast message of type %u with %u bytes\n",
- (unsigned int) ntohs (msg->type),
- (unsigned int) ntohs (msg->size));
- done = GNUNET_NO;
- for (tc = clients_head; NULL != tc; tc = tc->next)
- {
- if ( (GNUNET_YES == may_drop) &&
- (GNUNET_YES != tc->send_payload) )
- continue; /* skip, this client does not care about payload */
- unicast (tc, msg, may_drop);
- done = GNUNET_YES;
- }
- if (GNUNET_NO == done)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Message of type %u not delivered, is CORE service up?\n",
- ntohs (msg->type));
-}
-
-
-/**
- * Send the given message to a particular client
- *
- * @param client target of the message
- * @param msg message to transmit
- * @param may_drop #GNUNET_YES if the message can be dropped
- */
-void
-GST_clients_unicast (struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *msg,
- int may_drop)
-{
- struct TransportClient *tc;
-
- tc = lookup_client (client);
- if (NULL == tc)
- return; /* client got disconnected in the meantime, drop message */
- unicast (tc, msg, may_drop);
-}
-
-
-/**
- * Broadcast the new active address to all clients monitoring the peer.
- *
- * @param peer peer this update is about (never NULL)
- * @param address address, NULL on disconnect
- * @param state the current state of the peer
- * @param state_timeout the time out for the state
- */
-void
-GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- enum GNUNET_TRANSPORT_PeerState state,
- struct GNUNET_TIME_Absolute state_timeout)
-{
- struct PeerIterateResponseMessage *msg;
- struct MonitoringClient *mc;
-
- msg = compose_address_iterate_response_message (peer, address);
- msg->state = htonl (state);
- msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
- for (mc = peer_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 (peer_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.
- *
- * @param cls NULL
- * @param peer peer that got disconnected
- * @param value a `struct SendTransmitContinuationContext` to mark
- * @return #GNUNET_OK (continue to iterate)
- */
-static int
-mark_peer_down (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- void *value)
-{
- struct SendTransmitContinuationContext *stcc = value;
-
- stcc->down = GNUNET_YES;
- return GNUNET_OK;
-}
-
-
-/**
- * Notify all clients about a disconnect, and cancel
- * pending SEND_OK messages for this peer.
- *
- * @param peer peer that disconnected
- */
-void
-GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer)
-{
- struct DisconnectInfoMessage disconnect_msg;
-
- GNUNET_CONTAINER_multipeermap_get_multiple (active_stccs,
- peer,
- &mark_peer_down,
- NULL);
- disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
- disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
- disconnect_msg.reserved = htonl (0);
- disconnect_msg.peer = *peer;
- GST_clients_broadcast (&disconnect_msg.header,
- GNUNET_NO);
-
-}
-
-
-/* end of file gnunet-service-transport_clients.c */
diff --git a/src/transport/gnunet-service-transport_clients.h b/src/transport/gnunet-service-transport_clients.h
deleted file mode 100644
index d85e1e340..000000000
--- a/src/transport/gnunet-service-transport_clients.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010,2011 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/gnunet-service-transport_clients.h
- * @brief client management API
- * @author Christian Grothoff
- */
-#ifndef GNUNET_SERVICE_TRANSPORT_CLIENTS_H
-#define GNUNET_SERVICE_TRANSPORT_CLIENTS_H
-
-#include "gnunet_transport_service.h"
-#include "gnunet_statistics_service.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_hello_lib.h"
-
-
-/**
- * Start handling requests from clients.
- *
- * @param server server used to accept clients from.
- */
-void
-GST_clients_start (struct GNUNET_SERVER_Handle *server);
-
-
-/**
- * Stop processing clients.
- */
-void
-GST_clients_stop (void);
-
-
-/**
- * Broadcast the given message to all of our clients.
- *
- * @param msg message to broadcast
- * @param may_drop #GNUNET_YES if the message can be dropped / is payload
- */
-void
-GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
- int may_drop);
-
-
-/**
- * Send the given message to a particular client
- *
- * @param client target of the message
- * @param msg message to transmit
- * @param may_drop #GNUNET_YES if the message can be dropped
- */
-void
-GST_clients_unicast (struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *msg,
- int may_drop);
-
-
-/**
- * Broadcast the new active address to all clients monitoring the peer.
- *
- * @param peer peer this update is about (never NULL)
- * @param address address, NULL on disconnect
- * @param state the current state of the peer
- * @param state_timeout the time out for the state
- */
-void
-GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- enum GNUNET_TRANSPORT_PeerState state,
- struct GNUNET_TIME_Absolute state_timeout);
-
-
-/**
- * Notify all clients about a disconnect, and cancel
- * pending SEND_OK messages for this peer.
- *
- * @param peer peer that disconnected
- */
-void
-GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer);
-
-
-#endif
-/* end of file gnunet-service-transport_clients.h */
diff --git a/src/transport/gnunet-service-transport_manipulation.c b/src/transport/gnunet-service-transport_manipulation.c
index 1af023d4d..f198d6e49 100644
--- a/src/transport/gnunet-service-transport_manipulation.c
+++ b/src/transport/gnunet-service-transport_manipulation.c
@@ -25,8 +25,6 @@
* @author Matthias Wachs
*/
#include "platform.h"
-#include "gnunet-service-transport_blacklist.h"
-#include "gnunet-service-transport_clients.h"
#include "gnunet-service-transport_hello.h"
#include "gnunet-service-transport_neighbours.h"
#include "gnunet-service-transport_plugins.h"
@@ -170,20 +168,14 @@ static struct GNUNET_SCHEDULER_Task *generic_send_delay_task;
/**
* Set traffic metric to manipulate
*
- * @param cls closure
- * @param client client sending message
* @param message containing information
*/
void
-GST_manipulation_set_metric (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+GST_manipulation_set_metric (const struct TrafficMetricMessage *tm)
{
- const struct TrafficMetricMessage *tm;
static struct GNUNET_PeerIdentity zero;
struct TM_Peer *tmp;
- tm = (const struct TrafficMetricMessage *) message;
if (0 == memcmp (&tm->peer,
&zero,
sizeof(struct GNUNET_PeerIdentity)))
@@ -192,13 +184,11 @@ GST_manipulation_set_metric (void *cls,
"Received traffic metrics for all peers\n");
delay_in = GNUNET_TIME_relative_ntoh (tm->delay_in);
delay_out = GNUNET_TIME_relative_ntoh (tm->delay_out);
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received traffic metrics for peer `%s'\n",
- GNUNET_i2s(&tm->peer));
+ GNUNET_i2s (&tm->peer));
if (NULL ==
(tmp = GNUNET_CONTAINER_multipeermap_get (peers,
&tm->peer)))
@@ -214,8 +204,6 @@ GST_manipulation_set_metric (void *cls,
&tm->properties);
tmp->delay_in = GNUNET_TIME_relative_ntoh (tm->delay_in);
tmp->delay_out = GNUNET_TIME_relative_ntoh (tm->delay_out);
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
}
@@ -494,7 +482,9 @@ GST_manipulation_peer_disconnect (const struct GNUNET_PeerIdentity *peer)
while (NULL != (dqe = next))
{
next = dqe->next;
- if (0 == memcmp(peer, &dqe->id, sizeof(dqe->id)))
+ if (0 == memcmp (peer,
+ &dqe->id,
+ sizeof (dqe->id)))
{
GNUNET_CONTAINER_DLL_remove (generic_dqe_head,
generic_dqe_tail,
diff --git a/src/transport/gnunet-service-transport_manipulation.h b/src/transport/gnunet-service-transport_manipulation.h
index 6c7cede41..312dd1168 100644
--- a/src/transport/gnunet-service-transport_manipulation.h
+++ b/src/transport/gnunet-service-transport_manipulation.h
@@ -28,8 +28,6 @@
#define GNUNET_SERVICE_TRANSPORT_MANIPULATION_H
#include "platform.h"
-#include "gnunet-service-transport_blacklist.h"
-#include "gnunet-service-transport_clients.h"
#include "gnunet-service-transport_hello.h"
#include "gnunet-service-transport_neighbours.h"
#include "gnunet-service-transport_plugins.h"
@@ -41,14 +39,10 @@
/**
* Set traffic metric to manipulate
*
- * @param cls closure
- * @param client client sending message
* @param message containing information
*/
void
-GST_manipulation_set_metric (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+GST_manipulation_set_metric (const struct TrafficMetricMessage *tm);
/**
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 2614c8551..d82112e03 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -26,8 +26,6 @@
#include "platform.h"
#include "gnunet_ats_service.h"
#include "gnunet-service-transport_ats.h"
-#include "gnunet-service-transport_blacklist.h"
-#include "gnunet-service-transport_clients.h"
#include "gnunet-service-transport_neighbours.h"
#include "gnunet-service-transport_manipulation.h"
#include "gnunet-service-transport_plugins.h"
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index 494f88f11..505626b59 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -25,8 +25,6 @@
*/
#include "platform.h"
#include "gnunet-service-transport_ats.h"
-#include "gnunet-service-transport_blacklist.h"
-#include "gnunet-service-transport_clients.h"
#include "gnunet-service-transport_hello.h"
#include "gnunet-service-transport_neighbours.h"
#include "gnunet-service-transport_plugins.h"
diff --git a/src/transport/test_transport_api_manipulation_recv_tcp.c b/src/transport/test_transport_api_manipulation_recv_tcp.c
index 3014715b1..69ccf5763 100644
--- a/src/transport/test_transport_api_manipulation_recv_tcp.c
+++ b/src/transport/test_transport_api_manipulation_recv_tcp.c
@@ -60,6 +60,16 @@ do_free (void *cls)
static void
+delayed_transmit (void *cls)
+{
+ struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
+
+ start_delayed = GNUNET_TIME_absolute_get ();
+ GNUNET_TRANSPORT_TESTING_large_send (sc);
+}
+
+
+static void
sendtask (void *cls)
{
struct GNUNET_TRANSPORT_TESTING_SendClosure *sc;
@@ -84,7 +94,11 @@ sendtask (void *cls)
&prop,
delay,
GNUNET_TIME_UNIT_ZERO);
- start_delayed = GNUNET_TIME_absolute_get();
+ /* wait 1s to allow manipulation to go into effect */
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &delayed_transmit,
+ sc);
+ return;
}
GNUNET_TRANSPORT_TESTING_large_send (sc);
}
diff --git a/src/transport/test_transport_api_manipulation_send_tcp.c b/src/transport/test_transport_api_manipulation_send_tcp.c
index fbb7ccbdb..602d4d277 100644
--- a/src/transport/test_transport_api_manipulation_send_tcp.c
+++ b/src/transport/test_transport_api_manipulation_send_tcp.c
@@ -59,6 +59,16 @@ do_free (void *cls)
static void
+delayed_transmit (void *cls)
+{
+ struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
+
+ start_delayed = GNUNET_TIME_absolute_get ();
+ GNUNET_TRANSPORT_TESTING_large_send (sc);
+}
+
+
+static void
sendtask (void *cls)
{
struct GNUNET_TRANSPORT_TESTING_SendClosure *sc;
@@ -76,14 +86,20 @@ sendtask (void *cls)
}
if (1 == messages_recv)
{
- memset (&prop, 0, sizeof (prop));
+ memset (&prop,
+ 0,
+ sizeof (prop));
delay = GNUNET_TIME_UNIT_SECONDS;
GNUNET_TRANSPORT_manipulation_set (ccc->p[0]->tmh,
&ccc->p[1]->id,
&prop,
GNUNET_TIME_UNIT_ZERO,
delay);
- start_delayed = GNUNET_TIME_absolute_get();
+ /* wait 1s to allow manipulation to go into effect */
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &delayed_transmit,
+ sc);
+ return;
}
GNUNET_TRANSPORT_TESTING_large_send (sc);
}
@@ -120,7 +136,7 @@ notify_receive (void *cls,
if (0 == messages_recv)
{
/* Received non-delayed message */
- dur_normal = GNUNET_TIME_absolute_get_duration(start_normal);
+ dur_normal = GNUNET_TIME_absolute_get_duration (start_normal);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received non-delayed message %u after %s\n",
messages_recv,