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

search for data in DHT More...

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

Go to the source code of this file.

Functions

static void cleanup_task (void *cls)
 Stop monitoring request and start shutdown. More...
 
static void timeout_task (void *cls)
 We hit a timeout. More...
 
static void get_callback (void *cls, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, uint32_t hop_count, uint32_t desired_replication_level, unsigned int path_length, const struct GNUNET_PeerIdentity *path, const struct GNUNET_HashCode *key)
 Callback called on each GET request going through the DHT. More...
 
static void get_resp_callback (void *cls, enum GNUNET_BLOCK_Type type, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const void *data, size_t size)
 Callback called on each GET reply going through the DHT. More...
 
static void put_callback (void *cls, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, uint32_t hop_count, uint32_t desired_replication_level, unsigned int path_length, const struct GNUNET_PeerIdentity *path, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const void *data, size_t size)
 Callback called on each PUT request going through the DHT. 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-monitor. More...
 

Variables

static unsigned int block_type
 The type of the query. More...
 
static char * query_key
 The key to be monitored. More...
 
static struct GNUNET_TIME_Relative timeout_request = { 60000 }
 User supplied timeout value (in seconds) More...
 
static int verbose
 Be verbose. 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_MonitorHandlemonitor_handle
 Handle for the get request. More...
 
static unsigned int result_count
 Count of messages received. 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
Bartlomiej Polot

Definition in file gnunet-dht-monitor.c.

Function Documentation

◆ cleanup_task()

static void cleanup_task ( void *  cls)
static

Stop monitoring request and start shutdown.

Parameters
clsclosure (unused)

Definition at line 86 of file gnunet-dht-monitor.c.

References GNUNET_DHT_disconnect(), GNUNET_DHT_monitor_stop(), GNUNET_SCHEDULER_cancel(), and verbose.

Referenced by run().

87 {
88  if (verbose)
89  fprintf(stderr, "%s", "Cleaning up!\n");
90  if (NULL != monitor_handle)
91  {
93  monitor_handle = NULL;
94  }
95  if (NULL != dht_handle)
96  {
98  dht_handle = NULL;
99  }
100  if (NULL != tt)
101  {
103  tt = NULL;
104  }
105 }
static int verbose
Be verbose.
static struct GNUNET_SCHEDULER_Task * tt
Task scheduled to handle timeout.
void GNUNET_DHT_monitor_stop(struct GNUNET_DHT_MonitorHandle *mh)
Stop monitoring.
Definition: dht_api.c:1234
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:913
static struct GNUNET_DHT_MonitorHandle * monitor_handle
Handle for the get request.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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

We hit a timeout.

Stop monitoring request and start shutdown

Parameters
clsclosure (unused)

Definition at line 114 of file gnunet-dht-monitor.c.

References GNUNET_SCHEDULER_shutdown().

Referenced by run().

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

◆ get_callback()

static void get_callback ( void *  cls,
enum GNUNET_DHT_RouteOption  options,
enum GNUNET_BLOCK_Type  type,
uint32_t  hop_count,
uint32_t  desired_replication_level,
unsigned int  path_length,
const struct GNUNET_PeerIdentity path,
const struct GNUNET_HashCode key 
)
static

Callback called on each GET request going through the DHT.

Parameters
clsClosure.
optionsOptions, for instance RecordRoute, DemultiplexEverywhere.
typeThe type of data in the request.
hop_countHop count so far.
path_lengthnumber of entries in path (or 0 if not recorded).
pathpeers on the GET path (or NULL if not recorded).
desired_replication_levelDesired replication level.
keyKey of the requested data.

Definition at line 134 of file gnunet-dht-monitor.c.

References GNUNET_h2s_full(), and result_count.

Referenced by run().

142 {
143  fprintf(stdout,
144  "GET #%u: type %d, key `%s'\n",
145  result_count,
146  (int)type,
147  GNUNET_h2s_full(key));
148  result_count++;
149 }
static unsigned int result_count
Count of messages received.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_resp_callback()

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

Callback called on each GET reply going through the DHT.

