[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r31300 - in gnunet/src: dv include namestore transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r31300 - in gnunet/src: dv include namestore transport |
Date: |
Thu, 12 Dec 2013 12:51:04 +0100 |
Author: grothoff
Date: 2013-12-12 12:51:03 +0100 (Thu, 12 Dec 2013)
New Revision: 31300
Modified:
gnunet/src/dv/plugin_transport_dv.c
gnunet/src/include/gnunet_transport_plugin.h
gnunet/src/namestore/gnunet-service-namestore.c
gnunet/src/transport/gnunet-service-transport_neighbours.c
gnunet/src/transport/gnunet-service-transport_plugins.c
gnunet/src/transport/plugin_transport_http_client.c
gnunet/src/transport/plugin_transport_http_server.c
gnunet/src/transport/plugin_transport_smtp.c
gnunet/src/transport/plugin_transport_tcp.c
gnunet/src/transport/plugin_transport_template.c
gnunet/src/transport/plugin_transport_udp.c
gnunet/src/transport/plugin_transport_unix.c
gnunet/src/transport/plugin_transport_wlan.c
gnunet/src/transport/test_plugin_transport.c
Log:
-extend transport plugin API with capability to just disconnect a single
session (not yet used)
Modified: gnunet/src/dv/plugin_transport_dv.c
===================================================================
--- gnunet/src/dv/plugin_transport_dv.c 2013-12-12 10:44:42 UTC (rev 31299)
+++ gnunet/src/dv/plugin_transport_dv.c 2013-12-12 11:51:03 UTC (rev 31300)
@@ -429,7 +429,7 @@
*/
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 @@
* @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;
@@ -572,6 +572,39 @@
/**
+ * 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 @@
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;
Modified: gnunet/src/include/gnunet_transport_plugin.h
===================================================================
--- gnunet/src/include/gnunet_transport_plugin.h 2013-12-12 10:44:42 UTC
(rev 31299)
+++ gnunet/src/include/gnunet_transport_plugin.h 2013-12-12 11:51:03 UTC
(rev 31300)
@@ -62,6 +62,7 @@
/* 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 @@
* @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,18 +95,19 @@
* @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.
* This function should also be called with "NULL" for the
@@ -123,16 +126,17 @@
* 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 @@
* @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 @@
* 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 @@
* @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 @@
*/
GNUNET_TRANSPORT_PluginReceiveCallback receive;
-
/**
* Function that returns our HELLO.
*/
@@ -302,7 +308,7 @@
/**
- * 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,12 +326,14 @@
* @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,39 +358,54 @@
* 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);
+
+
+/**
+ * Function that can be called to force a disconnect from the
* specified neighbour. This should also cancel all previously
* scheduled transmissions. Obviously the transmission may have been
* partially completed already, which is OK. The plugin is supposed
* 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 @@
* @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 @@
* @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,10 +460,12 @@
* @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
* This session will used to send data to this peer and the plugin will
@@ -448,8 +475,9 @@
* @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 @@
*
* @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 @@
* @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,9 +555,16 @@
* 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
* yet used by transport-service, but will be used in the future
* once the transport-API has been completed.
Modified: gnunet/src/namestore/gnunet-service-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-service-namestore.c 2013-12-12 10:44:42 UTC
(rev 31299)
+++ gnunet/src/namestore/gnunet-service-namestore.c 2013-12-12 11:51:03 UTC
(rev 31300)
@@ -454,10 +454,10 @@
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 @@
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 @@
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;
Modified: gnunet/src/transport/gnunet-service-transport_neighbours.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_neighbours.c 2013-12-12
10:44:42 UTC (rev 31299)
+++ gnunet/src/transport/gnunet-service-transport_neighbours.c 2013-12-12
11:51:03 UTC (rev 31300)
@@ -817,6 +817,7 @@
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_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 @@
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);
Modified: gnunet/src/transport/gnunet-service-transport_plugins.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_plugins.c 2013-12-12
10:44:42 UTC (rev 31299)
+++ gnunet/src/transport/gnunet-service-transport_plugins.c 2013-12-12
11:51:03 UTC (rev 31300)
@@ -219,14 +219,22 @@
"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)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
Modified: gnunet/src/transport/plugin_transport_http_client.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_client.c 2013-12-12 10:44:42 UTC
(rev 31299)
+++ gnunet/src/transport/plugin_transport_http_client.c 2013-12-12 11:51:03 UTC
(rev 31300)
@@ -107,6 +107,7 @@
*/
struct Session;
+
/**
* A connection handle
*
@@ -125,7 +126,6 @@
};
-
/**
* Session handle for connections.
*/
@@ -623,12 +623,12 @@
* 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 @@
* @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 @@
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 @@
/* 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 @@
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 @@
* 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 @@
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 @@
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 @@
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 @@
* 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 @@
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 @@
{
/* 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 @@
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;
Modified: gnunet/src/transport/plugin_transport_http_server.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_server.c 2013-12-12 10:44:42 UTC
(rev 31299)
+++ gnunet/src/transport/plugin_transport_http_server.c 2013-12-12 11:51:03 UTC
(rev 31300)
@@ -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 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 @@
/**
* Linked list head of open sessions.
*/
-
struct Session *head;
/**
@@ -225,7 +237,6 @@
*/
int verify_external_hostname;
-
/**
* Maximum number of sockets the plugin can use
* Each http inbound /outbound connections are two connections
@@ -440,12 +451,6 @@
/**
- * 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 @@
/**
- * 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 @@
*
* @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 @@
* 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 @@
* @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 @@
* 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 @@
}
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 @@
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 @@
* @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 @@
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 @@
*
* @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;
+ struct HTTP_Server_Plugin *plugin = cls;
+ 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;
+ 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 @@
* 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;
+ 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 @@
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 @@
* @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 @@
* 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 @@
/**
- * 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 @@
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 @@
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 @@
struct Session *s,
unsigned int to)
{
-#if MHD_VERSION >= 0x00090E00
/* Setting timeouts for other connections */
if (NULL != s->server_recv)
{
@@ -909,9 +919,9 @@
to);
server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO);
}
-#endif
}
+
/**
* Parse incoming URL for tag and target
*
@@ -919,9 +929,8 @@
* @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 @@
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 @@
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 @@
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 @@
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 @@
{
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 @@
* @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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
/**
* 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 @@
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 @@
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 @@
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 @@
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 @@
}
}
+
static void
server_log (void *arg, const char *fmt, va_list ap)
{
@@ -1717,8 +1727,6 @@
}
-#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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
plugin->ext_addr_len,
"http_client");
#endif
-
}
/* Stop to report addresses to transport service */
@@ -3000,18 +3009,17 @@
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);
+ 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);
- }
-
- 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 @@
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 @@
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;
Modified: gnunet/src/transport/plugin_transport_smtp.c
===================================================================
--- gnunet/src/transport/plugin_transport_smtp.c 2013-12-12 10:44:42 UTC
(rev 31299)
+++ gnunet/src/transport/plugin_transport_smtp.c 2013-12-12 11:51:03 UTC
(rev 31300)
@@ -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
Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2013-12-12 10:44:42 UTC (rev
31299)
+++ gnunet/src/transport/plugin_transport_tcp.c 2013-12-12 11:51:03 UTC (rev
31300)
@@ -298,12 +298,11 @@
* 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 @@
* 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 @@
GNUNET_free_non_null (session->addr);
GNUNET_assert (NULL == session->transmit_handle);
GNUNET_free (session);
+ return GNUNET_OK;
}
@@ -1172,7 +1174,7 @@
* 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 @@
* 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 @@
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 @@
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 @@
{
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 @@
"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 @@
"*");
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 @@
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 @@
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 @@
{
/* 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 @@
(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 @@
/* 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 @@
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 @@
_("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,
Modified: gnunet/src/transport/plugin_transport_template.c
===================================================================
--- gnunet/src/transport/plugin_transport_template.c 2013-12-12 10:44:42 UTC
(rev 31299)
+++ gnunet/src/transport/plugin_transport_template.c 2013-12-12 11:51:03 UTC
(rev 31300)
@@ -152,7 +152,7 @@
* @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 @@
* 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 @@
}
-
/**
* Function that can be used to force the plugin to disconnect
* from the given peer and cancel all previous transmissions
@@ -197,7 +196,8 @@
* @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
@@ -205,6 +205,25 @@
/**
+ * 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;
+}
+
+
+/**
* Function obtain the network type for a session
*
* @param cls closure ('struct Plugin*')
@@ -242,11 +261,10 @@
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 @@
* @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 @@
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 @@
*
* @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 @@
return NULL;
}
+
/**
* Entry point for the plugin.
*/
@@ -360,7 +378,7 @@
{
/* 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 @@
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;
Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2013-12-12 10:44:42 UTC (rev
31299)
+++ gnunet/src/transport/plugin_transport_udp.c 2013-12-12 11:51:03 UTC (rev
31300)
@@ -138,6 +138,7 @@
MSG_BEACON = 5
};
+
struct Session
{
/**
@@ -145,9 +146,17 @@
*/
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
*/
const struct sockaddr *sock_addr;
@@ -179,9 +188,11 @@
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 @@
const void *arg;
struct Session *session;
+
/**
* Number of bytes in source address.
*/
@@ -240,7 +252,7 @@
struct Session *session;
/**
- * Number of bytes in 'addr'.
+ * Number of bytes in @e addr.
*/
socklen_t addr_len;
@@ -292,27 +304,27 @@
/**
* 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 @@
GNUNET_TRANSPORT_TransmitContinuation cont;
/**
- * Closure for 'cont'.
+ * Closure for @e cont.
*/
void *cont_cls;
@@ -1110,7 +1122,8 @@
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 @@
&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 @@
if (udpw->session == s)
{
dequeue (plugin, udpw);
- call_continuation(udpw, GNUNET_SYSERR);
+ call_continuation (udpw, GNUNET_SYSERR);
GNUNET_free (udpw);
}
}
@@ -1243,7 +1261,7 @@
if (udpw->session == s)
{
dequeue (plugin, udpw);
- call_continuation(udpw, GNUNET_SYSERR);
+ call_continuation (udpw, GNUNET_SYSERR);
GNUNET_free (udpw);
}
}
@@ -1265,48 +1283,55 @@
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 @@
* 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 @@
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 @@
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 @@
if (NULL == addr)
{
- GNUNET_break (0);
- return NULL;
+ GNUNET_break (0);
+ return NULL;
}
switch (addrlen)
@@ -1399,11 +1426,12 @@
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 @@
}
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 @@
*
* @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 @@
{
/* 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 @@
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 @@
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 @@
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 @@
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 @@
}
/* 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 @@
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 @@
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;
Modified: gnunet/src/transport/plugin_transport_unix.c
===================================================================
--- gnunet/src/transport/plugin_transport_unix.c 2013-12-12 10:44:42 UTC
(rev 31299)
+++ gnunet/src/transport/plugin_transport_unix.c 2013-12-12 11:51:03 UTC
(rev 31300)
@@ -530,9 +530,6 @@
{
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 @@
* 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 @@
s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
}
GNUNET_free (s);
+ return GNUNET_OK;
}
@@ -610,13 +611,13 @@
* @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 @@
socklen_t un_len;
const char *unixpath;
-
GNUNET_assert (NULL != plugin);
if (NULL == send_handle)
{
@@ -734,7 +734,7 @@
const char *address;
/**
- * Number of bytes in 'address'
+ * Number of bytes in @e address
*/
size_t addrlen;
};
@@ -784,7 +784,7 @@
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 @@
* @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 @@
* 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 @@
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 @@
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 @@
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 @@
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 @@
* @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 @@
*
* @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 @@
/**
* 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 @@
* @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 @@
{
/* 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 @@
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 @@
/* 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;
Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c 2013-12-12 10:44:42 UTC
(rev 31299)
+++ gnunet/src/transport/plugin_transport_wlan.c 2013-12-12 11:51:03 UTC
(rev 31300)
@@ -597,8 +597,8 @@
if (NULL == endpoint)
{
- GNUNET_break (0);
- return;
+ GNUNET_break (0);
+ return;
}
if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
@@ -654,10 +654,12 @@
/**
* 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 @@
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 @@
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 @@
* 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 @@
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 @@
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 @@
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 @@
* @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 @@
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 @@
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;
Modified: gnunet/src/transport/test_plugin_transport.c
===================================================================
--- gnunet/src/transport/test_plugin_transport.c 2013-12-12 10:44:42 UTC
(rev 31299)
+++ gnunet/src/transport/test_plugin_transport.c 2013-12-12 11:51:03 UTC
(rev 31300)
@@ -695,8 +695,8 @@
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 ();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r31300 - in gnunet/src: dv include namestore transport,
gnunet <=