aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_plugin_transport_http.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-05-07 12:03:55 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-05-07 12:03:55 +0000
commita7f34525fa63e800e59dfcfd129da0b3c670c947 (patch)
treef2297dcf21288010d8ba1e7d6b59bae5441f5ac6 /src/transport/test_plugin_transport_http.c
parent1dea5b7075dc8cf916af6f2f8706224f852f1e75 (diff)
downloadgnunet-a7f34525fa63e800e59dfcfd129da0b3c670c947.tar.gz
gnunet-a7f34525fa63e800e59dfcfd129da0b3c670c947.zip
rewrite from scratch
Diffstat (limited to 'src/transport/test_plugin_transport_http.c')
-rw-r--r--src/transport/test_plugin_transport_http.c195
1 files changed, 39 insertions, 156 deletions
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index 84de2ca25..0ce1766c9 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -99,13 +99,6 @@ static struct GNUNET_TRANSPORT_PluginEnvironment env;
99static struct GNUNET_TRANSPORT_PluginFunctions *api; 99static struct GNUNET_TRANSPORT_PluginFunctions *api;
100 100
101/** 101/**
102 * Did the test pass or fail?
103 */
104static int fail;
105
106pid_t pid;
107
108/**
109 * ID of the task controlling the locking between two hostlist tests 102 * ID of the task controlling the locking between two hostlist tests
110 */ 103 */
111static GNUNET_SCHEDULER_TaskIdentifier ti_check_stat; 104static GNUNET_SCHEDULER_TaskIdentifier ti_check_stat;
@@ -113,16 +106,21 @@ static GNUNET_SCHEDULER_TaskIdentifier ti_check_stat;
113static unsigned int timeout_count; 106static unsigned int timeout_count;
114 107
115/** 108/**
109 * Did the test pass or fail?
110 */
111static int fail;
112
113/**
116 * Initialize Environment for this plugin 114 * Initialize Environment for this plugin
117 */ 115 */
118static struct GNUNET_TIME_Relative 116static struct GNUNET_TIME_Relative
119receive (void *cls, 117receive (void *cls,
120 const struct GNUNET_PeerIdentity * peer, 118 const struct GNUNET_PeerIdentity * peer,
121 const struct GNUNET_MessageHeader * message, 119 const struct GNUNET_MessageHeader * message,
122 uint32_t distance, 120 uint32_t distance,
123 struct Session *session, 121 struct Session *session,
124 const char *sender_address, 122 const char *sender_address,
125 uint16_t sender_address_len) 123 uint16_t sender_address_len)
126{ 124{
127 /* do nothing */ 125 /* do nothing */
128 return GNUNET_TIME_UNIT_ZERO; 126 return GNUNET_TIME_UNIT_ZERO;
@@ -132,33 +130,13 @@ void
132notify_address (void *cls, 130notify_address (void *cls,
133 const char *name, 131 const char *name,
134 const void *addr, 132 const void *addr,
135 uint16_t addrlen, 133 uint16_t addrlen,
136 struct GNUNET_TIME_Relative expires) 134 struct GNUNET_TIME_Relative expires)
137{
138}
139
140/**
141 * Simple example test that invokes
142 * the check_address function of the plugin.
143 */
144/* FIXME: won't work on IPv6 enabled systems where IPv4 mapping
145 * isn't enabled (eg. FreeBSD > 4)
146 */
147static void
148shutdown_clean ()
149{ 135{
150 GNUNET_assert (NULL ==
151 GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http",
152 api));
153 if (my_private_key != NULL)
154 GNUNET_CRYPTO_rsa_key_free (my_private_key);
155 136
156 if (ti_check_stat != GNUNET_SCHEDULER_NO_TASK)
157 GNUNET_SCHEDULER_cancel(sched, ti_check_stat);
158 GNUNET_SCHEDULER_shutdown(sched);
159 return;
160} 137}
161 138
139
162static void 140static void
163setup_plugin_environment () 141setup_plugin_environment ()
164{ 142{
@@ -172,30 +150,23 @@ setup_plugin_environment ()
172 env.max_connections = max_connect_per_transport; 150 env.max_connections = max_connect_per_transport;
173} 151}
174 152
175static int 153/**
176process_stat (void *cls, 154 * Simple example test that invokes
177 const char *subsystem, 155 * the check_address function of the plugin.
178 const char *name, 156 */
179 uint64_t value, 157/* FIXME: won't work on IPv6 enabled systems where IPv4 mapping
180 int is_persistent) 158 * isn't enabled (eg. FreeBSD > 4)
159 */
160static void
161shutdown_clean ()
181{ 162{
182 if (value==1) 163 GNUNET_assert (NULL ==
183 { 164 GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http",
184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown, plugin failed \n"); 165 api));
185 fail = GNUNET_YES; 166 GNUNET_SCHEDULER_shutdown(sched);
186 shutdown_clean(); 167 return;
187 return GNUNET_YES;
188 }
189 if (value==2)
190 {
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown, plugin not failed \n");
192 shutdown_clean();
193 return GNUNET_YES;
194 }
195 return GNUNET_YES;
196} 168}
197 169
198
199/** 170/**
200 * Task that checks if we should try to download a hostlist. 171 * Task that checks if we should try to download a hostlist.
201 * If so, we initiate the download, otherwise we schedule 172 * If so, we initiate the download, otherwise we schedule
@@ -205,12 +176,11 @@ static void
205task_check_stat (void *cls, 176task_check_stat (void *cls,
206 const struct GNUNET_SCHEDULER_TaskContext *tc) 177 const struct GNUNET_SCHEDULER_TaskContext *tc)
207{ 178{
208
209 ti_check_stat = GNUNET_SCHEDULER_NO_TASK; 179 ti_check_stat = GNUNET_SCHEDULER_NO_TASK;
210 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 180 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
211 return; 181 return;
212 182
213 if ( timeout_count > 10 ) 183 if ( timeout_count > 5 )
214 { 184 {
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n", timeout_count); 185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n", timeout_count);
216 fail = GNUNET_YES; 186 fail = GNUNET_YES;
@@ -219,14 +189,6 @@ task_check_stat (void *cls,
219 } 189 }
220 timeout_count++; 190 timeout_count++;
221 191
222 GNUNET_STATISTICS_get (stats,
223 "http-transport",
224 gettext_noop("shutdown"),
225 GNUNET_TIME_UNIT_MINUTES,
226 NULL,
227 &process_stat,
228 NULL);
229
230 ti_check_stat = GNUNET_SCHEDULER_add_delayed (sched, STAT_INTERVALL, &task_check_stat, NULL); 192 ti_check_stat = GNUNET_SCHEDULER_add_delayed (sched, STAT_INTERVALL, &task_check_stat, NULL);
231 return; 193 return;
232} 194}
@@ -244,98 +206,26 @@ run (void *cls,
244 char *const *args, 206 char *const *args,
245 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) 207 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
246{ 208{
247 unsigned long long tneigh; 209 char * libname;
248 char *keyfile;
249 char *libname;
250 210
251 sched = s; 211 sched = s;
252 cfg = c; 212 cfg = c;
253 213
254 /* parse configuration */
255 if ((GNUNET_OK !=
256 GNUNET_CONFIGURATION_get_value_number (c,
257 "TRANSPORT",
258 "NEIGHBOUR_LIMIT",
259 &tneigh)) ||
260 (GNUNET_OK !=
261 GNUNET_CONFIGURATION_get_value_filename (c,
262 "GNUNETD",
263 "HOSTKEY", &keyfile)))
264 {
265 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
266 _("Transport service is lacking key configuration settings. Exiting.\n"));
267 GNUNET_SCHEDULER_shutdown (s);
268 return;
269 }
270
271 pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
272 "gnunet-service-statistics",
273 "-L", "DEBUG",
274 "-c", "test_plugin_transport_data_http.conf", NULL);
275
276
277 if ( pid == -1)
278 {
279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
280 _("Failed to start service for `%s' http transport plugin test.\n"),
281 "statistics");
282 GNUNET_SCHEDULER_shutdown (s);
283 return;
284 }
285
286 stats = GNUNET_STATISTICS_create (sched, "http-transport", cfg);
287 env.stats = stats;
288 /*
289 max_connect_per_transport = (uint32_t) tneigh;
290 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
291 GNUNET_free (keyfile);
292
293 if (my_private_key == NULL)
294 {
295 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
296 _
297 ("Transport service could not access hostkey. Exiting.\n"));
298 GNUNET_SCHEDULER_shutdown (s);
299 return;
300 }
301 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
302 GNUNET_CRYPTO_hash (&my_public_key,
303 sizeof (my_public_key), &my_identity.hashPubKey);
304 */
305 /* load plugins... */ 214 /* load plugins... */
306 setup_plugin_environment (); 215 setup_plugin_environment ();
307 216 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading HTTP transport plugin\n"));
308 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http"); 217 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
309 218
310 api = GNUNET_PLUGIN_load (libname, &env); 219 api = GNUNET_PLUGIN_load (libname, &env);
311 if (api != NULL )
312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
313 "Loading http transport plugin `%s' was successful\n",libname);
314
315 GNUNET_free (libname); 220 GNUNET_free (libname);
316 if (api == NULL) 221 if (api == NULL)
317 { 222 {
318 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 223 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
319 _("Failed to load http transport plugin\n")); 224 _("Failed to load transport plugin for udp\n"));
320 fail = GNUNET_YES; 225 return;
321 shutdown_clean (); 226 }
322 return;
323
324 }
325 fail = GNUNET_NO;
326
327 char * test_message = "Hello World!";
328 size_t bs = 0;
329 size_t size = strlen(test_message) +1;
330
331 /* Testing to send */
332 bs = api->send(NULL, &my_identity,test_message,size,0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, NULL, NULL);
333 GNUNET_assert ( bs == size);
334
335 /* check statistics */
336 ti_check_stat = GNUNET_SCHEDULER_add_now(sched, &task_check_stat, NULL);
337 227
338 return; 228 ti_check_stat = GNUNET_SCHEDULER_add_now (sched, &task_check_stat, NULL);
339} 229}
340 230
341 231
@@ -349,7 +239,6 @@ run (void *cls,
349int 239int
350main (int argc, char *const *argv) 240main (int argc, char *const *argv)
351{ 241{
352 return GNUNET_NO;
353 static struct GNUNET_GETOPT_CommandLineOption options[] = { 242 static struct GNUNET_GETOPT_CommandLineOption options[] = {
354 GNUNET_GETOPT_OPTION_END 243 GNUNET_GETOPT_OPTION_END
355 }; 244 };
@@ -373,20 +262,14 @@ main (int argc, char *const *argv)
373 "WARNING", 262 "WARNING",
374#endif 263#endif
375 NULL); 264 NULL);
376 fail = GNUNET_YES;
377 ret = (GNUNET_OK == 265 ret = (GNUNET_OK ==
378 GNUNET_PROGRAM_run (5, 266 GNUNET_PROGRAM_run (5,
379 argv_prog, 267 argv_prog,
380 "test_plugin_transport_http", 268 "test_plugin_transport_http",
381 "testcase", options, &run, NULL)) ? fail : 1; 269 "testcase", options, &run, NULL)) ? GNUNET_YES : 1;
382 GNUNET_DISK_directory_remove ("/tmp/test_plugin_transport_http"); 270 GNUNET_DISK_directory_remove ("/tmp/test_plugin_transport_http");
383 271
384 if (0 != PLIBC_KILL (pid, SIGTERM)) 272 return GNUNET_NO;
385 {
386 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
387 fail = 1;
388 }
389 return fail;
390} 273}
391 274
392/* end of test_plugin_transport_http.c */ 275/* end of test_plugin_transport_http.c */