GNUnet  0.11.x
Functions | Variables
gnunet-dht-put.c File Reference

search for data in DHT More...

#include "platform.h"
#include "gnunet_dht_service.h"
Include dependency graph for gnunet-dht-put.c:

Go to the source code of this file.

Functions

static void shutdown_task (void *cls)
 
static void message_sent_cont (void *cls)
 Signature of the main function of a task. More...
 
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. More...
 
int main (int argc, char *const *argv)
 Entry point for gnunet-dht-put. More...
 

Variables

static unsigned int query_type
 The type of the query. More...
 
struct GNUNET_HashCode key
 The key used in the DHT. More...
 
static char * query_key
 The key for the query. More...
 
static struct GNUNET_TIME_Relative expiration
 User supplied expiration value. More...
 
static unsigned int replication = 5
 Desired replication level. More...
 
static unsigned int verbose
 Be verbose. More...
 
static int demultixplex_everywhere
 Use #GNUNET_DHT_DEMULTIPLEX_EVERYWHERE. More...
 
static int record_route
 Use GNUNET_DHT_RO_RECORD_ROUTE. More...
 
static struct GNUNET_DHT_Handledht_handle
 Handle to the DHT. More...
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Global handle of the configuration. More...
 
static int ret
 Global status value. More...
 
static char * data
 The data to insert into the dht. More...
 

Detailed Description

search for data in DHT

Author
Christian Grothoff
Nathan Evans

Definition in file gnunet-dht-put.c.

Function Documentation

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Definition at line 92 of file gnunet-dht-put.c.

References GNUNET_DHT_disconnect().

Referenced by message_sent_cont().

93 {
94  if (NULL != dht_handle)
95  {
97  dht_handle = NULL;
98  }
99 }
static struct GNUNET_DHT_Handle * dht_handle
Handle to the DHT.
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:918
Here is the call graph for this function:
Here is the caller graph for this function:

◆ message_sent_cont()

static void message_sent_cont ( void *  cls)
static

Signature of the main function of a task.

Parameters
clsclosure

Definition at line 108 of file gnunet-dht-put.c.

References GNUNET_SCHEDULER_add_now(), and shutdown_task().

Referenced by run().

109 {
111 }
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:1280
static void shutdown_task(void *cls)
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 c 
)
static

Main function that will be run by the scheduler.

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

Definition at line 123 of file gnunet-dht-put.c.

