GNUnet 0.22.2
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
48
52static unsigned int replication = 5;
53
57static unsigned int verbose;
58
63
67static int record_route;
68
73
74
78static const struct GNUNET_CONFIGURATION_Handle *cfg;
79
83static int ret;
84
88static char *data;
89
90
91static void
92shutdown_task (void *cls)
93{
94 if (NULL != dht_handle)
95 {
97 dht_handle = NULL;
98 }
99}
100
101
107static void
109{
111}
112
113
122static void
123run (void *cls,
124 char *const *args,
125 const char *cfgfile,
126 const struct GNUNET_CONFIGURATION_Handle *c)
127{
129
130 cfg = c;
131 if ((NULL == query_key) || (NULL == data))
132 {
133 fprintf (stderr, "%s", _ ("Must provide KEY and DATA for DHT put!\n"));
134 ret = 1;
135 return;
136 }
137
138 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1)))
139 {
140 fprintf (stderr, _ ("Could not connect to DHT service!\n"));
141 ret = 1;
142 return;
143 }
144 if (GNUNET_BLOCK_TYPE_ANY == query_type) /* Type of data not set */
146
148
149 if (verbose)
150 fprintf (stderr,
151 _ ("Issuing put request for `%s' with data `%s'!\n"),
152 query_key,
153 data);
157 if (record_route)
160 &key,
162 ro,
164 strlen (data),
165 data,
168 NULL);
169}
170
171
179int
180main (int argc, char *const *argv)
181{
184 'd',
185 "data",
186 "DATA",
188 "the data to insert under the key"),
189 &data),
191 'e',
192 "expiration",
193 "EXPIRATION",
194 gettext_noop ("how long to store this entry in the dht (in seconds)"),
195 &expiration),
197 'k',
198 "key",
199 "KEY",
200 gettext_noop ("the query key"),
201 &query_key),
203 'x',
204 "demultiplex",
206 "use DHT's demultiplex everywhere option"),
209 'r',
210 "replication",
211 "LEVEL",
212 gettext_noop ("how many replicas to create"),
213 &replication),
215 'R',
216 "record",
217 gettext_noop ("use DHT's record route option"),
218 &record_route),
220 't',
221 "type",
222 "TYPE",
223 gettext_noop ("the type to insert data as"),
224 &query_type),
227 };
228
229
231 ret = (GNUNET_OK ==
234 argc,
235 argv,
236 "gnunet-dht-put",
238 "Issue a PUT request to the GNUnet DHT insert DATA under KEY."),
239 options,
240 &run,
241 NULL))
242 ? ret
243 : 1;
244 return ret;
245}
246
247
248/* end of gnunet-dht-put.c */
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:74
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 void shutdown_task(void *cls)
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.
int main(int argc, char *const *argv)
Entry point for gnunet-dht-put.
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.
@ 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:1081
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:1030
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:1053
@ 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).
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:41
@ 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:407
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:1304
#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.