aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_blacklist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport_blacklist.c')
-rw-r--r--src/transport/gnunet-service-transport_blacklist.c87
1 files changed, 83 insertions, 4 deletions
diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c
index 9193922a9..361bf9c4e 100644
--- a/src/transport/gnunet-service-transport_blacklist.c
+++ b/src/transport/gnunet-service-transport_blacklist.c
@@ -371,16 +371,87 @@ read_blacklist_file ()
371 GNUNET_free (fn); 371 GNUNET_free (fn);
372} 372}
373 373
374/**
375 * Function to iterate over options in the blacklisting section for a peer.
376 *
377 * @param cls closure
378 * @param section name of the section
379 * @param option name of the option
380 * @param value value of the option
381 */
382void blacklist_cfg_iter (void *cls, const char *section,
383 const char *option,
384 const char *value)
385{
386 struct GNUNET_PeerIdentity peer;
387 char *plugs;
388 char *pos;
389 int *res = cls;
390
391 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string2(option,
392 strlen (option), &peer.hashPubKey))
393 return;
394
395 if ((NULL == value) || (0 == strcmp(value, "")))
396 {
397 /* Blacklist whole peer */
398 GST_blacklist_add_peer (&peer, NULL);
399 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
400 _("Adding blacklisting entry for peer `%s'\n"), GNUNET_i2s (&peer));
401 }
402 else
403 {
404 plugs = GNUNET_strdup (value);
405 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
406 {
407 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
408 _("Adding blacklisting entry for peer `%s':`%s'\n"),
409 GNUNET_i2s (&peer), pos);
410 GST_blacklist_add_peer (&peer, pos);
411 }
412 GNUNET_free (plugs);
413 }
414 (*res)++;
415
416}
417
418
419
420/**
421 * Read blacklist configuration
422 *
423 * @param cfg the configuration handle
424 * @param my_id my peer identity
425 */
426static void
427read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg,
428 const struct GNUNET_PeerIdentity *my_id)
429{
430 char *cfg_sect;
431 int res = 0;
432 GNUNET_asprintf (&cfg_sect, "transport-blacklist-%s", GNUNET_i2s_full (my_id));
433 GNUNET_CONFIGURATION_iterate_section_values (cfg, cfg_sect, &blacklist_cfg_iter, &res);
434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
435 "Loaded %u blacklisting entries from configuration\n", res);
436 GNUNET_free (cfg_sect);
437}
374 438
375/** 439/**
376 * Start blacklist subsystem. 440 * Start blacklist subsystem.
377 * 441 *
378 * @param server server used to accept clients from 442 * @param server server used to accept clients from
443 * @param cfg configuration handle
444 * @param my_id my peer id
379 */ 445 */
380void 446void
381GST_blacklist_start (struct GNUNET_SERVER_Handle *server) 447GST_blacklist_start (struct GNUNET_SERVER_Handle *server,
448 const struct GNUNET_CONFIGURATION_Handle *cfg,
449 const struct GNUNET_PeerIdentity *my_id)
382{ 450{
383 read_blacklist_file (); 451 GNUNET_assert (NULL != cfg);
452 GNUNET_assert (NULL != my_id);
453 //read_blacklist_file ();
454 read_blacklist_configuration (cfg, my_id);
384 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification, 455 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification,
385 NULL); 456 NULL);
386} 457}
@@ -399,7 +470,7 @@ free_blacklist_entry (void *cls, const struct GNUNET_HashCode * key, void *value
399{ 470{
400 char *be = value; 471 char *be = value;
401 472
402 GNUNET_free (be); 473 GNUNET_free_non_null (be);
403 return GNUNET_OK; 474 return GNUNET_OK;
404} 475}
405 476
@@ -679,6 +750,8 @@ void
679GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer, 750GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
680 const char *transport_name) 751 const char *transport_name)
681{ 752{
753 char * transport = NULL;
754
682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
683 "Adding peer `%s' with plugin `%s' to blacklist\n", 756 "Adding peer `%s' with plugin `%s' to blacklist\n",
684 GNUNET_i2s (peer), transport_name); 757 GNUNET_i2s (peer), transport_name);
@@ -686,8 +759,11 @@ GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
686 blacklist = 759 blacklist =
687 GNUNET_CONTAINER_multihashmap_create (TRANSPORT_BLACKLIST_HT_SIZE, 760 GNUNET_CONTAINER_multihashmap_create (TRANSPORT_BLACKLIST_HT_SIZE,
688 GNUNET_NO); 761 GNUNET_NO);
762 if (NULL != transport_name)
763 transport = GNUNET_strdup ("");
764
689 GNUNET_CONTAINER_multihashmap_put (blacklist, &peer->hashPubKey, 765 GNUNET_CONTAINER_multihashmap_put (blacklist, &peer->hashPubKey,
690 GNUNET_strdup (transport_name), 766 transport,
691 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 767 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
692} 768}
693 769
@@ -710,6 +786,9 @@ test_blacklisted (void *cls, const struct GNUNET_HashCode * key, void *value)
710 /* blacklist check for specific no specific transport*/ 786 /* blacklist check for specific no specific transport*/
711 if (transport_name == NULL) 787 if (transport_name == NULL)
712 return GNUNET_NO; 788 return GNUNET_NO;
789 /* all plugins for this peer were blacklisted */
790 if (NULL == value)
791 return GNUNET_NO;
713 792
714 /* blacklist check for specific transport */ 793 /* blacklist check for specific transport */
715 if (0 == strcmp (transport_name, be)) 794 if (0 == strcmp (transport_name, be))