aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-02-01 17:08:21 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-02-01 17:08:21 +0000
commit67f3331b28aee547a80a972099c85e91cb3d5382 (patch)
treeeb8bf6892b1943219a3c38876fcac9ba5ec1a0ed /src/transport
parent45071615217cedd90eaaaeb4f70712cb84427ece (diff)
downloadgnunet-67f3331b28aee547a80a972099c85e91cb3d5382.tar.gz
gnunet-67f3331b28aee547a80a972099c85e91cb3d5382.zip
fixing and testing blacklisting api and service
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am13
-rw-r--r--src/transport/gnunet-service-transport_blacklist.c1
-rw-r--r--src/transport/test_transport_api_blacklisting.c101
-rw-r--r--src/transport/transport_api_blacklist.c8
4 files changed, 104 insertions, 19 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index b816209b7..2fe7d8416 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -351,7 +351,8 @@ test_transport_api_blacklisting_LDADD = \
351 $(top_builddir)/src/transport/libgnunettransport.la \ 351 $(top_builddir)/src/transport/libgnunettransport.la \
352 $(top_builddir)/src/hello/libgnunethello.la \ 352 $(top_builddir)/src/hello/libgnunethello.la \
353 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 353 $(top_builddir)/src/statistics/libgnunetstatistics.la \
354 $(top_builddir)/src/util/libgnunetutil.la 354 $(top_builddir)/src/util/libgnunetutil.la \
355 $(top_builddir)/src/transport/libgnunettransporttesting.la
355 356
356test_transport_api_disconnect_tcp_SOURCES = \ 357test_transport_api_disconnect_tcp_SOURCES = \
357 test_transport_api_disconnect.c 358 test_transport_api_disconnect.c
@@ -378,7 +379,7 @@ test_transport_api_tcp_LDADD = \
378 $(top_builddir)/src/hello/libgnunethello.la \ 379 $(top_builddir)/src/hello/libgnunethello.la \
379 $(top_builddir)/src/util/libgnunetutil.la \ 380 $(top_builddir)/src/util/libgnunetutil.la \
380 $(top_builddir)/src/transport/libgnunettransporttesting.la 381 $(top_builddir)/src/transport/libgnunettransporttesting.la
381 382
382test_transport_api_bidirectional_connect_SOURCES = \ 383test_transport_api_bidirectional_connect_SOURCES = \
383 test_transport_api_bidirectional_connect.c 384 test_transport_api_bidirectional_connect.c
384test_transport_api_bidirectional_connect_LDADD = \ 385test_transport_api_bidirectional_connect_LDADD = \
@@ -404,7 +405,7 @@ test_transport_api_restart_2peers_LDADD = \
404 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 405 $(top_builddir)/src/statistics/libgnunetstatistics.la \
405 $(top_builddir)/src/util/libgnunetutil.la \ 406 $(top_builddir)/src/util/libgnunetutil.la \
406 $(top_builddir)/src/transport/libgnunettransporttesting.la 407 $(top_builddir)/src/transport/libgnunettransporttesting.la
407 408
408test_transport_api_limited_sockets_tcp_SOURCES = \ 409test_transport_api_limited_sockets_tcp_SOURCES = \
409 test_transport_api_limited_sockets.c 410 test_transport_api_limited_sockets.c
410test_transport_api_limited_sockets_tcp_LDADD = \ 411test_transport_api_limited_sockets_tcp_LDADD = \
@@ -444,7 +445,7 @@ test_transport_api_timeout_http_LDADD = \
444 $(top_builddir)/src/hello/libgnunethello.la \ 445 $(top_builddir)/src/hello/libgnunethello.la \
445 $(top_builddir)/src/util/libgnunetutil.la \ 446 $(top_builddir)/src/util/libgnunetutil.la \
446 $(top_builddir)/src/transport/libgnunettransporttesting.la 447 $(top_builddir)/src/transport/libgnunettransporttesting.la
447 448
448test_transport_api_timeout_https_SOURCES = \ 449test_transport_api_timeout_https_SOURCES = \
449 test_transport_api_timeout.c 450 test_transport_api_timeout.c
450test_transport_api_timeout_https_LDADD = \ 451test_transport_api_timeout_https_LDADD = \
@@ -452,7 +453,7 @@ test_transport_api_timeout_https_LDADD = \
452 $(top_builddir)/src/hello/libgnunethello.la \ 453 $(top_builddir)/src/hello/libgnunethello.la \
453 $(top_builddir)/src/util/libgnunetutil.la \ 454 $(top_builddir)/src/util/libgnunetutil.la \
454 $(top_builddir)/src/transport/libgnunettransporttesting.la 455 $(top_builddir)/src/transport/libgnunettransporttesting.la
455 456
456test_transport_api_reliability_tcp_nat_SOURCES = \ 457test_transport_api_reliability_tcp_nat_SOURCES = \
457 test_transport_api_reliability.c 458 test_transport_api_reliability.c
458test_transport_api_reliability_tcp_nat_LDADD = \ 459test_transport_api_reliability_tcp_nat_LDADD = \
@@ -516,7 +517,7 @@ test_transport_api_http_LDADD = \
516 $(top_builddir)/src/hello/libgnunethello.la \ 517 $(top_builddir)/src/hello/libgnunethello.la \
517 $(top_builddir)/src/util/libgnunetutil.la \ 518 $(top_builddir)/src/util/libgnunetutil.la \
518 $(top_builddir)/src/transport/libgnunettransporttesting.la 519 $(top_builddir)/src/transport/libgnunettransporttesting.la
519 520
520 test_transport_api_http_nat_SOURCES = \ 521 test_transport_api_http_nat_SOURCES = \
521 test_transport_api.c 522 test_transport_api.c
522test_transport_api_http_nat_LDADD = \ 523test_transport_api_http_nat_LDADD = \
diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c
index fc7a5cec3..2089949f7 100644
--- a/src/transport/gnunet-service-transport_blacklist.c
+++ b/src/transport/gnunet-service-transport_blacklist.c
@@ -489,6 +489,7 @@ do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
489 GNUNET_i2s (&bc->peer)); 489 GNUNET_i2s (&bc->peer));
490#endif 490#endif
491 bc->cont (bc->cont_cls, &bc->peer, GNUNET_OK); 491 bc->cont (bc->cont_cls, &bc->peer, GNUNET_OK);
492 GNUNET_CONTAINER_DLL_remove(bc_head, bc_tail, bc);
492 GNUNET_free (bc); 493 GNUNET_free (bc);
493 return; 494 return;
494 } 495 }
diff --git a/src/transport/test_transport_api_blacklisting.c b/src/transport/test_transport_api_blacklisting.c
index ee120cfc5..fc5ffda55 100644
--- a/src/transport/test_transport_api_blacklisting.c
+++ b/src/transport/test_transport_api_blacklisting.c
@@ -35,7 +35,7 @@
35#include "transport.h" 35#include "transport.h"
36#include "transport-testing.h" 36#include "transport-testing.h"
37 37
38#define VERBOSE GNUNET_YES 38#define VERBOSE GNUNET_EXTRA_LOGGING
39#define VERBOSE_ARM GNUNET_EXTRA_LOGGING 39#define VERBOSE_ARM GNUNET_EXTRA_LOGGING
40 40
41#define START_ARM GNUNET_YES 41#define START_ARM GNUNET_YES
@@ -67,6 +67,9 @@ struct GNUNET_TRANSPORT_TESTING_handle *tth;
67 67
68 68
69static int ok; 69static int ok;
70static int connected;
71static int blacklist_request_p1;
72static int blacklist_request_p2;
70 73
71struct GNUNET_TRANSPORT_Blacklist * blacklist_p1; 74struct GNUNET_TRANSPORT_Blacklist * blacklist_p1;
72 75
@@ -76,6 +79,8 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task;
76 79
77static GNUNET_SCHEDULER_TaskIdentifier send_task; 80static GNUNET_SCHEDULER_TaskIdentifier send_task;
78 81
82static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
83
79#if VERBOSE 84#if VERBOSE
80#define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 85#define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
81#else 86#else
@@ -84,7 +89,7 @@ static GNUNET_SCHEDULER_TaskIdentifier send_task;
84 89
85 90
86static void 91static void
87end () 92end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
88{ 93{
89 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping\n"); 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping\n");
90 95
@@ -92,27 +97,72 @@ end ()
92 GNUNET_SCHEDULER_cancel (send_task); 97 GNUNET_SCHEDULER_cancel (send_task);
93 98
94 if (die_task != GNUNET_SCHEDULER_NO_TASK) 99 if (die_task != GNUNET_SCHEDULER_NO_TASK)
100 {
95 GNUNET_SCHEDULER_cancel (die_task); 101 GNUNET_SCHEDULER_cancel (die_task);
102 die_task = GNUNET_SCHEDULER_NO_TASK;
103 }
104
105 if (cc != NULL)
106 {
107 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc);
108 cc = NULL;
109 }
96 110
97 if (th != NULL) 111 if (th != NULL)
98 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 112 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
99 th = NULL; 113 th = NULL;
100 114
101 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p1); 115 if (blacklist_p1 != NULL)
116 {
117 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p1);
118 blacklist_p1 = NULL;
119 }
102 120
103 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p2); 121 if (blacklist_p2 != NULL)
122 {
123 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p2);
124 blacklist_p2 = NULL;
125 }
104 126
105 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 127 if (p1 != NULL)
106 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); 128 {
129 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
130 p1 = NULL;
131 }
132 if (p2 != NULL)
133 {
134 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
135 p2 = NULL;
136 }
107 137
108 ok = 0; 138 if ((blacklist_request_p1 == GNUNET_YES) &&
139 (blacklist_request_p2 == GNUNET_YES) &&
140 (connected == GNUNET_NO))
141 {
142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Peers were not connected, success\n"));
143 ok = 0;
144 }
145 else
146 {
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Peers were not connected, fail\n"));
148 ok = 1;
149 }
109} 150}
110 151
111static void 152static void
112end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 153end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
113{ 154{
114 if (send_task != GNUNET_SCHEDULER_NO_TASK) 155 if (send_task != GNUNET_SCHEDULER_NO_TASK)
156 {
115 GNUNET_SCHEDULER_cancel (send_task); 157 GNUNET_SCHEDULER_cancel (send_task);
158 send_task = GNUNET_SCHEDULER_NO_TASK;
159 }
160
161 if (shutdown_task != GNUNET_SCHEDULER_NO_TASK)
162 {
163 GNUNET_SCHEDULER_cancel (shutdown_task);
164 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
165 }
116 166
117 if (cc != NULL) 167 if (cc != NULL)
118 { 168 {
@@ -166,13 +216,13 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
166 (MSIZE == ntohs (message->size))) 216 (MSIZE == ntohs (message->size)))
167 { 217 {
168 ok = 0; 218 ok = 0;
169 end (); 219 shutdown_task = GNUNET_SCHEDULER_add_now(&end, NULL);
170 } 220 }
171 else 221 else
172 { 222 {
173 GNUNET_break (0); 223 GNUNET_break (0);
174 ok = 1; 224 ok = 1;
175 end (); 225 shutdown_task = GNUNET_SCHEDULER_add_now(&end, NULL);
176 } 226 }
177} 227}
178 228
@@ -190,7 +240,10 @@ notify_ready (void *cls, size_t size, void *buf)
190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 240 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
191 "Timeout occurred while waiting for transmit_ready\n"); 241 "Timeout occurred while waiting for transmit_ready\n");
192 if (GNUNET_SCHEDULER_NO_TASK != die_task) 242 if (GNUNET_SCHEDULER_NO_TASK != die_task)
243 {
193 GNUNET_SCHEDULER_cancel (die_task); 244 GNUNET_SCHEDULER_cancel (die_task);
245 die_task = GNUNET_SCHEDULER_NO_TASK;
246 }
194 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 247 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
195 ok = 42; 248 ok = 42;
196 return 0; 249 return 0;
@@ -286,6 +339,8 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
286 p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); 339 p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
287 GNUNET_free (p1_c); 340 GNUNET_free (p1_c);
288 341
342
343
289 send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); 344 send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
290} 345}
291 346
@@ -294,8 +349,27 @@ int blacklist_cb (void *cls,
294 const struct 349 const struct
295 GNUNET_PeerIdentity * pid) 350 GNUNET_PeerIdentity * pid)
296{ 351{
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Blacklist request\n", GNUNET_i2s (pid)); 352 struct PeerContext * p = cls;
298 return GNUNET_YES; 353 int res = GNUNET_SYSERR;
354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u : Blacklist request for peer `%s'\n", p->no, GNUNET_i2s (pid));
355
356 if (p == p1)
357 {
358 blacklist_request_p1 = GNUNET_YES;
359 res = GNUNET_OK;
360 }
361 else if (p == p2)
362 {
363 blacklist_request_p2 = GNUNET_YES;
364 res = GNUNET_SYSERR;
365 }
366
367 if (((blacklist_request_p2 == GNUNET_YES) && (blacklist_request_p1 == GNUNET_YES)) && (shutdown_task == GNUNET_SCHEDULER_NO_TASK))
368 {
369 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3), &end, NULL);
370 }
371
372 return res;
299} 373}
300 374
301void 375void
@@ -328,6 +402,9 @@ run (void *cls, char *const *args, const char *cfgfile,
328 const struct GNUNET_CONFIGURATION_Handle *cfg) 402 const struct GNUNET_CONFIGURATION_Handle *cfg)
329{ 403{
330 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 404 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
405 connected = GNUNET_NO;
406 blacklist_request_p1 = GNUNET_NO;
407 blacklist_request_p2 = GNUNET_NO;
331 408
332 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_api_tcp_peer1.conf", 1, 409 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_api_tcp_peer1.conf", 1,
333 &notify_receive, &notify_connect, 410 &notify_receive, &notify_connect,
@@ -343,7 +420,7 @@ run (void *cls, char *const *args, const char *cfgfile,
343 &blacklist_cb, 420 &blacklist_cb,
344 p1); 421 p1);
345 422
346 blacklist_p2 = GNUNET_TRANSPORT_blacklist (p1->cfg, 423 blacklist_p2 = GNUNET_TRANSPORT_blacklist (p2->cfg,
347 &blacklist_cb, 424 &blacklist_cb,
348 p2); 425 p2);
349 426
diff --git a/src/transport/transport_api_blacklist.c b/src/transport/transport_api_blacklist.c
index b1c536a9d..be52623bb 100644
--- a/src/transport/transport_api_blacklist.c
+++ b/src/transport/transport_api_blacklist.c
@@ -145,6 +145,7 @@ transmit_blacklist_init (void *cls, size_t size, void *buf)
145 struct GNUNET_TRANSPORT_Blacklist *br = cls; 145 struct GNUNET_TRANSPORT_Blacklist *br = cls;
146 struct GNUNET_MessageHeader req; 146 struct GNUNET_MessageHeader req;
147 147
148 br->th = NULL;
148 if (buf == NULL) 149 if (buf == NULL)
149 { 150 {
150 reconnect (br); 151 reconnect (br);
@@ -153,7 +154,6 @@ transmit_blacklist_init (void *cls, size_t size, void *buf)
153 req.size = htons (sizeof (struct GNUNET_MessageHeader)); 154 req.size = htons (sizeof (struct GNUNET_MessageHeader));
154 req.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT); 155 req.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT);
155 memcpy (buf, &req, sizeof (req)); 156 memcpy (buf, &req, sizeof (req));
156 br->th = NULL;
157 receive (br); 157 receive (br);
158 return sizeof (req); 158 return sizeof (req);
159} 159}
@@ -194,6 +194,7 @@ transmit_blacklist_reply (void *cls, size_t size, void *buf)
194 struct GNUNET_TRANSPORT_Blacklist *br = cls; 194 struct GNUNET_TRANSPORT_Blacklist *br = cls;
195 struct BlacklistMessage req; 195 struct BlacklistMessage req;
196 196
197 br->th = NULL;
197 if (buf == NULL) 198 if (buf == NULL)
198 { 199 {
199 reconnect (br); 200 reconnect (br);
@@ -218,6 +219,7 @@ transmit_blacklist_reply (void *cls, size_t size, void *buf)
218static void 219static void
219reply (struct GNUNET_TRANSPORT_Blacklist *br) 220reply (struct GNUNET_TRANSPORT_Blacklist *br)
220{ 221{
222 GNUNET_assert (br->th == NULL);
221 br->th = 223 br->th =
222 GNUNET_CLIENT_notify_transmit_ready (br->client, 224 GNUNET_CLIENT_notify_transmit_ready (br->client,
223 sizeof (struct BlacklistMessage), 225 sizeof (struct BlacklistMessage),
@@ -261,6 +263,7 @@ GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
261 ret->cfg = cfg; 263 ret->cfg = cfg;
262 ret->cb = cb; 264 ret->cb = cb;
263 ret->cb_cls = cb_cls; 265 ret->cb_cls = cb_cls;
266 GNUNET_assert (ret->th == NULL);
264 ret->th = 267 ret->th =
265 GNUNET_CLIENT_notify_transmit_ready (client, 268 GNUNET_CLIENT_notify_transmit_ready (client,
266 sizeof (struct GNUNET_MessageHeader), 269 sizeof (struct GNUNET_MessageHeader),
@@ -281,7 +284,10 @@ void
281GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br) 284GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br)
282{ 285{
283 if (br->th != NULL) 286 if (br->th != NULL)
287 {
284 GNUNET_CLIENT_notify_transmit_ready_cancel (br->th); 288 GNUNET_CLIENT_notify_transmit_ready_cancel (br->th);
289 br->th = NULL;
290 }
285 GNUNET_CLIENT_disconnect (br->client, GNUNET_NO); 291 GNUNET_CLIENT_disconnect (br->client, GNUNET_NO);
286 GNUNET_free (br); 292 GNUNET_free (br);
287} 293}