aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2014-01-08 21:29:32 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2014-01-08 21:29:32 +0000
commit1c10ce20375a5dffb575cea7fd330a805ef3d7a1 (patch)
treeee46615716a1a292e3b341084c21851e97680404 /src/testing
parent7ab6edba583d8d09d2c830c9c5b6fe155d31b408 (diff)
- utility to list peer ids from a given hostkeys file
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/Makefile.am9
-rw-r--r--src/testing/list-keys.c109
2 files changed, 118 insertions, 0 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index f27b46ed02..8657d42cb6 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -30,6 +30,9 @@ libgnunettesting_la_LDFLAGS = \
bin_PROGRAMS = \
gnunet-testing
+noinst_PROGRAMS = \
+ list-keys
+
gnunet_testing_SOURCES = \
gnunet-testing.c
gnunet_testing_LDADD = \
@@ -39,6 +42,12 @@ gnunet_testing_LDADD = \
gnunet_testing_DEPENDENCIES = \
libgnunettesting.la
+list_keys_SOURCES = \
+ list-keys.c
+list_keys_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(GN_LIBINTL)
+
check_PROGRAMS = \
test_testing_portreservation \
diff --git a/src/testing/list-keys.c b/src/testing/list-keys.c
new file mode 100644
index 0000000000..1c469adccf
--- /dev/null
+++ b/src/testing/list-keys.c
@@ -0,0 +1,109 @@
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_lib.h"
+
+static unsigned int nkeys;
+static unsigned int nskip;
+static int result;
+
+
+
+
+
+/**
+ * Main run function.
+ *
+ * @param cls NULL
+ * @param args arguments passed to GNUNET_PROGRAM_run
+ * @param cfgfile the path to configuration file
+ * @param cfg the configuration file handle
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *config)
+{
+ char *idfile;
+ struct GNUNET_DISK_FileHandle *f;
+ void *data;
+ struct GNUNET_DISK_MapHandle *map;
+ struct GNUNET_CRYPTO_EddsaPrivateKey pkey;
+ struct GNUNET_PeerIdentity id;
+ unsigned int cnt;
+ uint64_t fsize;
+ unsigned int nmax;
+
+ if ((NULL == args) || (NULL == args[0]))
+ {
+ FPRINTF (stderr, "Need the hostkey file\n");
+ return;
+ }
+ idfile = args[0];
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (idfile, &fsize, GNUNET_YES, GNUNET_YES))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE))
+ {
+ FPRINTF (stderr,
+ _("Incorrect hostkey file format: %s\n"), idfile);
+ return;
+ }
+ f = GNUNET_DISK_file_open (idfile, GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
+ if (NULL == f)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ data = GNUNET_DISK_file_map (f, &map, GNUNET_DISK_MAP_TYPE_READ, fsize);
+ if (NULL == data)
+ {
+ GNUNET_break (0);
+ GNUNET_DISK_file_close (f);
+ return;
+ }
+ nmax = fsize / GNUNET_TESTING_HOSTKEYFILESIZE;
+ for (cnt = nskip; cnt < (nskip + nkeys); cnt++)
+ {
+ if (nskip + cnt >= nmax)
+ {
+ PRINTF ("Max keys %u reached\n", nmax);
+ break;
+ }
+ (void) memcpy (&pkey, data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE),
+ GNUNET_TESTING_HOSTKEYFILESIZE);
+ GNUNET_CRYPTO_eddsa_key_get_public (&pkey, &id.public_key);
+ PRINTF ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id));
+ }
+ result = GNUNET_OK;
+ GNUNET_DISK_file_unmap (map);
+ GNUNET_DISK_file_close (f);
+}
+
+
+int main (int argc, char *argv[])
+{
+ struct GNUNET_GETOPT_CommandLineOption option[] = {
+ {'n', "num-keys", "COUNT",
+ gettext_noop ("list COUNT number of keys"),
+ GNUNET_YES, &GNUNET_GETOPT_set_uint, &nkeys},
+ {'s', "skip", "COUNT",
+ gettext_noop ("skip COUNT number of keys in the beginning"),
+ GNUNET_YES, &GNUNET_GETOPT_set_uint, &nskip},
+ GNUNET_GETOPT_OPTION_END
+ };
+ int ret;
+
+ result = GNUNET_SYSERR;
+ nkeys = 10;
+ ret =
+ GNUNET_PROGRAM_run (argc, argv, "list-keys", "Lists the peer IDs corresponding to the given keys file\n",
+ option, &run, NULL);
+ if (GNUNET_OK != ret)
+ return 1;
+ if (GNUNET_SYSERR == result)
+ return 1;
+ return 0;
+}