Parameters
clsClosure.
typeThe type of data in the result.
get_pathPeers on GET 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.
expExpiration time of the data.
keyKey of the data.
dataPointer to the result data.
sizeNumber of bytes in data.

Definition at line 167 of file gnunet-dht-monitor.c.

References GNUNET_BLOCK_TYPE_TEST, GNUNET_h2s_full(), GNUNET_STRINGS_absolute_time_to_string(), and result_count.

Referenced by run().

177 {
178  fprintf(stdout,
180  ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n"
181  : "RESPONSE #%u (%s): type %d, key `%s'\n",
182  result_count,
184  (int)type,
185  GNUNET_h2s_full(key),
186  (unsigned int)size,
187  (char *)data);
188  result_count++;
189 }
static unsigned int result_count
Count of messages received.
static unsigned int size
Size of the "table".
Definition: peer.c:66
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
Block for testing.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:741
uint32_t data
The data value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ put_callback()

static void put_callback ( void *  cls,
enum GNUNET_DHT_RouteOption  options,
enum GNUNET_BLOCK_Type  type,
uint32_t  hop_count,
uint32_t  desired_replication_level,
unsigned int  path_length,
const struct GNUNET_PeerIdentity path,
struct GNUNET_TIME_Absolute  exp,
const struct GNUNET_HashCode key,
const void *  data,
size_t  size 
)
static

Callback called on each PUT request going through the DHT.

Parameters
clsClosure.
optionsOptions, for instance RecordRoute, DemultiplexEverywhere.
typeThe type of data in the request.
hop_countHop count so far.
path_lengthnumber of entries in path (or 0 if not recorded).
pathpeers on the PUT path (or NULL if not recorded).
desired_replication_levelDesired replication level.
expExpiration time of the data.
keyKey under which data is to be stored.
dataPointer to the data carried.
sizeNumber of bytes in data.

Definition at line 208 of file gnunet-dht-monitor.c.

References GNUNET_BLOCK_TYPE_TEST, GNUNET_h2s_full(), GNUNET_STRINGS_absolute_time_to_string(), and result_count.

Referenced by run().

219 {
220  fprintf(stdout,
222  ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n"
223  : "PUT %u (%s): type %d, key `%s'\n",
224  result_count,
226  (int)type,
227  GNUNET_h2s_full(key),
228  (unsigned int)size,
229  (char *)data);
230  result_count++;
231 }
static unsigned int result_count
Count of messages received.
static unsigned int size
Size of the "table".
Definition: peer.c:66
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
Block for testing.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:741
uint32_t data
The data value.
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 243 of file gnunet-dht-monitor.c.

