/*
This file is part of GNUnet
- (C) 2008--2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2008--2013 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
* The blacklist handle we obtain from transport when we register ourselves for
* access control
*/
-struct GNUNET_TRANSPORT_Blacklist *bh;
-
-/**
- * Task for shutdown
- */
-static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
+static struct GNUNET_TRANSPORT_Blacklist *bh;
/**
* Are we allowing or denying access from peers
static int mode;
-/**
- * @ingroup hashmap
- * Iterator over hash map entries.
- *
- * @param cls closure
- * @param key current key code
- * @param value value in the hash map
- * @return #GNUNET_YES if we should continue to
- * iterate,
- * #GNUNET_NO if not.
- */
-static int
-iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
-{
- GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (map, key,
- value));
- return GNUNET_YES;
-}
-
-
/**
* Cleaup and destroy the map
*/
{
if (NULL != map)
{
- GNUNET_assert (GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_iterate (map,
- &iterator,
- NULL));
GNUNET_CONTAINER_multipeermap_destroy (map);
map = NULL;
}
* Shutdown task to cleanup our resources and exit.
*
* @param cls NULL
- * @param tc scheduler task context
*/
static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls)
{
cleanup_map ();
if (NULL != bh)
* @param cfg the configuration for connecting to the peer's transport service
*/
static void
-setup_ac (const char *fname, const struct GNUNET_CONFIGURATION_Handle *cfg)
+setup_ac (const char *fname,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
uint64_t fsize;
unsigned int npeers;
unsigned int cnt;
- GNUNET_assert (GNUNET_OK != GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO,
- GNUNET_YES));
+ GNUNET_assert (GNUNET_OK !=
+ GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO,
+ GNUNET_YES));
if (0 != (fsize % sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_break (0);
}
for (cnt = 0; cnt < npeers; cnt++)
{
- if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt],
- &ilist[cnt],
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ if (GNUNET_SYSERR ==
+ GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt],
+ &ilist[cnt],
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
cleanup_map ();
GNUNET_free (ilist);
return;
}
}
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
bh = GNUNET_TRANSPORT_blacklist (cfg, &check_access, NULL);
}
* @param c configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
{
char *shome;
- char fname[PATH_MAX];
+ char *fname;
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (c, "PATHS",
- "SERVICEHOME",
- &shome))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (c, "PATHS",
+ "GNUNET_HOME",
+ &shome))
{
GNUNET_break (0);
return;
}
- GNUNET_assert (0 < GNUNET_snprintf (fname, PATH_MAX, "%s/whitelist", shome));
+ GNUNET_asprintf (&fname,
+ "%s/whitelist",
+ shome);
if (GNUNET_YES == GNUNET_DISK_file_test (fname))
{
mode = ACCESS_ALLOW;
setup_ac (fname, c);
GNUNET_free (shome);
+ GNUNET_free (fname);
return;
}
- GNUNET_assert (0 < GNUNET_snprintf (fname, PATH_MAX, "%s/blacklist", shome));
+ GNUNET_asprintf (&fname,
+ "%s/blacklist",
+ shome);
+ GNUNET_free (fname);
if (GNUNET_YES == GNUNET_DISK_file_test (fname))
{
mode = ACCESS_DENY;
};
int ret;
- if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_get_utf8_args (argc, argv,
+ &argc, &argv))
return 2;
ret =
(GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-testbed-blacklist",
- _
- ("Daemon to restrict incoming transport layer connections during testbed deployments"),
+ GNUNET_PROGRAM_run (argc, argv,
+ "gnunet-daemon-testbed-blacklist",
+ _("Daemon to restrict incoming transport layer connections during testbed deployments"),
options, &run, NULL)) ? 0 : 1;
GNUNET_free ((void*) argv);
return ret;