GNUnet  0.10.x
Macros | Functions | Variables
gnunet-dht-get.c File Reference

search for data in DHT More...

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

Go to the source code of this file.

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "dht-clients",__VA_ARGS__)
 

Functions

static void cleanup_task (void *cls)
 Task run to clean up on shutdown. More...
 
static void timeout_task (void *cls)
 Task run on timeout. More...
 
static void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data)
 Iterator called on each result obtained for a DHT operation that expects a reply. 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-get. More...
 

Variables

static unsigned int query_type
 The type of the query. More...
 
static unsigned int replication = 5
 Desired replication level. More...
 
static char * query_key
 The key for the query. More...
 
static struct GNUNET_TIME_Relative timeout_request = { 60000 }
 User supplied timeout value. More...
 
static unsigned int verbose
 Be verbose. More...
 
static int demultixplex_everywhere
 Use DHT demultixplex_everywhere. 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 struct GNUNET_DHT_GetHandleget_handle
 Handle for the get request. More...
 
static unsigned int result_count
 Count of results found. More...
 
static int ret
 Global status value. More...
 
static struct GNUNET_SCHEDULER_Tasktt
 Task scheduled to handle timeout. More...
 

Detailed Description

search for data in DHT

Author
Christian Grothoff
Nathan Evans

Definition in file gnunet-dht-get.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "dht-clients",__VA_ARGS__)

Definition at line 29 of file gnunet-dht-get.c.

Function Documentation

◆ cleanup_task()

static void cleanup_task ( void *  cls)
static

Task run to clean up on shutdown.

Parameters
clsunused

Definition at line 97 of file gnunet-dht-get.c.

References GNUNET_DHT_disconnect(), GNUNET_DHT_get_stop(), and GNUNET_SCHEDULER_cancel().

Referenced by run().

98 {
99  if (NULL != get_handle)
100  {
102  get_handle = NULL;
103  }
104  if (NULL != dht_handle)
105  {
107  dht_handle = NULL;
108  }
109  if (NULL != tt)
110  {
112  tt = NULL;
113  }
114 }
static struct GNUNET_DHT_Handle * dht_handle
Handle to the DHT.
static struct GNUNET_DHT_GetHandle * get_handle
Handle for the get request.
void GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
Stop async DHT-get.
Definition: dht_api.c:1160
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:923
static struct GNUNET_SCHEDULER_Task * tt
Task scheduled to handle timeout.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ timeout_task()

static void timeout_task ( void *  cls)
static

Task run on timeout.

Triggers shutdown.

Parameters
clsunused

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

References GNUNET_SCHEDULER_shutdown().

Referenced by run().

124 {
125  tt = NULL;
127 }
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
static struct GNUNET_SCHEDULER_Task * tt
Task scheduled to handle timeout.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_result_iterator()

static void get_result_iterator ( void *  cls,
struct GNUNET_TIME_Absolute  exp,
const struct GNUNET_HashCode key,
const struct GNUNET_PeerIdentity get_path,
unsigned int  get_path_length,
const struct GNUNET_PeerIdentity put_path,
unsigned int  put_path_length,
enum GNUNET_BLOCK_Type  type,
size_t  size,
const void *  data 
)
static

Iterator called on each result obtained for a DHT operation that expects a reply.

Parameters
clsclosure
expwhen will this value expire
keykey of the result
get_pathpeers on reply path (or NULL if not recorded)
get_path_lengthnumber of entries in get_path
put_pathpeers on the PUT path (or NULL if not recorded)
put_path_lengthnumber of entries in get_path
typetype of the result
sizenumber of bytes in data
datapointer to the result data

Definition at line 146 of file gnunet-dht-get.c.

References _, FPRINTF, GNUNET_BLOCK_TYPE_TEST, GNUNET_i2s(), result_count, and verbose.

Referenced by run().

155 {
156  FPRINTF (stdout,
158  ? _("Result %d, type %d:\n%.*s\n")
159  : _("Result %d, type %d:\n"),
160  result_count,
161  type,
162  (unsigned int) size,
163  (char *) data);
164  if (verbose)
165  {
166  FPRINTF (stdout,
167  " GET path: ");
168  for (unsigned int i=0;i<get_path_length;i++)
169  FPRINTF (stdout,
170  "%s%s",
171  (0 == i) ? "" : "-",
172  GNUNET_i2s (&get_path[i]));
173  FPRINTF (stdout,
174  "\n PUT path: ");
175  for (unsigned int i=0;i<put_path_length;i++)
176  FPRINTF (stdout,
177  "%s%s",
178  (0 == i) ? "" : "-",
179  GNUNET_i2s (&put_path[i]));
180  FPRINTF (stdout,
181  "\n");
182  }
183  result_count++;
184 }
#define FPRINTF
Definition: plibc.h:683
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static unsigned int result_count
Count of results found.
static unsigned int verbose
Be verbose.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Block for testing.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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 196 of file gnunet-dht-get.c.

