[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r20431 - in gnunet/src: include transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r20431 - in gnunet/src: include transport |
Date: |
Sun, 11 Mar 2012 00:17:45 +0100 |
Author: grothoff
Date: 2012-03-11 00:17:45 +0100 (Sun, 11 Mar 2012)
New Revision: 20431
Modified:
gnunet/src/include/gnunet_transport_plugin.h
gnunet/src/transport/plugin_transport_http.c
gnunet/src/transport/plugin_transport_tcp.c
gnunet/src/transport/plugin_transport_udp.c
gnunet/src/transport/plugin_transport_unix.c
gnunet/src/transport/plugin_transport_wlan.c
Log:
add support for stub-mode for transport plugins
Modified: gnunet/src/include/gnunet_transport_plugin.h
===================================================================
--- gnunet/src/include/gnunet_transport_plugin.h 2012-03-10 22:09:08 UTC
(rev 20430)
+++ gnunet/src/include/gnunet_transport_plugin.h 2012-03-10 23:17:45 UTC
(rev 20431)
@@ -218,7 +218,11 @@
/**
* Function that should be called by the transport plugin
- * whenever a message is received.
+ * whenever a message is received. If this field is "NULL",
+ * the plugin should load in 'stub' mode and NOT fully
+ * initialize and instead only return an API with the
+ * 'address_pretty_printer', 'address_to_string' and
+ * 'string_to_address' functions.
*/
GNUNET_TRANSPORT_PluginReceiveCallback receive;
Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c 2012-03-10 22:09:08 UTC
(rev 20430)
+++ gnunet/src/transport/plugin_transport_http.c 2012-03-10 23:17:45 UTC
(rev 20431)
@@ -1373,6 +1373,18 @@
struct Plugin *plugin;
int res;
+ if (NULL == env->receive)
+ {
+ /* 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->cls = NULL;
+ api->address_pretty_printer = &http_plugin_address_pretty_printer;
+ api->address_to_string = &http_plugin_address_to_string;
+ api->string_to_address = NULL; // FIXME!
+ return api;
+ }
+
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->env = env;
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
@@ -1381,6 +1393,7 @@
api->address_pretty_printer = &http_plugin_address_pretty_printer;
api->check_address = &http_plugin_address_suggested;
api->address_to_string = &http_plugin_address_to_string;
+ api->string_to_address = NULL; // FIXME!
api->get_session = &http_get_session;
api->send = &http_plugin_send;
@@ -1452,8 +1465,14 @@
{
struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
struct Plugin *plugin = api->cls;
- struct Session *s = NULL;
+ struct Session *s;
+ if (NULL == plugin)
+ {
+ GNUNET_free (api);
+ return NULL;
+ }
+
/* Stop reporting addresses to transport service */
stop_report_addresses (plugin);
Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2012-03-10 22:09:08 UTC (rev
20430)
+++ gnunet/src/transport/plugin_transport_tcp.c 2012-03-10 23:17:45 UTC (rev
20431)
@@ -2105,6 +2105,18 @@
struct sockaddr **addrs;
socklen_t *addrlens;
+ if (NULL == env->receive)
+ {
+ /* 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->cls = NULL;
+ api->address_pretty_printer = &tcp_plugin_address_pretty_printer;
+ api->address_to_string = &tcp_address_to_string;
+ api->string_to_address = &tcp_string_to_address;
+ return api;
+ }
+
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp",
"MAX_CONNECTIONS",
@@ -2143,8 +2155,6 @@
else
service = NULL;
-
-
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->sessionmap = GNUNET_CONTAINER_multihashmap_create(max_connections);
plugin->max_connections = max_connections;
@@ -2247,9 +2257,13 @@
struct Plugin *plugin = api->cls;
struct TCPProbeContext *tcp_probe;
+ if (NULL == plugin)
+ {
+ GNUNET_free (api);
+ return NULL;
+ }
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "Shutting down TCP
plugin\n");
-
/* Removing leftover sessions */
GNUNET_CONTAINER_multihashmap_iterate(plugin->sessionmap,
&session_disconnect_it, NULL);
/* Removing leftover NAT sessions */
Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2012-03-10 22:09:08 UTC (rev
20430)
+++ gnunet/src/transport/plugin_transport_udp.c 2012-03-10 23:17:45 UTC (rev
20431)
@@ -2053,6 +2053,18 @@
int res;
+ if (NULL == env->receive)
+ {
+ /* 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->cls = NULL;
+ api->address_pretty_printer = &udp_plugin_address_pretty_printer;
+ api->address_to_string = &udp_address_to_string;
+ api->string_to_address = NULL; // FIXME!
+ return api;
+ }
+
/* Get port number */
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT",
@@ -2158,6 +2170,7 @@
api->disconnect = &udp_disconnect;
api->address_pretty_printer = &udp_plugin_address_pretty_printer;
api->address_to_string = &udp_address_to_string;
+ api->string_to_address = NULL; // FIXME!
api->check_address = &udp_plugin_check_address;
api->get_session = &udp_plugin_get_session;
api->send = &udp_plugin_send;
@@ -2182,11 +2195,13 @@
return api;
}
-int heap_cleanup_iterator (void *cls,
- struct GNUNET_CONTAINER_HeapNode *
- node, void *element,
- GNUNET_CONTAINER_HeapCostType
- cost)
+
+static int
+heap_cleanup_iterator (void *cls,
+ struct GNUNET_CONTAINER_HeapNode *
+ node, void *element,
+ GNUNET_CONTAINER_HeapCostType
+ cost)
{
struct DefragContext * d_ctx = element;
@@ -2203,13 +2218,20 @@
* returns the udp transport API.
*
* @param cls our 'struct GNUNET_TRANSPORT_PluginEnvironment'
- * @return our 'struct GNUNET_TRANSPORT_PluginFunctions'
+ * @return NULL
*/
void *
libgnunet_plugin_transport_udp_done (void *cls)
{
struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
struct Plugin *plugin = api->cls;
+
+ if (NULL == plugin)
+ {
+ GNUNET_free (api);
+ return NULL;
+ }
+
stop_broadcast (plugin);
if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
Modified: gnunet/src/transport/plugin_transport_unix.c
===================================================================
--- gnunet/src/transport/plugin_transport_unix.c 2012-03-10 22:09:08 UTC
(rev 20430)
+++ gnunet/src/transport/plugin_transport_unix.c 2012-03-10 23:17:45 UTC
(rev 20431)
@@ -1027,6 +1027,18 @@
struct Plugin *plugin;
int sockets_created;
+ if (NULL == env->receive)
+ {
+ /* 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->cls = NULL;
+ api->address_pretty_printer = &unix_plugin_address_pretty_printer;
+ api->address_to_string = &unix_address_to_string;
+ api->string_to_address = NULL; // FIXME!
+ return api;
+ }
+
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-unix",
"PORT",
&port))
@@ -1062,6 +1074,11 @@
struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
struct Plugin *plugin = api->cls;
+ if (NULL == plugin)
+ {
+ GNUNET_free (api);
+ return NULL;
+ }
unix_transport_server_stop (plugin);
GNUNET_CONTAINER_multihashmap_iterate (plugin->session_map,
&get_session_delete_it, plugin);
Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c 2012-03-10 22:09:08 UTC
(rev 20430)
+++ gnunet/src/transport/plugin_transport_wlan.c 2012-03-10 23:17:45 UTC
(rev 20431)
@@ -3080,6 +3080,8 @@
}
}
+
+
/**
* Exit point from the plugin.
* @param cls pointer to the api struct
@@ -3091,15 +3093,21 @@
{
struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
struct Plugin *plugin = api->cls;
- struct MacEndpoint *endpoint = plugin->mac_head;
+ struct MacEndpoint *endpoint;
struct MacEndpoint *endpoint_next;
+ if (NULL == plugin)
+ {
+ GNUNET_free (api);
+ return NULL;
+ }
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"libgnunet_plugin_transport_wlan_done started\n");
wlan_transport_stop_wlan_helper (plugin);
GNUNET_assert (cls != NULL);
//free sessions
+ endpoint = plugin->mac_head;
while (endpoint != NULL)
{
endpoint_next = endpoint->next;
@@ -3121,6 +3129,7 @@
return NULL;
}
+
/**
* Entry point for the plugin.
*
@@ -3130,12 +3139,21 @@
void *
libgnunet_plugin_transport_wlan_init (void *cls)
{
- //struct GNUNET_SERVICE_Context *service;
struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
struct GNUNET_TRANSPORT_PluginFunctions *api;
struct Plugin *plugin;
- GNUNET_assert (cls != NULL);
+ if (NULL == env->receive)
+ {
+ /* 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->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!
+ return api;
+ }
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->env = env;
@@ -3199,4 +3217,7 @@
return api;
}
+
+
+
/* end of plugin_transport_wlan.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r20431 - in gnunet/src: include transport,
gnunet <=