GNUnet  0.10.x
list-keys.c
Go to the documentation of this file.
1 #include "platform.h"
2 #include "gnunet_util_lib.h"
3 #include "gnunet_testing_lib.h"
4 
5 static unsigned int nkeys;
6 static unsigned int nskip;
7 static int result;
8 
17 static void
18 run (void *cls, char *const *args, const char *cfgfile,
19  const struct GNUNET_CONFIGURATION_Handle *config)
20 {
21  char *idfile;
22  struct GNUNET_DISK_FileHandle *f;
23  void *data;
24  struct GNUNET_DISK_MapHandle *map;
26  struct GNUNET_PeerIdentity id;
27  unsigned int cnt;
28  uint64_t fsize;
29  unsigned int nmax;
30 
31  if ((NULL == args) || (NULL == args[0]))
32  {
33  FPRINTF (stderr, "Need the hostkey file\n");
34  return;
35  }
36  idfile = args[0];
37  if (GNUNET_OK !=
38  GNUNET_DISK_file_size (idfile, &fsize, GNUNET_YES, GNUNET_YES))
39  {
40  GNUNET_break (0);
41  return;
42  }
43  if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE))
44  {
45  FPRINTF (stderr,
46  _("Incorrect hostkey file format: %s\n"), idfile);
47  return;
48  }
51  if (NULL == f)
52  {
53  GNUNET_break (0);
54  return;
55  }
56  data = GNUNET_DISK_file_map (f, &map, GNUNET_DISK_MAP_TYPE_READ, fsize);
57  if (NULL == data)
58  {
59  GNUNET_break (0);
61  return;
62  }
63  nmax = fsize / GNUNET_TESTING_HOSTKEYFILESIZE;
64  for (cnt = nskip; cnt < (nskip + nkeys); cnt++)
65  {
66  if (nskip + cnt >= nmax)
67  {
68  PRINTF ("Max keys %u reached\n", nmax);
69  break;
70  }
71  GNUNET_memcpy (&pkey,
72  data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE),
73  GNUNET_TESTING_HOSTKEYFILESIZE);
75  PRINTF ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id));
76  }
77  result = GNUNET_OK;
80 }
81 
82 
83 int main (int argc, char *argv[])
84 {
85  struct GNUNET_GETOPT_CommandLineOption option[] = {
87  "num-keys",
88  "COUNT",
89  gettext_noop ("list COUNT number of keys"),
90  &nkeys),
92  };
93  int ret;
94 
96  nkeys = 10;
97  ret =
98  GNUNET_PROGRAM_run (argc, argv, "list-keys", "Lists the peer IDs corresponding to the given keys file\n",
99  option, &run, NULL);
100  if (GNUNET_OK != ret)
101  return 1;
102  if (GNUNET_SYSERR == result)
103  return 1;
104  return 0;
105 }
Open the file for reading.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1817
#define FPRINTF
Definition: plibc.h:683
static int result
Definition: list-keys.c:7
void * GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, enum GNUNET_DISK_MapType access, size_t len)
Map a file into memory.
Definition: disk.c:2020
Nobody is allowed to do anything to the file.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Definition of a command line option.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_TESTING_HOSTKEYFILESIZE
Size of each hostkey in the hostkey file (in BYTES).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config)
Main run function.
Definition: list-keys.c:18
static unsigned int nskip
Definition: list-keys.c:6
#define GNUNET_memcpy(dst, src, n)
Read-only memory map.
static const struct GNUNET_CONFIGURATION_Handle * config
static unsigned int nkeys
Definition: list-keys.c:5
#define PRINTF
Definition: plibc.h:682
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:2100
int GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:289
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:272
Private ECC key encoded for transmission.
The identity of the host (wraps the signing key of the peer).
configuration data
Definition: configuration.c:85
int GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:361
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
uint32_t data
The data value.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1673
int main(int argc, char *argv[])
Definition: list-keys.c:83
Handle used to access files (and pipes).
Handle for a memory-mapping operation.
Definition: disk.c:1985
struct GNUNET_CRYPTO_EddsaPublicKey public_key
#define gettext_noop(String)
Definition: gettext.h:69