diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-04 14:26:15 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-04 14:26:15 +0000 |
commit | f01a89dc61659fafac079ad8ff13d518238bc065 (patch) | |
tree | e028ff33e3bb76060ce29abbcac661cf4a474b16 /src/transport/gnunet-service-transport_plugins.c | |
parent | 3ba21d7f05658f4c9a090a41ffbe04c6729d0916 (diff) | |
download | gnunet-f01a89dc61659fafac079ad8ff13d518238bc065.tar.gz gnunet-f01a89dc61659fafac079ad8ff13d518238bc065.zip |
towards plugins implementation
Diffstat (limited to 'src/transport/gnunet-service-transport_plugins.c')
-rw-r--r-- | src/transport/gnunet-service-transport_plugins.c | 143 |
1 files changed, 138 insertions, 5 deletions
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c index 0db7120fd..c4bc03039 100644 --- a/src/transport/gnunet-service-transport_plugins.c +++ b/src/transport/gnunet-service-transport_plugins.c | |||
@@ -26,6 +26,56 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet-service-transport_plugins.h" | 27 | #include "gnunet-service-transport_plugins.h" |
28 | 28 | ||
29 | /** | ||
30 | * Entry in doubly-linked list of all of our plugins. | ||
31 | */ | ||
32 | struct TransportPlugin | ||
33 | { | ||
34 | /** | ||
35 | * This is a doubly-linked list. | ||
36 | */ | ||
37 | struct TransportPlugin *next; | ||
38 | |||
39 | /** | ||
40 | * This is a doubly-linked list. | ||
41 | */ | ||
42 | struct TransportPlugin *prev; | ||
43 | |||
44 | /** | ||
45 | * API of the transport as returned by the plugin's | ||
46 | * initialization function. | ||
47 | */ | ||
48 | struct GNUNET_TRANSPORT_PluginFunctions *api; | ||
49 | |||
50 | /** | ||
51 | * Short name for the plugin (i.e. "tcp"). | ||
52 | */ | ||
53 | char *short_name; | ||
54 | |||
55 | /** | ||
56 | * Name of the library (i.e. "gnunet_plugin_transport_tcp"). | ||
57 | */ | ||
58 | char *lib_name; | ||
59 | |||
60 | /** | ||
61 | * Environment this transport service is using | ||
62 | * for this plugin. | ||
63 | */ | ||
64 | struct GNUNET_TRANSPORT_PluginEnvironment env; | ||
65 | |||
66 | }; | ||
67 | |||
68 | /** | ||
69 | * Head of DLL of all loaded plugins. | ||
70 | */ | ||
71 | static struct TransportPlugin *plugins_head; | ||
72 | |||
73 | /** | ||
74 | * Head of DLL of all loaded plugins. | ||
75 | */ | ||
76 | // static struct TransportPlugin *plugins_tail; | ||
77 | |||
78 | |||
29 | 79 | ||
30 | /** | 80 | /** |
31 | * Load and initialize all plugins. The respective functions will be | 81 | * Load and initialize all plugins. The respective functions will be |
@@ -38,16 +88,64 @@ | |||
38 | * @param traffic_cb function to call for flow control | 88 | * @param traffic_cb function to call for flow control |
39 | * @param session_end_cb function to call when a session was terminated | 89 | * @param session_end_cb function to call when a session was terminated |
40 | * @param cost_cb function to call about ATS cost changes | 90 | * @param cost_cb function to call about ATS cost changes |
41 | * @return GNUNET_OK on success | ||
42 | */ | 91 | */ |
43 | int | 92 | void |
44 | GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, | 93 | GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, |
45 | GNUNET_TRANSPORT_AddressNotification address_cb, | 94 | GNUNET_TRANSPORT_AddressNotification address_cb, |
46 | GNUNET_TRANSPORT_TrafficReport traffic_cb, | 95 | GNUNET_TRANSPORT_TrafficReport traffic_cb, |
47 | GNUNET_TRANSPORT_SessionEnd session_end_cb, | 96 | GNUNET_TRANSPORT_SessionEnd session_end_cb, |
48 | GNUNET_TRANSPORT_CostReport cost_cb) | 97 | GNUNET_TRANSPORT_CostReport cost_cb) |
49 | { | 98 | { |
50 | return GNUNET_SYSERR; | 99 | #if 0 |
100 | struct TransportPlugin *plug; | ||
101 | char *libname; | ||
102 | |||
103 | /* load plugins... */ | ||
104 | no_transports = 1; | ||
105 | if (GNUNET_OK == | ||
106 | GNUNET_CONFIGURATION_get_value_string (c, | ||
107 | "TRANSPORT", "PLUGINS", &plugs)) | ||
108 | { | ||
109 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
110 | _("Starting transport plugins `%s'\n"), plugs); | ||
111 | pos = strtok (plugs, " "); | ||
112 | while (pos != NULL) | ||
113 | { | ||
114 | |||
115 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
116 | _("Loading `%s' transport plugin\n"), name); | ||
117 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", name); | ||
118 | plug = GNUNET_malloc (sizeof (struct TransportPlugin)); | ||
119 | plug->short_name = GNUNET_strdup (name); | ||
120 | plug->lib_name = libname; | ||
121 | plug->env.cfg = cfg; | ||
122 | plug->env.my_identity = &my_identity; | ||
123 | plug->env.our_hello = &our_hello; | ||
124 | plug->env.cls = plug->short_name; | ||
125 | plug->env.receive = &plugin_env_receive; | ||
126 | plug->env.notify_address = &plugin_env_notify_address; | ||
127 | plug->env.session_end = &plugin_env_session_end; | ||
128 | plug->env.max_connections = max_connect_per_transport; | ||
129 | plug->env.stats = stats; | ||
130 | plug->next = plugins; | ||
131 | plugins = plug; | ||
132 | plug->api = GNUNET_PLUGIN_load (libname, &plug->env); | ||
133 | if (plug->api == NULL) | ||
134 | { | ||
135 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
136 | _("Failed to load transport plugin for `%s'\n"), name); | ||
137 | GNUNET_free (plug->short_name); | ||
138 | plugins = plug->next; | ||
139 | GNUNET_free (libname); | ||
140 | GNUNET_free (plug); | ||
141 | } | ||
142 | start_transport (server, pos); | ||
143 | no_transports = 0; | ||
144 | pos = strtok (NULL, " "); | ||
145 | } | ||
146 | GNUNET_free (plugs); | ||
147 | } | ||
148 | #endif | ||
51 | } | 149 | } |
52 | 150 | ||
53 | 151 | ||
@@ -57,6 +155,26 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, | |||
57 | void | 155 | void |
58 | GST_plugins_unload () | 156 | GST_plugins_unload () |
59 | { | 157 | { |
158 | #if 0 | ||
159 | while (NULL != (plug = plugins)) | ||
160 | { | ||
161 | if (plug->address_update_task != GNUNET_SCHEDULER_NO_TASK) | ||
162 | { | ||
163 | GNUNET_SCHEDULER_cancel (plug->address_update_task); | ||
164 | plug->address_update_task = GNUNET_SCHEDULER_NO_TASK; | ||
165 | } | ||
166 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api)); | ||
167 | GNUNET_free (plug->lib_name); | ||
168 | GNUNET_free (plug->short_name); | ||
169 | while (NULL != (al = plug->addresses)) | ||
170 | { | ||
171 | plug->addresses = al->next; | ||
172 | GNUNET_free (al); | ||
173 | } | ||
174 | plugins = plug->next; | ||
175 | GNUNET_free (plug); | ||
176 | } | ||
177 | #endif | ||
60 | } | 178 | } |
61 | 179 | ||
62 | 180 | ||
@@ -69,7 +187,13 @@ GST_plugins_unload () | |||
69 | struct GNUNET_TRANSPORT_PluginFunctions * | 187 | struct GNUNET_TRANSPORT_PluginFunctions * |
70 | GST_plugins_find (const char *name) | 188 | GST_plugins_find (const char *name) |
71 | { | 189 | { |
72 | return NULL; | 190 | struct TransportPlugin *head = plugins_head; |
191 | |||
192 | while ((head != NULL) && (0 != strcmp (name, head->short_name))) | ||
193 | head = head->next; | ||
194 | if (NULL == head) | ||
195 | return NULL; | ||
196 | return head->api; | ||
73 | } | 197 | } |
74 | 198 | ||
75 | 199 | ||
@@ -87,7 +211,16 @@ GST_plugins_a2s (const char *name, | |||
87 | const void *addr, | 211 | const void *addr, |
88 | size_t addrlen) | 212 | size_t addrlen) |
89 | { | 213 | { |
90 | return "FIXME"; | 214 | struct GNUNET_TRANSPORT_PluginFunctions *api; |
215 | |||
216 | if (name == NULL) | ||
217 | return NULL; | ||
218 | api = GST_plugins_find (name); | ||
219 | if ( (api == NULL) || (addrlen == 0) || (addr == NULL) ) | ||
220 | return NULL; | ||
221 | return api->address_to_string (NULL, | ||
222 | addr, | ||
223 | addrlen); | ||
91 | } | 224 | } |
92 | 225 | ||
93 | 226 | ||