* @brief transport plugin for wlan
* @author David Brodski
* @author Christian Grothoff
- *
- * TODO:
- * - HELPER-continuation may be called after fragment times out (-> use after free, see FIXME)
*/
#include "platform.h"
#include "gnunet_hello_lib.h"
#include "gnunet_fragmentation_lib.h"
#include "gnunet_constants.h"
-#define PROTOCOL_PREFIX "wlan"
-
#define LOG(kind,...) GNUNET_log_from (kind, "transport-wlan",__VA_ARGS__)
/**
*/
struct Session
{
+ /**
+ * To whom are we talking to (set to our identity
+ * if we are still waiting for the welcome message)
+ */
+ struct GNUNET_PeerIdentity target;
/**
* API requirement (must be first).
*/
struct PendingMessage *pending_message_tail;
- /**
- * To whom are we talking to (set to our identity
- * if we are still waiting for the welcome message)
- */
- struct GNUNET_PeerIdentity target;
-
/**
* When should this session time out?
*/
*/
void *cont_cls;
+ /**
+ * Size of original message
+ */
+ size_t size_payload;
+
+ /**
+ * Number of bytes used to transmit message
+ */
+ size_t size_on_wire;
+
};
/**
* Generate the WLAN hardware header for one packet
*
+ * @param plugin the plugin handle
* @param header address to write the header to
* @param to_mac_addr address of the recipient
* @param size size of the whole packet, needed to calculate the time to send the packet
{
struct FragmentMessage *fm = cls;
+
fm->sh = NULL;
GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
}
&radio_header->header,
GNUNET_NO,
&fragment_transmission_done, fm);
+ fm->size_on_wire += size;
if (NULL != fm->sh)
GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN message fragments sent"),
1, GNUNET_NO);
else
GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
+ GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
+ "# bytes currently in WLAN buffers",
+ -msize, GNUNET_NO);
+ GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
+ "# bytes transmitted via WLAN",
+ msize, GNUNET_NO);
}
}
GNUNET_HELPER_send_cancel (fm->sh);
fm->sh = NULL;
}
- GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
+ GNUNET_FRAGMENT_context_destroy (fm->fragcontext, NULL, NULL);
if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (fm->timeout_task);
fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
if (NULL != fm->cont)
{
- fm->cont (fm->cont_cls, &fm->target, GNUNET_SYSERR);
+ fm->cont (fm->cont_cls, &fm->target, GNUNET_SYSERR, fm->size_payload, fm->size_on_wire);
fm->cont = NULL;
}
free_fragment_message (fm);
* @param timeout how long can the message wait?
* @param target peer that should receive the message
* @param msg message to transmit
+ * @param payload_size bytes of payload
* @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
struct GNUNET_TIME_Relative timeout,
const struct GNUNET_PeerIdentity *target,
const struct GNUNET_MessageHeader *msg,
+ size_t payload_size,
GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
fm = GNUNET_malloc (sizeof (struct FragmentMessage));
fm->macendpoint = endpoint;
fm->target = *target;
+ fm->size_payload = payload_size;
+ fm->size_on_wire = 0;
fm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
+ fm->cont = cont;
+ fm->cont_cls = cont_cls;
+ /* 1 MBit/s typical data rate, 1430 byte fragments => ~100 ms per message */
fm->fragcontext =
GNUNET_FRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
&plugin->tracker,
GNUNET_TIME_UNIT_SECONDS,
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ 100),
msg,
&transmit_fragment, fm);
fm->timeout_task =
GNUNET_CONTAINER_DLL_remove (plugin->mac_head,
plugin->mac_tail,
endpoint);
+
+ if (NULL != endpoint->defrag)
+ {
+ GNUNET_DEFRAGMENT_context_destroy(endpoint->defrag);
+ endpoint->defrag = NULL;
+ }
+
plugin->mac_count--;
if (GNUNET_SCHEDULER_NO_TASK != endpoint->timeout_task)
{
wlanheader->target = session->target;
wlanheader->crc = htonl (GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size));
memcpy (&wlanheader[1], msgbuf, msgbuf_size);
+
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ "# bytes currently in WLAN buffers",
+ msgbuf_size, GNUNET_NO);
+
send_with_fragmentation (session->mac,
to,
&session->target,
&wlanheader->header,
+ msgbuf_size,
cont, cont_cls);
return size;
}
* @param client pointer to the session this message belongs to
* @param hdr start of the message
*/
-static void
+static int
process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
{
struct Plugin *plugin = cls;
ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
ats[1].value = htonl (GNUNET_ATS_NET_WLAN);
msize = ntohs (hdr->size);
+
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ "# bytes received via WLAN",
+ msize, GNUNET_NO);
+
switch (ntohs (hdr->type))
{
case GNUNET_MESSAGE_TYPE_HELLO:
mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT);
if (NULL != fm->cont)
{
- fm->cont (fm->cont_cls, &fm->target, GNUNET_OK);
+ fm->cont (fm->cont_cls, &fm->target, GNUNET_OK, fm->size_payload, fm->size_on_wire);
fm->cont = NULL;
}
free_fragment_message (fm);
(mas->endpoint == NULL) ? 0 : sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
break;
}
+ return GNUNET_OK;
}
#undef NUM_ATS
* @param client client that send the data (not used)
* @param hdr header of the GNUNET_MessageHeader
*/
-static void
+static int
handle_helper_message (void *cls, void *client,
const struct GNUNET_MessageHeader *hdr)
{
/* remove old address */
plugin->env->notify_address (plugin->env->cls, GNUNET_NO,
&plugin->mac_address,
- sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
+ sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress),
+ "wlan");
}
plugin->mac_address = cm->mac;
plugin->have_mac = GNUNET_YES;
GNUNET_i2s (plugin->env->my_identity));
plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
&plugin->mac_address,
- sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
+ sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress),
+ "wlan");
break;
case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER:
LOG (GNUNET_ERROR_TYPE_DEBUG,
ntohs (hdr->type), ntohs (hdr->size));
break;
}
+ return GNUNET_OK;
}
static const char *
wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
{
- static char ret[40];
const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
if (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress) != addrlen)
return NULL;
}
mac = addr;
- GNUNET_snprintf (ret, sizeof (ret), "%s MAC address %s",
- PROTOCOL_PREFIX,
- mac_to_string (mac));
- return ret;
+ return mac_to_string (mac);
}
return;
}
mac = addr;
- GNUNET_asprintf (&ret,
- "%s MAC address %s",
- PROTOCOL_PREFIX,
- mac_to_string (mac));
+ ret = GNUNET_strdup (mac_to_string (mac));
asc (asc_cls, ret);
GNUNET_free (ret);
asc (asc_cls, NULL);
GNUNET_free (api);
return NULL;
}
+
+ if (GNUNET_YES == plugin->have_mac)
+ {
+ plugin->env->notify_address (plugin->env->cls, GNUNET_NO,
+ &plugin->mac_address,
+ sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress),
+ "wlan");
+ plugin->have_mac = GNUNET_NO;
+ }
+
if (GNUNET_SCHEDULER_NO_TASK != plugin->beacon_task)
{
GNUNET_SCHEDULER_cancel (plugin->beacon_task);
}
+/**
+ * Function called to convert a string address to
+ * a binary address.
+ *
+ * @param cls closure ('struct Plugin*')
+ * @param addr string address
+ * @param addrlen length of the address
+ * @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
+ */
+static int
+wlan_string_to_address (void *cls, const char *addr, uint16_t addrlen,
+ void **buf, size_t *added)
+{
+ struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
+ unsigned int a[6];
+ unsigned int i;
+
+ if ((NULL == addr) || (addrlen == 0))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if ('\0' != addr[addrlen - 1])
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (strlen (addr) != addrlen - 1)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (6 != SSCANF (addr,
+ "%X:%X:%X:%X:%X:%X",
+ &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ mac = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
+ for (i=0;i<6;i++)
+ mac->mac[i] = a[i];
+ *buf = mac;
+ *added = sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress);
+ return GNUNET_OK;
+}
+
+
/**
* Entry point for the plugin.
*
api->cls = NULL;
api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
api->address_to_string = &wlan_plugin_address_to_string;
- api->string_to_address = NULL; // FIXME!
+ api->string_to_address = &wlan_string_to_address;
return api;
}
+ testmode = 0;
/* check configuration */
if ( (GNUNET_YES ==
GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE")) &&
GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan",
"TESTMODE", &testmode)) ||
(testmode > 2) ) )
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Invalid configuration option `%s' in section `%s'\n"),
- "TESTMODE",
- "transport-wlan");
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "transport-wlan", "TESTMODE");
return NULL;
}
if ( (0 == testmode) &&
(env->cfg, "transport-wlan", "INTERFACE",
&interface))
{
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Missing configuration option `%s' in section `%s'\n"),
- "INTERFACE",
- "transport-wlan");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "transport-wlan", "INTERFACE");
return NULL;
}
plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
plugin->beacon_task = GNUNET_SCHEDULER_add_now (&send_hello_beacon,
plugin);
- switch (testmode)
+ /* some compilers do not like switch on 'long long'... */
+ switch ((unsigned int) testmode)
{
case 0: /* normal */
plugin->helper_argv[0] = (char *) "gnunet-helper-transport-wlan";
plugin->helper_argv[1] = interface;
plugin->helper_argv[2] = NULL;
- plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan",
+ plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO,
+ "gnunet-helper-transport-wlan",
plugin->helper_argv,
&handle_helper_message,
+ NULL,
plugin);
break;
case 1: /* testmode, peer 1 */
plugin->helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy";
plugin->helper_argv[1] = (char *) "1";
plugin->helper_argv[2] = NULL;
- plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan-dummy",
+ plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO,
+ "gnunet-helper-transport-wlan-dummy",
plugin->helper_argv,
&handle_helper_message,
+ NULL,
plugin);
break;
case 2: /* testmode, peer 2 */
plugin->helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy";
plugin->helper_argv[1] = (char *) "2";
plugin->helper_argv[2] = NULL;
- plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan-dummy",
+ plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO,
+ "gnunet-helper-transport-wlan-dummy",
plugin->helper_argv,
&handle_helper_message,
+ NULL,
plugin);
break;
default:
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;
+ api->string_to_address = &wlan_string_to_address;
return api;
}