diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-04 19:29:40 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-04 19:29:40 +0000 |
commit | b766cf70853e0732c0785648acd74c6958fea5a7 (patch) | |
tree | 8eb92fc0f768bd1b0382bdbba3a95a6a6fc49260 /src/transport/gnunet-service-transport_plugins.c | |
parent | 59e32c55941cd3927480d3971cec387e458914c9 (diff) | |
download | gnunet-b766cf70853e0732c0785648acd74c6958fea5a7.tar.gz gnunet-b766cf70853e0732c0785648acd74c6958fea5a7.zip |
implementing plugins subsystem
Diffstat (limited to 'src/transport/gnunet-service-transport_plugins.c')
-rw-r--r-- | src/transport/gnunet-service-transport_plugins.c | 124 |
1 files changed, 64 insertions, 60 deletions
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c index c4bc03039..bbc8d4183 100644 --- a/src/transport/gnunet-service-transport_plugins.c +++ b/src/transport/gnunet-service-transport_plugins.c | |||
@@ -24,6 +24,8 @@ | |||
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet-service-transport.h" | ||
28 | #include "gnunet-service-transport_hello.h" | ||
27 | #include "gnunet-service-transport_plugins.h" | 29 | #include "gnunet-service-transport_plugins.h" |
28 | 30 | ||
29 | /** | 31 | /** |
@@ -73,7 +75,7 @@ static struct TransportPlugin *plugins_head; | |||
73 | /** | 75 | /** |
74 | * Head of DLL of all loaded plugins. | 76 | * Head of DLL of all loaded plugins. |
75 | */ | 77 | */ |
76 | // static struct TransportPlugin *plugins_tail; | 78 | static struct TransportPlugin *plugins_tail; |
77 | 79 | ||
78 | 80 | ||
79 | 81 | ||
@@ -96,56 +98,66 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, | |||
96 | GNUNET_TRANSPORT_SessionEnd session_end_cb, | 98 | GNUNET_TRANSPORT_SessionEnd session_end_cb, |
97 | GNUNET_TRANSPORT_CostReport cost_cb) | 99 | GNUNET_TRANSPORT_CostReport cost_cb) |
98 | { | 100 | { |
99 | #if 0 | ||
100 | struct TransportPlugin *plug; | 101 | struct TransportPlugin *plug; |
102 | unsigned long long tneigh; | ||
101 | char *libname; | 103 | char *libname; |
102 | 104 | char *plugs; | |
103 | /* load plugins... */ | 105 | char *pos; |
104 | no_transports = 1; | 106 | |
105 | if (GNUNET_OK == | 107 | if (GNUNET_OK != |
106 | GNUNET_CONFIGURATION_get_value_string (c, | 108 | GNUNET_CONFIGURATION_get_value_number (GST_cfg, |
107 | "TRANSPORT", "PLUGINS", &plugs)) | 109 | "TRANSPORT", |
110 | "NEIGHBOUR_LIMIT", | ||
111 | &tneigh)) | ||
108 | { | 112 | { |
113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
114 | _("Transport service is lacking NEIGHBOUR_LIMIT option.\n")); | ||
115 | return; | ||
116 | } | ||
117 | if (GNUNET_OK != | ||
118 | GNUNET_CONFIGURATION_get_value_string (GST_cfg, | ||
119 | "TRANSPORT", "PLUGINS", &plugs)) | ||
120 | return; | ||
121 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
122 | _("Starting transport plugins `%s'\n"), | ||
123 | plugs); | ||
124 | for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " ")) | ||
125 | { | ||
109 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
110 | _("Starting transport plugins `%s'\n"), plugs); | 127 | _("Loading `%s' transport plugin\n"), pos); |
111 | pos = strtok (plugs, " "); | 128 | GNUNET_asprintf (&libname, |
112 | while (pos != NULL) | 129 | "libgnunet_plugin_transport_%s", |
113 | { | 130 | pos); |
114 | 131 | plug = GNUNET_malloc (sizeof (struct TransportPlugin)); | |
115 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 132 | plug->short_name = GNUNET_strdup (pos); |
116 | _("Loading `%s' transport plugin\n"), name); | 133 | plug->lib_name = libname; |
117 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", name); | 134 | plug->env.cfg = GST_cfg; |
118 | plug = GNUNET_malloc (sizeof (struct TransportPlugin)); | 135 | plug->env.my_identity = &GST_my_identity; |
119 | plug->short_name = GNUNET_strdup (name); | 136 | plug->env.get_our_hello = &GST_hello_get; |
120 | plug->lib_name = libname; | 137 | plug->env.cls = plug->short_name; |
121 | plug->env.cfg = cfg; | 138 | plug->env.receive = recv_cb; |
122 | plug->env.my_identity = &my_identity; | 139 | plug->env.notify_address = address_cb; |
123 | plug->env.our_hello = &our_hello; | 140 | plug->env.session_end = session_end_cb; |
124 | plug->env.cls = plug->short_name; | 141 | plug->env.max_connections = tneigh; |
125 | plug->env.receive = &plugin_env_receive; | 142 | plug->env.stats = GST_stats; |
126 | plug->env.notify_address = &plugin_env_notify_address; | 143 | GNUNET_CONTAINER_DLL_insert (plugins_head, |
127 | plug->env.session_end = &plugin_env_session_end; | 144 | plugins_tail, |
128 | plug->env.max_connections = max_connect_per_transport; | 145 | plug); |
129 | plug->env.stats = stats; | 146 | plug->api = GNUNET_PLUGIN_load (libname, &plug->env); |
130 | plug->next = plugins; | 147 | if (plug->api == NULL) |
131 | plugins = plug; | 148 | { |
132 | plug->api = GNUNET_PLUGIN_load (libname, &plug->env); | 149 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
133 | if (plug->api == NULL) | 150 | _("Failed to load transport plugin for `%s'\n"), |
134 | { | 151 | pos); |
135 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 152 | GNUNET_CONTAINER_DLL_remove (plugins_head, |
136 | _("Failed to load transport plugin for `%s'\n"), name); | 153 | plugins_tail, |
137 | GNUNET_free (plug->short_name); | 154 | plug); |
138 | plugins = plug->next; | 155 | GNUNET_free (plug->short_name); |
139 | GNUNET_free (libname); | 156 | GNUNET_free (plug->lib_name); |
140 | GNUNET_free (plug); | 157 | GNUNET_free (plug); |
141 | } | 158 | } |
142 | start_transport (server, pos); | ||
143 | no_transports = 0; | ||
144 | pos = strtok (NULL, " "); | ||
145 | } | ||
146 | GNUNET_free (plugs); | ||
147 | } | 159 | } |
148 | #endif | 160 | GNUNET_free (plugs); |
149 | } | 161 | } |
150 | 162 | ||
151 | 163 | ||
@@ -155,26 +167,18 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, | |||
155 | void | 167 | void |
156 | GST_plugins_unload () | 168 | GST_plugins_unload () |
157 | { | 169 | { |
158 | #if 0 | 170 | struct TransportPlugin *plug; |
159 | while (NULL != (plug = plugins)) | 171 | |
172 | while (NULL != (plug = plugins_head)) | ||
160 | { | 173 | { |
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)); | 174 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api)); |
167 | GNUNET_free (plug->lib_name); | 175 | GNUNET_free (plug->lib_name); |
168 | GNUNET_free (plug->short_name); | 176 | GNUNET_free (plug->short_name); |
169 | while (NULL != (al = plug->addresses)) | 177 | GNUNET_CONTAINER_DLL_remove (plugins_head, |
170 | { | 178 | plugins_tail, |
171 | plug->addresses = al->next; | 179 | plug); |
172 | GNUNET_free (al); | ||
173 | } | ||
174 | plugins = plug->next; | ||
175 | GNUNET_free (plug); | 180 | GNUNET_free (plug); |
176 | } | 181 | } |
177 | #endif | ||
178 | } | 182 | } |
179 | 183 | ||
180 | 184 | ||