aboutsummaryrefslogtreecommitdiff
path: root/src/dv/test_transport_api_dv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dv/test_transport_api_dv.c')
-rw-r--r--src/dv/test_transport_api_dv.c252
1 files changed, 221 insertions, 31 deletions
diff --git a/src/dv/test_transport_api_dv.c b/src/dv/test_transport_api_dv.c
index 8b4593814..bacec6f0f 100644
--- a/src/dv/test_transport_api_dv.c
+++ b/src/dv/test_transport_api_dv.c
@@ -60,6 +60,8 @@ struct PeerContext
60 struct GNUNET_CONFIGURATION_Handle *cfg; 60 struct GNUNET_CONFIGURATION_Handle *cfg;
61 struct GNUNET_TRANSPORT_Handle *th; 61 struct GNUNET_TRANSPORT_Handle *th;
62 struct GNUNET_PeerIdentity id; 62 struct GNUNET_PeerIdentity id;
63 const char *cfg_file;
64 const struct GNUNET_HELLO_Message *hello;
63#if START_ARM 65#if START_ARM
64 pid_t arm_pid; 66 pid_t arm_pid;
65#endif 67#endif
@@ -88,11 +90,12 @@ static void
88end () 90end ()
89{ 91{
90 /* do work here */ 92 /* do work here */
91 GNUNET_assert (ok == 6);
92 GNUNET_SCHEDULER_cancel (sched, die_task); 93 GNUNET_SCHEDULER_cancel (sched, die_task);
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transport 1!\n");
94 GNUNET_TRANSPORT_disconnect (p1.th); 95 GNUNET_TRANSPORT_disconnect (p1.th);
96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transport 2!\n");
95 GNUNET_TRANSPORT_disconnect (p2.th); 97 GNUNET_TRANSPORT_disconnect (p2.th);
98 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transport 3!\n");
96 GNUNET_TRANSPORT_disconnect (p3.th); 99 GNUNET_TRANSPORT_disconnect (p3.th);
97 100
98 die_task = GNUNET_SCHEDULER_NO_TASK; 101 die_task = GNUNET_SCHEDULER_NO_TASK;
@@ -104,8 +107,13 @@ static void
104stop_arm (struct PeerContext *p) 107stop_arm (struct PeerContext *p)
105{ 108{
106#if START_ARM 109#if START_ARM
107 if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) 110 p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
108 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 111 "gnunet-arm",
112#if VERBOSE
113 "-L", "DEBUG",
114#endif
115 "-c", p->cfg_file, "-e", NULL);
116
109 GNUNET_OS_process_wait (p->arm_pid); 117 GNUNET_OS_process_wait (p->arm_pid);
110#endif 118#endif
111 GNUNET_CONFIGURATION_destroy (p->cfg); 119 GNUNET_CONFIGURATION_destroy (p->cfg);
@@ -113,6 +121,34 @@ stop_arm (struct PeerContext *p)
113 121
114 122
115static void 123static void
124restart_transport (struct PeerContext *p)
125{
126#if START_ARM
127 p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
128 "gnunet-arm",
129#if VERBOSE
130 "-L", "DEBUG",
131#endif
132 "-c", p->cfg_file, "-k", "transport", NULL);
133
134 fprintf(stderr, "stop arm command returned %d\n", p->arm_pid);
135 GNUNET_OS_process_wait (p->arm_pid);
136#endif
137
138#if START_ARM
139 p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
140 "gnunet-arm",
141#if VERBOSE
142 "-L", "DEBUG",
143#endif
144 "-c", p->cfg_file, "-i", "transport", NULL);
145
146 GNUNET_OS_process_wait (p->arm_pid);
147#endif
148}
149
150
151static void
116end_badly () 152end_badly ()
117{ 153{
118 /* do work here */ 154 /* do work here */
@@ -139,17 +175,12 @@ notify_receive (void *cls,
139 if (ntohs(message->type) != MTYPE) 175 if (ntohs(message->type) != MTYPE)
140 return; 176 return;
141 177
142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer (%p)!\n", 178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer (%p) distance %d!\n",
143 ntohs(message->type), cls); 179 ntohs(message->type), cls, distance);
144
145 GNUNET_assert (ok == 5);
146 OKPP;
147 180
148 GNUNET_assert (MTYPE == ntohs (message->type)); 181 GNUNET_assert (MTYPE == ntohs (message->type));
149 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == 182 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
150 ntohs (message->size)); 183 ntohs (message->size));
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from peer (%p)!\n",
152 cls);
153 end (); 184 end ();
154} 185}
155 186
@@ -162,8 +193,7 @@ notify_ready (void *cls, size_t size, void *buf)
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
163 "Transmitting message to peer (%p) - %u!\n", cls, size); 194 "Transmitting message to peer (%p) - %u!\n", cls, size);
164 GNUNET_assert (size >= 256); 195 GNUNET_assert (size >= 256);
165 GNUNET_assert (ok == 4); 196
166 OKPP;
167 if (buf != NULL) 197 if (buf != NULL)
168 { 198 {
169 hdr = buf; 199 hdr = buf;
@@ -181,17 +211,36 @@ notify_connect (void *cls,
181 struct GNUNET_TIME_Relative latency, 211 struct GNUNET_TIME_Relative latency,
182 uint32_t distance) 212 uint32_t distance)
183{ 213{
214 int peer_num = 0;
215 int connect_num = 0;
216
217 if (cls == &p1)
218 peer_num = 1;
219 else if (cls == &p2)
220 peer_num = 2;
221 else if (cls == &p3)
222 peer_num = 3;
223
224 if (memcmp(peer, &p1.id, sizeof(struct GNUNET_PeerIdentity)) == 0)
225 connect_num = 1;
226 else if (memcmp(peer, &p2.id, sizeof(struct GNUNET_PeerIdentity)) == 0)
227 connect_num = 2;
228 else if (memcmp(peer, &p3.id, sizeof(struct GNUNET_PeerIdentity)) == 0)
229 connect_num = 3;
230
184 if ((cls == &p1) && (memcmp(peer, &p3.id, sizeof(struct GNUNET_PeerIdentity)) == 0)) 231 if ((cls == &p1) && (memcmp(peer, &p3.id, sizeof(struct GNUNET_PeerIdentity)) == 0))
185 { 232 {
233
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "Peer 1 notified about connection to peer 3!\n", GNUNET_i2s (peer), cls); 235 "Peer 1 notified about connection to peer 3, distance %d!\n", GNUNET_i2s (peer), cls, distance);
188 GNUNET_TRANSPORT_notify_transmit_ready (p1.th, 236
237 GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
189 &p3.id, 238 &p3.id,
190 256, 0, TIMEOUT, &notify_ready, 239 256, 0, TIMEOUT, &notify_ready,
191 &p1); 240 &p1);
192 } 241 }
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); 243 "Peer `%d' connected to peer `%d' distance %d!\n", peer_num, connect_num, distance);
195} 244}
196 245
197 246
@@ -208,21 +257,44 @@ static void
208setup_peer (struct PeerContext *p, const char *cfgname) 257setup_peer (struct PeerContext *p, const char *cfgname)
209{ 258{
210 p->cfg = GNUNET_CONFIGURATION_create (); 259 p->cfg = GNUNET_CONFIGURATION_create ();
260 p->cfg_file = strdup(cfgname);
211#if START_ARM 261#if START_ARM
212 p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 262 p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
213 "gnunet-service-arm", 263 "gnunet-arm",
214#if VERBOSE_ARM 264#if VERBOSE_ARM
215 "-L", "DEBUG", 265 "-L", "DEBUG",
216#endif 266#endif
217 "-c", cfgname, NULL); 267 "-c", cfgname, "-s", NULL);
218#endif 268#endif
219 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 269 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
220 270
221 p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, 271 /*p->th = GNUNET_TRANSPORT_connect (sched, p->cfg,
222 p, 272 p,
223 &notify_receive, 273 &notify_receive,
224 &notify_connect, &notify_disconnect); 274 &notify_connect, &notify_disconnect);*/
225 GNUNET_assert (p->th != NULL); 275 /*GNUNET_assert (p->th != NULL);*/
276}
277
278
279static void
280exchange_hello_last (void *cls,
281 const struct GNUNET_MessageHeader *message)
282{
283 struct PeerContext *me = cls;
284
285 GNUNET_TRANSPORT_get_hello_cancel (p3.th, &exchange_hello_last, me);
286
287 GNUNET_assert (message != NULL);
288 GNUNET_assert (GNUNET_OK ==
289 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
290 message, &me->id));
291
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "Received HELLO size %d\n", GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
294
295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
296 "Finished exchanging HELLOs, now waiting for transmission!\n");
297
226} 298}
227 299
228 300
@@ -235,8 +307,7 @@ exchange_hello_next (void *cls,
235 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_next, me); 307 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_next, me);
236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
237 "Exchanging HELLO with peer (%p)!\n", cls); 309 "Exchanging HELLO with peer (%p)!\n", cls);
238 GNUNET_assert (ok >= 3); 310
239 OKPP;
240 GNUNET_assert (message != NULL); 311 GNUNET_assert (message != NULL);
241 GNUNET_assert (GNUNET_OK == 312 GNUNET_assert (GNUNET_OK ==
242 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 313 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
@@ -247,8 +318,8 @@ exchange_hello_next (void *cls,
247 318
248 GNUNET_TRANSPORT_offer_hello (p3.th, message); 319 GNUNET_TRANSPORT_offer_hello (p3.th, message);
249 320
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 321 GNUNET_TRANSPORT_get_hello (p3.th, &exchange_hello_last, &p3);
251 "Finished exchanging HELLOs, now waiting for transmission!\n"); 322
252 323
253} 324}
254 325
@@ -260,10 +331,16 @@ exchange_hello (void *cls,
260 struct PeerContext *me = cls; 331 struct PeerContext *me = cls;
261 332
262 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, me); 333 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, me);
334 p2.th = GNUNET_TRANSPORT_connect (sched, p2.cfg,
335 &p2,
336 &notify_receive,
337 &notify_connect, &notify_disconnect);
338
339 GNUNET_assert(p2.th != NULL);
340
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264 "Exchanging HELLO with peer (%p)!\n", cls); 342 "Exchanging HELLO with peer (%p)!\n", cls);
265 GNUNET_assert (ok >= 2); 343
266 OKPP;
267 GNUNET_assert (message != NULL); 344 GNUNET_assert (message != NULL);
268 GNUNET_assert (GNUNET_OK == 345 GNUNET_assert (GNUNET_OK ==
269 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 346 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
@@ -277,6 +354,115 @@ exchange_hello (void *cls,
277} 354}
278 355
279static void 356static void
357blacklist_setup_third (void *cls,
358 const struct GNUNET_MessageHeader *message)
359{
360 struct PeerContext *me = cls;
361 char *blacklist_filename;
362 struct GNUNET_DISK_FileHandle *file;
363 struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc;
364 char *buf;
365 size_t size;
366
367 GNUNET_TRANSPORT_get_hello_cancel (p3.th, &blacklist_setup_third, &p3);
368
369 GNUNET_assert (message != NULL);
370 GNUNET_assert (GNUNET_OK ==
371 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
372 message, &me->id));
373
374 GNUNET_asprintf(&blacklist_filename, "/tmp/test-gnunetd-transport-peer-1/blacklist");
375 if (blacklist_filename != NULL)
376 {
377 file = GNUNET_DISK_file_open(blacklist_filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | GNUNET_DISK_OPEN_CREATE,
378 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
379 GNUNET_free(blacklist_filename);
380
381 if (file == NULL)
382 {
383 GNUNET_SCHEDULER_cancel(sched, die_task);
384 GNUNET_SCHEDULER_add_now(sched, &end_badly, NULL);
385 return;
386 }
387 GNUNET_CRYPTO_hash_to_enc(&me->id.hashPubKey, &peer_enc);
388 size = GNUNET_asprintf(&buf, "%s:%s\n", "tcp", (char *)&peer_enc);
389 GNUNET_DISK_file_write(file, buf, size);
390 GNUNET_free_non_null(buf);
391 }
392
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 "Restarting transport service (%p) with gnunet-arm -c %s -L DEBUG -k transport!\n", cls, p1.cfg_file);
395
396 restart_transport(&p1);
397
398 p1.th = GNUNET_TRANSPORT_connect (sched, p1.cfg,
399 &p1,
400 &notify_receive,
401 &notify_connect, &notify_disconnect);
402
403 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
404}
405
406static void
407blacklist_setup_first (void *cls,
408 const struct GNUNET_MessageHeader *message)
409{
410 struct PeerContext *me = cls;
411 char *blacklist_filename;
412 struct GNUNET_DISK_FileHandle *file;
413 struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc;
414 char *buf;
415 size_t size;
416
417 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &blacklist_setup_first, me);
418 sleep(2);
419
420 GNUNET_assert (message != NULL);
421 GNUNET_assert (GNUNET_OK ==
422 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
423 message, &me->id));
424
425 GNUNET_asprintf(&blacklist_filename, "/tmp/test-gnunetd-transport-peer-3/blacklist");
426 if (blacklist_filename != NULL)
427 {
428 file = GNUNET_DISK_file_open(blacklist_filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | GNUNET_DISK_OPEN_CREATE,
429 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
430 GNUNET_free(blacklist_filename);
431
432 if (file == NULL)
433 {
434 GNUNET_SCHEDULER_cancel(sched, die_task);
435 GNUNET_SCHEDULER_add_now(sched, &end_badly, NULL);
436 return;
437 }
438 GNUNET_CRYPTO_hash_to_enc(&me->id.hashPubKey, &peer_enc);
439 size = GNUNET_asprintf(&buf, "%s:%s\n", "tcp", (char *)&peer_enc);
440 GNUNET_DISK_file_write(file, buf, size);
441 GNUNET_free_non_null(buf);
442 }
443
444 GNUNET_TRANSPORT_disconnect(p1.th);
445
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
447 "Restarting transport service (%p) with gnunet-arm -c %s -L DEBUG -k transport!\n", cls, p3.cfg_file);
448 restart_transport(&p3);
449
450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
451 "reconnecting to transport (%p)!\n", cls);
452 p3.th = GNUNET_TRANSPORT_connect (sched, p3.cfg,
453 &p3,
454 &notify_receive,
455 &notify_connect, &notify_disconnect);
456 if (p3.th != NULL)
457 GNUNET_TRANSPORT_get_hello (p3.th, &blacklist_setup_third, &p3);
458 else
459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
460 "reconnecting to transport (%p) failed.!\n", cls);
461 //GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
462}
463
464
465static void
280run (void *cls, 466run (void *cls,
281 struct GNUNET_SCHEDULER_Handle *s, 467 struct GNUNET_SCHEDULER_Handle *s,
282 char *const *args, 468 char *const *args,
@@ -293,11 +479,15 @@ run (void *cls,
293 setup_peer (&p2, "test_transport_api_dv_peer2.conf"); 479 setup_peer (&p2, "test_transport_api_dv_peer2.conf");
294 setup_peer (&p3, "test_transport_api_dv_peer3.conf"); 480 setup_peer (&p3, "test_transport_api_dv_peer3.conf");
295 481
482 p1.th = GNUNET_TRANSPORT_connect (sched, p1.cfg,
483 &p1,
484 &notify_receive,
485 &notify_connect, &notify_disconnect);
296 GNUNET_assert(p1.th != NULL); 486 GNUNET_assert(p1.th != NULL);
297 GNUNET_assert(p2.th != NULL); 487 /*GNUNET_assert(p2.th != NULL);
298 GNUNET_assert(p3.th != NULL); 488 GNUNET_assert(p3.th != NULL);*/
299 489
300 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); 490 GNUNET_TRANSPORT_get_hello (p1.th, &blacklist_setup_first, &p1);
301} 491}
302 492
303static int 493static int