GNUnet 0.22.2
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:1464
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:1053

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:567

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);
130 }
131 else
132 {
134 args[0],
136 NULL);
137 }
138}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
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:1030
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:1440
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:1476
#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:1339
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define EXIT_NOTCONFIGURED
Definition: platform.h:269

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 };
156
157 iret = GNUNET_PROGRAM_run (
159 argc,
160 argv,
161 "gnunet-dht-hello [URL]",
163 "Obtain HELLO from DHT or provide HELLO to DHT for bootstrapping"),
164 options,
165 &run,
166 NULL);
167 if (GNUNET_SYSERR == iret)
168 return EXIT_FAILURE;
169 if (GNUNET_NO == iret)
170 return EXIT_SUCCESS;
171 return global_ret;
172}
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 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.
@ GNUNET_NO
@ GNUNET_SYSERR
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
Definition of a command line option.

References gettext_noop, global_ret, GNUNET_GETOPT_OPTION_END, GNUNET_NO, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), 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().