References _, cleanup_task(), demultixplex_everywhere, FPRINTF, get_result_iterator(), GNUNET_BLOCK_TYPE_ANY, GNUNET_BLOCK_TYPE_TEST, GNUNET_CRYPTO_hash(), GNUNET_DHT_connect(), GNUNET_DHT_get_start(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_DHT_RO_NONE, GNUNET_h2s_full(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_shutdown(), query_key, query_type, replication, ret, timeout_task(), and verbose.

Referenced by main().

198 {
199  struct GNUNET_HashCode key;
200 
201  cfg = c;
202  if (NULL == query_key)
203  {
204  FPRINTF (stderr, "%s", _("Must provide key for DHT GET!\n"));
205  ret = 1;
206  return;
207  }
208  if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1)))
209  {
210  FPRINTF (stderr, "%s", _("Failed to connect to DHT service!\n"));
211  ret = 1;
212  return;
213  }
214  if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */
217  if (verbose)
218  FPRINTF (stderr, "%s `%s' \n",
219  _("Issuing DHT GET with key"),
220  GNUNET_h2s_full (&key));
223  &timeout_task,
224  NULL);
225  get_handle =
228  NULL, 0,
230  NULL);
231 }
static void timeout_task(void *cls)
Task run on timeout.
Any type of block, used as a wildcard when searching.
#define FPRINTF
Definition: plibc.h:683
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
static struct GNUNET_TIME_Relative timeout_request
User supplied timeout value.
static unsigned int query_type
The type of the query.
static char * query_key
The key for the query.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct GNUNET_DHT_Handle * dht_handle
Handle to the DHT.
static struct GNUNET_DHT_GetHandle * get_handle
Handle for the get request.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
static int demultixplex_everywhere
Use DHT demultixplex_everywhere.
A 512-bit hashcode.
static unsigned int replication
Desired replication level.
static void cleanup_task(void *cls)
Task run to clean up on shutdown.
static void get_result_iterator(void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data)
Iterator called on each result obtained for a DHT operation that expects a reply. ...
static unsigned int verbose
Be verbose.
struct GNUNET_HashCode key
The key used in the DHT.
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:895
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
Block for testing.
static int ret
Global status value.
struct GNUNET_DHT_GetHandle * GNUNET_DHT_get_start(struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, const void *xquery, size_t xquery_size, GNUNET_DHT_GetIterator iter, void *iter_cls)
Perform an asynchronous GET operation on the DHT identified.
Definition: dht_api.c:1072
static struct GNUNET_SCHEDULER_Task * tt
Task scheduled to handle timeout.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Global handle of the configuration.
Each peer along the way should look at &#39;enc&#39; (otherwise only the k-peers closest to the key should lo...
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-get.

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

Definition at line 242 of file gnunet-dht-get.c.

References demultixplex_everywhere, 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(), query_key, query_type, replication, ret, run(), and verbose.

243 {
246  "key",
247  "KEY",
248  gettext_noop ("the query key"),
249  &query_key),
251  "replication",
252  "LEVEL",
253  gettext_noop ("how many parallel requests (replicas) to create"),
254  &replication),
256  "type",
257  "TYPE",
258  gettext_noop ("the type of data to look for"),
259  &query_type),
261  "timeout",
262  "TIMEOUT",
263  gettext_noop ("how long to execute this query before giving up?"),
264  &timeout_request),
266  "demultiplex",
267  gettext_noop ("use DHT's demultiplex everywhere option"),
271  };
272 
273 
274 
275  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
276  return 2;
277  return (GNUNET_OK ==
278  GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-get",
280  ("Issue a GET request to the GNUnet DHT, prints results."),
281  options, &run, NULL)) ? ret : 1;
282 }
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 options[]
Definition: 002.c:5
static struct GNUNET_TIME_Relative timeout_request
User supplied timeout value.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the &#39;-V&#39; 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:1521
static unsigned int query_type
The type of the query.
static char * query_key
The key for the query.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Definition of a command line option.
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 int demultixplex_everywhere
Use DHT demultixplex_everywhere.
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 unsigned int replication
Desired replication level.
static unsigned int verbose
Be verbose.
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:361
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.
#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 33 of file gnunet-dht-get.c.

Referenced by main(), and run().

◆ replication

unsigned int replication = 5
static

Desired replication level.

Definition at line 38 of file gnunet-dht-get.c.

Referenced by main(), and run().

◆ query_key

char* query_key
static

The key for the query.

Definition at line 43 of file gnunet-dht-get.c.

Referenced by main(), resolve_interface_name(), and run().

◆ timeout_request

struct GNUNET_TIME_Relative timeout_request = { 60000 }
static

User supplied timeout value.

Definition at line 48 of file gnunet-dht-get.c.

◆ verbose

unsigned int verbose
static

Be verbose.

Definition at line 53 of file gnunet-dht-get.c.

Referenced by get_result_iterator(), main(), and run().

◆ demultixplex_everywhere

int demultixplex_everywhere
static

Use DHT demultixplex_everywhere.

Definition at line 58 of file gnunet-dht-get.c.

Referenced by main(), and run().

◆ dht_handle

struct GNUNET_DHT_Handle* dht_handle
static

Handle to the DHT.

Definition at line 63 of file gnunet-dht-get.c.

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Global handle of the configuration.

Definition at line 68 of file gnunet-dht-get.c.

◆ get_handle

struct GNUNET_DHT_GetHandle* get_handle
static

Handle for the get request.

Definition at line 73 of file gnunet-dht-get.c.

Referenced by get_result_iterator(), and process_client_result().

◆ result_count

unsigned int result_count
static

Count of results found.

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

Referenced by get_result_iterator().

◆ ret

int ret
static

Global status value.

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

Referenced by main(), and run().

◆ tt

struct GNUNET_SCHEDULER_Task* tt
static

Task scheduled to handle timeout.

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