GNUnet  0.19.3
gnunet-namecache.c File Reference

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

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_IDENTITY_PublicKey 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:

  • test

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 72 of file gnunet-namecache.c.

73 {
74  if (NULL != qe)
75  {
77  qe = NULL;
78  }
79  if (NULL != ns)
80  {
82  ns = NULL;
83  }
84 }
static struct GNUNET_NAMECACHE_QueueEntry * qe
Queue entry for the 'query' operation.
static struct GNUNET_NAMECACHE_Handle * ns
Handle to the namecache.
void GNUNET_NAMECACHE_disconnect(struct GNUNET_NAMECACHE_Handle *h)
Disconnect from the namecache service (and free associated resources).
void GNUNET_NAMECACHE_cancel(struct GNUNET_NAMECACHE_QueueEntry *qe)
Cancel a namecache operation.

References GNUNET_NAMECACHE_cancel(), GNUNET_NAMECACHE_disconnect(), ns, and qe.

Referenced by run().

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 95 of file gnunet-namecache.c.

98 {
99  const char *typestring;
100  char *s;
101  unsigned int i;
102 
103  if (0 == rd_len)
104  {
105  fprintf (stdout, _ ("No records found for `%s'"), name);
106  return;
107  }
108  fprintf (stdout, "%s:\n", name);
109  for (i = 0; i < rd_len; i++)
110  {
112  s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
113  rd[i].data,
114  rd[i].data_size);
115  if (NULL == s)
116  {
117  fprintf (stdout,
118  _ ("\tCorrupt or unsupported record of type %u\n"),
119  (unsigned int) rd[i].record_type);
120  continue;
121  }
122  fprintf (stdout, "\t%s: %s\n", typestring, s);
123  GNUNET_free (s);
124  }
125  fprintf (stdout, "%s", "\n");
126 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
static char * typestring
Type of the record to add/remove, NULL to remove all.
Definition: gnunet-abd.c:197
uint32_t data
The data value.
static char * name
Name (label) of the records to list.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
const char * GNUNET_GNSRECORD_number_to_typename(uint32_t type)
Convert a type number to the corresponding type string (e.g.
Definition: gnsrecord.c:227
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the 'value' of a record to a string.
Definition: gnsrecord.c:155
#define GNUNET_free(ptr)
Wrapper around free.
#define _(String)
GNU gettext support macro.
Definition: platform.h:177

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

Referenced by handle_block().

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 136 of file gnunet-namecache.c.

137 {
138  qe = NULL;
139  if (NULL == block)
140  {
141  fprintf (stderr, "No matching block found\n");
142  }
143  else if (GNUNET_OK !=
145  &pubkey,
146  name,
148  NULL))
149  {
150  fprintf (stderr, "Failed to decrypt block!\n");
151  }
153 }
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.
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_decrypt(const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_IDENTITY_PublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
Decrypt block.
@ GNUNET_OK
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:534

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

Referenced by run().

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 165 of file gnunet-namecache.c.

169 {
170  struct GNUNET_HashCode dhash;
171 
172  if (NULL == pkey)
173  {
174  fprintf (stderr, _ ("You must specify which zone should be accessed\n"));
175  return;
176  }
177 
178  if (GNUNET_OK !=
180  {
181  fprintf (stderr, _ ("Invalid public key for zone `%s'\n"), pkey);
183  return;
184  }
185  if (NULL == name)
186  {
187  fprintf (stderr, _ ("You must specify a name\n"));
188  return;
189  }
190 
194  qe = GNUNET_NAMECACHE_lookup_block (ns, &dhash, &handle_block, NULL);
195 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static char * pkey
Public key of the zone to look in, in ASCII.
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).
void GNUNET_GNSRECORD_query_from_public_key(const struct GNUNET_IDENTITY_PublicKey *pub, const char *label, struct GNUNET_HashCode *query)
Calculate the DHT query for a given label in a given zone.
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_public_key_from_string(const char *str, struct GNUNET_IDENTITY_PublicKey *key)
Parses a (Base32) string representation of the public key.
struct GNUNET_NAMECACHE_Handle * GNUNET_NAMECACHE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namecache service.
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.
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,...
Definition: scheduler.c:1303
A 512-bit hashcode.

References _, cfg, do_shutdown(), GNUNET_GNSRECORD_query_from_public_key(), GNUNET_IDENTITY_public_key_from_string(), GNUNET_NAMECACHE_connect(), GNUNET_NAMECACHE_lookup_block(), GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), handle_block(), name, ns, pkey, pubkey, and qe.

Referenced by main().

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 206 of file gnunet-namecache.c.

207 {
210  "name",
211  "NAME",
212  gettext_noop (
213  "name of the record to add/delete/display"),
214  &name),
215 
217  'z',
218  "zone",
219  "PKEY",
220  gettext_noop ("specifies the public key of the zone to look in"),
221  &pkey),
222 
224 
225  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
226  return 2;
227 
228  GNUNET_log_setup ("gnunet-namecache", "WARNING", NULL);
229  if (GNUNET_OK != GNUNET_PROGRAM_run (argc,
230  argv,
231  "gnunet-namecache",
232  _ ("GNUnet zone manipulation tool"),
233  options,
234  &run,
235  NULL))
236  {
237  GNUNET_free_nz ((void *) argv);
238  return 1;
239  }
240  GNUNET_free_nz ((void *) argv);
241  return ret;
242 }
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:70
static int ret
Global return value.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
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.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue 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,...
Definition: program.c:400
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1222
Definition of a command line option.

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

Here is the call graph for this function:

Variable Documentation

◆ ns

struct GNUNET_NAMECACHE_Handle* ns
static

Handle to the namecache.

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

Referenced by do_shutdown(), and run().

◆ qe

struct GNUNET_NAMECACHE_QueueEntry* qe
static

Queue entry for the 'query' operation.

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

Referenced by do_shutdown(), handle_block(), and run().

◆ name

char* name
static

Name (label) of the records to list.

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

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

◆ pubkey

◆ pkey

◆ ret

int ret
static

Global return value.

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

Referenced by main().