/*
This file is part of GNUnet
- (C) 2010-2014 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2010-2014 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
/**
* Timeout task (for this message).
*/
- GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+ struct GNUNET_SCHEDULER_Task * timeout_task;
};
/**
* Timeout task (for the session).
*/
- GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+ struct GNUNET_SCHEDULER_Task * timeout_task;
};
/**
* Timeout task.
*/
- GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+ struct GNUNET_SCHEDULER_Task * timeout_task;
/**
* Continuation to call when we're done with this message.
*/
GNUNET_TRANSPORT_TransmitContinuation cont;
+ /**
+ * Message we need to fragment and transmit, NULL after the
+ * @e fragmentcontext has been created.
+ */
+ struct GNUNET_MessageHeader *msg;
+
/**
* Closure for @e cont
*/
/**
* Timeout task.
*/
- GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+ struct GNUNET_SCHEDULER_Task * timeout_task;
/**
* count of messages in the fragment out queue for this mac endpoint
/**
* The interface of the wlan card given to us by the user.
*/
- char *interface;
+ char *wlan_interface;
/**
* Tokenizer for demultiplexing of data packets resulting from
/**
* Task that periodically sends a HELLO beacon via the helper.
*/
- GNUNET_SCHEDULER_TaskIdentifier beacon_task;
+ struct GNUNET_SCHEDULER_Task *beacon_task;
/**
* Tracker for bandwidth limit
* @param hdr pointer to the hdr where the ack is stored
*/
static void
-send_ack (void *cls, uint32_t msg_id,
+send_ack (void *cls,
+ uint32_t msg_id,
const struct GNUNET_MessageHeader *hdr)
{
struct MacEndpoint *endpoint = cls;
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending ACK to helper\n");
+ "Sending ACK to %s\n",
+ mac_to_string (&endpoint->wlan_addr.mac));
radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf;
get_radiotap_header (endpoint, radio_header, size);
get_wlan_header (endpoint->plugin,
session);
notify_session_monitor (plugin,
session,
- GNUNET_TRANSPORT_SS_DOWN);
+ GNUNET_TRANSPORT_SS_DONE);
GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head,
endpoint->sessions_tail,
session);
- if (session->timeout_task != GNUNET_SCHEDULER_NO_TASK)
+ if (session->timeout_task != NULL)
{
GNUNET_SCHEDULER_cancel (session->timeout_task);
- session->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ session->timeout_task = NULL;
}
GNUNET_STATISTICS_update (plugin->env->stats,
_("# Sessions allocated"),
struct Session *session = cls;
struct GNUNET_TIME_Relative left;
- session->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ session->timeout_task = NULL;
left = GNUNET_TIME_absolute_get_remaining (session->timeout);
if (0 != left.rel_value_us)
{
session->timeout_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout,
session);
+ notify_session_monitor (endpoint->plugin,
+ session,
+ GNUNET_TRANSPORT_SS_INIT);
notify_session_monitor (endpoint->plugin,
session,
GNUNET_TRANSPORT_SS_UP);
{
struct FragmentMessage *fm = cls;
-
fm->sh = NULL;
GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
}
radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf;
get_radiotap_header (endpoint, radio_header, size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending %u bytes of data to MAC `%s'\n",
+ (unsigned int) msize,
+ mac_to_string (&endpoint->wlan_addr.mac));
+
get_wlan_header (endpoint->plugin,
&radio_header->frame,
&endpoint->wlan_addr.mac,
&fragment_transmission_done, fm);
fm->size_on_wire += size;
if (NULL != fm->sh)
+ {
GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
_("# message fragments sent"),
1,
GNUNET_NO);
+ }
else
+ {
GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
+ }
GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
"# bytes currently in buffers",
-msize, GNUNET_NO);
GNUNET_HELPER_send_cancel (fm->sh);
fm->sh = NULL;
}
- GNUNET_FRAGMENT_context_destroy (fm->fragcontext,
- &endpoint->msg_delay,
- &endpoint->ack_delay);
- if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
+ if (NULL != fm->msg)
+ {
+ GNUNET_free (fm->msg);
+ fm->msg = NULL;
+ }
+ if (NULL != fm->fragcontext)
+ {
+ GNUNET_FRAGMENT_context_destroy (fm->fragcontext,
+ &endpoint->msg_delay,
+ &endpoint->ack_delay);
+ fm->fragcontext = NULL;
+ }
+ if (NULL != fm->timeout_task)
{
GNUNET_SCHEDULER_cancel (fm->timeout_task);
- fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ fm->timeout_task = NULL;
}
GNUNET_free (fm);
}
{
struct FragmentMessage *fm = cls;
- fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ fm->timeout_task = NULL;
if (NULL != fm->cont)
{
fm->cont (fm->cont_cls,
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,
- endpoint->msg_delay,
- endpoint->ack_delay,
- msg,
- &transmit_fragment, fm);
fm->timeout_task =
GNUNET_SCHEDULER_add_delayed (timeout,
- &fragmentmessage_timeout, fm);
+ &fragmentmessage_timeout,
+ fm);
+ if (GNUNET_YES == plugin->have_mac)
+ {
+ fm->fragcontext =
+ GNUNET_FRAGMENT_context_create (plugin->env->stats,
+ WLAN_MTU,
+ &plugin->tracker,
+ fm->macendpoint->msg_delay,
+ fm->macendpoint->ack_delay,
+ msg,
+ &transmit_fragment, fm);
+ }
+ else
+ {
+ fm->msg = GNUNET_copy_message (msg);
+ }
GNUNET_CONTAINER_DLL_insert_tail (endpoint->sending_messages_head,
endpoint->sending_messages_tail,
fm);
}
plugin->mac_count--;
- if (GNUNET_SCHEDULER_NO_TASK != endpoint->timeout_task)
+ if (NULL != endpoint->timeout_task)
{
GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
- endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ endpoint->timeout_task = NULL;
}
GNUNET_free (endpoint);
}
struct MacEndpoint *endpoint = cls;
struct GNUNET_TIME_Relative timeout;
- endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ endpoint->timeout_task = NULL;
timeout = GNUNET_TIME_absolute_get_remaining (endpoint->timeout);
if (0 == timeout.rel_value_us)
{
wlanheader->sender = *plugin->env->my_identity;
wlanheader->target = session->target;
wlanheader->crc = htonl (GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size));
- memcpy (&wlanheader[1], msgbuf, msgbuf_size);
-
+ memcpy (&wlanheader[1],
+ msgbuf,
+ msgbuf_size);
GNUNET_STATISTICS_update (plugin->env->stats,
"# bytes currently in buffers",
msgbuf_size,
GNUNET_NO);
-
send_with_fragmentation (session->mac,
to,
&session->target,
struct Plugin *plugin = cls;
struct GNUNET_HELLO_Address *address;
struct MacAndSession *mas = client;
- struct MacAndSession xmas;
struct GNUNET_ATS_Information ats;
struct FragmentMessage *fm;
struct GNUNET_PeerIdentity tmpsource;
PLUGIN_NAME,
&mas->endpoint->wlan_addr,
sizeof (mas->endpoint->wlan_addr),
- GNUNET_HELLO_ADDRESS_INFO_INBOUND);
+ GNUNET_HELLO_ADDRESS_INFO_NONE);
+ mas->session = lookup_session (mas->endpoint,
+ &tmpsource);
+ if (NULL == mas->session)
+ {
+ mas->session = create_session (mas->endpoint,
+ &tmpsource);
+ plugin->env->session_start (plugin->env->cls,
+ address,
+ mas->session,
+ &ats, 1);
+ }
plugin->env->receive (plugin->env->cls,
address,
mas->session,
break;
}
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "ACK not matched against any active fragmentation with MAC `%s'\n",
- wlan_plugin_address_to_string (NULL,
- &mas->endpoint->wlan_addr,
- sizeof (mas->endpoint->wlan_addr)));
+ if (NULL == fm)
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "ACK not matched against any active fragmentation with MAC `%s'\n",
+ wlan_plugin_address_to_string (NULL,
+ &mas->endpoint->wlan_addr,
+ sizeof (mas->endpoint->wlan_addr)));
break;
case GNUNET_MESSAGE_TYPE_WLAN_DATA:
if (NULL == mas->endpoint)
GNUNET_NO);
break;
}
- xmas.endpoint = mas->endpoint;
- if (NULL == (xmas.session = lookup_session (mas->endpoint,
- &wlanheader->sender)))
+ mas->session = lookup_session (mas->endpoint,
+ &wlanheader->sender);
+ if (NULL == mas->session)
{
- xmas.session = create_session (mas->endpoint,
+ mas->session = create_session (mas->endpoint,
&wlanheader->sender);
address = GNUNET_HELLO_address_allocate (&wlanheader->sender,
PLUGIN_NAME,
&mas->endpoint->wlan_addr,
sizeof (struct WlanAddress),
GNUNET_HELLO_ADDRESS_INFO_NONE);
- plugin->env->session_start (NULL,
+ plugin->env->session_start (plugin->env->cls,
address,
- xmas.session,
+ mas->session,
NULL, 0);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Notifying transport about peer `%s''s new session %p \n",
+ "Notifying transport about peer `%s''s new session %p \n",
GNUNET_i2s (&wlanheader->sender),
- xmas.session);
+ mas->session);
GNUNET_HELLO_address_free (address);
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Processing %u bytes of DATA from peer `%s'\n",
(unsigned int) msize,
GNUNET_i2s (&wlanheader->sender));
- xmas.session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ mas->session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
(void) GNUNET_SERVER_mst_receive (plugin->wlan_header_payload_tokenizer,
- &xmas,
+ mas,
(const char *) &wlanheader[1],
msize - sizeof (struct WlanHeader),
GNUNET_YES,
}
+/**
+ * Task to (periodically) send a HELLO beacon
+ *
+ * @param cls pointer to the plugin struct
+ * @param tc scheduler context
+ */
+static void
+send_hello_beacon (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct Plugin *plugin = cls;
+ uint16_t size;
+ uint16_t hello_size;
+ struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radioHeader;
+ const struct GNUNET_MessageHeader *hello;
+
+ hello = plugin->env->get_our_hello ();
+ hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
+ GNUNET_assert (sizeof (struct WlanHeader) + hello_size <= WLAN_MTU);
+ size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + hello_size;
+ {
+ char buf[size] GNUNET_ALIGN;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending %u byte HELLO beacon\n",
+ (unsigned int) size);
+ radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*) buf;
+ get_radiotap_header (NULL, radioHeader, size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Broadcasting %u bytes of data to MAC `%s'\n",
+ (unsigned int) size,
+ mac_to_string (&bc_all_mac));
+ get_wlan_header (plugin, &radioHeader->frame, &bc_all_mac, size);
+ memcpy (&radioHeader[1], hello, hello_size);
+ if (NULL !=
+ GNUNET_HELPER_send (plugin->suid_helper,
+ &radioHeader->header,
+ GNUNET_YES /* can drop */,
+ NULL, NULL))
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ _("# HELLO beacons sent"),
+ 1, GNUNET_NO);
+ }
+ plugin->beacon_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (HELLO_BEACON_SCALING_FACTOR,
+ plugin->mac_count + 1),
+ &send_hello_beacon,
+ plugin);
+
+}
+
+
/**
* Function used for to process the data from the suid process
*
struct WlanAddress wa;
struct MacAndSession mas;
uint16_t msize;
+ struct FragmentMessage *fm;
+ struct MacEndpoint *endpoint;
msize = ntohs (hdr->size);
switch (ntohs (hdr->type))
GNUNET_NO,
my_address);
GNUNET_HELLO_address_free (my_address);
+ plugin->mac_address = cm->mac;
+ }
+ else
+ {
+ plugin->mac_address = cm->mac;
+ plugin->have_mac = GNUNET_YES;
+ for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next)
+ {
+ for (fm = endpoint->sending_messages_head; NULL != fm; fm = fm->next)
+ {
+ if (NULL != fm->fragcontext)
+ {
+ GNUNET_break (0); /* should not happen */
+ continue;
+ }
+ fm->fragcontext =
+ GNUNET_FRAGMENT_context_create (plugin->env->stats,
+ WLAN_MTU,
+ &plugin->tracker,
+ fm->macendpoint->msg_delay,
+ fm->macendpoint->ack_delay,
+ fm->msg,
+ &transmit_fragment, fm);
+ GNUNET_free (fm->msg);
+ fm->msg = NULL;
+ }
+ }
+ GNUNET_break (NULL == plugin->beacon_task);
+ plugin->beacon_task = GNUNET_SCHEDULER_add_now (&send_hello_beacon,
+ plugin);
+
}
- plugin->mac_address = cm->mac;
- plugin->have_mac = GNUNET_YES;
memset (&wa, 0, sizeof (struct WlanAddress));
wa.mac = plugin->mac_address;
GNUNET_NO);
if (msize < sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage))
{
- GNUNET_break (0);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Size of packet is too small (%u bytes)\n",
- msize);
+ "Size of packet is too small (%u bytes < %u)\n",
+ msize, sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage));
break;
}
rxinfo = (const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) hdr;
"Receiving %u bytes of data from MAC `%s'\n",
(unsigned int) (msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
mac_to_string (&rxinfo->frame.addr2));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Receiving %u bytes of data to MAC `%s'\n",
+ (unsigned int) (msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
+ mac_to_string (&rxinfo->frame.addr1));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Receiving %u bytes of data with BSSID MAC `%s'\n",
+ (unsigned int) (msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
+ mac_to_string (&rxinfo->frame.addr3));
wa.mac = rxinfo->frame.addr2;
wa.options = htonl (0);
mas.endpoint = create_macendpoint (plugin, &wa);
}
-/**
- * Task to (periodically) send a HELLO beacon
- *
- * @param cls pointer to the plugin struct
- * @param tc scheduler context
- */
-static void
-send_hello_beacon (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct Plugin *plugin = cls;
- uint16_t size;
- uint16_t hello_size;
- struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radioHeader;
- const struct GNUNET_MessageHeader *hello;
-
- hello = plugin->env->get_our_hello ();
- hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
- GNUNET_assert (sizeof (struct WlanHeader) + hello_size <= WLAN_MTU);
- size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + hello_size;
- {
- char buf[size] GNUNET_ALIGN;
-
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending %u byte HELLO beacon\n",
- (unsigned int) size);
- radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*) buf;
- get_radiotap_header (NULL, radioHeader, size);
- get_wlan_header (plugin, &radioHeader->frame, &bc_all_mac, size);
- memcpy (&radioHeader[1], hello, hello_size);
- if (NULL !=
- GNUNET_HELPER_send (plugin->suid_helper,
- &radioHeader->header,
- GNUNET_YES /* can drop */,
- NULL, NULL))
- GNUNET_STATISTICS_update (plugin->env->stats,
- _("# HELLO beacons sent"),
- 1, GNUNET_NO);
- }
- plugin->beacon_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (HELLO_BEACON_SCALING_FACTOR,
- plugin->mac_count + 1),
- &send_hello_beacon,
- plugin);
-
-}
-
-
/**
* Another peer has suggested an address for this
* peer and transport plugin. Check that this could be a valid
GNUNET_HELLO_address_free (address);
}
- if (GNUNET_SCHEDULER_NO_TASK != plugin->beacon_task)
+ if (NULL != plugin->beacon_task)
{
GNUNET_SCHEDULER_cancel (plugin->beacon_task);
- plugin->beacon_task = GNUNET_SCHEDULER_NO_TASK;
+ plugin->beacon_task = NULL;
}
if (NULL != plugin->suid_helper)
{
GNUNET_SERVER_mst_destroy (plugin->helper_payload_tokenizer);
plugin->helper_payload_tokenizer = NULL;
}
- GNUNET_free_non_null (plugin->interface);
+ GNUNET_free_non_null (plugin->wlan_interface);
GNUNET_free (plugin);
GNUNET_free (api);
return NULL;
{
for (mac = plugin->mac_head; NULL != mac; mac = mac->next)
for (session = mac->sessions_head; NULL != session; session = session->next)
+ {
+ notify_session_monitor (plugin,
+ session,
+ GNUNET_TRANSPORT_SS_INIT);
notify_session_monitor (plugin,
session,
GNUNET_TRANSPORT_SS_UP);
+ }
sic (sic_cls, NULL, NULL);
}
}
const struct GNUNET_PeerIdentity *peer,
struct Session *session)
{
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != session->timeout_task);
+ GNUNET_assert (NULL != session->timeout_task);
session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
}
struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
struct GNUNET_TRANSPORT_PluginFunctions *api;
struct Plugin *plugin;
- char *interface;
+ char *wlan_interface;
unsigned long long testmode;
char *binary;
GNUNET_CONFIGURATION_get_value_string (env->cfg,
CONFIG_NAME,
"INTERFACE",
- &interface))
+ &wlan_interface))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
CONFIG_NAME,
}
plugin = GNUNET_new (struct Plugin);
- plugin->interface = interface;
+ plugin->wlan_interface = wlan_interface;
plugin->env = env;
GNUNET_STATISTICS_set (plugin->env->stats,
_("# sessions allocated"),
GNUNET_BANDWIDTH_value_init (100 * 1024 *
1024 / 8),
100);
- plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
- plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
- plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
- plugin->beacon_task = GNUNET_SCHEDULER_add_now (&send_hello_beacon,
- plugin);
+ plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data,
+ plugin);
+ plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data,
+ plugin);
+ plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data,
+ plugin);
plugin->options = 0;
{
case 0: /* normal */
plugin->helper_argv[0] = (char *) HELPER_NAME;
- plugin->helper_argv[1] = interface;
+ plugin->helper_argv[1] = wlan_interface;
plugin->helper_argv[2] = NULL;
plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO,
HELPER_NAME,