GNUnet 0.28.1-dev.5-1-gae1c02d74
 
Loading...
Searching...
No Matches
gnunet-namecache.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
28#include "platform.h"
29#include "gnunet_util_lib.h"
33
34
39
44
48static char *name;
49
54
58static char *pkey;
59
63static int ret;
64
68static int del;
69
70
76static void
77do_shutdown (void *cls)
78{
79 if (NULL != qe)
80 {
82 qe = NULL;
83 }
84 if (NULL != ns)
85 {
87 ns = NULL;
88 }
89}
90
91
99static void
101 unsigned int rd_len,
102 const struct GNUNET_GNSRECORD_Data *rd)
103{
104 const char *typestring;
105 char *s;
106 unsigned int i;
107
108 if (0 == rd_len)
109 {
110 fprintf (stdout, _ ("No records found for `%s'"), name);
111 return;
112 }
113 fprintf (stdout, "%s:\n", name);
114 for (i = 0; i < rd_len; i++)
115 {
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,
123 _ ("\tCorrupt or unsupported record of type %u\n"),
124 (unsigned int) rd[i].record_type);
125 continue;
126 }
127 fprintf (stdout, "\t%s: %s\n", typestring, s);
128 GNUNET_free (s);
129 }
130 fprintf (stdout, "%s", "\n");
131}
132
133
140static void
141handle_block (void *cls, const struct GNUNET_GNSRECORD_Block *block)
142{
143 qe = NULL;
144 if (NULL == block)
145 {
146 fprintf (stderr, "No matching block found\n");
147 }
148 else if (GNUNET_OK !=
150 &pubkey,
151 name,
153 NULL))
154 {
155 fprintf (stderr, "Failed to decrypt block!\n");
156 }
158}
159
160
169static void
170handle_delete (void *cls,
171 int32_t success,
172 const char *emsg)
173{
174 qe = NULL;
175 switch (success)
176 {
177 case GNUNET_OK:
178 fprintf (stdout,
179 _ ("Removed cached block for `%s'\n"),
180 name);
181 break;
182
183 case GNUNET_NO:
184 fprintf (stdout,
185 _ ("No cached block for `%s'\n"),
186 name);
187 break;
188
189 default:
190 fprintf (stderr,
191 _ ("Failed to remove cached block for `%s': %s\n"),
192 name,
193 (NULL != emsg) ? emsg : "unknown error");
194 ret = 1;
195 break;
196 }
198}
199
200
209static void
210run (void *cls,
211 char *const *args,
212 const char *cfgfile,
213 const struct GNUNET_CONFIGURATION_Handle *cfg)
214{
215 struct GNUNET_HashCode dhash;
216
217 if (NULL == pkey)
218 {
219 fprintf (stderr, _ ("You must specify which zone should be accessed\n"));
220 return;
221 }
222
223 if (GNUNET_OK !=
225 {
226 fprintf (stderr, _ ("Invalid public key for zone `%s'\n"), pkey);
228 return;
229 }
230 if (NULL == name)
231 {
232 fprintf (stderr, _ ("You must specify a name\n"));
233 return;
234 }
235
239 if (del)
241 else
243}
244
245
253int
254main (int argc, char *const *argv)
255{
258 "delete",
260 "remove the cached block, so that the next resolution goes to the DHT"),
261 &del),
262
264 "name",
265 "NAME",
267 "name of the record to add/delete/display"),
268 &name),
269
271 'z',
272 "zone",
273 "PKEY",
274 gettext_noop ("specifies the public key of the zone to look in"),
275 &pkey),
276
278
279 GNUNET_log_setup ("gnunet-namecache", "WARNING", NULL);
280 if (GNUNET_OK !=
282 argc,
283 argv,
284 "gnunet-namecache",
285 _ ("GNUnet zone manipulation tool"),
286 options,
287 &run,
288 NULL))
289 {
290 return 1;
291 }
292 return ret;
293}
294
295
296/* end of gnunet-namecache.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
#define gettext_noop(String)
Definition gettext.h:74
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
static char * data
The data to insert into the dht.
static struct GNUNET_CRYPTO_BlindablePublicKey pubkey
Public key of the zone to look in.
static char * pkey
Public key of the zone to look in, in ASCII.
static struct GNUNET_NAMECACHE_QueueEntry * qe
Queue entry for the 'query' 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.
static char * name
Name (label) of the records to list.
static int ret
Global return value.
static struct GNUNET_NAMECACHE_Handle * ns
Handle to the namecache.
static void handle_delete(void *cls, int32_t success, const char *emsg)
Block removal finished.
static void handle_block(void *cls, const struct GNUNET_GNSRECORD_Block *block)
Display block obtained from listing (by name).
static int del
Remove the block instead of displaying it?
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static size_t data_size
Number of bytes in data.
static char * typestring
Type of the record to add/remove, NULL to remove all.
API that can be used to manipulate GNS record data.
Identity service; implements identity management for GNUnet.
API that can be used to store naming information on a GNUnet node.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
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.
const char * GNUNET_GNSRECORD_number_to_typename(uint32_t type)
Convert a type number to the corresponding type string (e.g.
Definition gnsrecord.c:219
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_decrypt(const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_BlindablePublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
Decrypt block.
void GNUNET_GNSRECORD_query_from_public_key(const struct GNUNET_CRYPTO_BlindablePublicKey *pub, const char *label, struct GNUNET_HashCode *query)
Calculate the DHT query for a given label in a given zone.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the binary value data of a record of type type to a human-readable string.
Definition gnsrecord.c:147
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blindable_public_key_from_string(const char *str, struct GNUNET_CRYPTO_BlindablePublicKey *key)
Parses a (Base32) string representation of the public key.
@ GNUNET_OK
@ GNUNET_NO
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_NAMECACHE_Handle * GNUNET_NAMECACHE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namecache service.
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.
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_NAMECACHE_QueueEntry * GNUNET_NAMECACHE_block_delete(struct GNUNET_NAMECACHE_Handle *h, const struct GNUNET_HashCode *derived_hash, GNUNET_NAMECACHE_ContinuationWithStatus cont, void *cont_cls)
Remove a block from the namecache, so that the next resolution of the label goes back to the DHT.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, 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:406
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:572
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:1345
#define _(String)
GNU gettext support macro.
Definition platform.h:179
An identity key as per LSD0001.
Definition of a command line option.
A 512-bit hashcode.
Connection to the NAMECACHE service.
An QueueEntry used to store information for a pending NAMECACHE record operation.