GNUnet  0.10.x
Functions | Variables
gnunet-namecache.c File Reference

command line tool to inspect the name cache More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_dnsparser_lib.h"
#include "gnunet_identity_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_namecache_service.h"
Include dependency graph for gnunet-namecache.c:

Go to the source code of this file.

Functions

static void do_shutdown (void *cls)
 Task run on shutdown. More...
 
static void display_records_from_block (void *cls, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
 Process a record that was stored in the namecache in a block. More...
 
static void handle_block (void *cls, const struct GNUNET_GNSRECORD_Block *block)
 Display block obtained from listing (by name). More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run. More...
 
int main (int argc, char *const *argv)
 The main function for gnunet-namecache. More...
 

Variables

static struct GNUNET_NAMECACHE_Handlens
 Handle to the namecache. More...
 
static struct GNUNET_NAMECACHE_QueueEntryqe
 Queue entry for the 'query' operation. More...
 
static char * name
 Name (label) of the records to list. More...
 
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey
 Public key of the zone to look in. More...
 
static char * pkey
 Public key of the zone to look in, in ASCII. More...
 
static int ret
 Global return value. More...
 

Detailed Description

command line tool to inspect the name cache

Author
Christian Grothoff

TODO:

Definition in file gnunet-namecache.c.

Function Documentation

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Task run on shutdown.

Cleans up everything.

Parameters
clsunused

Definition at line 73 of file gnunet-namecache.c.

References GNUNET_NAMECACHE_cancel(), and GNUNET_NAMECACHE_disconnect().

Referenced by run().

74 {
75  if (NULL != qe)
76  {
78  qe = NULL;
79  }
80  if (NULL != ns)
81  {
83  ns = NULL;
84  }
85 }
static struct GNUNET_NAMECACHE_Handle * ns
Handle to the namecache.
void GNUNET_NAMECACHE_cancel(struct GNUNET_NAMECACHE_QueueEntry *qe)
Cancel a namecache operation.
static struct GNUNET_NAMECACHE_QueueEntry * qe
Queue entry for the 'query' operation.
void GNUNET_NAMECACHE_disconnect(struct GNUNET_NAMECACHE_Handle *h)
Disconnect from the namecache service (and free associated resources).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_records_from_block()

static void display_records_from_block ( void *  cls,
unsigned int  rd_len,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Process a record that was stored in the namecache in a block.

Parameters
clsclosure, NULL
rd_lennumber of entries in rd array
rdarray of records with data to store

Definition at line 96 of file gnunet-namecache.c.

References _, data, data_size, FPRINTF, GNUNET_free, GNUNET_GNSRECORD_number_to_typename(), GNUNET_GNSRECORD_value_to_string(), name, and typestring.

Referenced by handle_block().

99 {
100  const char *typestring;
101  char *s;
102  unsigned int i;
103 
104  if (0 == rd_len)
105  {
106  FPRINTF (stdout,
107  _("No records found for `%s'"),
108  name);
109  return;
110  }
111  FPRINTF (stdout,
112  "%s:\n",
113  name);
114  for (i=0;i<rd_len;i++)
115  {
116  typestring = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
117  s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
118  rd[i].data,
119  rd[i].data_size);
120  if (NULL == s)
121  {
122  FPRINTF (stdout, _("\tCorrupt or unsupported record of type %u\n"),
123  (unsigned int) rd[i].record_type);
124  continue;
125  }
126  FPRINTF (stdout,
127  "\t%s: %s\n",
128  typestring,
129  s);
130  GNUNET_free (s);
131  }
132  FPRINTF (stdout, "%s", "\n");
133 }
#define FPRINTF
Definition: plibc.h:683
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char * name
Name (label) of the records to list.
static char * typestring
Type of the record to add/remove, NULL to remove all.
uint32_t data
The data value.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
Definition: gnsrecord.c:143
static size_t data_size
Number of bytes in data.
const char * GNUNET_GNSRECORD_number_to_typename(uint32_t type)
Convert a type number (i.e.
Definition: gnsrecord.c:231
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_block()

static void handle_block ( void *  cls,
const struct GNUNET_GNSRECORD_Block block 
)
static

Display block obtained from listing (by name).

Parameters
clsNULL
blockNULL if not found

Definition at line 143 of file gnunet-namecache.c.

References display_records_from_block(), GNUNET_GNSRECORD_block_decrypt(), GNUNET_OK, GNUNET_SCHEDULER_shutdown(), name, and pubkey.

Referenced by run().

145 {
146  qe = NULL;
147  if (NULL == block)
148  {
149  fprintf (stderr,
150  "No matching block found\n");
151  }
152  else if (GNUNET_OK !=
154  &pubkey,
155  name,
157  NULL))
158  {
159  fprintf (stderr,
160  "Failed to decrypt block!\n");
161  }
163 }
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey
Public key of the zone to look in.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
static char * name
Name (label) of the records to list.
int GNUNET_GNSRECORD_block_decrypt(const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
Decrypt block.
static struct GNUNET_NAMECACHE_QueueEntry * qe
Queue entry for the &#39;query&#39; operation.
static void display_records_from_block(void *cls, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in the namecache in a block.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Main function that will be run.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 175 of file gnunet-namecache.c.

References _, do_shutdown(), GNUNET_CRYPTO_ecdsa_public_key_from_string(), GNUNET_GNSRECORD_query_from_public_key(), GNUNET_NAMECACHE_connect(), GNUNET_NAMECACHE_lookup_block(), GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), handle_block(), name, pkey, and pubkey.

Referenced by main().

177 {
178  struct GNUNET_HashCode dhash;
179 
180  if (NULL == pkey)
181  {
182  fprintf (stderr,
183  _("You must specify which zone should be accessed\n"));
184  return;
185  }
186 
187  if (GNUNET_OK !=
189  strlen (pkey),
190  &pubkey))
191  {
192  fprintf (stderr,
193  _("Invalid public key for zone `%s'\n"),
194  pkey);
196  return;
197  }
198  if (NULL == name)
199  {
200  fprintf (stderr,
201  _("You must specify a name\n"));
202  return;
203  }
204 
206  NULL);
209  name,
210  &dhash);
212  &dhash,
213  &handle_block,
214  NULL);
215 }
struct GNUNET_NAMECACHE_Handle * GNUNET_NAMECACHE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namecache service.
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey
Public key of the zone to look in.
static char * pkey
Public key of the zone to look in, in ASCII.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct GNUNET_NAMECACHE_Handle * ns
Handle to the namecache.
A 512-bit hashcode.
static char * name
Name (label) of the records to list.
struct GNUNET_NAMECACHE_QueueEntry * GNUNET_NAMECACHE_lookup_block(struct GNUNET_NAMECACHE_Handle *h, const struct GNUNET_HashCode *derived_hash, GNUNET_NAMECACHE_BlockProcessor proc, void *proc_cls)
Get a result for a particular key from the namecache.
int GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:468
static struct GNUNET_NAMECACHE_QueueEntry * qe
Queue entry for the &#39;query&#39; operation.
void GNUNET_GNSRECORD_query_from_public_key(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, const char *label, struct GNUNET_HashCode *query)
Calculate the DHT query for a given label in a given zone.
static void do_shutdown(void *cls)
Task run on shutdown.
static void handle_block(void *cls, const struct GNUNET_GNSRECORD_Block *block)
Display block obtained from listing (by name).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function for gnunet-namecache.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 226 of file gnunet-namecache.c.

