aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-03-10 23:17:45 +0000
committerChristian Grothoff <christian@grothoff.org>2012-03-10 23:17:45 +0000
commit854e1e4d0d1fcfa9812336ebfae76538a9197351 (patch)
tree83bbf1e3e17cc7400ea85d21e9177bff522b1f11 /src
parentda6e72d97f0125825d5348d12b75b39efc7d2b39 (diff)
downloadgnunet-854e1e4d0d1fcfa9812336ebfae76538a9197351.tar.gz
gnunet-854e1e4d0d1fcfa9812336ebfae76538a9197351.zip
add support for stub-mode for transport plugins
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_transport_plugin.h6
-rw-r--r--src/transport/plugin_transport_http.c21
-rw-r--r--src/transport/plugin_transport_tcp.c20
-rw-r--r--src/transport/plugin_transport_udp.c34
-rw-r--r--src/transport/plugin_transport_unix.c17
-rw-r--r--src/transport/plugin_transport_wlan.c27
6 files changed, 111 insertions, 14 deletions
diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h
index 194d4d214..d5d587922 100644
--- a/src/include/gnunet_transport_plugin.h
+++ b/src/include/gnunet_transport_plugin.h
@@ -218,7 +218,11 @@ struct GNUNET_TRANSPORT_PluginEnvironment
218 218
219 /** 219 /**
220 * Function that should be called by the transport plugin 220 * Function that should be called by the transport plugin
221 * whenever a message is received. 221 * whenever a message is received. If this field is "NULL",
222 * the plugin should load in 'stub' mode and NOT fully
223 * initialize and instead only return an API with the
224 * 'address_pretty_printer', 'address_to_string' and
225 * 'string_to_address' functions.
222 */ 226 */
223 GNUNET_TRANSPORT_PluginReceiveCallback receive; 227 GNUNET_TRANSPORT_PluginReceiveCallback receive;
224 228
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index f88ff3388..8e3bd737c 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -1373,6 +1373,18 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
1373 struct Plugin *plugin; 1373 struct Plugin *plugin;
1374 int res; 1374 int res;
1375 1375
1376 if (NULL == env->receive)
1377 {
1378 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1379 initialze the plugin or the API */
1380 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1381 api->cls = NULL;
1382 api->address_pretty_printer = &http_plugin_address_pretty_printer;
1383 api->address_to_string = &http_plugin_address_to_string;
1384 api->string_to_address = NULL; // FIXME!
1385 return api;
1386 }
1387
1376 plugin = GNUNET_malloc (sizeof (struct Plugin)); 1388 plugin = GNUNET_malloc (sizeof (struct Plugin));
1377 plugin->env = env; 1389 plugin->env = env;
1378 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 1390 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
@@ -1381,6 +1393,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
1381 api->address_pretty_printer = &http_plugin_address_pretty_printer; 1393 api->address_pretty_printer = &http_plugin_address_pretty_printer;
1382 api->check_address = &http_plugin_address_suggested; 1394 api->check_address = &http_plugin_address_suggested;
1383 api->address_to_string = &http_plugin_address_to_string; 1395 api->address_to_string = &http_plugin_address_to_string;
1396 api->string_to_address = NULL; // FIXME!
1384 api->get_session = &http_get_session; 1397 api->get_session = &http_get_session;
1385 api->send = &http_plugin_send; 1398 api->send = &http_plugin_send;
1386 1399
@@ -1452,7 +1465,13 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
1452{ 1465{
1453 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 1466 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1454 struct Plugin *plugin = api->cls; 1467 struct Plugin *plugin = api->cls;
1455 struct Session *s = NULL; 1468 struct Session *s;
1469
1470 if (NULL == plugin)
1471 {
1472 GNUNET_free (api);
1473 return NULL;
1474 }
1456 1475
1457 /* Stop reporting addresses to transport service */ 1476 /* Stop reporting addresses to transport service */
1458 stop_report_addresses (plugin); 1477 stop_report_addresses (plugin);
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 628a0ff42..e10dd74c1 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -2105,6 +2105,18 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2105 struct sockaddr **addrs; 2105 struct sockaddr **addrs;
2106 socklen_t *addrlens; 2106 socklen_t *addrlens;
2107 2107
2108 if (NULL == env->receive)
2109 {
2110 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2111 initialze the plugin or the API */
2112 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2113 api->cls = NULL;
2114 api->address_pretty_printer = &tcp_plugin_address_pretty_printer;
2115 api->address_to_string = &tcp_address_to_string;
2116 api->string_to_address = &tcp_string_to_address;
2117 return api;
2118 }
2119
2108 if (GNUNET_OK != 2120 if (GNUNET_OK !=
2109 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", 2121 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp",
2110 "MAX_CONNECTIONS", 2122 "MAX_CONNECTIONS",
@@ -2143,8 +2155,6 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2143 else 2155 else
2144 service = NULL; 2156 service = NULL;
2145 2157
2146
2147
2148 plugin = GNUNET_malloc (sizeof (struct Plugin)); 2158 plugin = GNUNET_malloc (sizeof (struct Plugin));
2149 plugin->sessionmap = GNUNET_CONTAINER_multihashmap_create(max_connections); 2159 plugin->sessionmap = GNUNET_CONTAINER_multihashmap_create(max_connections);
2150 plugin->max_connections = max_connections; 2160 plugin->max_connections = max_connections;
@@ -2247,9 +2257,13 @@ libgnunet_plugin_transport_tcp_done (void *cls)
2247 struct Plugin *plugin = api->cls; 2257 struct Plugin *plugin = api->cls;
2248 struct TCPProbeContext *tcp_probe; 2258 struct TCPProbeContext *tcp_probe;
2249 2259
2260 if (NULL == plugin)
2261 {
2262 GNUNET_free (api);
2263 return NULL;
2264 }
2250 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "Shutting down TCP plugin\n"); 2265 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "Shutting down TCP plugin\n");
2251 2266
2252
2253 /* Removing leftover sessions */ 2267 /* Removing leftover sessions */
2254 GNUNET_CONTAINER_multihashmap_iterate(plugin->sessionmap, &session_disconnect_it, NULL); 2268 GNUNET_CONTAINER_multihashmap_iterate(plugin->sessionmap, &session_disconnect_it, NULL);
2255 /* Removing leftover NAT sessions */ 2269 /* Removing leftover NAT sessions */
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 7141563a2..ed6fc847a 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -2053,6 +2053,18 @@ libgnunet_plugin_transport_udp_init (void *cls)
2053 2053
2054 int res; 2054 int res;
2055 2055
2056 if (NULL == env->receive)
2057 {
2058 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2059 initialze the plugin or the API */
2060 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2061 api->cls = NULL;
2062 api->address_pretty_printer = &udp_plugin_address_pretty_printer;
2063 api->address_to_string = &udp_address_to_string;
2064 api->string_to_address = NULL; // FIXME!
2065 return api;
2066 }
2067
2056 /* Get port number */ 2068 /* Get port number */
2057 if (GNUNET_OK != 2069 if (GNUNET_OK !=
2058 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT", 2070 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT",
@@ -2158,6 +2170,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
2158 api->disconnect = &udp_disconnect; 2170 api->disconnect = &udp_disconnect;
2159 api->address_pretty_printer = &udp_plugin_address_pretty_printer; 2171 api->address_pretty_printer = &udp_plugin_address_pretty_printer;
2160 api->address_to_string = &udp_address_to_string; 2172 api->address_to_string = &udp_address_to_string;
2173 api->string_to_address = NULL; // FIXME!
2161 api->check_address = &udp_plugin_check_address; 2174 api->check_address = &udp_plugin_check_address;
2162 api->get_session = &udp_plugin_get_session; 2175 api->get_session = &udp_plugin_get_session;
2163 api->send = &udp_plugin_send; 2176 api->send = &udp_plugin_send;
@@ -2182,11 +2195,13 @@ libgnunet_plugin_transport_udp_init (void *cls)
2182 return api; 2195 return api;
2183} 2196}
2184 2197
2185int heap_cleanup_iterator (void *cls, 2198
2186 struct GNUNET_CONTAINER_HeapNode * 2199static int
2187 node, void *element, 2200heap_cleanup_iterator (void *cls,
2188 GNUNET_CONTAINER_HeapCostType 2201 struct GNUNET_CONTAINER_HeapNode *
2189 cost) 2202 node, void *element,
2203 GNUNET_CONTAINER_HeapCostType
2204 cost)
2190{ 2205{
2191 struct DefragContext * d_ctx = element; 2206 struct DefragContext * d_ctx = element;
2192 2207
@@ -2203,13 +2218,20 @@ int heap_cleanup_iterator (void *cls,
2203 * returns the udp transport API. 2218 * returns the udp transport API.
2204 * 2219 *
2205 * @param cls our 'struct GNUNET_TRANSPORT_PluginEnvironment' 2220 * @param cls our 'struct GNUNET_TRANSPORT_PluginEnvironment'
2206 * @return our 'struct GNUNET_TRANSPORT_PluginFunctions' 2221 * @return NULL
2207 */ 2222 */
2208void * 2223void *
2209libgnunet_plugin_transport_udp_done (void *cls) 2224libgnunet_plugin_transport_udp_done (void *cls)
2210{ 2225{
2211 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 2226 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2212 struct Plugin *plugin = api->cls; 2227 struct Plugin *plugin = api->cls;
2228
2229 if (NULL == plugin)
2230 {
2231 GNUNET_free (api);
2232 return NULL;
2233 }
2234
2213 stop_broadcast (plugin); 2235 stop_broadcast (plugin);
2214 2236
2215 if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) 2237 if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index 499cc23ad..51fbcd081 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -1027,6 +1027,18 @@ libgnunet_plugin_transport_unix_init (void *cls)
1027 struct Plugin *plugin; 1027 struct Plugin *plugin;
1028 int sockets_created; 1028 int sockets_created;
1029 1029
1030 if (NULL == env->receive)
1031 {
1032 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1033 initialze the plugin or the API */
1034 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1035 api->cls = NULL;
1036 api->address_pretty_printer = &unix_plugin_address_pretty_printer;
1037 api->address_to_string = &unix_address_to_string;
1038 api->string_to_address = NULL; // FIXME!
1039 return api;
1040 }
1041
1030 if (GNUNET_OK != 1042 if (GNUNET_OK !=
1031 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-unix", "PORT", 1043 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-unix", "PORT",
1032 &port)) 1044 &port))
@@ -1062,6 +1074,11 @@ libgnunet_plugin_transport_unix_done (void *cls)
1062 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 1074 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1063 struct Plugin *plugin = api->cls; 1075 struct Plugin *plugin = api->cls;
1064 1076
1077 if (NULL == plugin)
1078 {
1079 GNUNET_free (api);
1080 return NULL;
1081 }
1065 unix_transport_server_stop (plugin); 1082 unix_transport_server_stop (plugin);
1066 1083
1067 GNUNET_CONTAINER_multihashmap_iterate (plugin->session_map, &get_session_delete_it, plugin); 1084 GNUNET_CONTAINER_multihashmap_iterate (plugin->session_map, &get_session_delete_it, plugin);
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 7aebad93a..084fc611c 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -3080,6 +3080,8 @@ wlan_process_helper (void *cls, void *client,
3080 } 3080 }
3081} 3081}
3082 3082
3083
3084
3083/** 3085/**
3084 * Exit point from the plugin. 3086 * Exit point from the plugin.
3085 * @param cls pointer to the api struct 3087 * @param cls pointer to the api struct
@@ -3091,15 +3093,21 @@ libgnunet_plugin_transport_wlan_done (void *cls)
3091{ 3093{
3092 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 3094 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3093 struct Plugin *plugin = api->cls; 3095 struct Plugin *plugin = api->cls;
3094 struct MacEndpoint *endpoint = plugin->mac_head; 3096 struct MacEndpoint *endpoint;
3095 struct MacEndpoint *endpoint_next; 3097 struct MacEndpoint *endpoint_next;
3096 3098
3099 if (NULL == plugin)
3100 {
3101 GNUNET_free (api);
3102 return NULL;
3103 }
3097 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 3104 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3098 "libgnunet_plugin_transport_wlan_done started\n"); 3105 "libgnunet_plugin_transport_wlan_done started\n");
3099 wlan_transport_stop_wlan_helper (plugin); 3106 wlan_transport_stop_wlan_helper (plugin);
3100 3107
3101 GNUNET_assert (cls != NULL); 3108 GNUNET_assert (cls != NULL);
3102 //free sessions 3109 //free sessions
3110 endpoint = plugin->mac_head;
3103 while (endpoint != NULL) 3111 while (endpoint != NULL)
3104 { 3112 {
3105 endpoint_next = endpoint->next; 3113 endpoint_next = endpoint->next;
@@ -3121,6 +3129,7 @@ libgnunet_plugin_transport_wlan_done (void *cls)
3121 return NULL; 3129 return NULL;
3122} 3130}
3123 3131
3132
3124/** 3133/**
3125 * Entry point for the plugin. 3134 * Entry point for the plugin.
3126 * 3135 *
@@ -3130,12 +3139,21 @@ libgnunet_plugin_transport_wlan_done (void *cls)
3130void * 3139void *
3131libgnunet_plugin_transport_wlan_init (void *cls) 3140libgnunet_plugin_transport_wlan_init (void *cls)
3132{ 3141{
3133 //struct GNUNET_SERVICE_Context *service;
3134 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 3142 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
3135 struct GNUNET_TRANSPORT_PluginFunctions *api; 3143 struct GNUNET_TRANSPORT_PluginFunctions *api;
3136 struct Plugin *plugin; 3144 struct Plugin *plugin;
3137 3145
3138 GNUNET_assert (cls != NULL); 3146 if (NULL == env->receive)
3147 {
3148 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
3149 initialze the plugin or the API */
3150 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
3151 api->cls = NULL;
3152 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
3153 api->address_to_string = &wlan_plugin_address_to_string;
3154 api->string_to_address = NULL; // FIXME!
3155 return api;
3156 }
3139 3157
3140 plugin = GNUNET_malloc (sizeof (struct Plugin)); 3158 plugin = GNUNET_malloc (sizeof (struct Plugin));
3141 plugin->env = env; 3159 plugin->env = env;
@@ -3199,4 +3217,7 @@ libgnunet_plugin_transport_wlan_init (void *cls)
3199 return api; 3217 return api;
3200} 3218}
3201 3219
3220
3221
3222
3202/* end of plugin_transport_wlan.c */ 3223/* end of plugin_transport_wlan.c */