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