[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r16377 - in gnunet/src: include transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r16377 - in gnunet/src: include transport |
Date: |
Thu, 4 Aug 2011 21:29:40 +0200 |
Author: grothoff
Date: 2011-08-04 21:29:40 +0200 (Thu, 04 Aug 2011)
New Revision: 16377
Modified:
gnunet/src/include/gnunet_transport_plugin.h
gnunet/src/transport/gnunet-service-transport-new.c
gnunet/src/transport/gnunet-service-transport.c
gnunet/src/transport/gnunet-service-transport_plugins.c
gnunet/src/transport/plugin_transport_wlan.c
Log:
implementing plugins subsystem
Modified: gnunet/src/include/gnunet_transport_plugin.h
===================================================================
--- gnunet/src/include/gnunet_transport_plugin.h 2011-08-04 16:44:14 UTC
(rev 16376)
+++ gnunet/src/include/gnunet_transport_plugin.h 2011-08-04 19:29:40 UTC
(rev 16377)
@@ -177,6 +177,12 @@
/**
+ * Function that returns a HELLO message.
+ */
+typedef const struct GNUNET_MessageHeader *
(*GNUNET_TRANSPORT_GetHelloCallback)(void);
+
+
+/**
* The transport service will pass a pointer to a struct
* of this type as the first and only argument to the
* entry point of each transport plugin.
@@ -194,12 +200,6 @@
const struct GNUNET_PeerIdentity *my_identity;
/**
- * Pointer (!) to our HELLO message. Note that the address
- * referred to "*our_hello" might change over time.
- */
- struct GNUNET_HELLO_Message *const*our_hello;
-
- /**
* Closure for the various callbacks.
*/
void *cls;
@@ -215,7 +215,13 @@
*/
GNUNET_TRANSPORT_PluginReceiveCallback receive;
+
/**
+ * Function that returns our HELLO.
+ */
+ GNUNET_TRANSPORT_GetHelloCallback get_our_hello;
+
+ /**
* Function that must be called by each plugin to notify the
* transport service about the addresses under which the transport
* provided by the plugin can be reached.
Modified: gnunet/src/transport/gnunet-service-transport-new.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport-new.c 2011-08-04 16:44:14 UTC
(rev 16376)
+++ gnunet/src/transport/gnunet-service-transport-new.c 2011-08-04 19:29:40 UTC
(rev 16377)
@@ -89,6 +89,32 @@
/**
+ * Function that will be called for each address the transport
+ * is aware that it might be reachable under. Update our HELLO.
+ *
+ * @param cls name of the plugin (const char*)
+ * @param add_remove should the address added (YES) or removed (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
+ */
+static void
+plugin_env_address_change_notification (void *cls,
+ int add_remove,
+ const void *addr,
+ size_t addrlen)
+{
+ const char *plugin_name = cls;
+
+ GST_hello_modify_addresses (add_remove,
+ plugin_name,
+ addr,
+ addrlen);
+}
+
+
+/**
* Function called when the service shuts down. Unloads our plugins
* and cancels pending validations.
*
@@ -99,6 +125,8 @@
shutdown_task (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+
+ GST_plugins_unload ();
GST_hello_stop ();
if (GST_peerinfo != NULL)
@@ -174,7 +202,14 @@
GNUNET_SCHEDULER_shutdown ();
return;
}
+
+ /* start subsystems */
GST_hello_start (&process_hello_update, NULL);
+ GST_plugins_load (NULL, // FIXME...
+ &plugin_env_address_change_notification,
+ NULL, // FIXME...
+ NULL, // FIXME...
+ NULL); // FIXME...
}
Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c 2011-08-04 16:44:14 UTC
(rev 16376)
+++ gnunet/src/transport/gnunet-service-transport.c 2011-08-04 19:29:40 UTC
(rev 16377)
@@ -6131,6 +6131,13 @@
}
+static const struct GNUNET_MessageHeader *
+do_get_our_hello ()
+{
+ return (const struct GNUNET_MessageHeader*) our_hello;
+}
+
+
/**
* Setup the environment for this plugin.
*/
@@ -6139,7 +6146,7 @@
{
plug->env.cfg = cfg;
plug->env.my_identity = &my_identity;
- plug->env.our_hello = &our_hello;
+ plug->env.get_our_hello = &do_get_our_hello;
plug->env.cls = plug;
plug->env.receive = &plugin_env_receive;
plug->env.notify_address = &plugin_env_notify_address;
Modified: gnunet/src/transport/gnunet-service-transport_plugins.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_plugins.c 2011-08-04
16:44:14 UTC (rev 16376)
+++ gnunet/src/transport/gnunet-service-transport_plugins.c 2011-08-04
19:29:40 UTC (rev 16377)
@@ -24,6 +24,8 @@
* @author Christian Grothoff
*/
#include "platform.h"
+#include "gnunet-service-transport.h"
+#include "gnunet-service-transport_hello.h"
#include "gnunet-service-transport_plugins.h"
/**
@@ -73,7 +75,7 @@
/**
* Head of DLL of all loaded plugins.
*/
-// static struct TransportPlugin *plugins_tail;
+static struct TransportPlugin *plugins_tail;
@@ -96,56 +98,66 @@
GNUNET_TRANSPORT_SessionEnd session_end_cb,
GNUNET_TRANSPORT_CostReport cost_cb)
{
-#if 0
struct TransportPlugin *plug;
+ unsigned long long tneigh;
char *libname;
+ char *plugs;
+ char *pos;
- /* load plugins... */
- no_transports = 1;
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (c,
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (GST_cfg,
+ "TRANSPORT",
+ "NEIGHBOUR_LIMIT",
+ &tneigh))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Transport service is lacking NEIGHBOUR_LIMIT option.\n"));
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (GST_cfg,
"TRANSPORT", "PLUGINS", &plugs))
- {
+ return;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Starting transport plugins `%s'\n"),
+ plugs);
+ for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
+ {
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Starting transport plugins `%s'\n"), plugs);
- pos = strtok (plugs, " ");
- while (pos != NULL)
- {
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Loading `%s' transport plugin\n"), name);
- GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", name);
- plug = GNUNET_malloc (sizeof (struct TransportPlugin));
- plug->short_name = GNUNET_strdup (name);
- plug->lib_name = libname;
- plug->env.cfg = cfg;
- plug->env.my_identity = &my_identity;
- plug->env.our_hello = &our_hello;
- plug->env.cls = plug->short_name;
- plug->env.receive = &plugin_env_receive;
- plug->env.notify_address = &plugin_env_notify_address;
- plug->env.session_end = &plugin_env_session_end;
- plug->env.max_connections = max_connect_per_transport;
- plug->env.stats = stats;
- plug->next = plugins;
- plugins = plug;
- plug->api = GNUNET_PLUGIN_load (libname, &plug->env);
- if (plug->api == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load transport plugin for `%s'\n"),
name);
- GNUNET_free (plug->short_name);
- plugins = plug->next;
- GNUNET_free (libname);
- GNUNET_free (plug);
- }
- start_transport (server, pos);
- no_transports = 0;
- pos = strtok (NULL, " ");
- }
- GNUNET_free (plugs);
+ _("Loading `%s' transport plugin\n"), pos);
+ GNUNET_asprintf (&libname,
+ "libgnunet_plugin_transport_%s",
+ pos);
+ plug = GNUNET_malloc (sizeof (struct TransportPlugin));
+ plug->short_name = GNUNET_strdup (pos);
+ plug->lib_name = libname;
+ plug->env.cfg = GST_cfg;
+ plug->env.my_identity = &GST_my_identity;
+ plug->env.get_our_hello = &GST_hello_get;
+ plug->env.cls = plug->short_name;
+ plug->env.receive = recv_cb;
+ plug->env.notify_address = address_cb;
+ plug->env.session_end = session_end_cb;
+ plug->env.max_connections = tneigh;
+ plug->env.stats = GST_stats;
+ GNUNET_CONTAINER_DLL_insert (plugins_head,
+ plugins_tail,
+ plug);
+ plug->api = GNUNET_PLUGIN_load (libname, &plug->env);
+ if (plug->api == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to load transport plugin for `%s'\n"),
+ pos);
+ GNUNET_CONTAINER_DLL_remove (plugins_head,
+ plugins_tail,
+ plug);
+ GNUNET_free (plug->short_name);
+ GNUNET_free (plug->lib_name);
+ GNUNET_free (plug);
+ }
}
-#endif
+ GNUNET_free (plugs);
}
@@ -155,26 +167,18 @@
void
GST_plugins_unload ()
{
-#if 0
- while (NULL != (plug = plugins))
+ struct TransportPlugin *plug;
+
+ while (NULL != (plug = plugins_head))
{
- if (plug->address_update_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (plug->address_update_task);
- plug->address_update_task = GNUNET_SCHEDULER_NO_TASK;
- }
GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
GNUNET_free (plug->lib_name);
GNUNET_free (plug->short_name);
- while (NULL != (al = plug->addresses))
- {
- plug->addresses = al->next;
- GNUNET_free (al);
- }
- plugins = plug->next;
+ GNUNET_CONTAINER_DLL_remove (plugins_head,
+ plugins_tail,
+ plug);
GNUNET_free (plug);
}
-#endif
}
Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c 2011-08-04 16:44:14 UTC
(rev 16376)
+++ gnunet/src/transport/plugin_transport_wlan.c 2011-08-04 19:29:40 UTC
(rev 16377)
@@ -1353,8 +1353,10 @@
struct ieee80211_frame * ieeewlanheader;
struct Radiotap_Send * radioHeader;
struct GNUNET_MessageHeader * msgheader2;
+ const struct GNUNET_MessageHeader *hello;
- hallo_size = GNUNET_HELLO_size(*(plugin->env->our_hello));
+ hello = plugin->env->get_our_hello ();
+ hallo_size = GNUNET_HELLO_size(hello);
GNUNET_assert(sizeof(struct WlanHeader) + hallo_size <= WLAN_MTU);
size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send)
+ sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader)
@@ -1370,12 +1372,11 @@
getWlanHeader(ieeewlanheader, &bc_all_mac, plugin, size);
msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1];
- msgheader2->size = htons(
- GNUNET_HELLO_size(*(plugin->env->our_hello))
+ msgheader2->size = htons(GNUNET_HELLO_size(hello)
+ sizeof(struct GNUNET_MessageHeader));
msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);
- memcpy(&msgheader2[1], *plugin->env->our_hello, hallo_size);
+ memcpy(&msgheader2[1], hello, hallo_size);
bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r16377 - in gnunet/src: include transport,
gnunet <=