/*
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
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
#define WLAN_MTU 1430
+/**
+ * Which network scope do we belong to?
+ */
+#if BUILD_WLAN
+static const enum GNUNET_ATS_Network_Type scope = GNUNET_ATS_NET_WLAN;
+#else
+static const enum GNUNET_ATS_Network_Type scope = GNUNET_ATS_NET_BT;
+#endif
+
/**
* Maximum number of messages in defragmentation queue per MAC
/**
* Session handle for connections with other peers.
*/
-struct Session
+struct GNUNET_ATS_Session
{
/**
* To whom are we talking to (set to our identity
* We keep all sessions in a DLL at their respective
* `struct MACEndpoint *`.
*/
- struct Session *next;
+ struct GNUNET_ATS_Session *next;
/**
* We keep all sessions in a DLL at their respective
* `struct MACEndpoint *`.
*/
- struct Session *prev;
+ struct GNUNET_ATS_Session *prev;
/**
* MAC endpoint with the address of this peer.
/**
* Head of sessions that use this MAC.
*/
- struct Session *sessions_head;
+ struct GNUNET_ATS_Session *sessions_head;
/**
* Tail of sessions that use this MAC.
*/
- struct Session *sessions_tail;
+ struct GNUNET_ATS_Session *sessions_tail;
/**
* Head of messages we are currently sending to this MAC.
/**
* NULL if the identity of the other peer is not known.
*/
- struct Session *session;
+ struct GNUNET_ATS_Session *session;
/**
* MAC address of the other peer, NULL if not known.
*/
static void
notify_session_monitor (struct Plugin *plugin,
- struct Session *session,
+ struct GNUNET_ATS_Session *session,
enum GNUNET_TRANSPORT_SessionState state)
{
struct GNUNET_TRANSPORT_SessionInfo info;
*/
static int
wlan_plugin_disconnect_session (void *cls,
- struct Session *session)
+ struct GNUNET_ATS_Session *session)
{
struct MacEndpoint *endpoint = session->mac;
struct Plugin *plugin = endpoint->plugin;
session_timeout (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct Session *session = cls;
+ struct GNUNET_ATS_Session *session = cls;
struct GNUNET_TIME_Relative left;
session->timeout_task = NULL;
* @param peer peer identity to use for this session
* @return returns the session or NULL
*/
-static struct Session *
+static struct GNUNET_ATS_Session *
lookup_session (struct MacEndpoint *endpoint,
const struct GNUNET_PeerIdentity *peer)
{
- struct Session *session;
+ struct GNUNET_ATS_Session *session;
for (session = endpoint->sessions_head; NULL != session; session = session->next)
if (0 == memcmp (peer, &session->target, sizeof (struct GNUNET_PeerIdentity)))
* @param peer peer identity to use for this session
* @return returns the session or NULL
*/
-static struct Session *
+static struct GNUNET_ATS_Session *
create_session (struct MacEndpoint *endpoint,
const struct GNUNET_PeerIdentity *peer)
{
- struct Session *session;
+ struct GNUNET_ATS_Session *session;
GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
_("# Sessions allocated"),
1,
GNUNET_NO);
- session = GNUNET_new (struct Session);
+ session = GNUNET_new (struct GNUNET_ATS_Session);
GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
endpoint->sessions_tail,
session);
* @param peer peer identity to use for this session
* @return returns the session
*/
-static struct Session *
+static struct GNUNET_ATS_Session *
get_session (struct MacEndpoint *endpoint,
const struct GNUNET_PeerIdentity *peer)
{
- struct Session *session;
+ struct GNUNET_ATS_Session *session;
if (NULL != (session = lookup_session (endpoint, peer)))
return session;
fm->sh = NULL;
GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
- fm->fragcontext = NULL;
}
else
{
GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
- fm->fragcontext = NULL;
}
GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
"# bytes currently in buffers",
GNUNET_FRAGMENT_context_destroy (fm->fragcontext,
&endpoint->msg_delay,
&endpoint->ack_delay);
+ fm->fragcontext = NULL;
}
if (NULL != fm->timeout_task)
{
{
struct Plugin *plugin = endpoint->plugin;
struct FragmentMessage *fm;
- struct Session *session;
+ struct GNUNET_ATS_Session *session;
GNUNET_STATISTICS_update (plugin->env->stats,
_("# MAC endpoints allocated"),
*/
static enum GNUNET_ATS_Network_Type
wlan_plugin_get_network (void *cls,
- struct Session *session)
+ struct GNUNET_ATS_Session *session)
+{
+#if BUILD_WLAN
+ return GNUNET_ATS_NET_WLAN;
+#else
+ return GNUNET_ATS_NET_BT;
+#endif
+}
+
+
+/**
+ * Function obtain the network type for an address.
+ *
+ * @param cls closure (`struct Plugin *`)
+ * @param address the address
+ * @return the network type
+ */
+static enum GNUNET_ATS_Network_Type
+wlan_plugin_get_network_for_address (void *cls,
+ const struct GNUNET_HELLO_Address *address)
{
#if BUILD_WLAN
return GNUNET_ATS_NET_WLAN;
* @param address the address
* @return the session or NULL of max connections exceeded
*/
-static struct Session *
+static struct GNUNET_ATS_Session *
wlan_plugin_get_session (void *cls,
const struct GNUNET_HELLO_Address *address)
{
const struct GNUNET_PeerIdentity *target)
{
struct Plugin *plugin = cls;
- struct Session *session;
+ struct GNUNET_ATS_Session *session;
struct MacEndpoint *endpoint;
for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next)
*/
static ssize_t
wlan_plugin_send (void *cls,
- struct Session *session,
+ struct GNUNET_ATS_Session *session,
const char *msgbuf, size_t msgbuf_size,
unsigned int priority,
struct GNUNET_TIME_Relative to,
struct Plugin *plugin = cls;
struct GNUNET_HELLO_Address *address;
struct MacAndSession *mas = client;
- struct GNUNET_ATS_Information ats;
struct FragmentMessage *fm;
struct GNUNET_PeerIdentity tmpsource;
const struct WlanHeader *wlanheader;
int ret;
uint16_t msize;
- ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
-#if BUILD_WLAN
- ats.value = htonl (GNUNET_ATS_NET_WLAN);
-#else
- ats.value = htonl (GNUNET_ATS_NET_BT);
-#endif
msize = ntohs (hdr->size);
GNUNET_STATISTICS_update (plugin->env->stats,
plugin->env->session_start (plugin->env->cls,
address,
mas->session,
- &ats, 1);
+ scope);
}
plugin->env->receive (plugin->env->cls,
address,
mas->session,
hdr);
- plugin->env->update_address_metrics (plugin->env->cls,
- address,
- mas->session,
- &ats, 1);
GNUNET_HELLO_address_free (address);
break;
case GNUNET_MESSAGE_TYPE_FRAGMENT:
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)
plugin->env->session_start (plugin->env->cls,
address,
mas->session,
- NULL, 0);
+ scope);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Notifying transport about peer `%s''s new session %p \n",
GNUNET_i2s (&wlanheader->sender),
mas->session->address,
mas->session,
hdr);
- plugin->env->update_address_metrics (plugin->env->cls,
- mas->session->address,
- mas->session,
- &ats, 1);
break;
}
return GNUNET_OK;
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;
+ if (NULL != 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;
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,
{
struct Plugin *plugin = cls;
struct MacEndpoint *mac;
- struct Session *session;
+ struct GNUNET_ATS_Session *session;
plugin->sic = sic;
plugin->sic_cls = sic_cls;
static void
wlan_plugin_update_session_timeout (void *cls,
const struct GNUNET_PeerIdentity *peer,
- struct Session *session)
+ struct GNUNET_ATS_Session *session)
{
GNUNET_assert (NULL != session->timeout_task);
session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
static void
wlan_plugin_update_inbound_delay (void *cls,
const struct GNUNET_PeerIdentity *peer,
- struct Session *session,
+ struct GNUNET_ATS_Session *session,
struct GNUNET_TIME_Relative delay)
{
/* does nothing, as inbound delay is not supported by WLAN */
api->address_to_string = &wlan_plugin_address_to_string;
api->string_to_address = &wlan_plugin_string_to_address;
api->get_network = &wlan_plugin_get_network;
+ api->get_network_for_address = &wlan_plugin_get_network_for_address;
api->update_session_timeout = &wlan_plugin_update_session_timeout;
api->update_inbound_delay = &wlan_plugin_update_inbound_delay;
api->setup_monitor = &wlan_plugin_setup_monitor;