GNUnet 0.28.1-dev.5-1-gae1c02d74
 
Loading...
Searching...
No Matches
gnunet-dht-put.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009, 2017 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 */
26#include "platform.h"
27#include "gnunet_dht_service.h"
28
32static unsigned int query_type;
33
38
42static char *query_key;
43
47static int raw_key;
48
53
57static unsigned int replication = 5;
58
62static unsigned int verbose;
63
68
72static int record_route;
73
78
79
83static const struct GNUNET_CONFIGURATION_Handle *cfg;
84
88static int ret;
89
93static char *data;
94
95
96static void
97shutdown_task (void *cls)
98{
99 if (NULL != dht_handle)
100 {
102 dht_handle = NULL;
103 }
104}
105
106
112static void
114{
116}
117
118
127static void
128run (void *cls,
129 char *const *args,
130 const char *cfgfile,
131 const struct GNUNET_CONFIGURATION_Handle *c)
132{
134
135 cfg = c;
136 if ((NULL == query_key) || (NULL == data))
137 {
138 fprintf (stderr, "%s", _ ("Must provide KEY and DATA for DHT put!\n"));
139 ret = 1;
140 return;
141 }
142
143 /* Resolve the key before connecting, so that a bad key does not leak
144 the DHT handle. */
145 if (raw_key)
146 {
147 if (GNUNET_OK !=
149 &key))
150 {
151 fprintf (stderr,
152 _ ("`%s' is not a valid key\n"),
153 query_key);
154 ret = 1;
155 return;
156 }
157 }
158 else
159 {
161 strlen (query_key),
162 &key);
163 }
164 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1)))
165 {
166 fprintf (stderr, _ ("Could not connect to DHT service!\n"));
167 ret = 1;
168 return;
169 }
170 if (GNUNET_BLOCK_TYPE_ANY == query_type) /* Type of data not set */
172
173 if (verbose)
174 fprintf (stderr,
175 _ ("Issuing put request for `%s' with data `%s'!\n"),
176 query_key,
177 data);
181 if (record_route)
184 &key,
186 ro,
188 strlen (data),
189 data,
192 NULL);
193}
194
195
203int
204main (int argc, char *const *argv)
205{
208 'd',
209 "data",
210 "DATA",
212 "the data to insert under the key"),
213 &data),
215 'e',
216 "expiration",
217 "EXPIRATION",
218 gettext_noop ("how long to store this entry in the dht (in seconds)"),
219 &expiration),
221 'k',
222 "key",
223 "KEY",
225 "the string to hash into the query key (see -K to give the key itself)")
226 ,
227 &query_key),
229 'K',
230 "raw-key",
232 "interpret -k as the query key itself, in the base32 form GNUnet prints it, instead of hashing it"),
233 &raw_key),
235 'x',
236 "demultiplex",
238 "use DHT's demultiplex everywhere option"),
241 'r',
242 "replication",
243 "LEVEL",
244 gettext_noop ("how many replicas to create"),
245 &replication),
247 'R',
248 "record",
249 gettext_noop ("use DHT's record route option"),
250 &record_route),
252 't',
253 "type",
254 "TYPE",
255 gettext_noop ("the type to insert data as"),
256 &query_type),
259 };
260
261
263 ret = (GNUNET_OK ==
266 argc,
267 argv,
268 "gnunet-dht-put",
270 "Issue a PUT request to the GNUnet DHT insert DATA under KEY."),
271 options,
272 &run,
273 NULL))
274 ? ret
275 : 1;
276 return ret;
277}
278
279
280/* end of gnunet-dht-put.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 int raw_key
Is query_key the key itself rather than its preimage?
static unsigned int query_type
The type of the query.
static unsigned int verbose
Be verbose.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Global handle of the configuration.
static void message_sent_cont(void *cls)
Signature of the main function of a task.
static int ret
Global status value.
static char * query_key
The key for the query.
static struct GNUNET_DHT_Handle * dht_handle
Handle to the DHT.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run by the scheduler.
static char * data
The data to insert into the dht.
static unsigned int replication
Desired replication level.
static int demultixplex_everywhere
Use #GNUNET_DHT_DEMULTIPLEX_EVERYWHERE.
struct GNUNET_HashCode key
The key used in the DHT.
static int record_route
Use GNUNET_DHT_RO_RECORD_ROUTE.
static struct GNUNET_TIME_Relative expiration
User supplied expiration value.
struct GNUNET_SCHEDULER_Task * shutdown_task
@ GNUNET_BLOCK_TYPE_TEST
Block for testing.
@ GNUNET_BLOCK_TYPE_ANY
Identifier for any block.
API to the DHT service.
GNUNET_DHT_RouteOption
Options for routing.
struct GNUNET_DHT_PutHandle * GNUNET_DHT_put(struct GNUNET_DHT_Handle *handle, const struct GNUNET_HashCode *key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, size_t size, const void *data, struct GNUNET_TIME_Absolute exp, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Perform a PUT operation storing data in the DHT.
Definition dht_api.c:1086
struct GNUNET_DHT_Handle * GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int ht_len)
Initialize the connection with the DHT service.
Definition dht_api.c:1036
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition dht_api.c:1058
@ GNUNET_DHT_RO_NONE
Default.
@ GNUNET_DHT_RO_RECORD_ROUTE
We should keep track of the route that the message took in the P2P network.
@ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
Each peer along the way should process the request (otherwise only peers locally closest to the key w...
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.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time(char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Relative *val)
Allow user to specify a struct GNUNET_TIME_Relative (using human-readable "fancy" time).
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' verbosity option.
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.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
#define GNUNET_CRYPTO_hash_from_string(enc, result)
Convert ASCII encoding back to struct GNUNET_HashCode
@ GNUNET_OK
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
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1310
#define GNUNET_TIME_UNIT_HOURS
One hour.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
#define _(String)
GNU gettext support macro.
Definition platform.h:179
Connection to the DHT service.
Definition dht_api.c:235
Definition of a command line option.
A 512-bit hashcode.
Time for relative time used by GNUnet, in microseconds.