From 95659c78f10bb8a925bd2ba2e5287fa36562633b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 12 Dec 2013 11:51:03 +0000 Subject: -extend transport plugin API with capability to just disconnect a single session (not yet used) --- src/dv/plugin_transport_dv.c | 42 ++- src/include/gnunet_transport_plugin.h | 209 ++++++----- src/namestore/gnunet-service-namestore.c | 14 +- .../gnunet-service-transport_neighbours.c | 12 +- src/transport/gnunet-service-transport_plugins.c | 12 +- src/transport/plugin_transport_http_client.c | 58 ++-- src/transport/plugin_transport_http_server.c | 386 +++++++++++---------- src/transport/plugin_transport_smtp.c | 2 +- src/transport/plugin_transport_tcp.c | 69 ++-- src/transport/plugin_transport_template.c | 83 +++-- src/transport/plugin_transport_udp.c | 202 ++++++----- src/transport/plugin_transport_unix.c | 76 ++-- src/transport/plugin_transport_wlan.c | 38 +- src/transport/test_plugin_transport.c | 4 +- 14 files changed, 679 insertions(+), 528 deletions(-) (limited to 'src') diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c index 1f9a32fe4..93792e0d9 100644 --- a/src/dv/plugin_transport_dv.c +++ b/src/dv/plugin_transport_dv.c @@ -429,7 +429,7 @@ free_session (struct Session *session) */ static void handle_dv_disconnect (void *cls, - const struct GNUNET_PeerIdentity *peer) + const struct GNUNET_PeerIdentity *peer) { struct Plugin *plugin = cls; struct Session *session; @@ -543,8 +543,8 @@ dv_plugin_send (void *cls, * @param target peer from which to disconnect */ static void -dv_plugin_disconnect (void *cls, - const struct GNUNET_PeerIdentity *target) +dv_plugin_disconnect_peer (void *cls, + const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; struct Session *session; @@ -571,6 +571,39 @@ dv_plugin_disconnect (void *cls, } +/** + * Function that can be used to force the plugin to disconnect + * from the given peer and cancel all previous transmissions + * (and their continuations). + * + * @param cls closure with the `struct Plugin *` + * @param session which session to disconnect + * @return #GNUNET_OK + */ +static int +dv_plugin_disconnect_session (void *cls, + struct Session *session) +{ + struct PendingRequest *pr; + + while (NULL != (pr = session->pr_head)) + { + GNUNET_CONTAINER_DLL_remove (session->pr_head, + session->pr_tail, + pr); + GNUNET_DV_send_cancel (pr->th); + pr->th = NULL; + if (NULL != pr->transmit_cont) + pr->transmit_cont (pr->transmit_cont_cls, + &session->sender, + GNUNET_SYSERR, 0, 0); + GNUNET_free (pr); + } + session->active = GNUNET_NO; + return GNUNET_OK; +} + + /** * Convert the transports address to a nice, human-readable * format. @@ -759,7 +792,8 @@ libgnunet_plugin_transport_dv_init (void *cls) api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = plugin; api->send = &dv_plugin_send; - api->disconnect = &dv_plugin_disconnect; + api->disconnect_peer = &dv_plugin_disconnect_peer; + api->disconnect_session = &dv_plugin_disconnect_session; api->address_pretty_printer = &dv_plugin_address_pretty_printer; api->check_address = &dv_plugin_check_address; api->address_to_string = &dv_plugin_address_to_string; diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h index 7df04edfe..6bf365243 100644 --- a/src/include/gnunet_transport_plugin.h +++ b/src/include/gnunet_transport_plugin.h @@ -62,6 +62,7 @@ struct SessionHeader /* empty, for now */ }; + /** * Function that will be called whenever the plugin internally * cleans up a session pointer and hence the service needs to @@ -75,9 +76,10 @@ struct SessionHeader * @param peer which peer was the session for * @param session which session is being destoyed */ -typedef void (*GNUNET_TRANSPORT_SessionEnd) (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct Session * session); +typedef void +(*GNUNET_TRANSPORT_SessionEnd) (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct Session *session); /** @@ -93,17 +95,18 @@ typedef void (*GNUNET_TRANSPORT_SessionEnd) (void *cls, * @param address_len length of the @a address * @param session session * @param ats ATS information - * @param ats_count number of ATS information contained + * @param ats_count number of entries in @a ats array */ typedef void (*GNUNET_TRANSPORT_SessionStart) (void *cls, - const struct GNUNET_PeerIdentity *peer, - const char *plugin, - const void *address, - uint16_t address_len, - struct Session *session, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count); + const struct GNUNET_PeerIdentity *peer, + const char *plugin, + const void *address, + uint16_t address_len, + struct Session *session, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count); + /** * Function called by the transport for each received message. @@ -123,16 +126,17 @@ typedef void * that we could establish ourselves a connection to that * IP address and get the same system) * @param sender_address_len number of bytes in @a sender_address - * @return how long the plugin should wait until receiving more data - * (plugins that do not support this, can ignore the return value) + * @return how long the plugin should wait until receiving more data; + * returning #GNUNET_TIME_UNIT_FOREVER_REL means that the + * connection should be closed */ -typedef struct - GNUNET_TIME_Relative (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - struct Session *session, - const char *sender_address, - uint16_t sender_address_len); +typedef struct GNUNET_TIME_Relative +(*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_MessageHeader *message, + struct Session *session, + const char *sender_address, + uint16_t sender_address_len); /** @@ -159,7 +163,7 @@ typedef struct GNUNET_ATS_Information * @param address_len length of the @a address * @param session session * @param ats ATS information - * @param ats_count number of ATS information contained in @a ats + * @param ats_count number entries in the @a ats array */ typedef void (*GNUNET_TRANSPORT_UpdateAddressMetrics) (void *cls, @@ -175,18 +179,19 @@ typedef void * is aware that it might be reachable under. * * @param cls closure - * @param add_remove should the address added (YES) or removed (NO) from the + * @param add_remove should the address added (#GNUNET_YES) or removed (#GNUNET_NO) from the * set of valid addresses? * @param addr one of the addresses of the host * the specific address format depends on the transport - * @param addrlen length of the address + * @param addrlen length of the @a addr * @param dest_plugin plugin to use this address with */ -typedef void (*GNUNET_TRANSPORT_AddressNotification) (void *cls, - int add_remove, - const void *addr, - size_t addrlen, - const char *dest_plugin); +typedef void +(*GNUNET_TRANSPORT_AddressNotification) (void *cls, + int add_remove, + const void *addr, + size_t addrlen, + const char *dest_plugin); /** @@ -202,18 +207,20 @@ typedef void (*GNUNET_TRANSPORT_AddressNotification) (void *cls, * @param peer which peer did we read data from * @param amount_recved number of bytes read (can be zero) * @return how long to wait until reading more from this peer - * (to enforce inbound quotas) + * (to enforce inbound quotas); returning #GNUNET_TIME_UNIT_FOREVER_REL + * means that the connection should be closed */ -typedef struct GNUNET_TIME_Relative (*GNUNET_TRANSPORT_TrafficReport) (void *cls, - const struct GNUNET_PeerIdentity* peer, - size_t amount_recved); +typedef struct GNUNET_TIME_Relative +(*GNUNET_TRANSPORT_TrafficReport) (void *cls, + const struct GNUNET_PeerIdentity *peer, + size_t amount_recved); /** * Function that returns a HELLO message. */ typedef const struct GNUNET_MessageHeader * - (*GNUNET_TRANSPORT_GetHelloCallback) (void); +(*GNUNET_TRANSPORT_GetHelloCallback) (void); /** @@ -253,7 +260,6 @@ struct GNUNET_TRANSPORT_PluginEnvironment */ GNUNET_TRANSPORT_PluginReceiveCallback receive; - /** * Function that returns our HELLO. */ @@ -302,7 +308,7 @@ struct GNUNET_TRANSPORT_PluginEnvironment /** - * Function called by the GNUNET_TRANSPORT_TransmitFunction + * Function called by the #GNUNET_TRANSPORT_TransmitFunction * upon "completion". In the case that a peer disconnects, * this function must be called for each pending request * (with a 'failure' indication) AFTER notifying the service @@ -320,11 +326,13 @@ struct GNUNET_TRANSPORT_PluginEnvironment * @param size_on_wire bytes required on wire for transmission, * 0 if result == #GNUNET_SYSERR */ -typedef void (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls, - const struct GNUNET_PeerIdentity *target, - int result, - size_t size_payload, - size_t size_on_wire); +typedef void +(*GNUNET_TRANSPORT_TransmitContinuation) (void *cls, + const struct GNUNET_PeerIdentity *target, + int result, + size_t size_payload, + size_t size_on_wire); + /** * The new send function with just the session and no address @@ -350,19 +358,37 @@ typedef void (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls, * been transmitted (or if the transport is ready * for the next transmission call; or if the * peer disconnected...); can be NULL - * @param cont_cls closure for cont + * @param cont_cls closure for @a cont * @return number of bytes used (on the physical network, with overheads); * -1 on hard errors (i.e. address invalid); 0 is a legal value * and does NOT mean that the message was not transmitted (DV) */ -typedef ssize_t (*GNUNET_TRANSPORT_TransmitFunction) (void *cls, - struct Session *session, - const char *msgbuf, - size_t msgbuf_size, - unsigned int priority, - struct GNUNET_TIME_Relative to, - GNUNET_TRANSPORT_TransmitContinuation cont, - void *cont_cls); +typedef ssize_t +(*GNUNET_TRANSPORT_TransmitFunction) (void *cls, + struct Session *session, + const char *msgbuf, + size_t msgbuf_size, + unsigned int priority, + struct GNUNET_TIME_Relative to, + GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls); + + +/** + * Function that can be called to force a disconnect from the + * specified neighbour for the given session only. . This should + * also cancel all previously scheduled transmissions for this + * session. Obviously the transmission may have been partially + * completed already, which is OK. The plugin is supposed to close + * the connection (if applicable). + * + * @param cls closure with the `struct Plugin` + * @param session session to destroy + * @return #GNUNET_OK on success + */ +typedef int +(*GNUNET_TRANSPORT_DisconnectSessionFunction) (void *cls, + struct Session *session); /** @@ -373,16 +399,13 @@ typedef ssize_t (*GNUNET_TRANSPORT_TransmitFunction) (void *cls, * to close the connection (if applicable) and no longer call the * transmit continuation(s). * - * Finally, plugin MUST NOT call the services's receive function to - * notify the service that the connection to the specified target was - * closed after a getting this call. - * * @param cls closure * @param target peer for which the last transmission is * to be cancelled */ -typedef void (*GNUNET_TRANSPORT_DisconnectFunction) (void *cls, - const struct GNUNET_PeerIdentity *target); +typedef void +(*GNUNET_TRANSPORT_DisconnectPeerFunction) (void *cls, + const struct GNUNET_PeerIdentity *target); /** @@ -393,8 +416,9 @@ typedef void (*GNUNET_TRANSPORT_DisconnectFunction) (void *cls, * @param address one of the names for the host, NULL * on the last call to the callback */ -typedef void (*GNUNET_TRANSPORT_AddressStringCallback) (void *cls, - const char *address); +typedef void +(*GNUNET_TRANSPORT_AddressStringCallback) (void *cls, + const char *address); /** @@ -405,20 +429,21 @@ typedef void (*GNUNET_TRANSPORT_AddressStringCallback) (void *cls, * @param type name of the transport that generated the address * @param addr one of the addresses of the host, NULL for the last address * the specific address format depends on the transport - * @param addrlen length of the address + * @param addrlen length of the @a addr * @param numeric should (IP) addresses be displayed in numeric form? * @param timeout after how long should we give up? * @param asc function to call on each string * @param asc_cls closure for @a asc */ -typedef void (*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls, - const char *type, - const void *addr, - size_t addrlen, - int numeric, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressStringCallback asc, - void *asc_cls); +typedef void +(*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls, + const char *type, + const void *addr, + size_t addrlen, + int numeric, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressStringCallback asc, + void *asc_cls); /** @@ -435,9 +460,11 @@ typedef void (*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls, * @return #GNUNET_OK if this is a plausible address for this peer * and transport, #GNUNET_SYSERR if not */ -typedef int (*GNUNET_TRANSPORT_CheckAddress) (void *cls, - const void *addr, - size_t addrlen); +typedef int +(*GNUNET_TRANSPORT_CheckAddress) (void *cls, + const void *addr, + size_t addrlen); + /** * Create a new session to transmit data to the target @@ -448,8 +475,9 @@ typedef int (*GNUNET_TRANSPORT_CheckAddress) (void *cls, * @param address the hello address * @return the session if the address is valid, NULL otherwise */ -typedef struct Session * (*GNUNET_TRANSPORT_CreateSession) (void *cls, - const struct GNUNET_HELLO_Address *address); +typedef struct Session * +(*GNUNET_TRANSPORT_CreateSession) (void *cls, + const struct GNUNET_HELLO_Address *address); /** @@ -460,30 +488,33 @@ typedef struct Session * (*GNUNET_TRANSPORT_CreateSession) (void *cls, * * @param cls closure * @param addr binary address - * @param addr_len length of the address + * @param addr_len length of the @a addr * @return string representing the same address */ -typedef const char *(*GNUNET_TRANSPORT_AddressToString) (void *cls, - const void *addr, - size_t addrlen); +typedef const char * +(*GNUNET_TRANSPORT_AddressToString) (void *cls, + const void *addr, + size_t addrlen); + /** * Function called to convert a string address to * a binary address. * - * @param cls closure ('struct Plugin*') + * @param cls closure (`struct Plugin*`) * @param addr string address - * @param addrlen length of the address including '\0' termination + * @param addrlen length of the @a addr including \0 termination * @param buf location to store the buffer * If the function returns #GNUNET_SYSERR, its contents are undefined. * @param added length of created address * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ -typedef int (*GNUNET_TRANSPORT_StringToAddress) (void *cls, - const char *addr, - uint16_t addrlen, - void **buf, - size_t *added); +typedef int +(*GNUNET_TRANSPORT_StringToAddress) (void *cls, + const char *addr, + uint16_t addrlen, + void **buf, + size_t *added); /** @@ -493,8 +524,9 @@ typedef int (*GNUNET_TRANSPORT_StringToAddress) (void *cls, * @param session the session * @return the network type */ -typedef enum GNUNET_ATS_Network_Type (*GNUNET_TRANSPORT_GetNetworkType) (void *cls, - struct Session *session); +typedef enum GNUNET_ATS_Network_Type +(*GNUNET_TRANSPORT_GetNetworkType) (void *cls, + struct Session *session); /** @@ -523,7 +555,14 @@ struct GNUNET_TRANSPORT_PluginFunctions * the given peer and cancel all previous transmissions (and their * continuations). */ - GNUNET_TRANSPORT_DisconnectFunction disconnect; + GNUNET_TRANSPORT_DisconnectPeerFunction disconnect_peer; + + /** + * Function that can be used to force the plugin to disconnect from + * the given peer and cancel all previous transmissions (and their + * continuations). + */ + GNUNET_TRANSPORT_DisconnectSessionFunction disconnect_session; /** * Function to pretty-print addresses. NOTE: this function is not diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 7eb7660ce..c2b62419d 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c @@ -454,10 +454,10 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) static void merge_with_nick_records ( const struct GNUNET_GNSRECORD_Data *nick_rd, - unsigned int rdc2, - const struct GNUNET_GNSRECORD_Data *rd2, - unsigned int *rdc_res, - struct GNUNET_GNSRECORD_Data **rd_res) + unsigned int rdc2, + const struct GNUNET_GNSRECORD_Data *rd2, + unsigned int *rdc_res, + struct GNUNET_GNSRECORD_Data **rd_res) { uint64_t latest_expiration; int c; @@ -675,7 +675,7 @@ refresh_block (struct GNUNET_SERVER_Client *client, nick = get_nick_record (zone_key); res_count = rd_count; - res = rd; + res = (struct GNUNET_GNSRECORD_Data *) rd; /* fixme: a bit unclean... */ if (NULL != nick) { nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; @@ -754,8 +754,8 @@ lookup_it (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, rdc_res = 0; rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; merge_with_nick_records ( rlc->nick, - rd_count, rd, - &rdc_res, &rd_res); + rd_count, rd, + &rdc_res, &rd_res); rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res, rd_res); rlc->res_rd_count = rdc_res; diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index a55e6a07d..a3b5639a0 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -817,6 +817,7 @@ set_address (struct NeighbourAddress *na, int is_active) { struct GNUNET_TRANSPORT_PluginFunctions *papi; + if (NULL == (papi = GST_plugins_find (address->transport_name))) { GNUNET_break (0); @@ -918,13 +919,8 @@ free_neighbour (struct NeighbourMapEntry *n, int keep_sessions) free_address (&n->primary_address); free_address (&n->alternative_address); - /* FIXME-PLUGIN-API: This does not seem to guarantee that all - transport sessions eventually get killed due to inactivity; they - MUST have their own timeout logic (but at least TCP doesn't have - one yet). Are we sure that EVERY 'session' of a plugin is - actually cleaned up this way!? Note that if we are switching - between two TCP sessions to the same peer, the existing plugin - API gives us not even the means to selectively kill only one of + /* FIXME: Note that if we are switching between two TCP sessions to + the same peer, we might want to selectively kill only one of them! Killing all sessions like this seems to be very, very wrong. */ @@ -932,7 +928,7 @@ free_neighbour (struct NeighbourMapEntry *n, int keep_sessions) if ((GNUNET_NO == keep_sessions) && (NULL != backup_primary) && (NULL != (papi = GST_plugins_find (backup_primary->transport_name)))) - papi->disconnect (papi->cls, &n->id); + papi->disconnect_peer (papi->cls, &n->id); GNUNET_free_non_null (backup_primary); diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c index 83c062ec3..34f409255 100644 --- a/src/transport/gnunet-service-transport_plugins.c +++ b/src/transport/gnunet-service-transport_plugins.c @@ -219,12 +219,20 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, "send", plug->lib_name); } - if (NULL == plug->api->disconnect) + if (NULL == plug->api->disconnect_peer) { fail = GNUNET_YES; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Missing function `%s' in transport plugin for `%s'\n"), - "disconnect", + "disconnect_peer", + plug->lib_name); + } + if (NULL == plug->api->disconnect_session) + { + fail = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Missing function `%s' in transport plugin for `%s'\n"), + "disconnect_session", plug->lib_name); } if (GNUNET_YES == fail) diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index c3a34a3fd..07a0de2ac 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c @@ -107,6 +107,7 @@ struct HTTP_Message */ struct Session; + /** * A connection handle * @@ -125,7 +126,6 @@ struct ConnectionHandle }; - /** * Session handle for connections. */ @@ -623,12 +623,12 @@ client_delete_session (struct Session *s) * Disconnect a session * * @param s session - * @return GNUNET_OK on success, GNUNET_SYSERR on error + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -client_disconnect (struct Session *s) +http_client_session_disconnect (struct HTTP_Client_Plugin *plugin, + struct Session *s) { - struct HTTP_Client_Plugin *plugin = s->plugin; struct HTTP_Message *msg; struct HTTP_Message *t; int res = GNUNET_OK; @@ -730,7 +730,8 @@ client_disconnect (struct Session *s) * @param target peer from which to disconnect */ static void -http_client_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) +http_client_peer_disconnect (void *cls, + const struct GNUNET_PeerIdentity *target) { struct HTTP_Client_Plugin *plugin = cls; struct Session *next = NULL; @@ -749,12 +750,13 @@ http_client_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *targ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Disconnecting session %p to `%pos'\n", pos, GNUNET_i2s (target)); - GNUNET_assert (GNUNET_OK == client_disconnect (pos)); + GNUNET_assert (GNUNET_OK == http_client_session_disconnect (plugin, + pos)); } } - } + /** * Check if a sessions exists for an specific address * @@ -1221,7 +1223,7 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /* Disconnect other transmission direction and tell transport */ s->get.easyhandle = NULL; s->get.s = NULL; - client_disconnect (s); + http_client_session_disconnect (plugin, s); } } } @@ -1535,8 +1537,8 @@ http_client_plugin_get_session (void *cls, return NULL; } - s = GNUNET_malloc (sizeof (struct Session)); - memcpy (&s->target, &address->peer, sizeof (struct GNUNET_PeerIdentity)); + s = GNUNET_new (struct Session); + s->target = address->peer; s->plugin = plugin; s->addr = GNUNET_malloc (address->address_length); memcpy (s->addr, address->address, address->address_length); @@ -1574,7 +1576,7 @@ http_client_plugin_get_session (void *cls, * Setup http_client plugin * * @param plugin the plugin handle - * @return GNUNET_OK on success, GNUNET_SYSERR on error + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int client_start (struct HTTP_Client_Plugin *plugin) @@ -1598,7 +1600,6 @@ client_start (struct HTTP_Client_Plugin *plugin) static void client_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - GNUNET_assert (NULL != cls); struct Session *s = cls; s->timeout_task = GNUNET_SCHEDULER_NO_TASK; @@ -1609,7 +1610,8 @@ client_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc GNUNET_YES)); /* call session destroy function */ - GNUNET_assert (GNUNET_OK == client_disconnect (s)); + GNUNET_assert (GNUNET_OK == http_client_session_disconnect (s->plugin, + s)); } @@ -1729,13 +1731,13 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) next = plugin->head; while (NULL != (pos = next)) { - next = pos->next; - client_disconnect (pos); + next = pos->next; + http_client_session_disconnect (plugin, pos); } if (GNUNET_SCHEDULER_NO_TASK != plugin->client_perform_task) { - GNUNET_SCHEDULER_cancel (plugin->client_perform_task); - plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_SCHEDULER_cancel (plugin->client_perform_task); + plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; } @@ -1760,7 +1762,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) * Configure plugin * * @param plugin the plugin handle - * @return GNUNET_OK on success, GNUNET_SYSERR on failure + * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int client_configure_plugin (struct HTTP_Client_Plugin *plugin) @@ -1780,13 +1782,16 @@ client_configure_plugin (struct HTTP_Client_Plugin *plugin) return GNUNET_OK; } -const char *http_plugin_address_to_string (void *cls, - const void *addr, - size_t addrlen) + +static const char * +http_plugin_address_to_string (void *cls, + const void *addr, + size_t addrlen) { - return http_common_plugin_address_to_string (cls, PLUGIN_NAME, addr, addrlen); + return http_common_plugin_address_to_string (cls, PLUGIN_NAME, addr, addrlen); } + /** * Entry point for the plugin. */ @@ -1801,7 +1806,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) { /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully initialze the plugin or the API */ - api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = NULL; api->address_to_string = &http_plugin_address_to_string; api->string_to_address = &http_common_plugin_string_to_address; @@ -1809,13 +1814,14 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) return api; } - plugin = GNUNET_malloc (sizeof (struct HTTP_Client_Plugin)); + plugin = GNUNET_new (struct HTTP_Client_Plugin); p = plugin; plugin->env = env; - api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = plugin; api->send = &http_client_plugin_send; - api->disconnect = &http_client_plugin_disconnect; + api->disconnect_session = &http_client_session_disconnect; + api->disconnect_peer = &http_client_peer_disconnect; api->check_address = &http_client_plugin_address_suggested; api->get_session = &http_client_plugin_get_session; api->address_to_string = &http_plugin_address_to_string; diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 6d706efba..72562607d 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -23,7 +23,6 @@ * @brief HTTP/S server transport plugin * @author Matthias Wachs */ - #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_statistics_service.h" @@ -49,7 +48,9 @@ #define _SEND 1 -/* Enable output for debbuging URL's of incoming requests */ +/** + * Enable output for debbuging URL's of incoming requests + */ #define DEBUG_URL_PARSE GNUNET_NO @@ -159,22 +160,34 @@ struct Session struct ServerConnection { - /* _RECV or _SEND */ + /** + * _RECV or _SEND + */ int direction; - /* Should this connection get disconnected? GNUNET_YES/NO */ + /** + * Should this connection get disconnected? GNUNET_YES/NO + */ int disconnect; - /* For PUT connections: Is this the first or last callback with size 0 */ + /** + * For PUT connections: Is this the first or last callback with size 0 + */ int connected; - /* The session this server connection belongs to */ + /** + * The session this server connection belongs to + */ struct Session *session; - /* The MHD connection */ + /** + * The MHD connection + */ struct MHD_Connection *mhd_conn; - /* The MHD daemon */ + /** + * The MHD daemon + */ struct MHD_Daemon *mhd_daemon; }; @@ -192,7 +205,6 @@ struct HTTP_Server_Plugin /** * Linked list head of open sessions. */ - struct Session *head; /** @@ -225,7 +237,6 @@ struct HTTP_Server_Plugin */ int verify_external_hostname; - /** * Maximum number of sockets the plugin can use * Each http inbound /outbound connections are two connections @@ -439,12 +450,6 @@ struct HTTP_Message }; -/** - * The http_server plugin handle - */ -static struct HTTP_Server_Plugin * p; - - /** * Start session timeout for session s * @param s the session @@ -470,11 +475,15 @@ server_stop_session_timeout (struct Session *s); /** - * Disconnect a session s + * Disconnect session @a s + * + * @param cls closure with the `struct HTTP_Server_Plugin` * @param s the session + * @return #GNUNET_OK on success */ static int -server_disconnect (struct Session *s); +http_server_plugin_disconnect_session (void *cls, + struct Session *s); /** @@ -482,7 +491,7 @@ server_disconnect (struct Session *s); * * @param plugin the plugin handle * @param s the session - * @return GNUNET_YES on success, GNUNET_NO on error + * @return #GNUNET_YES on success, #GNUNET_NO on error */ static int server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s); @@ -492,12 +501,13 @@ server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s); * Reschedule the execution of both IPv4 and IPv6 server * @param plugin the plugin * @param server which server to schedule v4 or v6? - * @param now GNUNET_YES to schedule execution immediately, GNUNET_NO to wait + * @param now #GNUNET_YES to schedule execution immediately, #GNUNET_NO to wait * until timeout */ static void -server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, - int now); +server_reschedule (struct HTTP_Server_Plugin *plugin, + struct MHD_Daemon *server, + int now); /** @@ -511,7 +521,7 @@ server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, * @param cls closure * @param session which session must be used * @param msgbuf the message to transmit - * @param msgbuf_size number of bytes in 'msgbuf' + * @param msgbuf_size number of bytes in @a msgbuf * @param priority how important is the message (most plugins will * ignore message priority and just FIFO) * @param to how long to wait at most for the transmission (does not @@ -522,7 +532,7 @@ server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, * been transmitted (or if the transport is ready * for the next transmission call; or if the * peer disconnected...); can be NULL - * @param cont_cls closure for cont + * @param cont_cls closure for @a cont * @return number of bytes used (on the physical network, with overheads); * -1 on hard errors (i.e. address invalid); 0 is a legal value * and does NOT mean that the message was not transmitted (DV) @@ -562,8 +572,8 @@ http_server_plugin_send (void *cls, } else { - if (GNUNET_YES == session->server_send->disconnect) - return GNUNET_SYSERR; + if (GNUNET_YES == session->server_send->disconnect) + return GNUNET_SYSERR; } @@ -592,16 +602,15 @@ http_server_plugin_send (void *cls, if (NULL != session->server_send) { - server_reschedule (session->plugin, - session->server_send->mhd_daemon, - GNUNET_YES); - server_reschedule_session_timeout (session); + server_reschedule (session->plugin, + session->server_send->mhd_daemon, + GNUNET_YES); + server_reschedule_session_timeout (session); } return bytes_sent; } - /** * Function that can be used to force the plugin to disconnect * from the given peer and cancel all previous transmissions @@ -611,16 +620,16 @@ http_server_plugin_send (void *cls, * @param target peer from which to disconnect */ static void -http_server_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) +http_server_plugin_disconnect_peer (void *cls, + const struct GNUNET_PeerIdentity *target) { struct HTTP_Server_Plugin *plugin = cls; - struct Session *next = NULL; - struct Session *pos = NULL; + struct Session *next; + struct Session *pos; GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Transport tells me to disconnect `%s'\n", GNUNET_i2s (target)); - next = plugin->head; while (NULL != (pos = next)) { @@ -630,10 +639,9 @@ http_server_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *targ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Disconnecting session %p to `%s'\n", pos, GNUNET_i2s (target)); - server_disconnect (pos); + http_server_plugin_disconnect_session (plugin, pos); } } - } @@ -645,41 +653,42 @@ http_server_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *targ * * @param cls closure * @param addr pointer to the address - * @param addrlen length of addr - * @return GNUNET_OK if this is a plausible address for this peer + * @param addrlen length of @a addr + * @return #GNUNET_OK if this is a plausible address for this peer * and transport */ static int -http_server_plugin_address_suggested (void *cls, const void *addr, - size_t addrlen) +http_server_plugin_address_suggested (void *cls, + const void *addr, + size_t addrlen) { - struct HttpAddressWrapper *next; - struct HttpAddressWrapper *pos; - const struct HttpAddress *haddr = addr; - - if ((NULL != p->ext_addr) && - GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, - p->ext_addr, p->ext_addr_len))) - { - /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ - if ((ntohl(haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != - (p->options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) - return GNUNET_NO; /* VERIFY option not set as required! */ - return GNUNET_OK; - } - - next = p->addr_head; - while (NULL != (pos = next)) - { - next = pos->next; - if (GNUNET_YES == (http_common_cmp_addresses(addr, - addrlen, - pos->address, - pos->addrlen))) - return GNUNET_OK; - - } - return GNUNET_NO; + struct HTTP_Server_Plugin *plugin = cls; + struct HttpAddressWrapper *next; + struct HttpAddressWrapper *pos; + const struct HttpAddress *haddr = addr; + + if ((NULL != plugin->ext_addr) && + GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, + plugin->ext_addr, + plugin->ext_addr_len))) + { + /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ + if ((ntohl (haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != + (plugin->options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) + return GNUNET_NO; /* VERIFY option not set as required! */ + return GNUNET_OK; + } + next = plugin->addr_head; + while (NULL != (pos = next)) + { + next = pos->next; + if (GNUNET_YES == (http_common_cmp_addresses(addr, + addrlen, + pos->address, + pos->addrlen))) + return GNUNET_OK; + } + return GNUNET_NO; } @@ -705,33 +714,32 @@ http_server_plugin_get_session (void *cls, * Deleting the session * Must not be used afterwards * + * @param cls closure with the `struct HTTP_ServerPlugin` * @param s the session to delete + * @return #GNUNET_OK on success */ -static void -server_delete_session (struct Session *s) +static int +server_delete_session (void *cls, + struct Session *s) { - struct HTTP_Server_Plugin *plugin = s->plugin; - server_stop_session_timeout(s); + struct HTTP_Server_Plugin *plugin = cls; + struct HTTP_Message *msg; + struct HTTP_Message *tmp; + server_stop_session_timeout(s); GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s); - struct HTTP_Message *msg = s->msg_head; - struct HTTP_Message *tmp = NULL; - - while (msg != NULL) + msg = s->msg_head; + while (NULL != msg) { tmp = msg->next; - GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg); - if (msg->transmit_cont != NULL) - { + if (NULL != msg->transmit_cont) msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR, msg->size, msg->pos + msg->overhead); - } GNUNET_free (msg); msg = tmp; } - - if (s->msg_tk != NULL) + if (NULL != s->msg_tk) { GNUNET_SERVER_mst_destroy (s->msg_tk); s->msg_tk = NULL; @@ -739,9 +747,11 @@ server_delete_session (struct Session *s) GNUNET_free (s->addr); GNUNET_free_non_null (s->server_recv); GNUNET_free_non_null (s->server_send); - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + plugin->name, "Session %p destroyed\n", s); GNUNET_free (s); + return GNUNET_OK; } @@ -770,11 +780,11 @@ server_stop_session_timeout (struct Session *s) * @param plugin plugin * @param daemon_handle the MHD daemon handle * @param now schedule immediately - * @return gnunet task identifier + * @return task identifier */ static GNUNET_SCHEDULER_TaskIdentifier server_schedule (struct HTTP_Server_Plugin *plugin, - struct MHD_Daemon *daemon_handle, + struct MHD_Daemon *daemon_handle, int now); @@ -782,12 +792,13 @@ server_schedule (struct HTTP_Server_Plugin *plugin, * Reschedule the execution of both IPv4 and IPv6 server * @param plugin the plugin * @param server which server to schedule v4 or v6? - * @param now GNUNET_YES to schedule execution immediately, GNUNET_NO to wait + * @param now #GNUNET_YES to schedule execution immediately, #GNUNET_NO to wait * until timeout */ static void -server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, - int now) +server_reschedule (struct HTTP_Server_Plugin *plugin, + struct MHD_Daemon *server, + int now) { if ((server == plugin->server_v4) && (plugin->server_v4 != NULL)) { @@ -824,21 +835,24 @@ server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, /** - * Disconnect session s + * Disconnect session @a s * + * @param cls closure with the `struct HTTP_Server_Plugin` * @param s the session - * @return GNUNET_OK on success + * @return #GNUNET_OK on success */ static int -server_disconnect (struct Session *s) +http_server_plugin_disconnect_session (void *cls, + struct Session *s) { - struct ServerConnection * send = NULL; - struct ServerConnection * recv = NULL; + struct HTTP_Server_Plugin *plugin = cls; + struct ServerConnection * send; + struct ServerConnection * recv; - if (GNUNET_NO == server_exist_session (p, s)) + if (GNUNET_NO == server_exist_session (plugin, s)) { - GNUNET_break (0); - return GNUNET_SYSERR; + GNUNET_break (0); + return GNUNET_SYSERR; } send = (struct ServerConnection *) s->server_send; @@ -849,10 +863,9 @@ server_disconnect (struct Session *s) s, s->server_send, GNUNET_i2s (&s->target)); send->disconnect = GNUNET_YES; -#if MHD_VERSION >= 0x00090E00 - MHD_set_connection_option (send->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, - 1); -#endif + MHD_set_connection_option (send->mhd_conn, + MHD_CONNECTION_OPTION_TIMEOUT, + 1); server_reschedule (s->plugin, send->mhd_daemon, GNUNET_YES); } @@ -864,17 +877,15 @@ server_disconnect (struct Session *s) s, s->server_recv, GNUNET_i2s (&s->target)); recv->disconnect = GNUNET_YES; -#if MHD_VERSION >= 0x00090E00 - MHD_set_connection_option (recv->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, - 1); -#endif + MHD_set_connection_option (recv->mhd_conn, + MHD_CONNECTION_OPTION_TIMEOUT, + 1); server_reschedule (s->plugin, recv->mhd_daemon, GNUNET_YES); } return GNUNET_OK; } - /** * Tell MHD that the connection should timeout after @a to seconds. * @@ -887,7 +898,6 @@ server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, struct Session *s, unsigned int to) { -#if MHD_VERSION >= 0x00090E00 /* Setting timeouts for other connections */ if (NULL != s->server_recv) { @@ -909,9 +919,9 @@ server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, to); server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO); } -#endif } + /** * Parse incoming URL for tag and target * @@ -919,9 +929,8 @@ server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, * @param url incoming url * @param target where to store the target * @param tag where to store the tag - * @return GNUNET_OK on success, GNUNET_SYSERR on error + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ - static int server_parse_url (struct HTTP_Server_Plugin *plugin, const char *url, @@ -1136,7 +1145,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, return NULL; } - s = GNUNET_malloc (sizeof (struct Session)); + s = GNUNET_new (struct Session); memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity)); s->plugin = plugin; s->addr = addr; @@ -1155,9 +1164,11 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Creating new session %p for peer `%s' connecting from `%s'\n", s, GNUNET_i2s (&target), - http_common_plugin_address_to_string (NULL, p->protocol, addr, addr_len)); + http_common_plugin_address_to_string (NULL, + plugin->protocol, + addr, addr_len)); } - sc = GNUNET_malloc (sizeof (struct ServerConnection)); + sc = GNUNET_new (struct ServerConnection); if (conn_info->client_addr->sa_family == AF_INET) sc->mhd_daemon = plugin->server_v4; if (conn_info->client_addr->sa_family == AF_INET6) @@ -1218,19 +1229,16 @@ server_lookup_session (struct HTTP_Server_Plugin *plugin, return NULL; } -int -server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s) + +static int +server_exist_session (struct HTTP_Server_Plugin *plugin, + struct Session *s) { struct Session * head; - GNUNET_assert (NULL != plugin); - GNUNET_assert (NULL != s); - for (head = plugin->head; head != NULL; head = head->next) - { if (head == s) return GNUNET_YES; - } return GNUNET_NO; } @@ -1252,8 +1260,7 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) struct HTTP_Message *msg; char *stat_txt; - GNUNET_assert (NULL != p); - if (GNUNET_NO == server_exist_session (p, s)) + if (GNUNET_NO == server_exist_session (s->plugin, s)) return 0; msg = s->msg_head; if (NULL != msg) @@ -1278,12 +1285,14 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, "Sent %u bytes to peer `%s' with session %p \n", bytes_read, GNUNET_i2s (&s->target), s); - GNUNET_asprintf (&stat_txt, "# bytes currently in %s_server buffers", p->protocol); - GNUNET_STATISTICS_update (p->env->stats, + GNUNET_asprintf (&stat_txt, "# bytes currently in %s_server buffers", + s->plugin->protocol); + GNUNET_STATISTICS_update (s->plugin->env->stats, stat_txt, -bytes_read, GNUNET_NO); GNUNET_free (stat_txt); - GNUNET_asprintf (&stat_txt, "# bytes transmitted via %s_server", p->protocol); - GNUNET_STATISTICS_update (p->env->stats, + GNUNET_asprintf (&stat_txt, "# bytes transmitted via %s_server", + s->plugin->protocol); + GNUNET_STATISTICS_update (s->plugin->env->stats, stat_txt, bytes_read, GNUNET_NO); GNUNET_free (stat_txt); } @@ -1297,7 +1306,7 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) * @param cls current session as closure * @param client client * @param message the message to be forwarded to transport service - * @return GNUNET_OK + * @return #GNUNET_OK */ static int server_receive_mst_cb (void *cls, void *client, @@ -1309,8 +1318,7 @@ server_receive_mst_cb (void *cls, void *client, struct GNUNET_TIME_Relative delay; char *stat_txt; - GNUNET_assert (NULL != p); - if (GNUNET_NO == server_exist_session(p, s)) + if (GNUNET_NO == server_exist_session (s->plugin, s)) return GNUNET_OK; @@ -1340,7 +1348,9 @@ server_receive_mst_cb (void *cls, void *client, GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Peer `%s' address `%s' next read delayed for %s\n", GNUNET_i2s (&s->target), - http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen), + http_common_plugin_address_to_string (NULL, + plugin->protocol, + s->addr, s->addrlen), GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); } @@ -1448,7 +1458,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, s, sc, GNUNET_i2s (&s->target), http_common_plugin_address_to_string (NULL, - p->protocol, + plugin->protocol, s->addr, s->addrlen)); sc->connected = GNUNET_YES; @@ -1462,7 +1472,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, s, sc, GNUNET_i2s (&s->target), http_common_plugin_address_to_string (NULL, - p->protocol, + plugin->protocol, s->addr, s->addrlen)); sc->connected = GNUNET_NO; @@ -1482,7 +1492,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, s, sc, GNUNET_i2s (&s->target), http_common_plugin_address_to_string (NULL, - p->protocol, + plugin->protocol, s->addr, s->addrlen), *upload_data_size); @@ -1526,7 +1536,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, /** * Callback from MHD when a connection disconnects * - * @param cls closure + * @param cls closure with the `struct HTTP_Server_Plugin *` * @param connection the disconnected MHD connection * @param httpSessionCache the pointer to distinguish */ @@ -1534,37 +1544,34 @@ static void server_disconnect_cb (void *cls, struct MHD_Connection *connection, void **httpSessionCache) { + struct HTTP_Server_Plugin *plugin = cls; struct ServerConnection *sc = *httpSessionCache; struct Session *s = NULL; struct Session *t = NULL; - struct HTTP_Server_Plugin *plugin = NULL; - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, p->name, + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + plugin->name, "Disconnect for connection %p \n", sc); if (sc == NULL) return; - if (NULL == (s = server_lookup_session (p, sc))) + if (NULL == (s = server_lookup_session (plugin, sc))) return; - - GNUNET_assert (NULL != p); - for (t = p->head; t != NULL; t = t->next) - { + for (t = plugin->head; t != NULL; t = t->next) if (t == s) break; - } if (NULL == t) return; - plugin = s->plugin; if (sc->direction == _SEND) { - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Peer `%s' connection %p, GET on address `%s' disconnected\n", GNUNET_i2s (&s->target), s->server_send, - http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen)); + http_common_plugin_address_to_string (NULL, + plugin->protocol, + s->addr, s->addrlen)); s->server_send = NULL; if (NULL != (s->server_recv)) { @@ -1582,7 +1589,9 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Peer `%s' connection %p PUT on address `%s' disconnected\n", GNUNET_i2s (&s->target), s->server_recv, - http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen)); + http_common_plugin_address_to_string (NULL, + plugin->protocol, + s->addr, s->addrlen)); s->server_recv = NULL; /* Do not terminate session when PUT disconnects if (NULL != (s->server_send)) @@ -1610,7 +1619,9 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Peer `%s' on address `%s' disconnected\n", GNUNET_i2s (&s->target), - http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen)); + http_common_plugin_address_to_string (NULL, + plugin->protocol, + s->addr, s->addrlen)); if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended)) { @@ -1618,20 +1629,18 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, s->session_ended = GNUNET_YES; plugin->env->session_end (plugin->env->cls, &s->target, s); } - server_delete_session (s); + server_delete_session (plugin, s); } - } /** * Check if incoming connection is accepted. - + * * @param cls plugin as closure * @param addr address of incoming connection * @param addr_len address length of incoming connection * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected - * */ static int server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) @@ -1655,6 +1664,7 @@ server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) } } + static void server_log (void *arg, const char *fmt, va_list ap) { @@ -1717,8 +1727,6 @@ server_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } -#define UNSIGNED_MHD_LONG_LONG unsigned MHD_LONG_LONG - /** * Function that queries MHD's select sets and * starts the task waiting for them. @@ -1740,7 +1748,7 @@ server_schedule (struct HTTP_Server_Plugin *plugin, struct GNUNET_NETWORK_FDSet *wws; struct GNUNET_NETWORK_FDSet *wes; int max; - UNSIGNED_MHD_LONG_LONG timeout; + MHD_UNSIGNED_LONG_LONG timeout; static unsigned long long last_timeout = 0; int haveto; @@ -2158,8 +2166,6 @@ server_stop (struct HTTP_Server_Plugin *plugin) GNUNET_SCHEDULER_cancel (plugin->server_v6_task); plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; } - p = NULL; - #if BUILD_HTTPS GNUNET_free_non_null (plugin->crypto_init); GNUNET_free_non_null (plugin->cert); @@ -2198,7 +2204,9 @@ server_add_address (void *cls, int add_remove, const struct sockaddr *addr, GNUNET_CONTAINER_DLL_insert(plugin->addr_head, plugin->addr_tail, w); GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Notifying transport to add address `%s'\n", - http_common_plugin_address_to_string (NULL, p->protocol, w->address, w->addrlen)); + http_common_plugin_address_to_string (NULL, + plugin->protocol, + w->address, w->addrlen)); #if BUILD_HTTPS plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); #else @@ -2240,7 +2248,9 @@ server_remove_address (void *cls, int add_remove, const struct sockaddr *addr, GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Notifying transport to remove address `%s'\n", - http_common_plugin_address_to_string (NULL, p->protocol, w->address, w->addrlen)); + http_common_plugin_address_to_string (NULL, + plugin->protocol, + w->address, w->addrlen)); GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w); #if BUILD_HTTPS plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); @@ -2880,7 +2890,6 @@ server_configure_plugin (struct HTTP_Server_Plugin *plugin) static void server_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - GNUNET_assert (NULL != cls); struct Session *s = cls; s->timeout_task = GNUNET_SCHEDULER_NO_TASK; @@ -2891,7 +2900,8 @@ server_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc GNUNET_YES)); /* call session destroy function */ - GNUNET_assert (GNUNET_OK == server_disconnect (s)); + GNUNET_assert (GNUNET_OK == + http_server_plugin_disconnect_session (s->plugin, s)); } @@ -2966,24 +2976,24 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) if (GNUNET_SCHEDULER_NO_TASK != plugin->notify_ext_task) { - GNUNET_SCHEDULER_cancel (plugin->notify_ext_task); - plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_SCHEDULER_cancel (plugin->notify_ext_task); + plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK; } if (NULL != plugin->ext_addr) { - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Notifying transport to remove address `%s'\n", - http_common_plugin_address_to_string (NULL, - p->protocol, - plugin->ext_addr, - plugin->ext_addr_len)); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Notifying transport to remove address `%s'\n", + http_common_plugin_address_to_string (NULL, + plugin->protocol, + plugin->ext_addr, + plugin->ext_addr_len)); #if BUILD_HTTPS - plugin->env->notify_address (plugin->env->cls, - GNUNET_NO, - plugin->ext_addr, - plugin->ext_addr_len, - "https_client"); + plugin->env->notify_address (plugin->env->cls, + GNUNET_NO, + plugin->ext_addr, + plugin->ext_addr_len, + "https_client"); #else plugin->env->notify_address (plugin->env->cls, GNUNET_NO, @@ -2991,7 +3001,6 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) plugin->ext_addr_len, "http_client"); #endif - } /* Stop to report addresses to transport service */ @@ -3000,18 +3009,17 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) next = plugin->head; while (NULL != (pos = next)) { - next = pos->next; - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Removing left over session %p\n", pos); - - if ((GNUNET_YES == pos->session_passed) && (GNUNET_NO == pos->session_ended)) - { - /* Notify transport immediately that this session is invalid */ - pos->session_ended = GNUNET_YES; - plugin->env->session_end (plugin->env->cls, &pos->target, pos); - } + next = pos->next; + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, + "Removing left over session %p\n", pos); - server_delete_session (pos); + if ((GNUNET_YES == pos->session_passed) && (GNUNET_NO == pos->session_ended)) + { + /* Notify transport immediately that this session is invalid */ + pos->session_ended = GNUNET_YES; + plugin->env->session_end (plugin->env->cls, &pos->target, pos); + } + server_delete_session (plugin, pos); } /* Clean up */ @@ -3071,15 +3079,14 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) struct GNUNET_TRANSPORT_PluginFunctions *api; struct HTTP_Server_Plugin *plugin; - plugin = GNUNET_malloc (sizeof (struct HTTP_Server_Plugin)); + plugin = GNUNET_new (struct HTTP_Server_Plugin); plugin->env = env; - p = plugin; if (NULL == env->receive) { /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully initialze the plugin or the API */ - api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = NULL; api->address_to_string = &http_plugin_address_to_string; api->string_to_address = &http_common_plugin_string_to_address; @@ -3087,10 +3094,11 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) return api; } - api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = plugin; api->send = &http_server_plugin_send; - api->disconnect = &http_server_plugin_disconnect; + api->disconnect_peer = &http_server_plugin_disconnect_peer; + api->disconnect_session = &http_server_plugin_disconnect_session; api->check_address = &http_server_plugin_address_suggested; api->get_session = &http_server_plugin_get_session; diff --git a/src/transport/plugin_transport_smtp.c b/src/transport/plugin_transport_smtp.c index 740d25d00..c886fd132 100644 --- a/src/transport/plugin_transport_smtp.c +++ b/src/transport/plugin_transport_smtp.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet - (C) 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and other contributing authors) + (C) 2003-2013 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 273d39873..bd624c1d5 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -298,12 +298,11 @@ struct Session * call or on our 'accept' call). * * struct IPv4TcpAddress or struct IPv6TcpAddress - * */ void *addr; /** - * Length of connect_addr. + * Length of @e addr. */ size_t addrlen; @@ -1019,12 +1018,14 @@ process_pending_messages (struct Session *session) * establish a connection. * * @param session session to close down + * @return #GNUNET_OK on success */ -static void -disconnect_session (struct Session *session) +static int +tcp_disconnect_session (void *cls, + struct Session *session) { + struct Plugin *plugin = cls; struct PendingMessage *pm; - struct Plugin * plugin = session->plugin; LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting session of peer `%s' address `%s'\n", @@ -1101,6 +1102,7 @@ disconnect_session (struct Session *session) GNUNET_free_non_null (session->addr); GNUNET_assert (NULL == session->transmit_handle); GNUNET_free (session); + return GNUNET_OK; } @@ -1172,7 +1174,7 @@ find_session (struct Plugin *plugin, struct Session *session) * been transmitted (or if the transport is ready * for the next transmission call; or if the * peer disconnected...); can be NULL - * @param cont_cls closure for cont + * @param cont_cls closure for @a cont * @return number of bytes used (on the physical network, with overheads); * -1 on hard errors (i.e. address invalid); 0 is a legal value * and does NOT mean that the message was not transmitted (DV) @@ -1315,15 +1317,19 @@ session_lookup_it (void *cls, * Task cleaning up a NAT connection attempt after timeout */ static void -nat_connect_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +nat_connect_timeout (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Session *session = cls; session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; LOG (GNUNET_ERROR_TYPE_DEBUG, "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", - GNUNET_i2s (&session->target), tcp_address_to_string(NULL, session->addr, session->addrlen)); - disconnect_session (session); + GNUNET_i2s (&session->target), + tcp_address_to_string (NULL, + session->addr, session->addrlen)); + tcp_disconnect_session (session->plugin, + session); } @@ -1491,7 +1497,7 @@ tcp_plugin_get_session (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Running NAT client for `%4s' at `%s' failed\n", GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); - disconnect_session (session); + tcp_disconnect_session (plugin, session); return NULL; } } @@ -1544,13 +1550,15 @@ session_disconnect_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) { + struct Plugin *plugin = cls; struct Session *session = value; GNUNET_STATISTICS_update (session->plugin->env->stats, gettext_noop ("# transport-service disconnect requests for TCP"), 1, GNUNET_NO); - disconnect_session (session); + tcp_disconnect_session (plugin, + session); return GNUNET_YES; } @@ -1980,7 +1988,7 @@ handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client, { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - disconnect_session (session); + tcp_disconnect_session (plugin, session); return; } GNUNET_assert (GNUNET_CONTAINER_multipeermap_remove @@ -2021,7 +2029,7 @@ handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client, "Bad address for incoming connection!\n"); GNUNET_free (vaddr); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - disconnect_session (session); + tcp_disconnect_session (plugin, session); return; } GNUNET_free (vaddr); @@ -2334,18 +2342,18 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) "*"); if (plugin->cur_connections == plugin->max_connections) - GNUNET_SERVER_resume (plugin->server); /* Resume server */ + GNUNET_SERVER_resume (plugin->server); /* Resume server */ if (plugin->cur_connections < 1) - GNUNET_break (0); + GNUNET_break (0); else - plugin->cur_connections--; + plugin->cur_connections--; GNUNET_STATISTICS_update (session->plugin->env->stats, gettext_noop ("# network-level TCP disconnect events"), 1, GNUNET_NO); - disconnect_session (session); + tcp_disconnect_session (plugin, session); } @@ -2451,7 +2459,7 @@ session_timeout (void *cls, GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_YES)); /* call session destroy function */ - disconnect_session (s); + tcp_disconnect_session(s->plugin, s); } @@ -2461,11 +2469,10 @@ session_timeout (void *cls, static void start_session_timeout (struct Session *s) { - GNUNET_assert (NULL != s); GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - &session_timeout, - s); + &session_timeout, + s); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout for session %p set to %s\n", s, @@ -2567,7 +2574,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) { /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully initialze the plugin or the API */ - api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = NULL; api->address_pretty_printer = &tcp_plugin_address_pretty_printer; api->address_to_string = &tcp_address_to_string; @@ -2592,8 +2599,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) (aport > 65535))) { LOG (GNUNET_ERROR_TYPE_ERROR, - _ - ("Require valid port number for service `%s' in configuration!\n"), + _("Require valid port number for service `%s' in configuration!\n"), "transport-tcp"); return NULL; } @@ -2617,7 +2623,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) /* Initialize my flags */ myoptions = 0; - plugin = GNUNET_malloc (sizeof (struct Plugin)); + plugin = GNUNET_new (struct Plugin); plugin->sessionmap = GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES); plugin->max_connections = max_connections; plugin->cur_connections = 0; @@ -2659,14 +2665,15 @@ libgnunet_plugin_transport_tcp_init (void *cls) api->send = &tcp_plugin_send; api->get_session = &tcp_plugin_get_session; - api->disconnect = &tcp_plugin_disconnect; + api->disconnect_session = &tcp_disconnect_session; + api->disconnect_peer = &tcp_plugin_disconnect; api->address_pretty_printer = &tcp_plugin_address_pretty_printer; api->check_address = &tcp_plugin_check_address; api->address_to_string = &tcp_address_to_string; api->string_to_address = &tcp_string_to_address; api->get_network = &tcp_get_network; plugin->service = service; - if (service != NULL) + if (NULL != service) { plugin->server = GNUNET_SERVICE_get_server (service); } @@ -2703,13 +2710,11 @@ libgnunet_plugin_transport_tcp_init (void *cls) _("TCP transport listening on port %llu\n"), bport); else LOG (GNUNET_ERROR_TYPE_INFO, - _ - ("TCP transport not listening on any port (client only)\n")); + _("TCP transport not listening on any port (client only)\n")); if (aport != bport) LOG (GNUNET_ERROR_TYPE_INFO, - _ - ("TCP transport advertises itself as being on port %llu\n"), - aport); + _("TCP transport advertises itself as being on port %llu\n"), + aport); /* Initially set connections to 0 */ GNUNET_assert (NULL != plugin->env->stats); GNUNET_STATISTICS_set (plugin->env->stats, diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c index dedc8e857..feb0802d9 100644 --- a/src/transport/plugin_transport_template.c +++ b/src/transport/plugin_transport_template.c @@ -152,7 +152,7 @@ struct Plugin * @param cls closure * @param session which session must be used * @param msgbuf the message to transmit - * @param msgbuf_size number of bytes in 'msgbuf' + * @param msgbuf_size number of bytes in @a msgbuf * @param priority how important is the message (most plugins will * ignore message priority and just FIFO) * @param to how long to wait at most for the transmission (does not @@ -163,7 +163,7 @@ struct Plugin * been transmitted (or if the transport is ready * for the next transmission call; or if the * peer disconnected...); can be NULL - * @param cont_cls closure for cont + * @param cont_cls closure for @a cont * @return number of bytes used (on the physical network, with overheads); * -1 on hard errors (i.e. address invalid); 0 is a legal value * and does NOT mean that the message was not transmitted (DV) @@ -187,7 +187,6 @@ template_plugin_send (void *cls, } - /** * Function that can be used to force the plugin to disconnect * from the given peer and cancel all previous transmissions @@ -197,10 +196,30 @@ template_plugin_send (void *cls, * @param target peer from which to disconnect */ static void -template_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) +template_plugin_disconnect_peer (void *cls, + const struct GNUNET_PeerIdentity *target) +{ + // struct Plugin *plugin = cls; + // FIXME +} + + +/** + * 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 session session from which to disconnect + * @return #GNUNET_OK on success + */ +static int +template_plugin_disconnect_session (void *cls, + struct Session *session) { // struct Plugin *plugin = cls; // FIXME + return GNUNET_SYSERR; } @@ -242,11 +261,10 @@ template_plugin_address_pretty_printer (void *cls, const char *type, GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) { - if (0 == addrlen) - { - asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING); - } - + if (0 == addrlen) + { + asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING); + } asc (asc_cls, NULL); } @@ -261,7 +279,7 @@ template_plugin_address_pretty_printer (void *cls, const char *type, * @param cls closure * @param addr pointer to the address * @param addrlen length of addr - * @return GNUNET_OK if this is a plausible address for this peer + * @return #GNUNET_OK if this is a plausible address for this peer * and transport */ static int @@ -288,14 +306,14 @@ template_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) static const char * template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) { - /* - * Print address in format template.options.address - */ + /* + * Print address in format template.options.address + */ - if (0 == addrlen) - { - return TRANSPORT_SESSION_INBOUND_STRING; - } + if (0 == addrlen) + { + return TRANSPORT_SESSION_INBOUND_STRING; + } GNUNET_break (0); return NULL; @@ -308,22 +326,21 @@ template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) * * @param cls closure ('struct Plugin*') * @param addr string address - * @param addrlen length of the address + * @param addrlen length of the @a addr * @param buf location to store the buffer * @param added location to store the number of bytes in the buffer. - * If the function returns GNUNET_SYSERR, its contents are undefined. - * @return GNUNET_OK on success, GNUNET_SYSERR on failure + * If the function returns #GNUNET_SYSERR, its contents are undefined. + * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -template_plugin_string_to_address (void *cls, const char *addr, uint16_t addrlen, - void **buf, size_t *added) +template_plugin_string_to_address (void *cls, + const char *addr, + uint16_t addrlen, + void **buf, size_t *added) { - - /* - * Parse string in format template.options.address - */ - - + /* + * Parse string in format template.options.address + */ GNUNET_break (0); return GNUNET_SYSERR; } @@ -346,6 +363,7 @@ template_plugin_get_session (void *cls, return NULL; } + /** * Entry point for the plugin. */ @@ -360,7 +378,7 @@ libgnunet_plugin_transport_template_init (void *cls) { /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully initialze the plugin or the API */ - api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = NULL; api->address_to_string = &template_plugin_address_to_string; api->string_to_address = &template_plugin_string_to_address; @@ -368,12 +386,13 @@ libgnunet_plugin_transport_template_init (void *cls) return api; } - plugin = GNUNET_malloc (sizeof (struct Plugin)); + plugin = GNUNET_new (struct Plugin); plugin->env = env; - api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = plugin; api->send = &template_plugin_send; - api->disconnect = &template_plugin_disconnect; + api->disconnect_peer = &template_plugin_disconnect_peer; + api->disconnect_session = &template_plugin_disconnect_session; api->address_pretty_printer = &template_plugin_address_pretty_printer; api->check_address = &template_plugin_address_suggested; api->address_to_string = &template_plugin_address_to_string; diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 9bc579b2f..99d4f9fb1 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -138,6 +138,7 @@ enum UDP_MessageType MSG_BEACON = 5 }; + struct Session { /** @@ -145,7 +146,15 @@ struct Session */ struct GNUNET_PeerIdentity target; - struct UDP_FragmentationContext * frag_ctx; + /** + * Plugin this session belongs to. + */ + struct Plugin *plugin; + + /** + * Context for dealing with fragments. + */ + struct UDP_FragmentationContext *frag_ctx; /** * Address of the other peer @@ -179,9 +188,11 @@ struct Session struct GNUNET_ATS_Information ats; + /** + * Number of bytes in @e sock_addr. + */ size_t addrlen; - unsigned int rc; int in_destroy; @@ -214,6 +225,7 @@ struct SourceInformation const void *arg; struct Session *session; + /** * Number of bytes in source address. */ @@ -240,7 +252,7 @@ struct FindReceiveContext struct Session *session; /** - * Number of bytes in 'addr'. + * Number of bytes in @e addr. */ socklen_t addr_len; @@ -292,27 +304,27 @@ struct UDP_FragmentationContext /** * Next in linked list */ - struct UDP_FragmentationContext * next; + struct UDP_FragmentationContext *next; /** * Previous in linked list */ - struct UDP_FragmentationContext * prev; + struct UDP_FragmentationContext *prev; /** * The plugin */ - struct Plugin * plugin; + struct Plugin *plugin; /** * Handle for GNUNET_FRAGMENT context */ - struct GNUNET_FRAGMENT_Context * frag; + struct GNUNET_FRAGMENT_Context *frag; /** * The session this fragmentation context belongs to */ - struct Session * session; + struct Session *session; /** * Function to call upon completion of the transmission. @@ -320,7 +332,7 @@ struct UDP_FragmentationContext GNUNET_TRANSPORT_TransmitContinuation cont; /** - * Closure for 'cont'. + * Closure for @e cont. */ void *cont_cls; @@ -1110,7 +1122,8 @@ free_session (struct Session *s) static void -dequeue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) +dequeue (struct Plugin *plugin, + struct UDP_MessageWrapper * udpw) { if (plugin->bytes_in_buffer < udpw->msg_size) GNUNET_break (0); @@ -1195,28 +1208,33 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result) &s->last_expected_msg_delay, &s->last_expected_ack_delay); s->frag_ctx = NULL; - GNUNET_free (fc ); + GNUNET_free (fc); } + /** * Functions with this signature are called whenever we need * to close a session due to a disconnect or failure to * establish a connection. * + * @param cls closure with the `struct Plugin` * @param s session to close down + * @return #GNUNET_OK on success */ -static void -disconnect_session (struct Session *s) +static int +udp_disconnect_session (void *cls, + struct Session *s) { + struct Plugin *plugin = cls; struct UDP_MessageWrapper *udpw; struct UDP_MessageWrapper *next; GNUNET_assert (GNUNET_YES != s->in_destroy); LOG (GNUNET_ERROR_TYPE_DEBUG, - "Session %p to peer `%s' address ended \n", - s, - GNUNET_i2s (&s->target), - GNUNET_a2s (s->sock_addr, s->addrlen)); + "Session %p to peer `%s' address ended\n", + s, + GNUNET_i2s (&s->target), + GNUNET_a2s (s->sock_addr, s->addrlen)); stop_session_timeout (s); if (NULL != s->frag_ctx) @@ -1232,7 +1250,7 @@ disconnect_session (struct Session *s) if (udpw->session == s) { dequeue (plugin, udpw); - call_continuation(udpw, GNUNET_SYSERR); + call_continuation (udpw, GNUNET_SYSERR); GNUNET_free (udpw); } } @@ -1243,7 +1261,7 @@ disconnect_session (struct Session *s) if (udpw->session == s) { dequeue (plugin, udpw); - call_continuation(udpw, GNUNET_SYSERR); + call_continuation (udpw, GNUNET_SYSERR); GNUNET_free (udpw); } } @@ -1265,48 +1283,55 @@ disconnect_session (struct Session *s) GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, &s->target, s)); - GNUNET_STATISTICS_set(plugin->env->stats, - "# UDP, sessions active", - GNUNET_CONTAINER_multipeermap_size(plugin->sessions), - GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, + "# UDP, sessions active", + GNUNET_CONTAINER_multipeermap_size(plugin->sessions), + GNUNET_NO); if (s->rc > 0) s->in_destroy = GNUNET_YES; else free_session (s); + return GNUNET_OK; } + /** * Destroy a session, plugin is being unloaded. * - * @param cls unused + * @param cls the `struct Plugin` * @param key hash of public key of target peer - * @param value a 'struct PeerSession*' to clean up - * @return GNUNET_OK (continue to iterate) + * @param value a `struct PeerSession *` to clean up + * @return #GNUNET_OK (continue to iterate) */ static int -disconnect_and_free_it (void *cls, const struct GNUNET_PeerIdentity * key, void *value) +disconnect_and_free_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { - disconnect_session(value); + struct Plugin *plugin = cls; + + udp_disconnect_session (plugin, value); return GNUNET_OK; } /** - * Disconnect from a remote node. Clean up session if we have one for this peer + * Disconnect from a remote node. Clean up session if we have one for + * this peer. * * @param cls closure for this call (should be handle to Plugin) * @param target the peeridentity of the peer to disconnect - * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed + * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed */ static void -udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) +udp_disconnect (void *cls, + const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; - GNUNET_assert (plugin != NULL); - GNUNET_assert (target != NULL); LOG (GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting from peer `%s'\n", GNUNET_i2s (target)); + "Disconnecting from peer `%s'\n", + GNUNET_i2s (target)); /* Clean up sessions */ GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, target, &disconnect_and_free_it, plugin); @@ -1317,9 +1342,9 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) * Session was idle, so disconnect it */ static void -session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +session_timeout (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { - GNUNET_assert (NULL != cls); struct Session *s = cls; s->timeout_task = GNUNET_SCHEDULER_NO_TASK; @@ -1329,7 +1354,8 @@ session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, GNUNET_YES)); /* call session destroy function */ - disconnect_session (s); + udp_disconnect_session (s->plugin, + s); } @@ -1374,7 +1400,8 @@ reschedule_session_timeout (struct Session *s) static struct Session * -create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, +create_session (struct Plugin *plugin, + const struct GNUNET_PeerIdentity *target, const void *addr, size_t addrlen, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) { @@ -1387,8 +1414,8 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, if (NULL == addr) { - GNUNET_break (0); - return NULL; + GNUNET_break (0); + return NULL; } switch (addrlen) @@ -1399,11 +1426,12 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, LOG (GNUNET_ERROR_TYPE_DEBUG, "Could not create session for peer `%s' address `%s': IPv4 is not enabled\n", GNUNET_i2s(target), - udp_address_to_string(NULL, addr, addrlen)); + udp_address_to_string (NULL, addr, addrlen)); return NULL; } t4 = addr; s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in)); + s->plugin = plugin; len = sizeof (struct sockaddr_in); v4 = (struct sockaddr_in *) &s[1]; v4->sin_family = AF_INET; @@ -1425,6 +1453,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, } t6 = addr; s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6)); + s->plugin = plugin; len = sizeof (struct sockaddr_in6); v6 = (struct sockaddr_in6 *) &s[1]; v6->sin6_family = AF_INET6; @@ -1512,7 +1541,7 @@ session_cmp_it (void *cls, * * @param cls closure ('struct Plugin*') * @param session the session - * @return the network type in HBO or GNUNET_SYSERR + * @return the network type in HBO or #GNUNET_SYSERR */ static enum GNUNET_ATS_Network_Type udp_get_network (void *cls, @@ -2991,7 +3020,7 @@ libgnunet_plugin_transport_udp_init (void *cls) { /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully initialze the plugin or the API */ - api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = NULL; api->address_pretty_printer = &udp_plugin_address_pretty_printer; api->address_to_string = &udp_address_to_string; @@ -3002,8 +3031,7 @@ libgnunet_plugin_transport_udp_init (void *cls) GNUNET_assert (NULL != env->stats); /* Get port number: port == 0 : autodetect a port, - * > 0 : use this port, - * not given : 2086 default */ + * > 0 : use this port, not given : 2086 default */ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT", &port)) @@ -3097,7 +3125,7 @@ libgnunet_plugin_transport_udp_init (void *cls) udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ } - p = GNUNET_malloc (sizeof (struct Plugin)); + p = GNUNET_new (struct Plugin); p->port = port; p->aport = aport; p->broadcast_interval = interval; @@ -3130,10 +3158,11 @@ libgnunet_plugin_transport_udp_init (void *cls) setup_broadcast (p, &server_addrv6, &server_addrv4); } - api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = p; api->send = NULL; - api->disconnect = &udp_disconnect; + api->disconnect_session = &udp_disconnect_session; + api->disconnect_peer = &udp_disconnect; api->address_pretty_printer = &udp_plugin_address_pretty_printer; api->address_to_string = &udp_address_to_string; api->string_to_address = &udp_string_to_address; @@ -3148,10 +3177,9 @@ libgnunet_plugin_transport_udp_init (void *cls) static int heap_cleanup_iterator (void *cls, - struct GNUNET_CONTAINER_HeapNode * - node, void *element, - GNUNET_CONTAINER_HeapCostType - cost) + struct GNUNET_CONTAINER_HeapNode *node, + void *element, + GNUNET_CONTAINER_HeapCostType cost) { struct DefragContext * d_ctx = element; @@ -3197,35 +3225,37 @@ libgnunet_plugin_transport_udp_done (void *cls) } /* Closing sockets */ - if (GNUNET_YES ==plugin->enable_ipv4) + if (GNUNET_YES == plugin->enable_ipv4) { - if (plugin->sockv4 != NULL) - { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); - plugin->sockv4 = NULL; - } - GNUNET_NETWORK_fdset_destroy (plugin->rs_v4); - GNUNET_NETWORK_fdset_destroy (plugin->ws_v4); + if (NULL != plugin->sockv4) + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); + plugin->sockv4 = NULL; + } + GNUNET_NETWORK_fdset_destroy (plugin->rs_v4); + GNUNET_NETWORK_fdset_destroy (plugin->ws_v4); } - if (GNUNET_YES ==plugin->enable_ipv6) + if (GNUNET_YES == plugin->enable_ipv6) { - if (plugin->sockv6 != NULL) - { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); - plugin->sockv6 = NULL; + if (NULL != plugin->sockv6) + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); + plugin->sockv6 = NULL; - GNUNET_NETWORK_fdset_destroy (plugin->rs_v6); - GNUNET_NETWORK_fdset_destroy (plugin->ws_v6); - } + GNUNET_NETWORK_fdset_destroy (plugin->rs_v6); + GNUNET_NETWORK_fdset_destroy (plugin->ws_v6); + } } if (NULL != plugin->nat) - GNUNET_NAT_unregister (plugin->nat); - - if (plugin->defrag_ctxs != NULL) { - GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs, - heap_cleanup_iterator, NULL); - GNUNET_CONTAINER_heap_destroy(plugin->defrag_ctxs); + GNUNET_NAT_unregister (plugin->nat); + plugin->nat = NULL; + } + if (NULL != plugin->defrag_ctxs) + { + GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, + heap_cleanup_iterator, NULL); + GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); plugin->defrag_ctxs = NULL; } if (plugin->mst != NULL) @@ -3266,12 +3296,12 @@ libgnunet_plugin_transport_udp_done (void *cls) next = ppc_dll_head; for (cur = next; NULL != cur; cur = next) { - next = cur->next; - GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, cur); - GNUNET_RESOLVER_request_cancel (cur->resolver_handle); - GNUNET_SCHEDULER_cancel (cur->timeout_task); - GNUNET_free (cur); - GNUNET_break (0); + next = cur->next; + GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, cur); + GNUNET_RESOLVER_request_cancel (cur->resolver_handle); + GNUNET_SCHEDULER_cancel (cur->timeout_task); + GNUNET_free (cur); + GNUNET_break (0); } plugin->nat = NULL; @@ -3281,16 +3311,16 @@ libgnunet_plugin_transport_udp_done (void *cls) struct Allocation *allocation; while (NULL != ahead) { - allocation = ahead; - GNUNET_CONTAINER_DLL_remove (ahead, atail, allocation); - GNUNET_free (allocation); + allocation = ahead; + GNUNET_CONTAINER_DLL_remove (ahead, atail, allocation); + GNUNET_free (allocation); } struct Allocator *allocator; while (NULL != aehead) { - allocator = aehead; - GNUNET_CONTAINER_DLL_remove (aehead, aetail, allocator); - GNUNET_free (allocator); + allocator = aehead; + GNUNET_CONTAINER_DLL_remove (aehead, aetail, allocator); + GNUNET_free (allocator); } #endif return NULL; diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index e78445a0a..3d6ac4d23 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c @@ -530,9 +530,6 @@ lookup_session (struct Plugin *plugin, { struct LookupCtx lctx; - GNUNET_assert (NULL != plugin); - GNUNET_assert (NULL != sender); - GNUNET_assert (NULL != ua); lctx.s = NULL; lctx.ua = ua; lctx.ua_len = ua_len; @@ -548,12 +545,15 @@ lookup_session (struct Plugin *plugin, * to close a session due to a disconnect or failure to * establish a connection. * + * @param cls closure with the `struct Plugin` * @param s session to close down + * @return #GNUNET_OK on success */ -static void -disconnect_session (struct Session *s) +static int +unix_session_disconnect (void *cls, + struct Session *s) { - struct Plugin *plugin = s->plugin; + struct Plugin *plugin = cls; struct UNIXMessageWrapper *msgw; struct UNIXMessageWrapper *next; int removed; @@ -595,6 +595,7 @@ disconnect_session (struct Session *s) s->timeout_task = GNUNET_SCHEDULER_NO_TASK; } GNUNET_free (s); + return GNUNET_OK; } @@ -610,13 +611,13 @@ disconnect_session (struct Session *s) * @param priority how important is the message (ignored by UNIX) * @param timeout when should we time out (give up) if we can not transmit? * @param addr the addr to send the message to, needs to be a sockaddr for us - * @param addrlen the len of addr + * @param addrlen the len of @a addr * @param payload bytes payload to send * @param cont continuation to call once the message has * been transmitted (or if the transport is ready * for the next transmission call; or if the * peer disconnected...) - * @param cont_cls closure for cont + * @param cont_cls closure for @a cont * @return on success the number of bytes written, RETRY for retry, -1 on errors */ static ssize_t @@ -637,7 +638,6 @@ unix_real_send (void *cls, socklen_t un_len; const char *unixpath; - GNUNET_assert (NULL != plugin); if (NULL == send_handle) { @@ -734,7 +734,7 @@ struct GetSessionIteratorContext const char *address; /** - * Number of bytes in 'address' + * Number of bytes in @e address */ size_t addrlen; }; @@ -784,7 +784,7 @@ session_timeout (void *cls, s, GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_YES)); - disconnect_session (s); + unix_session_disconnect (s->plugin, s); } @@ -903,7 +903,7 @@ unix_plugin_get_session (void *cls, * @param cls closure * @param session which session must be used * @param msgbuf the message to transmit - * @param msgbuf_size number of bytes in 'msgbuf' + * @param msgbuf_size number of bytes in @a msgbuf * @param priority how important is the message (most plugins will * ignore message priority and just FIFO) * @param to how long to wait at most for the transmission (does not @@ -914,7 +914,7 @@ unix_plugin_get_session (void *cls, * been transmitted (or if the transport is ready * for the next transmission call; or if the * peer disconnected...); can be NULL - * @param cont_cls closure for cont + * @param cont_cls closure for @a cont * @return number of bytes used (on the physical network, with overheads); * -1 on hard errors (i.e. address invalid); 0 is a legal value * and does NOT mean that the message was not transmitted (DV) @@ -932,9 +932,6 @@ unix_plugin_send (void *cls, struct UNIXMessage *message; int ssize; - GNUNET_assert (NULL != plugin); - GNUNET_assert (NULL != session); - if (GNUNET_OK != GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, &session->target, @@ -960,7 +957,7 @@ unix_plugin_send (void *cls, sizeof (struct GNUNET_PeerIdentity)); memcpy (&message[1], msgbuf, msgbuf_size); reschedule_session_timeout (session); - wrapper = GNUNET_malloc (sizeof (struct UNIXMessageWrapper)); + wrapper = GNUNET_new (struct UNIXMessageWrapper); wrapper->msg = message; wrapper->msgsize = ssize; wrapper->payload = msgbuf_size; @@ -1001,9 +998,7 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, struct GNUNET_HELLO_Address * addr; GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED); - GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message from %s\n", unix_address_to_string(NULL, ua, ua_len)); @@ -1329,10 +1324,10 @@ unix_transport_server_start (void *cls) static int unix_check_address (void *cls, const void *addr, size_t addrlen) { - struct Plugin* plugin = cls; - struct UnixAddress *ua = (struct UnixAddress *) addr; - char *addrstr; - size_t addr_str_len; + struct Plugin* plugin = cls; + struct UnixAddress *ua = (struct UnixAddress *) addr; + char *addrstr; + size_t addr_str_len; if ((NULL == addr) || (0 == addrlen) || (sizeof (struct UnixAddress) > addrlen)) { @@ -1366,11 +1361,11 @@ unix_check_address (void *cls, const void *addr, size_t addrlen) * @param type name of the transport that generated the address * @param addr one of the addresses of the host, NULL for the last address * the specific address format depends on the transport - * @param addrlen length of the address + * @param addrlen length of the @a addr * @param numeric should (IP) addresses be displayed in numeric form? * @param timeout after how long should we give up? * @param asc function to call on each string - * @param asc_cls closure for asc + * @param asc_cls closure for @a asc */ static void unix_plugin_address_pretty_printer (void *cls, const char *type, @@ -1403,15 +1398,16 @@ unix_plugin_address_pretty_printer (void *cls, const char *type, * * @param cls closure ('struct Plugin*') * @param addr string address - * @param addrlen length of the address (strlen(addr) + '\0') + * @param addrlen length of the @a addr (strlen(addr) + '\0') * @param buf location to store the buffer - * If the function returns GNUNET_SYSERR, its contents are undefined. + * If the function returns #GNUNET_SYSERR, its contents are undefined. * @param added length of created address - * @return GNUNET_OK on success, GNUNET_SYSERR on failure + * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -unix_string_to_address (void *cls, const char *addr, uint16_t addrlen, - void **buf, size_t *added) +unix_string_to_address (void *cls, + const char *addr, uint16_t addrlen, + void **buf, size_t *added) { struct UnixAddress *ua; char *address; @@ -1532,19 +1528,20 @@ reschedule_session_timeout (struct Session *s) /** * Function called on sessions to disconnect * - * @param cls the plugin (unused) + * @param cls the plugin * @param key peer identity (unused) * @param value the 'struct Session' to disconnect - * @return GNUNET_YES (always, continue to iterate) + * @return #GNUNET_YES (always, continue to iterate) */ static int get_session_delete_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) { + struct Plugin *plugin = cls; struct Session *s = value; - disconnect_session (s); + unix_session_disconnect (plugin, s); return GNUNET_YES; } @@ -1557,8 +1554,8 @@ get_session_delete_it (void *cls, * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed */ static void -unix_disconnect (void *cls, - const struct GNUNET_PeerIdentity *target) +unix_peer_disconnect (void *cls, + const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; @@ -1589,7 +1586,7 @@ libgnunet_plugin_transport_unix_init (void *cls) { /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully initialze the plugin or the API */ - api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = NULL; api->address_pretty_printer = &unix_plugin_address_pretty_printer; api->address_to_string = &unix_address_to_string; @@ -1600,7 +1597,7 @@ libgnunet_plugin_transport_unix_init (void *cls) GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-unix", "PORT", &port)) port = UNIX_NAT_DEFAULT_PORT; - plugin = GNUNET_malloc (sizeof (struct Plugin)); + plugin = GNUNET_new (struct Plugin); plugin->port = port; plugin->env = env; GNUNET_asprintf (&plugin->unix_socket_path, @@ -1610,12 +1607,13 @@ libgnunet_plugin_transport_unix_init (void *cls) /* Initialize my flags */ myoptions = 0; - api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = plugin; api->get_session = &unix_plugin_get_session; api->send = &unix_plugin_send; - api->disconnect = &unix_disconnect; + api->disconnect_peer = &unix_peer_disconnect; + api->disconnect_session = &unix_session_disconnect; api->address_pretty_printer = &unix_plugin_address_pretty_printer; api->address_to_string = &unix_address_to_string; api->check_address = &unix_check_address; diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 0957676f2..3e1a6396c 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -597,8 +597,8 @@ send_ack (void *cls, uint32_t msg_id, if (NULL == endpoint) { - GNUNET_break (0); - return; + GNUNET_break (0); + return; } if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) @@ -654,10 +654,12 @@ wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr) /** * Free a session * + * @param cls our `struct Plugin`. * @param session the session free */ -static void -free_session (struct Session *session) +static int +wlan_plugin_disconnect_session (void *cls, + struct Session *session) { struct MacEndpoint *endpoint = session->mac; struct PendingMessage *pm; @@ -685,9 +687,11 @@ free_session (struct Session *session) GNUNET_SCHEDULER_cancel (session->timeout_task); session->timeout_task = GNUNET_SCHEDULER_NO_TASK; } - GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN sessions allocated"), -1, + GNUNET_STATISTICS_update (endpoint->plugin->env->stats, + _("# WLAN sessions allocated"), -1, GNUNET_NO); GNUNET_free (session); + return GNUNET_OK; } @@ -700,14 +704,15 @@ free_session (struct Session *session) static void session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct Session * session = cls; + struct Session *session = cls; struct GNUNET_TIME_Relative timeout; session->timeout_task = GNUNET_SCHEDULER_NO_TASK; timeout = GNUNET_TIME_absolute_get_remaining (session->timeout); if (0 == timeout.rel_value_us) { - free_session (session); + wlan_plugin_disconnect_session (session->mac->plugin, + session); return; } session->timeout_task = @@ -804,7 +809,7 @@ get_session (struct MacEndpoint *endpoint, * the next fragment. * * @param cls the 'struct FragmentMessage' - * @param result result of the operation (GNUNET_OK on success, GNUNET_NO if the helper died, GNUNET_SYSERR + * @param result result of the operation (#GNUNET_OK on success, #GNUNET_NO if the helper died, #GNUNET_SYSERR * if the helper was stopped) */ static void @@ -894,8 +899,8 @@ free_fragment_message (struct FragmentMessage *fm) fm->sh = NULL; } GNUNET_FRAGMENT_context_destroy (fm->fragcontext, - &endpoint->msg_delay, - &endpoint->ack_delay); + &endpoint->msg_delay, + &endpoint->ack_delay); if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (fm->timeout_task); @@ -944,7 +949,7 @@ fragmentmessage_timeout (void *cls, static void send_with_fragmentation (struct MacEndpoint *endpoint, struct GNUNET_TIME_Relative timeout, - const struct GNUNET_PeerIdentity *target, + const struct GNUNET_PeerIdentity *target, const struct GNUNET_MessageHeader *msg, size_t payload_size, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) @@ -994,7 +999,8 @@ free_macendpoint (struct MacEndpoint *endpoint) GNUNET_STATISTICS_update (plugin->env->stats, _("# WLAN MAC endpoints allocated"), -1, GNUNET_NO); while (NULL != (session = endpoint->sessions_head)) - free_session (session); + wlan_plugin_disconnect_session (plugin, + session); while (NULL != (fm = endpoint->sending_messages_head)) free_fragment_message (fm); GNUNET_CONTAINER_DLL_remove (plugin->mac_head, @@ -1142,7 +1148,8 @@ wlan_plugin_get_session (void *cls, * @param target peer from which to disconnect */ static void -wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) +wlan_plugin_disconnect_peer (void *cls, + const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; struct Session *session; @@ -1153,7 +1160,7 @@ wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) if (0 == memcmp (target, &session->target, sizeof (struct GNUNET_PeerIdentity))) { - free_session (session); + wlan_plugin_disconnect_session (plugin, session); break; /* inner-loop only (in case peer has another MAC as well!) */ } } @@ -1959,7 +1966,8 @@ libgnunet_plugin_transport_wlan_init (void *cls) api->cls = plugin; api->send = &wlan_plugin_send; api->get_session = &wlan_plugin_get_session; - api->disconnect = &wlan_plugin_disconnect; + api->disconnect_peer = &wlan_plugin_disconnect_peer; + api->disconnect_session = &wlan_plugin_disconnect_session; api->address_pretty_printer = &wlan_plugin_address_pretty_printer; api->check_address = &wlan_plugin_address_suggested; api->address_to_string = &wlan_plugin_address_to_string; diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c index 98806fbb8..6c81acb49 100644 --- a/src/transport/test_plugin_transport.c +++ b/src/transport/test_plugin_transport.c @@ -695,8 +695,8 @@ run (void *cls, char *const *args, const char *cfgfile, end_badly_now (); return; } - GNUNET_assert (NULL != api->disconnect); - if (NULL == api->disconnect) + GNUNET_assert (NULL != api->disconnect_peer); + if (NULL == api->disconnect_peer) { GNUNET_break (0); end_badly_now (); -- cgit v1.2.3