References _, data, demultixplex_everywhere, expiration, GNUNET_BLOCK_TYPE_ANY, GNUNET_BLOCK_TYPE_TEST, GNUNET_CRYPTO_hash(), GNUNET_DHT_connect(), GNUNET_DHT_put(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_DHT_RO_NONE, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_TIME_relative_to_absolute(), key, message_sent_cont(), query_key, query_type, record_route, replication, ret, and verbose.

Referenced by main().

127 {
128  enum GNUNET_DHT_RouteOption ro;
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);
154  ro = GNUNET_DHT_RO_NONE;
157  if (record_route)
160  &key,
161  replication,
162  ro,
163  query_type,
164  strlen (data),
165  data,
168  NULL);
169 }
We should keep track of the route that the message took in the P2P network.
static struct GNUNET_DHT_Handle * dht_handle
Handle to the DHT.
static unsigned int query_type
The type of the query.
Any type of block, used as a wildcard when searching.
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:246
static char * query_key
The key for the query.
static void message_sent_cont(void *cls)
Signature of the main function of a task.
static unsigned int verbose
Be verbose.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
static unsigned int replication
Desired replication level.
GNUNET_DHT_RouteOption
Options for routing.
static int demultixplex_everywhere
Use #GNUNET_DHT_DEMULTIPLEX_EVERYWHERE.
struct GNUNET_HashCode key
The key used in the DHT.
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:966
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:890
static int record_route
Use GNUNET_DHT_RO_RECORD_ROUTE.
static int ret
Global status value.
Block for testing.
static struct GNUNET_TIME_Relative expiration
User supplied expiration value.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Global handle of the configuration.
Each peer along the way should look at 'enc' (otherwise only the k-peers closest to the key should lo...
static char * data
The data to insert into the dht.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

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

Entry point for gnunet-dht-put.

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

Definition at line 180 of file gnunet-dht-put.c.

References data, demultixplex_everywhere, expiration, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_relative_time(), GNUNET_GETOPT_option_string(), GNUNET_GETOPT_option_uint(), GNUNET_GETOPT_option_verbose(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), GNUNET_TIME_UNIT_HOURS, query_key, query_type, record_route, replication, ret, run(), and verbose.

181 {
184  "data",
185  "DATA",
186  gettext_noop (
187  "the data to insert under the key"),
188  &data),
190  'e',
191  "expiration",
192  "EXPIRATION",
193  gettext_noop ("how long to store this entry in the dht (in seconds)"),
194  &expiration),
196  "key",
197  "KEY",
198  gettext_noop ("the query key"),
199  &query_key),
201  "demultiplex",
202  gettext_noop (
203  "use DHT's demultiplex everywhere option"),
206  "replication",
207  "LEVEL",
208  gettext_noop ("how many replicas to create"),
209  &replication),
211  "record",
212  gettext_noop ("use DHT's record route option"),
213  &record_route),
215  "type",
216  "TYPE",
217  gettext_noop ("the type to insert data as"),
218  &query_type),
221 
222 
223  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
224  return 2;
226  return (GNUNET_OK ==
228  argc,
229  argv,
230  "gnunet-dht-put",
231  gettext_noop (
232  "Issue a PUT request to the GNUnet DHT insert DATA under KEY."),
233  options,
234  &run,
235  NULL))
236  ? ret
237  : 1;
238 }
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_TIME_UNIT_HOURS
One hour.
static unsigned int query_type
The type of the query.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' verbosity option.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1438
static char * query_key
The key for the query.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
static unsigned int verbose
Be verbose.
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.
static unsigned int replication
Desired replication level.
static int demultixplex_everywhere
Use #GNUNET_DHT_DEMULTIPLEX_EVERYWHERE.
static int record_route
Use GNUNET_DHT_RO_RECORD_ROUTE.
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 int ret
Global status value.
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.
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:367
static struct GNUNET_TIME_Relative expiration
User supplied expiration value.
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.
static char * data
The data to insert into the dht.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ query_type

unsigned int query_type
static

The type of the query.

Definition at line 32 of file gnunet-dht-put.c.

Referenced by main(), and run().

◆ key

struct GNUNET_HashCode key

◆ query_key

char* query_key
static

The key for the query.

Definition at line 42 of file gnunet-dht-put.c.

Referenced by main(), and run().

◆ expiration

struct GNUNET_TIME_Relative expiration
static

User supplied expiration value.

Definition at line 47 of file gnunet-dht-put.c.

Referenced by main(), and run().

◆ replication

unsigned int replication = 5
static

Desired replication level.

Definition at line 52 of file gnunet-dht-put.c.

Referenced by main(), and run().

◆ verbose

unsigned int verbose
static

Be verbose.

Definition at line 57 of file gnunet-dht-put.c.

Referenced by main(), and run().

◆ demultixplex_everywhere

int demultixplex_everywhere
static

Use #GNUNET_DHT_DEMULTIPLEX_EVERYWHERE.

Definition at line 62 of file gnunet-dht-put.c.

Referenced by main(), and run().

◆ record_route

int record_route
static

Use GNUNET_DHT_RO_RECORD_ROUTE.

Definition at line 67 of file gnunet-dht-put.c.

Referenced by main(), and run().

◆ dht_handle

struct GNUNET_DHT_Handle* dht_handle
static

Handle to the DHT.

Definition at line 72 of file gnunet-dht-put.c.

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Global handle of the configuration.

Definition at line 78 of file gnunet-dht-put.c.

◆ ret

int ret
static

Global status value.

Definition at line 83 of file gnunet-dht-put.c.

Referenced by main(), and run().

◆ data

char* data
static

The data to insert into the dht.

Definition at line 88 of file gnunet-dht-put.c.

Referenced by main(), and run().