References _, block_type, cleanup_task(), get_callback(), get_resp_callback(), GNUNET_BLOCK_TYPE_ANY, GNUNET_BLOCK_TYPE_TEST, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_from_string, GNUNET_DHT_connect(), GNUNET_DHT_monitor_start(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_STRINGS_relative_time_to_string(), key, put_callback(), query_key, ret, timeout_task(), and verbose.

Referenced by main().

247 {
248  struct GNUNET_HashCode *key;
249  struct GNUNET_HashCode hc;
250 
251  cfg = c;
252 
253  if (NULL == (dht_handle = GNUNET_DHT_connect(cfg, 1)))
254  {
255  fprintf(stderr, "%s", _("Failed to connect to DHT service!\n"));
256  ret = 1;
257  return;
258  }
259  if (GNUNET_BLOCK_TYPE_ANY == block_type) /* Type of data not set */
261  if (NULL != query_key)
262  {
263  key = &hc;
265  GNUNET_CRYPTO_hash(query_key, strlen(query_key), key);
266  }
267  else
268  {
269  key = NULL;
270  }
271  if (verbose)
272  fprintf(stderr,
273  "Monitoring for %s\n",
275  GNUNET_NO));
279  block_type,
280  key,
281  &get_callback,
283  &put_callback,
284  NULL);
285 }
static int verbose
Be verbose.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Global handle of the configuration.
Any type of block, used as a wildcard when searching.
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:1284
static void timeout_task(void *cls)
We hit a timeout.
static struct GNUNET_SCHEDULER_Task * tt
Task scheduled to handle timeout.
static struct GNUNET_DHT_Handle * dht_handle
Handle to the DHT.
static void put_callback(void *cls, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, uint32_t hop_count, uint32_t desired_replication_level, unsigned int path_length, const struct GNUNET_PeerIdentity *path, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const void *data, size_t size)
Callback called on each PUT request going through the DHT.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static struct GNUNET_TIME_Relative timeout_request
User supplied timeout value (in seconds)
static char * query_key
The key to be monitored.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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:1237
struct GNUNET_DHT_MonitorHandle * GNUNET_DHT_monitor_start(struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *key, GNUNET_DHT_MonitorGetCB get_cb, GNUNET_DHT_MonitorGetRespCB get_resp_cb, GNUNET_DHT_MonitorPutCB put_cb, void *cb_cls)
Start monitoring the local DHT service.
Definition: dht_api.c:1195
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
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:686
A 512-bit hashcode.
static void get_resp_callback(void *cls, enum GNUNET_BLOCK_Type type, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const void *data, size_t size)
Callback called on each GET reply going through the DHT.
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:885
static int ret
Global status value.
static struct GNUNET_DHT_MonitorHandle * monitor_handle
Handle for the get request.
Block for testing.
static void cleanup_task(void *cls)
Stop monitoring request and start shutdown.
static unsigned int block_type
The type of the query.
#define GNUNET_CRYPTO_hash_from_string(enc, result)
Convert ASCII encoding back to struct GNUNET_HashCode
static void get_callback(void *cls, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, uint32_t hop_count, uint32_t desired_replication_level, unsigned int path_length, const struct GNUNET_PeerIdentity *path, const struct GNUNET_HashCode *key)
Callback called on each GET request going through 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-monitor.

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

Definition at line 295 of file gnunet-dht-monitor.c.

References block_type, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_relative_time(), GNUNET_GETOPT_option_string(), GNUNET_GETOPT_option_uint(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), query_key, ret, run(), and verbose.

296 {
299  "key",
300  "KEY",
301  gettext_noop("the query key"),
302  &query_key),
303 
305  "type",
306  "TYPE",
307  gettext_noop("the type of data to look for"),
308  &block_type),
309 
311  'T',
312  "timeout",
313  "TIMEOUT",
314  gettext_noop("how long should the monitor command run"),
315  &timeout_request),
316 
318  "verbose",
319  gettext_noop(
320  "be verbose (print progress information)"),
321  &verbose),
322 
324  };
325 
326 
327  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
328  return 2;
329 
330  return (GNUNET_OK ==
331  GNUNET_PROGRAM_run(argc,
332  argv,
333  "gnunet-dht-monitor",
334  gettext_noop(
335  "Prints all packets that go through the DHT."),
336  options,
337  &run,
338  NULL))
339  ? ret
340  : 1;
341 }
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)...
static int verbose
Be verbose.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1439
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static struct GNUNET_TIME_Relative timeout_request
User supplied timeout value (in seconds)
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 char * query_key
The key to be monitored.
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 unsigned int block_type
The type of the query.
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

◆ block_type

unsigned int block_type
static

The type of the query.

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

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

◆ query_key

char* query_key
static

The key to be monitored.

Definition at line 37 of file gnunet-dht-monitor.c.

Referenced by main(), and run().

◆ timeout_request

struct GNUNET_TIME_Relative timeout_request = { 60000 }
static

User supplied timeout value (in seconds)

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

◆ verbose

int verbose
static

Be verbose.

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

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

◆ dht_handle

struct GNUNET_DHT_Handle* dht_handle
static

Handle to the DHT.

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

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Global handle of the configuration.

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

◆ monitor_handle

struct GNUNET_DHT_MonitorHandle* monitor_handle
static

Handle for the get request.

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

◆ result_count

unsigned int result_count
static

Count of messages received.

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

Referenced by get_callback(), get_resp_callback(), and put_callback().

◆ ret

int ret
static

Global status value.

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

Referenced by main(), and run().

◆ tt

struct GNUNET_SCHEDULER_Task* tt
static

Task scheduled to handle timeout.

Definition at line 77 of file gnunet-dht-monitor.c.