aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_plugin_transport.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-08-23 11:48:27 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-08-23 11:48:27 +0000
commit092f6ee135d29f88264d9553d26829c2772f7e16 (patch)
tree59e02683c642f4ddee2a469535bf1f92bc40cb2a /src/transport/test_plugin_transport.c
parentca97e047b8f7052e571e01ec4395f260709ec4a7 (diff)
downloadgnunet-092f6ee135d29f88264d9553d26829c2772f7e16.tar.gz
gnunet-092f6ee135d29f88264d9553d26829c2772f7e16.zip
plugin test
Diffstat (limited to 'src/transport/test_plugin_transport.c')
-rw-r--r--src/transport/test_plugin_transport.c82
1 files changed, 61 insertions, 21 deletions
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c
index dbd6c6c63..bc7df9880 100644
--- a/src/transport/test_plugin_transport.c
+++ b/src/transport/test_plugin_transport.c
@@ -40,7 +40,8 @@
40/** 40/**
41 * How long until we give up on transmitting the message? 41 * How long until we give up on transmitting the message?
42 */ 42 */
43#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 43#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
44#define TIMEOUT GNUNET_TIME_relative_multiply (WAIT, 3)
44 45
45/** 46/**
46 * Our public key. 47 * Our public key.
@@ -68,6 +69,11 @@ const struct GNUNET_CONFIGURATION_Handle *cfg;
68struct GNUNET_STATISTICS_Handle *stats; 69struct GNUNET_STATISTICS_Handle *stats;
69 70
70/** 71/**
72 * Our HELLO
73 */
74struct GNUNET_HELLO_Message *hello;
75
76/**
71 * Number of neighbours we'd like to have. 77 * Number of neighbours we'd like to have.
72 */ 78 */
73static uint32_t max_connect_per_transport; 79static uint32_t max_connect_per_transport;
@@ -88,13 +94,27 @@ struct GNUNET_TRANSPORT_PluginFunctions *api;
88static GNUNET_SCHEDULER_TaskIdentifier timeout_task; 94static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
89 95
90/** 96/**
97 * Timeout task
98 */
99static GNUNET_SCHEDULER_TaskIdentifier timeout_wait;
100
101/**
91 * Library name 102 * Library name
92 */ 103 */
93static char *libname; 104static char *libname;
94 105
106/**
107 * Plugin addresses head
108 */
95struct AddressWrapper *head; 109struct AddressWrapper *head;
110
111/**
112 * Plugin addresses tail
113 */
96struct AddressWrapper *tail; 114struct AddressWrapper *tail;
97 115
116unsigned int addresses_reported;
117
98/** 118/**
99 * Did the test pass or fail? 119 * Did the test pass or fail?
100 */ 120 */
@@ -115,21 +135,13 @@ struct AddressWrapper
115static void 135static void
116end () 136end ()
117{ 137{
118 if (NULL != head)
119 {
120
121 }
122
123 if (GNUNET_SCHEDULER_NO_TASK != timeout_task) 138 if (GNUNET_SCHEDULER_NO_TASK != timeout_task)
124 { 139 {
125 GNUNET_SCHEDULER_cancel (timeout_task); 140 GNUNET_SCHEDULER_cancel (timeout_task);
126 timeout_task = GNUNET_SCHEDULER_NO_TASK; 141 timeout_task = GNUNET_SCHEDULER_NO_TASK;
127 } 142 }
128
129 if (NULL != api) 143 if (NULL != api)
130 {
131 GNUNET_PLUGIN_unload (libname, api); 144 GNUNET_PLUGIN_unload (libname, api);
132 }
133 GNUNET_free (libname); 145 GNUNET_free (libname);
134 libname = NULL; 146 libname = NULL;
135 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 147 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
@@ -139,13 +151,16 @@ end ()
139} 151}
140 152
141static void 153static void
142
143end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 154end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
144{ 155{
145 struct AddressWrapper *w; 156 struct AddressWrapper *w;
146 int c = 0; 157 int c = 0;
147
148 timeout_task = GNUNET_SCHEDULER_NO_TASK; 158 timeout_task = GNUNET_SCHEDULER_NO_TASK;
159 if (GNUNET_SCHEDULER_NO_TASK != timeout_wait)
160 {
161 GNUNET_SCHEDULER_cancel (timeout_wait);
162 timeout_wait = GNUNET_SCHEDULER_NO_TASK;
163 }
149 if (NULL != libname) 164 if (NULL != libname)
150 { 165 {
151 if (NULL != api) 166 if (NULL != api)
@@ -178,10 +193,25 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
178 ok = 1; 193 ok = 1;
179} 194}
180 195
196static void
197wait_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
198{
199 timeout_wait = GNUNET_SCHEDULER_NO_TASK;
200 if (0 == addresses_reported)
201 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
202 _("Plugin did not report any addresses, could not check plugin \n"));
203 end ();
204}
205
181 206
182static void 207static void
183end_badly_now () 208end_badly_now ()
184{ 209{
210 if (GNUNET_SCHEDULER_NO_TASK != timeout_wait)
211 {
212 GNUNET_SCHEDULER_cancel (timeout_wait);
213 timeout_wait = GNUNET_SCHEDULER_NO_TASK;
214 }
185 if (GNUNET_SCHEDULER_NO_TASK != timeout_task) 215 if (GNUNET_SCHEDULER_NO_TASK != timeout_task)
186 { 216 {
187 GNUNET_SCHEDULER_cancel (timeout_task); 217 GNUNET_SCHEDULER_cancel (timeout_task);
@@ -202,7 +232,6 @@ env_receive (void *cls,
202 uint16_t sender_address_len) 232 uint16_t sender_address_len)
203{ 233{
204 /* do nothing */ 234 /* do nothing */
205 GNUNET_break (0);
206 return GNUNET_TIME_relative_get_zero_(); 235 return GNUNET_TIME_relative_get_zero_();
207} 236}
208 237
@@ -220,7 +249,8 @@ env_notify_address (void *cls,
220 249
221 if (GNUNET_YES == add_remove) 250 if (GNUNET_YES == add_remove)
222 { 251 {
223 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 252 addresses_reported ++;
253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 _("Adding address of length %u\n"), addrlen); 254 _("Adding address of length %u\n"), addrlen);
225 255
226 w = GNUNET_malloc (sizeof (struct AddressWrapper)); 256 w = GNUNET_malloc (sizeof (struct AddressWrapper));
@@ -271,10 +301,16 @@ env_notify_address (void *cls,
271 end_badly_now(); 301 end_badly_now();
272 return; 302 return;
273 } 303 }
304 if (GNUNET_SCHEDULER_NO_TASK != timeout_wait)
305 {
306 GNUNET_SCHEDULER_cancel (timeout_wait);
307 timeout_wait = GNUNET_SCHEDULER_NO_TASK;
308 }
309 timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL);
274 } 310 }
275 else if (GNUNET_NO == add_remove) 311 else if (GNUNET_NO == add_remove)
276 { 312 {
277 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
278 _("Removing address of length %u\n"), addrlen); 314 _("Removing address of length %u\n"), addrlen);
279 315
280 w = head; 316 w = head;
@@ -304,8 +340,9 @@ env_notify_address (void *cls,
304 { 340 {
305 GNUNET_break (0); 341 GNUNET_break (0);
306 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
307 _("Invalid operation\n")); 343 _("Invalid operation: %u \n"), add_remove);
308 end_badly_now (); 344 end_badly_now ();
345 return;
309 } 346 }
310} 347}
311 348
@@ -315,17 +352,15 @@ env_get_address_type (void *cls,
315 size_t addrlen) 352 size_t addrlen)
316{ 353{
317 struct GNUNET_ATS_Information ats; 354 struct GNUNET_ATS_Information ats;
318 ats.type = htonl (0); 355 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
319 ats.value = htonl (0); 356 ats.value = htonl (GNUNET_ATS_NET_LOOPBACK);
320 return ats; 357 return ats;
321} 358}
322 359
323
324const struct GNUNET_MessageHeader * 360const struct GNUNET_MessageHeader *
325env_get_our_hello (void) 361env_get_our_hello (void)
326{ 362{
327 GNUNET_break (0); 363 return (const struct GNUNET_MessageHeader *) hello;
328 return NULL;
329} 364}
330 365
331void env_session_end (void *cls, 366void env_session_end (void *cls,
@@ -409,6 +444,9 @@ run (void *cls, char *const *args, const char *cfgfile,
409 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), 444 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
410 &my_identity.hashPubKey); 445 &my_identity.hashPubKey);
411 446
447
448 hello = GNUNET_HELLO_create(&my_public_key, NULL, NULL);
449
412 /* load plugins... */ 450 /* load plugins... */
413 setup_plugin_environment (); 451 setup_plugin_environment ();
414 452
@@ -431,11 +469,13 @@ run (void *cls, char *const *args, const char *cfgfile,
431 if (api == NULL) 469 if (api == NULL)
432 { 470 {
433 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 471 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
434 _("Failed to load transport plugin for tcp\n")); 472 _("Failed to load transport plugin for %s\n"), plugin);
435 end_badly_now (); 473 end_badly_now ();
436 return; 474 return;
437 } 475 }
438 476
477 timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL);
478
439 /* Check if all functions are implemented */ 479 /* Check if all functions are implemented */
440 if (NULL == api->address_pretty_printer) 480 if (NULL == api->address_pretty_printer)
441 { 481 {