GNUnet  0.17.6
gnunet-dht-hello.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2022 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
25 #include "platform.h"
26 #include "gnunet_dht_service.h"
27 
28 #define LOG(kind, ...) GNUNET_log_from (kind, "dht-clients", __VA_ARGS__)
29 
34 
39 
43 static int global_ret;
44 
45 
51 static void
52 cleanup_task (void *cls)
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 }
65 
66 
72 static void
73 hello_done_cb (void *cls)
74 {
76 }
77 
78 
85 static void
86 hello_result_cb (void *cls,
87  const char *url)
88 {
89  get_hello_handle = NULL;
90  fprintf (stdout,
91  "%s\n",
92  url);
94 }
95 
96 
105 static void
106 run (void *cls,
107  char *const *args,
108  const char *cfgfile,
109  const struct GNUNET_CONFIGURATION_Handle *cfg)
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 }
139 
140 
148 int
149 main (int argc,
150  char *const *argv)
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 }
176 
177 
178 /* end of gnunet-dht-hello.c */
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 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 struct GNUNET_DHT_Handle * dht_handle
Handle to the DHT.
static void hello_done_cb(void *cls)
Task run when we are finished.
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.
static struct GNUNET_DHT_HelloGetHandle * get_hello_handle
Handle to the DHT hello get operation.
int main(int argc, char *const *argv)
Entry point for gnunet-dht-hello.
static void hello_result_cb(void *cls, const char *url)
Function called on our HELLO.
API to the DHT service.
void GNUNET_DHT_hello_get_cancel(struct GNUNET_DHT_HelloGetHandle *hgh)
Cancel hello get operation.
Definition: dht_api.c:1468
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:1039
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:1444
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:1062
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:1480
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:96
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_NO
Definition: gnunet_common.h:98
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
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
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:533
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:1316
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
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
#define EXIT_NOTCONFIGURED
Definition: platform.h:268
Connection to the DHT service.
Definition: dht_api.c:237
Handle to get a HELLO URL from the DHT for manual bootstrapping.
Definition: dht_api.c:203
Definition of a command line option.