diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-01-15 09:38:53 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-01-15 09:38:53 +0000 |
commit | 697aa41b1e22503e2eb2d8802bdaf627b3931997 (patch) | |
tree | 94db401e3973e955cf72b373efe325d344349161 | |
parent | 38ab83f306e3e627af5140aaf8875bf2e1cc6241 (diff) |
simplifying transport plugin API
-rw-r--r-- | src/arm/arm.h | 2 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist.c | 2 | ||||
-rw-r--r-- | src/topology/gnunet-daemon-topology.c | 4 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport.c | 37 | ||||
-rw-r--r-- | src/transport/plugin_transport.h | 21 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 70 | ||||
-rw-r--r-- | src/transport/plugin_transport_template.c | 17 |
7 files changed, 38 insertions, 115 deletions
diff --git a/src/arm/arm.h b/src/arm/arm.h index 562113068c..2f107351cf 100644 --- a/src/arm/arm.h +++ b/src/arm/arm.h @@ -31,6 +31,6 @@ * This option will turn on the DEBUG loglevel for * all processes controlled by this ARM! */ -#define DEBUG_ARM GNUNET_NO +#define DEBUG_ARM GNUNET_YES #endif diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index a98aa52fe7..0d5ab561de 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c @@ -35,7 +35,7 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 150) static int ok; diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index ad306e03c9..40582029d8 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c @@ -33,7 +33,7 @@ #include "gnunet_util_lib.h" -#define DEBUG_TOPOLOGY GNUNET_YES +#define DEBUG_TOPOLOGY GNUNET_NO /** * For how long do we blacklist a peer after a failed @@ -388,7 +388,7 @@ static void connect_notify (void *cls, #if DEBUG_TOPOLOGY GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Core told us that we connected to `%s'\n", + "Core told us that we are connecting to `%s'\n", GNUNET_i2s (peer)); #endif connection_count++; diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 67ad5bfc27..292f380391 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -251,12 +251,6 @@ struct ReadyList struct NeighbourList *neighbour; /** - * Opaque handle (specific to the plugin) for the - * connection to our target; can be NULL. - */ - void *plugin_handle; - - /** * What was the last latency observed for this plugin * and peer? Invalid if connected is GNUNET_NO. */ @@ -887,7 +881,6 @@ transmit_send_continuation (void *cls, "Transmission to peer `%s' failed, marking connection as down.\n", GNUNET_i2s(target)); rl->connected = GNUNET_NO; - rl->plugin_handle = NULL; } if (!mq->internal_msg) rl->transmit_ready = GNUNET_YES; @@ -986,15 +979,13 @@ try_transmission_to_peer (struct NeighbourList *neighbour) ntohs (mq->message->type), GNUNET_i2s (&neighbour->id), rl->plugin->short_name); #endif - rl->plugin_handle - = rl->plugin->api->send (rl->plugin->api->cls, - rl->plugin_handle, - rl, - &neighbour->id, - mq->priority, - mq->message, - GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - &transmit_send_continuation, mq); + rl->plugin->api->send (rl->plugin->api->cls, + rl, + &neighbour->id, + mq->priority, + mq->message, + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + &transmit_send_continuation, mq); } @@ -1939,7 +1930,6 @@ disconnect_neighbour (struct NeighbourList *n, GNUNET_assert (rpos->neighbour == n); if (GNUNET_YES == rpos->connected) rpos->plugin->api->cancel (rpos->plugin->api->cls, - rpos->plugin_handle, rpos, &n->id); GNUNET_free (rpos); @@ -2054,9 +2044,6 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer) * and generally forward to our receive callback. * * @param cls the "struct TransportPlugin *" we gave to the plugin - * @param plugin_context value to pass to this plugin - * to respond to the given peer (use is optional, - * but may speed up processing) * @param service_context value passed to the transport-service * to identify the neighbour; will be NULL on the first * call for a given peer @@ -2070,7 +2057,6 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer) */ static struct ReadyList * plugin_env_receive (void *cls, - void *plugin_context, struct ReadyList *service_context, struct GNUNET_TIME_Relative latency, const struct GNUNET_PeerIdentity *peer, @@ -2114,12 +2100,8 @@ plugin_env_receive (void *cls, GNUNET_i2s(&n->id)); #endif /* TODO: call stats */ - if ((service_context != NULL) && - (service_context->plugin_handle == plugin_context)) - { - service_context->connected = GNUNET_NO; - service_context->plugin_handle = NULL; - } + if (service_context != NULL) + service_context->connected = GNUNET_NO; disconnect_neighbour (n, GNUNET_YES); return NULL; } @@ -2138,7 +2120,6 @@ plugin_env_receive (void *cls, } service_context->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); - service_context->plugin_handle = plugin_context; service_context->latency = latency; } /* update traffic received amount ... */ diff --git a/src/transport/plugin_transport.h b/src/transport/plugin_transport.h index 1c545480d0..a309f0edf8 100644 --- a/src/transport/plugin_transport.h +++ b/src/transport/plugin_transport.h @@ -58,9 +58,6 @@ struct ReadyList; * message to signal that the other peer disconnected. * * @param cls closure - * @param plugin_context value to pass to this plugin - * to respond to the given peer (use is optional, - * but may speed up processing) * @param service_context value passed to the transport-service * to identify the neighbour; will be NULL on the first * call for a given peer @@ -79,7 +76,6 @@ struct ReadyList; */ typedef struct ReadyList * (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, - void *plugin_context, struct ReadyList * service_context, struct GNUNET_TIME_Relative @@ -299,9 +295,6 @@ typedef void * a fresh connection to another peer. * * @param cls closure - * @param plugin_context value we were asked to pass to this plugin - * to respond to the given peer (use is optional, - * but may speed up processing), can be NULL * @param service_context value passed to the transport-service * to identify the neighbour; NULL is used to indicate * an urgent message. If the urgent message can not be @@ -316,12 +309,9 @@ typedef void * for the next transmission call; or if the * peer disconnected...); can be NULL * @param cont_cls closure for cont - * @return plugin_context that should be used next time for - * sending messages to the specified peer */ -typedef void * +typedef void (*GNUNET_TRANSPORT_TransmitFunction) (void *cls, - void *plugin_context, struct ReadyList * service_context, const struct GNUNET_PeerIdentity * target, @@ -346,14 +336,6 @@ typedef void * * closed after a getting this call. * * @param cls closure - * @param plugin_context value we were asked to pass to this plugin - * to respond to the given peer (use is optional, - * but may speed up processing), can be NULL (if - * NULL was returned from the transmit function); note - * that use of NULL is dangerous since then this call may - * cancel any session with the target peer (including - * HELLO validation sessions), which is likely not what - * is intended. * @param service_context must correspond to the service context * of the corresponding Transmit call; the plugin should * not cancel a send call made with a different service @@ -363,7 +345,6 @@ typedef void * */ typedef void (*GNUNET_TRANSPORT_CancelFunction) (void *cls, - void *plugin_context, struct ReadyList * service_context, const struct GNUNET_PeerIdentity * target); diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index af35d5a74b..89fff4be0a 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -386,6 +386,11 @@ struct Plugin struct GNUNET_SERVER_MessageHandler *handlers; /** + * Handle for request of hostname resolution, non-NULL if pending. + */ + struct GNUNET_RESOLVER_RequestHandle *hostname_dns; + + /** * ID of task used to update our addresses when one expires. */ GNUNET_SCHEDULER_TaskIdentifier address_update_task; @@ -404,13 +409,6 @@ struct Plugin }; - -/** - * Handle for request of hostname resolution, non-NULL if pending. - */ -static struct GNUNET_RESOLVER_RequestHandle *hostname_dns; - - /** * Find the session handle for the given peer. */ @@ -837,7 +835,6 @@ disconnect_session (struct Session *session) know about this one, so we need to notify transport service about disconnect */ session->plugin->env->receive (session->plugin->env->cls, - session, session->service_context, GNUNET_TIME_UNIT_ZERO, &session->target, NULL); @@ -1058,9 +1055,6 @@ session_try_connect (void *cls, * a message using the plugin. * * @param cls closure - * @param plugin_context value we were asked to pass to this plugin - * to respond to the given peer (use is optional, - * but may speed up processing), can be NULL * @param service_context value passed to the transport-service * to identify the neighbour * @param target who should receive this message @@ -1072,12 +1066,9 @@ session_try_connect (void *cls, * for the next transmission call; or if the * peer disconnected...) * @param cont_cls closure for cont - * @return plugin_context that should be used next time for - * sending messages to the specified peer */ -static void * +static void tcp_plugin_send (void *cls, - void *plugin_context, struct ReadyList *service_context, const struct GNUNET_PeerIdentity *target, unsigned int priority, @@ -1086,12 +1077,11 @@ tcp_plugin_send (void *cls, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) { struct Plugin *plugin = cls; - struct Session *session = plugin_context; + struct Session *session; struct PendingMessage *pm; struct PendingMessage *pme; - if (session == NULL) - session = find_session_by_target (plugin, target); + session = find_session_by_target (plugin, target); pm = GNUNET_malloc (sizeof (struct PendingMessage) + ntohs (msg->size)); pm->msg = (struct GNUNET_MessageHeader *) &pm[1]; memcpy (pm->msg, msg, ntohs (msg->size)); @@ -1120,7 +1110,7 @@ tcp_plugin_send (void *cls, plugin->env->sched, target, 0, timeout, &session_try_connect, session); - return session; + return; } GNUNET_assert (session != NULL); GNUNET_assert (session->client != NULL); @@ -1142,7 +1132,6 @@ tcp_plugin_send (void *cls, "tcp", "Asked to transmit, added message to list.\n"); #endif process_pending_messages (session); - return session; } @@ -1160,14 +1149,6 @@ tcp_plugin_send (void *cls, * closed after a getting this call. * * @param cls closure - * @param plugin_context value we were asked to pass to this plugin - * to respond to the given peer (use is optional, - * but may speed up processing), can be NULL (if - * NULL was returned from the transmit function); note - * that use of NULL is dangerous since then this call may - * cancel any session with the target peer (including - * HELLO validation sessions), which is likely not what - * is intended. * @param service_context must correspond to the service context * of the corresponding Transmit call; the plugin should * not cancel a send call made with a different service @@ -1177,24 +1158,14 @@ tcp_plugin_send (void *cls, */ static void tcp_plugin_cancel (void *cls, - void *plugin_context, struct ReadyList *service_context, const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; - struct Session *session = plugin_context; + struct Session *session; struct PendingMessage *pm; - if (session == NULL) - { -#if DEBUG_TCP - GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, - "tcp", - "Asked to cancel with `%4s' without specification of specifics; will try to find an applicable session\n", - GNUNET_i2s(target)); -#endif - session = find_session_by_target (plugin, target); - } + session = find_session_by_target (plugin, target); if (session == NULL) { GNUNET_break (0); @@ -1886,7 +1857,6 @@ handle_tcp_data (void *cls, #endif session->service_context = plugin->env->receive (plugin->env->cls, - session, session->service_context, latency, &session->target, msg); /* update bandwidth used */ @@ -2014,7 +1984,7 @@ process_hostname_ips (void *cls, if (addr == NULL) { - hostname_dns = NULL; + plugin->hostname_dns = NULL; return; } process_interfaces (plugin, @@ -2100,11 +2070,11 @@ libgnunet_plugin_transport_tcp_init (void *cls) GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); - hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched, - env->cfg, - AF_UNSPEC, - HOSTNAME_RESOLVE_TIMEOUT, - &process_hostname_ips, plugin); + plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched, + env->cfg, + AF_UNSPEC, + HOSTNAME_RESOLVE_TIMEOUT, + &process_hostname_ips, plugin); return api; } @@ -2121,10 +2091,10 @@ libgnunet_plugin_transport_tcp_done (void *cls) while (NULL != (session = plugin->sessions)) disconnect_session (session); - if (NULL != hostname_dns) + if (NULL != plugin->hostname_dns) { - GNUNET_RESOLVER_request_cancel (hostname_dns); - hostname_dns = NULL; + GNUNET_RESOLVER_request_cancel (plugin->hostname_dns); + plugin->hostname_dns = NULL; } GNUNET_SERVICE_stop (plugin->service); GNUNET_free (plugin->handlers); diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c index 95fd2de5f7..1d949f3450 100644 --- a/src/transport/plugin_transport_template.c +++ b/src/transport/plugin_transport_template.c @@ -163,9 +163,6 @@ template_plugin_validate (void *cls, * a message using the plugin. * * @param cls closure - * @param plugin_context value we were asked to pass to this plugin - * to respond to the given peer (use is optional, - * but may speed up processing), can be NULL * @param service_context value passed to the transport-service * to identify the neighbour * @param target who should receive this message @@ -177,12 +174,9 @@ template_plugin_validate (void *cls, * for the next transmission call; or if the * peer disconnected...) * @param cont_cls closure for cont - * @return plugin_context that should be used next time for - * sending messages to the specified peer */ -static void * +static void template_plugin_send (void *cls, - void *plugin_context, struct ReadyList *service_context, const struct GNUNET_PeerIdentity *target, unsigned int priority, @@ -192,18 +186,16 @@ template_plugin_send (void *cls, void *cont_cls) { // struct Plugin *plugin = cls; - return NULL; } /** + * Function that can be used to force the plugin to disconnect + * from the given peer and cancel all previous transmissions + * (and their continuationc). * * @param cls closure - * @param plugin_context value we were asked to pass to this plugin - * to respond to the given peer (use is optional, - * but may speed up processing), can be NULL (if - * NULL was returned from the transmit function) * @param service_context must correspond to the service context * of the corresponding Transmit call; the plugin should * not cancel a send call made with a different service @@ -213,7 +205,6 @@ template_plugin_send (void *cls, */ static void template_plugin_cancel (void *cls, - void *plugin_context, struct ReadyList *service_context, const struct GNUNET_PeerIdentity *target) { |