diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-03-27 12:35:39 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-03-27 12:35:39 +0000 |
commit | a353783db723953fe2b18973f38b6b64cd93cb06 (patch) | |
tree | db799143ec3c193f0404baa0decb526e3f1c7514 /src/transport/gnunet-service-transport.c | |
parent | 88809f6c07d0ba65b175e03d7486aa85b513e162 (diff) | |
download | gnunet-a353783db723953fe2b18973f38b6b64cd93cb06.tar.gz gnunet-a353783db723953fe2b18973f38b6b64cd93cb06.zip |
blacklist checks have to be cancelled when session is terminated, especially when blacklist clients are active
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 105 |
1 files changed, 55 insertions, 50 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 7b734ab0c..b64a5a121 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -252,6 +252,31 @@ kill_session_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
252 | GNUNET_free(sk); | 252 | GNUNET_free(sk); |
253 | } | 253 | } |
254 | 254 | ||
255 | static void | ||
256 | cancel_pending_blacklist_checks (const struct GNUNET_HELLO_Address *address, struct Session *session) | ||
257 | { | ||
258 | struct BlacklistCheckContext *blctx; | ||
259 | struct BlacklistCheckContext *next; | ||
260 | next = bc_head; | ||
261 | for (blctx = next; NULL != blctx; blctx = next) | ||
262 | { | ||
263 | next = blctx->next; | ||
264 | if ((NULL != blctx->address) && (0 == GNUNET_HELLO_address_cmp(blctx->address, address)) && (blctx->session == session)) | ||
265 | { | ||
266 | GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, blctx); | ||
267 | if (NULL != blctx->blc) | ||
268 | { | ||
269 | GST_blacklist_test_cancel (blctx->blc); | ||
270 | blctx->blc = NULL; | ||
271 | } | ||
272 | GNUNET_HELLO_address_free (blctx->address); | ||
273 | GNUNET_free_non_null (blctx->msg); | ||
274 | GNUNET_free_non_null (blctx->ats); | ||
275 | GNUNET_free (blctx); | ||
276 | } | ||
277 | } | ||
278 | } | ||
279 | |||
255 | /** | 280 | /** |
256 | * Force plugin to terminate session due to communication | 281 | * Force plugin to terminate session due to communication |
257 | * issue. | 282 | * issue. |
@@ -282,33 +307,7 @@ kill_session (const char *plugin_name, struct Session *session) | |||
282 | GNUNET_CONTAINER_DLL_insert(sk_head, sk_tail, sk); | 307 | GNUNET_CONTAINER_DLL_insert(sk_head, sk_tail, sk); |
283 | } | 308 | } |
284 | 309 | ||
285 | /** | ||
286 | * Black list check result for try_connect call | ||
287 | * If connection to the peer is allowed request adddress and | ||
288 | * | ||
289 | * @param cls blc_ctx bl context | ||
290 | * @param peer the peer | ||
291 | * @param result the result | ||
292 | */ | ||
293 | static void | ||
294 | connect_address_bl_check_cont (void *cls, | ||
295 | const struct GNUNET_PeerIdentity *peer, int result) | ||
296 | { | ||
297 | struct BlacklistCheckContext *blctx = cls; | ||
298 | 310 | ||
299 | if (GNUNET_OK == result) | ||
300 | { | ||
301 | GST_ats_add_address (blctx->address, blctx->session, NULL, 0); | ||
302 | } | ||
303 | else | ||
304 | { | ||
305 | kill_session (blctx->address->transport_name, blctx->session); | ||
306 | } | ||
307 | |||
308 | GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, blctx); | ||
309 | GNUNET_HELLO_address_free (blctx->address); | ||
310 | GNUNET_free (blctx); | ||
311 | } | ||
312 | 311 | ||
313 | /** | 312 | /** |
314 | * Black list check result for try_connect call | 313 | * Black list check result for try_connect call |
@@ -323,37 +322,31 @@ connect_bl_check_cont (void *cls, | |||
323 | const struct GNUNET_PeerIdentity *peer, int result) | 322 | const struct GNUNET_PeerIdentity *peer, int result) |
324 | { | 323 | { |
325 | struct BlacklistCheckContext *blctx = cls; | 324 | struct BlacklistCheckContext *blctx = cls; |
326 | struct BlacklistCheckContext *blctx_address; | 325 | |
327 | struct GST_BlacklistCheck *blc; | 326 | GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, blctx); |
327 | blctx->blc = NULL; | ||
328 | |||
328 | if (GNUNET_OK == result) | 329 | if (GNUNET_OK == result) |
329 | { | 330 | { |
330 | /* Check if incoming address can be used to communicate */ | ||
331 | blctx_address = GNUNET_new (struct BlacklistCheckContext); | ||
332 | blctx_address->address = GNUNET_HELLO_address_copy (blctx->address); | ||
333 | blctx_address->session = blctx->session; | ||
334 | |||
335 | GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, blctx_address); | ||
336 | if (NULL != (blc = GST_blacklist_test_allowed (&blctx_address->address->peer, | ||
337 | blctx_address->address->transport_name, | ||
338 | &connect_address_bl_check_cont, blctx_address))) | ||
339 | { | ||
340 | blctx_address->blc = blc; | ||
341 | } | ||
342 | |||
343 | /* Blacklist allows to speak to this peer, forward CONNECT to neighbours */ | 331 | /* Blacklist allows to speak to this peer, forward CONNECT to neighbours */ |
344 | if (GNUNET_OK != GST_neighbours_handle_connect (blctx->msg, | 332 | if (GNUNET_OK != GST_neighbours_handle_connect (blctx->msg, |
345 | &blctx->address->peer, blctx->address, blctx->session)) | 333 | &blctx->address->peer, blctx->address, blctx->session)) |
346 | { | 334 | { |
335 | cancel_pending_blacklist_checks (blctx->address, blctx->session); | ||
347 | kill_session (blctx->address->transport_name, blctx->session); | 336 | kill_session (blctx->address->transport_name, blctx->session); |
348 | } | 337 | } |
349 | } | 338 | } |
350 | else | 339 | else |
351 | { | 340 | { |
352 | /* Blacklist denies to speak to this peer */ | 341 | /* Blacklist denies to speak to this peer */ |
342 | |||
343 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
344 | "Discarding CONNECT message from `%s' due to denied blacklist check\n", | ||
345 | GNUNET_i2s (peer)); | ||
346 | cancel_pending_blacklist_checks (blctx->address, blctx->session); | ||
353 | kill_session (blctx->address->transport_name, blctx->session); | 347 | kill_session (blctx->address->transport_name, blctx->session); |
354 | } | 348 | } |
355 | 349 | ||
356 | GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, blctx); | ||
357 | if (NULL != blctx->address) | 350 | if (NULL != blctx->address) |
358 | GNUNET_HELLO_address_free (blctx->address); | 351 | GNUNET_HELLO_address_free (blctx->address); |
359 | GNUNET_free (blctx->msg); | 352 | GNUNET_free (blctx->msg); |
@@ -406,7 +399,7 @@ GST_receive_callback (void *cls, | |||
406 | if (GNUNET_OK != GST_validation_handle_hello (message)) | 399 | if (GNUNET_OK != GST_validation_handle_hello (message)) |
407 | { | 400 | { |
408 | GNUNET_break_op(0); | 401 | GNUNET_break_op(0); |
409 | kill_session (plugin_name, session); | 402 | cancel_pending_blacklist_checks (address, session); |
410 | } | 403 | } |
411 | return ret; | 404 | return ret; |
412 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: | 405 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: |
@@ -414,7 +407,10 @@ GST_receive_callback (void *cls, | |||
414 | "Processing `%s' from `%s'\n", "PING", GST_plugins_a2s (address)); | 407 | "Processing `%s' from `%s'\n", "PING", GST_plugins_a2s (address)); |
415 | if (GNUNET_OK | 408 | if (GNUNET_OK |
416 | != GST_validation_handle_ping (&address->peer, message, address, session)) | 409 | != GST_validation_handle_ping (&address->peer, message, address, session)) |
410 | { | ||
411 | cancel_pending_blacklist_checks (address, session); | ||
417 | kill_session (plugin_name, session); | 412 | kill_session (plugin_name, session); |
413 | } | ||
418 | break; | 414 | break; |
419 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: | 415 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: |
420 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 416 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
@@ -423,6 +419,7 @@ GST_receive_callback (void *cls, | |||
423 | if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message)) | 419 | if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message)) |
424 | { | 420 | { |
425 | GNUNET_break_op(0); | 421 | GNUNET_break_op(0); |
422 | cancel_pending_blacklist_checks (address, session); | ||
426 | kill_session (plugin_name, session); | 423 | kill_session (plugin_name, session); |
427 | } | 424 | } |
428 | break; | 425 | break; |
@@ -444,6 +441,7 @@ GST_receive_callback (void *cls, | |||
444 | if (GNUNET_OK != GST_neighbours_handle_connect_ack (message, | 441 | if (GNUNET_OK != GST_neighbours_handle_connect_ack (message, |
445 | &address->peer, address, session)) | 442 | &address->peer, address, session)) |
446 | { | 443 | { |
444 | cancel_pending_blacklist_checks (address, session); | ||
447 | kill_session (plugin_name, session); | 445 | kill_session (plugin_name, session); |
448 | } | 446 | } |
449 | break; | 447 | break; |
@@ -452,6 +450,7 @@ GST_receive_callback (void *cls, | |||
452 | != GST_neighbours_handle_session_ack (message, &address->peer, address, session)) | 450 | != GST_neighbours_handle_session_ack (message, &address->peer, address, session)) |
453 | { | 451 | { |
454 | GNUNET_break_op(0); | 452 | GNUNET_break_op(0); |
453 | cancel_pending_blacklist_checks (address, session); | ||
455 | kill_session (plugin_name, session); | 454 | kill_session (plugin_name, session); |
456 | } | 455 | } |
457 | break; | 456 | break; |
@@ -545,6 +544,9 @@ plugin_env_session_end (void *cls, const struct GNUNET_HELLO_Address *address, | |||
545 | 544 | ||
546 | /* Tell ATS that session has ended */ | 545 | /* Tell ATS that session has ended */ |
547 | GNUNET_ATS_address_destroyed (GST_ats, address, session); | 546 | GNUNET_ATS_address_destroyed (GST_ats, address, session); |
547 | |||
548 | cancel_pending_blacklist_checks (address, session); | ||
549 | |||
548 | for (sk = sk_head; NULL != sk; sk = sk->next) | 550 | for (sk = sk_head; NULL != sk; sk = sk->next) |
549 | { | 551 | { |
550 | if (sk->session == session) | 552 | if (sk->session == session) |
@@ -631,23 +633,23 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address, | |||
631 | return; | 633 | return; |
632 | } | 634 | } |
633 | 635 | ||
634 | net = papi->get_network (NULL, session); | 636 | net = papi->get_network (papi->cls, session); |
635 | if (GNUNET_ATS_NET_UNSPECIFIED == net) | 637 | if (GNUNET_ATS_NET_UNSPECIFIED == net) |
636 | { | 638 | { |
637 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 639 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
638 | _("Could not obtain a valid network for `%s' %s (%s)\n"), | 640 | _("Could not obtain a valid network for `%s' %s (%s)\n"), |
639 | GNUNET_i2s (&address->peer), GST_plugins_a2s (address), | 641 | GNUNET_i2s (&address->peer), GST_plugins_a2s (address), |
640 | address->transport_name); | 642 | address->transport_name); |
641 | GNUNET_break(0); | 643 | return; |
642 | } | 644 | } |
643 | ats2[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | 645 | ats2[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); |
644 | ats2[0].value = htonl (net); | 646 | ats2[0].value = htonl (net); |
645 | memcpy (&ats2[1], ats, sizeof(struct GNUNET_ATS_Information) * ats_count); | 647 | memcpy (&ats2[1], ats, sizeof(struct GNUNET_ATS_Information) * ats_count); |
646 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 648 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
647 | "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n", | 649 | "Notifying ATS about peer `%s''s new address `%s' session %p in network %s %u\n", |
648 | GNUNET_i2s (&address->peer), | 650 | GNUNET_i2s (&address->peer), |
649 | (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address), | 651 | (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address), |
650 | session, GNUNET_ATS_print_network_type (net)); | 652 | session, GNUNET_ATS_print_network_type (net), net); |
651 | GNUNET_ATS_address_add (GST_ats, address, session, ats2, ats_count + 1); | 653 | GNUNET_ATS_address_add (GST_ats, address, session, ats2, ats_count + 1); |
652 | } | 654 | } |
653 | 655 | ||
@@ -729,6 +731,9 @@ plugin_env_session_start_bl_check_cont (void *cls, | |||
729 | { | 731 | { |
730 | struct BlacklistCheckContext *blctx = cls; | 732 | struct BlacklistCheckContext *blctx = cls; |
731 | 733 | ||
734 | GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, blctx); | ||
735 | blctx->blc = NULL; | ||
736 | |||
732 | if (GNUNET_OK == result) | 737 | if (GNUNET_OK == result) |
733 | { | 738 | { |
734 | GST_ats_add_address (blctx->address, blctx->session, | 739 | GST_ats_add_address (blctx->address, blctx->session, |
@@ -736,10 +741,10 @@ plugin_env_session_start_bl_check_cont (void *cls, | |||
736 | } | 741 | } |
737 | else | 742 | else |
738 | { | 743 | { |
744 | cancel_pending_blacklist_checks (blctx->address, blctx->session); | ||
739 | kill_session (blctx->address->transport_name, blctx->session); | 745 | kill_session (blctx->address->transport_name, blctx->session); |
740 | } | 746 | } |
741 | 747 | ||
742 | GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, blctx); | ||
743 | GNUNET_HELLO_address_free (blctx->address); | 748 | GNUNET_HELLO_address_free (blctx->address); |
744 | GNUNET_free_non_null (blctx->ats); | 749 | GNUNET_free_non_null (blctx->ats); |
745 | GNUNET_free (blctx); | 750 | GNUNET_free (blctx); |