}
GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# Bluetooth sessions allocated"), 1,
GNUNET_NO);
- session = GNUNET_malloc (sizeof (struct Session));
+ session = GNUNET_new (struct Session);
GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
endpoint->sessions_tail,
session);
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)
struct Plugin *plugin;
plugin = endpoint->plugin;
- fm = GNUNET_malloc (sizeof (struct FragmentMessage));
+ fm = GNUNET_new (struct FragmentMessage);
fm->macendpoint = endpoint;
fm->target = *target;
fm->size_payload = payload_size;
for (pos = plugin->mac_head; NULL != pos; pos = pos->next)
if (0 == memcmp (addr, &pos->addr, sizeof (struct WlanAddress)))
return pos;
- pos = GNUNET_malloc (sizeof (struct MacEndpoint));
+ pos = GNUNET_new (struct MacEndpoint);
pos->addr = *addr;
pos->plugin = plugin;
pos->defrag =
* @param target peer from which to disconnect
*/
static void
-bluetooth_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
+bluetooth_plugin_disconnect_peer (void *cls, const struct GNUNET_PeerIdentity *target)
{
struct Plugin *plugin = cls;
struct Session *session;
for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next)
for (session = endpoint->sessions_head; NULL != session; session = session->next)
if (0 == memcmp (target, &session->target,
- sizeof (struct GNUNET_PeerIdentity)))
+ sizeof (struct GNUNET_PeerIdentity)))
{
free_session (session);
- break; /* inner-loop only (in case peer has another MAC as well!) */
+ break; /* inner-loop only (in case peer has another MAC as well!) */
}
}
+/**
+ * Function that can be used to force the plugin to disconnect
+ * from the given peer and cancel all previous transmissions
+ * (and their continuation).
+ *
+ * @param cls closure
+ * @param session session to disconnect
+ */
+static int
+bluetooth_plugin_disconnect_session (void *cls,
+ struct Session *session)
+{
+ free_session (session);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function that is called to get the keepalive factor.
+ * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
+ * calculate the interval between keepalive packets.
+ *
+ * @param cls closure with the `struct Plugin`
+ * @return keepalive factor
+ */
+static unsigned int
+bluetooth_query_keepalive_factor (void *cls)
+{
+ return 3;
+}
+
+
/**
* Function that can be used by the transport service to transmit
* a message using the plugin. Note that in the case of a
GNUNET_break (0);
return GNUNET_SYSERR;
}
- wa = GNUNET_malloc (sizeof (struct WlanAddress));
+ wa = GNUNET_new (struct WlanAddress);
for (i=0;i<6;i++)
wa->mac.mac[i] = a[i];
wa->options = htonl (0);
return GNUNET_OK;
}
+static void
+bluetooth_plugin_update_session_timeout (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct Session *session)
+{
+ if (GNUNET_SCHEDULER_NO_TASK != session->timeout_task)
+ GNUNET_SCHEDULER_cancel (session->timeout_task);
+ session->timeout_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session);
+}
+
+
/**
* Entry point for the plugin.
{
/* 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 = &bluetooth_plugin_address_pretty_printer;
api->address_to_string = &bluetooth_plugin_address_to_string;
return NULL;
}
- plugin = GNUNET_malloc (sizeof (struct Plugin));
+ plugin = GNUNET_new (struct Plugin);
plugin->interface = interface;
plugin->env = env;
GNUNET_STATISTICS_set (plugin->env->stats, _("# Bluetooth sessions allocated"),
GNUNET_assert (0);
}
- api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
+ api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
api->cls = plugin;
api->send = &bluetooth_plugin_send;
api->get_session = &bluetooth_plugin_get_session;
- api->disconnect = &bluetooth_plugin_disconnect;
+ api->disconnect_peer = &bluetooth_plugin_disconnect_peer;
+ api->disconnect_session = &bluetooth_plugin_disconnect_session;
+ api->query_keepalive_factor = &bluetooth_query_keepalive_factor;
api->address_pretty_printer = &bluetooth_plugin_address_pretty_printer;
api->check_address = &bluetooth_plugin_address_suggested;
api->address_to_string = &bluetooth_plugin_address_to_string;;
api->string_to_address = &bluetooth_string_to_address;
api->get_network = &bluetooth_get_network;
+ api->update_session_timeout = &bluetooth_plugin_update_session_timeout;
return api;
}