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

Obtain HELLO from DHT for bootstrapping. More...

#include "platform.h"
#include "gnunet_dht_service.h"
Include dependency graph for gnunet-dht-hello.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 hello_done_cb (void *cls)
 Task run when we are finished. More...
 
static void hello_result_cb (void *cls, const char *url)
 Function called on our HELLO. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run by the scheduler. More...
 
int main (int argc, char *const *argv)
 Entry point for gnunet-dht-hello. More...
 

Variables

static struct GNUNET_DHT_Handledht_handle
 Handle to the DHT. More...
 
static struct GNUNET_DHT_HelloGetHandleget_hello_handle
 Handle to the DHT hello get operation. More...
 
static int global_ret
 Global status value. More...
 

Detailed Description

Obtain HELLO from DHT for bootstrapping.

Author
Christian Grothoff

Definition in file gnunet-dht-hello.c.

Macro Definition Documentation

◆ LOG

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

Definition at line 28 of file gnunet-dht-hello.c.

Function Documentation

◆ cleanup_task()

static void cleanup_task ( void *  cls)
static

Task run to clean up on shutdown.

Parameters
clsunused

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

53 {
54  if (NULL != get_hello_handle)
55  {
57  get_hello_handle = NULL;
58  }
59  if (NULL != dht_handle)
60  {
62  dht_handle = NULL;
63  }
64 }
static struct GNUNET_DHT_Handle * dht_handle
Handle to the DHT.
static struct GNUNET_DHT_HelloGetHandle * get_hello_handle
Handle to the DHT hello get operation.
void GNUNET_DHT_hello_get_cancel(struct GNUNET_DHT_HelloGetHandle *hgh)
Cancel hello get operation.
Definition: dht_api.c:1401
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:1012

References dht_handle, get_hello_handle, GNUNET_DHT_disconnect(), and GNUNET_DHT_hello_get_cancel().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hello_done_cb()

static void hello_done_cb ( void *  cls)
static

Task run when we are finished.

Triggers shutdown.

Parameters
clsunused

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

74 {
76 }
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531

References GNUNET_SCHEDULER_shutdown().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hello_result_cb()

static void hello_result_cb ( void *  cls,
const char *  url 
)
static

Function called on our HELLO.

Parameters
clsclosure
urlthe HELLO URL

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

88 {
89  get_hello_handle = NULL;
90  fprintf (stdout,
91  "%s\n",
92  url);
94 }

References get_hello_handle, and GNUNET_SCHEDULER_shutdown().

Referenced by run().

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 cfg 
)
static

Main function that will be run by the scheduler.

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

Definition at line 106 of file gnunet-dht-hello.c.

110 {
111  (void) cls;
112  (void) cfgfile;
114  NULL);
115  if (NULL == (dht_handle = GNUNET_DHT_connect (cfg,
116  1)))
117  {
118  fprintf (stderr,
119  _ ("Failed to connect to DHT service!\n"));
122  return;
123  }
124  if (NULL == args[0])
125  {
128  NULL);
129  GNUNET_break (NULL != get_hello_handle);
130  }
131  else
132  {
134  args[0],
135  &hello_done_cb,
136  NULL);
137  }
138 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static int global_ret
Global status value.
static void cleanup_task(void *cls)
Task run to clean up on shutdown.
static void hello_done_cb(void *cls)
Task run when we are finished.
static void hello_result_cb(void *cls, const char *url)
Function called on our HELLO.
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:989
struct GNUNET_DHT_HelloGetHandle * GNUNET_DHT_hello_get(struct GNUNET_DHT_Handle *dht_handle, GNUNET_DHT_HelloGetCallback cb, void *cb_cls)
Obtain HELLO URL of the DHT identified by dht_handle.
Definition: dht_api.c:1377
void GNUNET_DHT_hello_offer(struct GNUNET_DHT_Handle *dht_handle, const char *url, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Offer HELLO URL of the DHT identified by dht_handle.
Definition: dht_api.c:1413
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
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,...
Definition: scheduler.c:1331
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
#define EXIT_NOTCONFIGURED
Definition: platform.h:268

References _, consensus-simulation::args, cfg, cleanup_task(), dht_handle, EXIT_NOTCONFIGURED, get_hello_handle, global_ret, GNUNET_break, GNUNET_DHT_connect(), GNUNET_DHT_hello_get(), GNUNET_DHT_hello_offer(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), hello_done_cb(), and hello_result_cb().

Referenced by main().

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-hello.

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

Definition at line 149 of file gnunet-dht-hello.c.

151 {
154  };
155  enum GNUNET_GenericReturnValue iret;
156 
157  if (GNUNET_OK !=
158  GNUNET_STRINGS_get_utf8_args (argc, argv,
159  &argc, &argv))
160  return 2;
161  iret = GNUNET_PROGRAM_run (
162  argc,
163  argv,
164  "gnunet-dht-hello [URL]",
165  gettext_noop (
166  "Obtain HELLO from DHT or provide HELLO to DHT for bootstrapping"),
167  options,
168  &run,
169  NULL);
170  if (GNUNET_SYSERR == iret)
171  return EXIT_FAILURE;
172  if (GNUNET_NO == iret)
173  return EXIT_SUCCESS;
174  return global_ret;
175 }
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:69
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
enum GNUNET_GenericReturnValue 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,...
Definition: program.c:399
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1223
Definition of a command line option.

References gettext_noop, global_ret, GNUNET_GETOPT_OPTION_END, GNUNET_NO, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), GNUNET_SYSERR, options, and run().

Here is the call graph for this function:

Variable Documentation

◆ dht_handle

struct GNUNET_DHT_Handle* dht_handle
static

Handle to the DHT.

Definition at line 33 of file gnunet-dht-hello.c.

Referenced by cleanup_task(), and run().

◆ get_hello_handle

struct GNUNET_DHT_HelloGetHandle* get_hello_handle
static

Handle to the DHT hello get operation.

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

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

◆ global_ret

int global_ret
static

Global status value.

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

Referenced by main(), and run().