References _, gettext_noop, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_string(), GNUNET_log_setup(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), name, pkey, ret, and run().

227 {
230  "name",
231  "NAME",
232  gettext_noop ("name of the record to add/delete/display"),
233  &name),
234 
236  "zone",
237  "PKEY",
238  gettext_noop ("specifies the public key of the zone to look in"),
239  &pkey),
240 
242  };
243 
244  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
245  return 2;
246 
247  GNUNET_log_setup ("gnunet-namecache", "WARNING", NULL);
248  if (GNUNET_OK !=
249  GNUNET_PROGRAM_run (argc, argv, "gnunet-namecache",
250  _("GNUnet zone manipulation tool"),
251  options,
252  &run, NULL))
253  {
254  GNUNET_free ((void*) argv);
255  return 1;
256  }
257  GNUNET_free ((void*) argv);
258  return ret;
259 }
static char * pkey
Public key of the zone to look in, in ASCII.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1521
static int ret
Global return value.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Definition of a command line option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char * name
Name (label) of the records to list.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
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
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ ns

struct GNUNET_NAMECACHE_Handle* ns
static

Handle to the namecache.

Definition at line 39 of file gnunet-namecache.c.

◆ qe

struct GNUNET_NAMECACHE_QueueEntry* qe
static

Queue entry for the 'query' operation.

Definition at line 44 of file gnunet-namecache.c.

◆ name

char* name
static

Name (label) of the records to list.

Definition at line 49 of file gnunet-namecache.c.

Referenced by display_records_from_block(), handle_block(), main(), and run().

◆ pubkey

struct GNUNET_CRYPTO_EcdsaPublicKey pubkey
static

Public key of the zone to look in.

Definition at line 54 of file gnunet-namecache.c.

Referenced by handle_block(), and run().

◆ pkey

char* pkey
static

◆ ret

int ret
static

Global return value.

Definition at line 64 of file gnunet-namecache.c.

Referenced by main().