aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_plugin_transport.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-01-19 14:20:54 +0000
committerNathan S. Evans <evans@in.tum.de>2010-01-19 14:20:54 +0000
commitb6dbf7e98bb79907562bf67d423b67a030b503e7 (patch)
tree4a63aa64d332add505dd167289630c4c5a385233 /src/transport/test_plugin_transport.c
parentfff6dc1db59348e426b4c6cc5a5729080d93a163 (diff)
downloadgnunet-b6dbf7e98bb79907562bf67d423b67a030b503e7.tar.gz
gnunet-b6dbf7e98bb79907562bf67d423b67a030b503e7.zip
pre-commit
Diffstat (limited to 'src/transport/test_plugin_transport.c')
-rw-r--r--src/transport/test_plugin_transport.c146
1 files changed, 65 insertions, 81 deletions
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c
index d4183fc27..407150d3a 100644
--- a/src/transport/test_plugin_transport.c
+++ b/src/transport/test_plugin_transport.c
@@ -93,24 +93,20 @@ static int ok;
93 * Initialize Environment for this plugin 93 * Initialize Environment for this plugin
94 */ 94 */
95static void 95static void
96receive(void *cls, 96receive (void *cls,
97 struct GNUNET_TIME_Relative 97 struct GNUNET_TIME_Relative
98 latency, 98 latency,
99 const struct GNUNET_PeerIdentity 99 const struct GNUNET_PeerIdentity
100 * peer, 100 *peer, const struct GNUNET_MessageHeader *message)
101 const struct GNUNET_MessageHeader
102 * message)
103{ 101{
104 /* do nothing */ 102 /* do nothing */
105} 103}
106 104
107void notify_address(void *cls, 105void
108 const char *name, 106notify_address (void *cls,
109 const void *addr, 107 const char *name,
110 size_t addrlen, 108 const void *addr,
111 struct 109 size_t addrlen, struct GNUNET_TIME_Relative expires)
112 GNUNET_TIME_Relative
113 expires)
114{ 110{
115} 111}
116 112
@@ -122,19 +118,19 @@ void notify_address(void *cls,
122 * @param cfg configuration to use 118 * @param cfg configuration to use
123 */ 119 */
124static void 120static void
125unload_plugins (void *cls, 121unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
126 const struct GNUNET_CONFIGURATION_Handle *cfg) 122{
127{ 123 GNUNET_assert (NULL ==
128 GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_tcp",api)); 124 GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_tcp",
125 api));
129 if (my_private_key != NULL) 126 if (my_private_key != NULL)
130 GNUNET_CRYPTO_rsa_key_free (my_private_key); 127 GNUNET_CRYPTO_rsa_key_free (my_private_key);
131 128
132} 129}
133 130
134 131
135static void 132static void
136unload_task (void *cls, 133unload_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
137 const struct GNUNET_SCHEDULER_TaskContext *tc)
138{ 134{
139 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 135 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
140 unload_plugins (NULL, cfg); 136 unload_plugins (NULL, cfg);
@@ -144,12 +140,11 @@ unload_task (void *cls,
144static GNUNET_SCHEDULER_TaskIdentifier validation_timeout_task; 140static GNUNET_SCHEDULER_TaskIdentifier validation_timeout_task;
145 141
146 142
147static void 143static void
148validation_notification (void *cls, 144validation_notification (void *cls,
149 const char *name, 145 const char *name,
150 const struct GNUNET_PeerIdentity *peer, 146 const struct GNUNET_PeerIdentity *peer,
151 uint32_t challenge, 147 uint32_t challenge, const char *sender_addr)
152 const char *sender_addr)
153{ 148{
154 if (validation_timeout_task != GNUNET_SCHEDULER_NO_TASK) 149 if (validation_timeout_task != GNUNET_SCHEDULER_NO_TASK)
155 { 150 {
@@ -158,24 +153,23 @@ validation_notification (void *cls,
158 } 153 }
159 154
160 GNUNET_assert (challenge == 42); 155 GNUNET_assert (challenge == 42);
161 156
162 ok = 0; /* if the last test succeeded, report success */ 157 ok = 0; /* if the last test succeeded, report success */
163 GNUNET_SCHEDULER_add_continuation (sched, 158 GNUNET_SCHEDULER_add_continuation (sched,
164 &unload_task, 159 &unload_task,
165 (void*) cfg, 160 (void *) cfg,
166 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 161 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
167} 162}
168 163
169 164
170static void 165static void
171validation_failed (void *cls, 166validation_failed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
172 const struct GNUNET_SCHEDULER_TaskContext *tc)
173{ 167{
174 validation_timeout_task = GNUNET_SCHEDULER_NO_TASK; 168 validation_timeout_task = GNUNET_SCHEDULER_NO_TASK;
175 GNUNET_break (0); /* output error */ 169 GNUNET_break (0); /* output error */
176 /* the "validation_notification" was not called 170 /* the "validation_notification" was not called
177 in a timely fashion; we should set an error 171 in a timely fashion; we should set an error
178 code for main and shut down */ 172 code for main and shut down */
179 unload_plugins (NULL, cfg); 173 unload_plugins (NULL, cfg);
180} 174}
181 175
@@ -198,42 +192,36 @@ static void
198test_validation () 192test_validation ()
199{ 193{
200 struct sockaddr_in soaddr; 194 struct sockaddr_in soaddr;
201 195
202 memset (&soaddr, 0, sizeof(soaddr)); 196 memset (&soaddr, 0, sizeof (soaddr));
203#if HAVE_SOCKADDR_IN_SIN_LEN 197#if HAVE_SOCKADDR_IN_SIN_LEN
204 soaddr.sin_len = sizeof (soaddr); 198 soaddr.sin_len = sizeof (soaddr);
205#endif 199#endif
206 soaddr.sin_family = AF_INET; 200 soaddr.sin_family = AF_INET;
207 soaddr.sin_port = htons(2368 /* FIXME: get from config! */); 201 soaddr.sin_port = htons (2368 /* FIXME: get from config! */ );
208 soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 202 soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
209 api->validate (api->cls, 203 api->validate (api->cls,
210 &my_identity, 204 &my_identity, 42, TIMEOUT, &soaddr, sizeof (soaddr));
211 42,
212 TIMEOUT,
213 &soaddr,
214 sizeof(soaddr));
215 /* add job to catch failure (timeout) */ 205 /* add job to catch failure (timeout) */
216 validation_timeout_task = 206 validation_timeout_task =
217 GNUNET_SCHEDULER_add_delayed (sched, 207 GNUNET_SCHEDULER_add_delayed (sched, TIMEOUT, &validation_failed, NULL);
218 TIMEOUT,
219 &validation_failed,
220 NULL);
221} 208}
222 209
223 210
224static void setup_plugin_environment() 211static void
212setup_plugin_environment ()
225{ 213{
226 env.cfg = cfg; 214 env.cfg = cfg;
227 env.sched = sched; 215 env.sched = sched;
228 env.my_public_key = &my_public_key; 216 env.my_public_key = &my_public_key;
229 env.my_private_key = my_private_key; 217 env.my_private_key = my_private_key;
230 env.my_identity = &my_identity; 218 env.my_identity = &my_identity;
231 env.cls=&env; 219 env.cls = &env;
232 env.receive=&receive; 220 env.receive = &receive;
233 env.notify_address=&notify_address; 221 env.notify_address = &notify_address;
234 env.notify_validation = &validation_notification; 222 env.notify_validation = &validation_notification;
235 env.max_connections = max_connect_per_transport; 223 env.max_connections = max_connect_per_transport;
236} 224}
237 225
238 226
239/** 227/**
@@ -247,9 +235,8 @@ static void
247run (void *cls, 235run (void *cls,
248 struct GNUNET_SCHEDULER_Handle *s, 236 struct GNUNET_SCHEDULER_Handle *s,
249 char *const *args, 237 char *const *args,
250 const char *cfgfile, 238 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
251 const struct GNUNET_CONFIGURATION_Handle *c) 239{
252{
253 unsigned long long tneigh; 240 unsigned long long tneigh;
254 char *keyfile; 241 char *keyfile;
255 char *libname; 242 char *libname;
@@ -268,7 +255,8 @@ run (void *cls,
268 "HOSTKEY", &keyfile))) 255 "HOSTKEY", &keyfile)))
269 { 256 {
270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
271 _("Transport service is lacking key configuration settings. Exiting.\n")); 258 _
259 ("Transport service is lacking key configuration settings. Exiting.\n"));
272 GNUNET_SCHEDULER_shutdown (s); 260 GNUNET_SCHEDULER_shutdown (s);
273 return; 261 return;
274 } 262 }
@@ -278,25 +266,23 @@ run (void *cls,
278 if (my_private_key == NULL) 266 if (my_private_key == NULL)
279 { 267 {
280 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 268 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
281 _("Transport service could not access hostkey. Exiting.\n")); 269 _
270 ("Transport service could not access hostkey. Exiting.\n"));
282 GNUNET_SCHEDULER_shutdown (s); 271 GNUNET_SCHEDULER_shutdown (s);
283 return; 272 return;
284 } 273 }
285 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, 274 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
286 &my_public_key);
287 GNUNET_CRYPTO_hash (&my_public_key, 275 GNUNET_CRYPTO_hash (&my_public_key,
288 sizeof (my_public_key), 276 sizeof (my_public_key), &my_identity.hashPubKey);
289 &my_identity.hashPubKey); 277
290 278
291 279
292 280 /* load plugins... */
293 /* load plugins... */ 281 setup_plugin_environment ();
294 setup_plugin_environment(); 282 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading tcp transport plugin\n"));
295 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
296 _("Loading tcp transport plugin\n"));
297 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_tcp"); 283 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_tcp");
298 284
299 api = GNUNET_PLUGIN_load(libname, &env); 285 api = GNUNET_PLUGIN_load (libname, &env);
300 GNUNET_free (libname); 286 GNUNET_free (libname);
301 if (api == NULL) 287 if (api == NULL)
302 { 288 {
@@ -304,7 +290,7 @@ run (void *cls,
304 _("Failed to load transport plugin for tcp\n")); 290 _("Failed to load transport plugin for tcp\n"));
305 /* FIXME: set some error code for main */ 291 /* FIXME: set some error code for main */
306 return; 292 return;
307 } 293 }
308 test_validation (); 294 test_validation ();
309} 295}
310 296
@@ -334,22 +320,20 @@ main (int argc, char *const *argv)
334 "WARNING", 320 "WARNING",
335#endif 321#endif
336 NULL 322 NULL
337 }; 323 };
338 GNUNET_log_setup ("test-plugin-transport", 324 GNUNET_log_setup ("test-plugin-transport",
339#if VERBOSE 325#if VERBOSE
340 "DEBUG", 326 "DEBUG",
341#else 327#else
342 "WARNING", 328 "WARNING",
343#endif 329#endif
344 NULL); 330 NULL);
345 ok = 1; /* set to fail */ 331 ok = 1; /* set to fail */
346 ret = (GNUNET_OK == 332 ret = (GNUNET_OK ==
347 GNUNET_PROGRAM_run (5, 333 GNUNET_PROGRAM_run (5,
348 argv_prog, 334 argv_prog,
349 "test-plugin-transport", 335 "test-plugin-transport",
350 "testcase", 336 "testcase", options, &run, NULL)) ? ok : 1;
351 options,
352 &run, NULL)) ? ok : 1;
353 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); 337 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport");
354 return ret; 338 return ret;
355} 339}