aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_blacklist.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-20 15:37:11 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-20 15:37:11 +0000
commit49b1ddee6e5e6f4043d7a084705e0a115ee64404 (patch)
treebf5396e5227b60fb0f29ef876202310af83a938d /src/transport/gnunet-service-transport_blacklist.c
parent32b8d7b6b2a32bca39e3ee7311df9f98615ac387 (diff)
downloadgnunet-49b1ddee6e5e6f4043d7a084705e0a115ee64404.tar.gz
gnunet-49b1ddee6e5e6f4043d7a084705e0a115ee64404.zip
-doxygen and minor style fixes
Diffstat (limited to 'src/transport/gnunet-service-transport_blacklist.c')
-rw-r--r--src/transport/gnunet-service-transport_blacklist.c140
1 files changed, 82 insertions, 58 deletions
diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c
index dc59ce595..b7303f8eb 100644
--- a/src/transport/gnunet-service-transport_blacklist.c
+++ b/src/transport/gnunet-service-transport_blacklist.c
@@ -21,7 +21,8 @@
21/** 21/**
22 * @file transport/gnunet-service-transport_blacklist.c 22 * @file transport/gnunet-service-transport_blacklist.c
23 * @brief blacklisting implementation 23 * @brief blacklisting implementation
24 * @author Christian Grothoff, Matthias Wachs 24 * @author Christian Grothoff
25 * @author Matthias Wachs
25 * @details This is the blacklisting component of transport service. With 26 * @details This is the blacklisting component of transport service. With
26 * blacklisting it is possible to deny connections to specific peers of 27 * blacklisting it is possible to deny connections to specific peers of
27 * to use a specific plugin to a specific peer. Peers can be blacklisted using 28 * to use a specific plugin to a specific peer. Peers can be blacklisted using
@@ -100,12 +101,12 @@ struct Blacklisters
100 struct GST_BlacklistCheck *bc; 101 struct GST_BlacklistCheck *bc;
101 102
102 /** 103 /**
103 * Set to GNUNET_YES if we're currently waiting for a reply. 104 * Set to #GNUNET_YES if we're currently waiting for a reply.
104 */ 105 */
105 int waiting_for_reply; 106 int waiting_for_reply;
106 107
107 /** 108 /**
108 * GNUNET_YES if we have to call receive_done for this client 109 * #GNUNET_YES if we have to call receive_done for this client
109 */ 110 */
110 int call_receive_done; 111 int call_receive_done;
111 112
@@ -140,7 +141,7 @@ struct GST_BlacklistCheck
140 GST_BlacklistTestContinuation cont; 141 GST_BlacklistTestContinuation cont;
141 142
142 /** 143 /**
143 * Closure for cont. 144 * Closure for @e cont.
144 */ 145 */
145 void *cont_cls; 146 void *cont_cls;
146 147
@@ -193,7 +194,7 @@ static struct GNUNET_CONTAINER_MultiPeerMap *blacklist;
193/** 194/**
194 * Perform next action in the blacklist check. 195 * Perform next action in the blacklist check.
195 * 196 *
196 * @param cls the 'struct BlacklistCheck*' 197 * @param cls the `struct BlacklistCheck*`
197 * @param tc unused 198 * @param tc unused
198 */ 199 */
199static void 200static void
@@ -213,7 +214,7 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
213 struct Blacklisters *bl; 214 struct Blacklisters *bl;
214 struct GST_BlacklistCheck *bc; 215 struct GST_BlacklistCheck *bc;
215 216
216 if (client == NULL) 217 if (NULL == client)
217 return; 218 return;
218 for (bl = bl_head; bl != NULL; bl = bl->next) 219 for (bl = bl_head; bl != NULL; bl = bl->next)
219 { 220 {
@@ -249,7 +250,8 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
249 * @param value value of the option 250 * @param value value of the option
250 */ 251 */
251static void 252static void
252blacklist_cfg_iter (void *cls, const char *section, 253blacklist_cfg_iter (void *cls,
254 const char *section,
253 const char *option, 255 const char *option,
254 const char *value) 256 const char *value)
255{ 257{
@@ -258,9 +260,10 @@ blacklist_cfg_iter (void *cls, const char *section,
258 char *plugs; 260 char *plugs;
259 char *pos; 261 char *pos;
260 262
261 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (option, 263 if (GNUNET_OK !=
262 strlen (option), 264 GNUNET_CRYPTO_eddsa_public_key_from_string (option,
263 &peer.public_key)) 265 strlen (option),
266 &peer.public_key))
264 return; 267 return;
265 268
266 if ((NULL == value) || (0 == strcmp(value, ""))) 269 if ((NULL == value) || (0 == strcmp(value, "")))
@@ -268,7 +271,8 @@ blacklist_cfg_iter (void *cls, const char *section,
268 /* Blacklist whole peer */ 271 /* Blacklist whole peer */
269 GST_blacklist_add_peer (&peer, NULL); 272 GST_blacklist_add_peer (&peer, NULL);
270 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 273 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
271 _("Adding blacklisting entry for peer `%s'\n"), GNUNET_i2s (&peer)); 274 _("Adding blacklisting entry for peer `%s'\n"),
275 GNUNET_i2s (&peer));
272 } 276 }
273 else 277 else
274 { 278 {
@@ -303,9 +307,13 @@ read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg,
303 sizeof (cfg_sect), 307 sizeof (cfg_sect),
304 "transport-blacklist-%s", 308 "transport-blacklist-%s",
305 GNUNET_i2s_full (my_id)); 309 GNUNET_i2s_full (my_id));
306 GNUNET_CONFIGURATION_iterate_section_values (cfg, cfg_sect, &blacklist_cfg_iter, &res); 310 GNUNET_CONFIGURATION_iterate_section_values (cfg,
311 cfg_sect,
312 &blacklist_cfg_iter,
313 &res);
307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
308 "Loaded %u blacklisting entries from configuration\n", res); 315 "Loaded %u blacklisting entries from configuration\n",
316 res);
309} 317}
310 318
311 319
@@ -324,7 +332,8 @@ GST_blacklist_start (struct GNUNET_SERVER_Handle *server,
324 GNUNET_assert (NULL != cfg); 332 GNUNET_assert (NULL != cfg);
325 GNUNET_assert (NULL != my_id); 333 GNUNET_assert (NULL != my_id);
326 read_blacklist_configuration (cfg, my_id); 334 read_blacklist_configuration (cfg, my_id);
327 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification, 335 GNUNET_SERVER_disconnect_notify (server,
336 &client_disconnect_notification,
328 NULL); 337 NULL);
329} 338}
330 339
@@ -335,7 +344,7 @@ GST_blacklist_start (struct GNUNET_SERVER_Handle *server,
335 * @param cls unused 344 * @param cls unused
336 * @param key host identity (unused) 345 * @param key host identity (unused)
337 * @param value the blacklist entry 346 * @param value the blacklist entry
338 * @return GNUNET_OK (continue to iterate) 347 * @return #GNUNET_OK (continue to iterate)
339 */ 348 */
340static int 349static int
341free_blacklist_entry (void *cls, 350free_blacklist_entry (void *cls,
@@ -355,23 +364,23 @@ free_blacklist_entry (void *cls,
355void 364void
356GST_blacklist_stop () 365GST_blacklist_stop ()
357{ 366{
358 if (NULL != blacklist) 367 if (NULL == blacklist)
359 { 368 return;
360 GNUNET_CONTAINER_multipeermap_iterate (blacklist, &free_blacklist_entry, 369 GNUNET_CONTAINER_multipeermap_iterate (blacklist,
361 NULL); 370 &free_blacklist_entry,
362 GNUNET_CONTAINER_multipeermap_destroy (blacklist); 371 NULL);
363 blacklist = NULL; 372 GNUNET_CONTAINER_multipeermap_destroy (blacklist);
364 } 373 blacklist = NULL;
365} 374}
366 375
367 376
368/** 377/**
369 * Transmit blacklist query to the client. 378 * Transmit blacklist query to the client.
370 * 379 *
371 * @param cls the 'struct GST_BlacklistCheck' 380 * @param cls the `struct GST_BlacklistCheck`
372 * @param size number of bytes allowed 381 * @param size number of bytes allowed
373 * @param buf where to copy the message 382 * @param buf where to copy the message
374 * @return number of bytes copied to buf 383 * @return number of bytes copied to @a buf
375 */ 384 */
376static size_t 385static size_t
377transmit_blacklist_message (void *cls, size_t size, void *buf) 386transmit_blacklist_message (void *cls, size_t size, void *buf)
@@ -413,11 +422,12 @@ transmit_blacklist_message (void *cls, size_t size, void *buf)
413/** 422/**
414 * Perform next action in the blacklist check. 423 * Perform next action in the blacklist check.
415 * 424 *
416 * @param cls the 'struct GST_BlacklistCheck*' 425 * @param cls the `struct GST_BlacklistCheck *`
417 * @param tc unused 426 * @param tc unused
418 */ 427 */
419static void 428static void
420do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 429do_blacklist_check (void *cls,
430 const struct GNUNET_SCHEDULER_TaskContext *tc)
421{ 431{
422 struct GST_BlacklistCheck *bc = cls; 432 struct GST_BlacklistCheck *bc = cls;
423 struct Blacklisters *bl; 433 struct Blacklisters *bl;
@@ -452,11 +462,12 @@ do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
452 * 462 *
453 * @param cls unused 463 * @param cls unused
454 * @param peer the neighbour that was investigated 464 * @param peer the neighbour that was investigated
455 * @param allowed GNUNET_OK if we can keep it, 465 * @param allowed #GNUNET_OK if we can keep it,
456 * GNUNET_NO if we must shutdown the connection 466 * #GNUNET_NO if we must shutdown the connection
457 */ 467 */
458static void 468static void
459confirm_or_drop_neighbour (void *cls, const struct GNUNET_PeerIdentity *peer, 469confirm_or_drop_neighbour (void *cls,
470 const struct GNUNET_PeerIdentity *peer,
460 int allowed) 471 int allowed)
461{ 472{
462 if (GNUNET_OK == allowed) 473 if (GNUNET_OK == allowed)
@@ -484,11 +495,12 @@ struct TestConnectionContext
484 struct Blacklisters *bl; 495 struct Blacklisters *bl;
485}; 496};
486 497
498
487/** 499/**
488 * Test if an existing connection is still acceptable given a new 500 * Test if an existing connection is still acceptable given a new
489 * blacklisting client. 501 * blacklisting client.
490 * 502 *
491 * @param cls the 'struct TestConnectionContest' 503 * @param cls the `struct TestConnectionContext *`
492 * @param peer neighbour's identity 504 * @param peer neighbour's identity
493 * @param address the address 505 * @param address the address
494 * @param state current state this peer is in 506 * @param state current state this peer is in
@@ -539,26 +551,26 @@ GST_blacklist_handle_init (void *cls, struct GNUNET_SERVER_Client *client,
539 struct Blacklisters *bl; 551 struct Blacklisters *bl;
540 struct TestConnectionContext tcc; 552 struct TestConnectionContext tcc;
541 553
542 bl = bl_head; 554 for (bl = bl_head; NULL != bl; bl = bl->next)
543 while (bl != NULL)
544 {
545 if (bl->client == client) 555 if (bl->client == client)
546 { 556 {
547 GNUNET_break (0); 557 GNUNET_break (0);
548 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 558 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
549 return; 559 return;
550 } 560 }
551 bl = bl->next;
552 }
553 561
554 GNUNET_SERVER_client_mark_monitor (client); 562 GNUNET_SERVER_client_mark_monitor (client);
555 bl = GNUNET_new (struct Blacklisters); 563 bl = GNUNET_new (struct Blacklisters);
556 bl->client = client; 564 bl->client = client;
557 bl->call_receive_done = GNUNET_YES; 565 bl->call_receive_done = GNUNET_YES;
558 GNUNET_SERVER_client_keep (client); 566 GNUNET_SERVER_client_keep (client);
559 GNUNET_CONTAINER_DLL_insert_after (bl_head, bl_tail, bl_tail, bl); 567 GNUNET_CONTAINER_DLL_insert_after (bl_head,
560 568 bl_tail,
561 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New blacklist client %p\n", client); 569 bl_tail,
570 bl);
571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
572 "New blacklist client %p\n",
573 client);
562 574
563 /* confirm that all existing connections are OK! */ 575 /* confirm that all existing connections are OK! */
564 tcc.bl = bl; 576 tcc.bl = bl;
@@ -586,15 +598,18 @@ GST_blacklist_handle_reply (void *cls, struct GNUNET_SERVER_Client *client,
586 bl = bl_head; 598 bl = bl_head;
587 while ((bl != NULL) && (bl->client != client)) 599 while ((bl != NULL) && (bl->client != client))
588 bl = bl->next; 600 bl = bl->next;
589 if (bl == NULL) 601 if (NULL == bl)
590 { 602 {
591 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Blacklist client disconnected\n"); 603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
604 "Blacklist client disconnected\n");
592 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 605 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
593 return; 606 return;
594 } 607 }
595 608
596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Blacklist client %p sent reply for `%s'\n", 609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
597 client, GNUNET_i2s(&msg->peer)); 610 "Blacklist client %p sent reply for `%s'\n",
611 client,
612 GNUNET_i2s(&msg->peer));
598 613
599 bc = bl->bc; 614 bc = bl->bc;
600 bl->bc = NULL; 615 bl->bc = NULL;
@@ -645,7 +660,7 @@ void
645GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer, 660GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
646 const char *transport_name) 661 const char *transport_name)
647{ 662{
648 char * transport = NULL; 663 char *transport = NULL;
649 664
650 if (NULL != transport_name) 665 if (NULL != transport_name)
651 { 666 {
@@ -658,7 +673,7 @@ GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
658 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 673 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
659 "Adding peer `%s' with all plugins to blacklist\n", 674 "Adding peer `%s' with all plugins to blacklist\n",
660 GNUNET_i2s (peer)); 675 GNUNET_i2s (peer));
661 if (blacklist == NULL) 676 if (NULL == blacklist)
662 blacklist = 677 blacklist =
663 GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE, 678 GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE,
664 GNUNET_NO); 679 GNUNET_NO);
@@ -720,24 +735,27 @@ test_blacklisted (void *cls,
720 * @param peer the identity of the peer to test 735 * @param peer the identity of the peer to test
721 * @param transport_name name of the transport to test, never NULL 736 * @param transport_name name of the transport to test, never NULL
722 * @param cont function to call with result 737 * @param cont function to call with result
723 * @param cont_cls closure for 'cont' 738 * @param cont_cls closure for @a cont
724 * @return handle to the blacklist check, NULL if the decision 739 * @return handle to the blacklist check, NULL if the decision
725 * was made instantly and 'cont' was already called 740 * was made instantly and @a cont was already called
726 */ 741 */
727struct GST_BlacklistCheck * 742struct GST_BlacklistCheck *
728GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer, 743GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
729 const char *transport_name, 744 const char *transport_name,
730 GST_BlacklistTestContinuation cont, void *cont_cls) 745 GST_BlacklistTestContinuation cont,
746 void *cont_cls)
731{ 747{
732 struct GST_BlacklistCheck *bc; 748 struct GST_BlacklistCheck *bc;
733 749
734 GNUNET_assert (peer != NULL); 750 GNUNET_assert (NULL != peer);
735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Blacklist check for peer `%s':%s\n", 751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
736 GNUNET_i2s (peer), (NULL != transport_name) ? transport_name : "unspecified"); 752 "Blacklist check for peer `%s':%s\n",
753 GNUNET_i2s (peer),
754 (NULL != transport_name) ? transport_name : "unspecified");
737 755
738 /* Check local blacklist by iterating over hashmap 756 /* Check local blacklist by iterating over hashmap
739 * If iteration is aborted, we found a matching blacklist entry */ 757 * If iteration is aborted, we found a matching blacklist entry */
740 if ((blacklist != NULL) && 758 if ((NULL != blacklist) &&
741 (GNUNET_SYSERR == 759 (GNUNET_SYSERR ==
742 GNUNET_CONTAINER_multipeermap_get_multiple (blacklist, peer, 760 GNUNET_CONTAINER_multipeermap_get_multiple (blacklist, peer,
743 &test_blacklisted, 761 &test_blacklisted,
@@ -747,20 +765,24 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
747 GNUNET_STATISTICS_update (GST_stats, 765 GNUNET_STATISTICS_update (GST_stats,
748 gettext_noop ("# disconnects due to blacklist"), 766 gettext_noop ("# disconnects due to blacklist"),
749 1, GNUNET_NO); 767 1, GNUNET_NO);
750 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Disallowing connection to peer `%s' on transport %s\n", 768 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
751 GNUNET_i2s (peer), (NULL != transport_name) ? transport_name : "unspecified"); 769 _("Disallowing connection to peer `%s' on transport %s\n"),
770 GNUNET_i2s (peer),
771 (NULL != transport_name) ? transport_name : "unspecified");
752 if (cont != NULL) 772 if (cont != NULL)
753 cont (cont_cls, peer, GNUNET_NO); 773 cont (cont_cls, peer, GNUNET_NO);
754 return NULL; 774 return NULL;
755 } 775 }
756 776
757 if (bl_head == NULL) 777 if (NULL == bl_head)
758 { 778 {
759 /* no blacklist clients, approve instantly */ 779 /* no blacklist clients, approve instantly */
760 if (cont != NULL) 780 if (cont != NULL)
761 cont (cont_cls, peer, GNUNET_OK); 781 cont (cont_cls, peer, GNUNET_OK);
762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Allowing connection to peer `%s' %s\n", 782 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
763 GNUNET_i2s (peer), (NULL != transport_name) ? transport_name : ""); 783 "Allowing connection to peer `%s' %s\n",
784 GNUNET_i2s (peer),
785 (NULL != transport_name) ? transport_name : "");
764 return NULL; 786 return NULL;
765 } 787 }
766 788
@@ -784,8 +806,10 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
784void 806void
785GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc) 807GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
786{ 808{
787 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc); 809 GNUNET_CONTAINER_DLL_remove (bc_head,
788 if (bc->bl_pos != NULL) 810 bc_tail,
811 bc);
812 if (NULL != bc->bl_pos)
789 { 813 {
790 if (bc->bl_pos->bc == bc) 814 if (bc->bl_pos->bc == bc)
791 { 815 {