GNUnet 0.22.2
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
43static int global_ret;
44
45
51static void
52cleanup_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
72static void
73hello_done_cb (void *cls)
74{
76}
77
78
85static void
86hello_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
105static void
106run (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);
130 }
131 else
132 {
134 args[0],
136 NULL);
137 }
138}
139
140
148int
149main (int argc,
150 char *const *argv)
151{
154 };
156
157 iret = GNUNET_PROGRAM_run (
158 argc,
159 argv,
160 "gnunet-dht-hello [URL]",
162 "Obtain HELLO from DHT or provide HELLO to DHT for bootstrapping"),
163 options,
164 &run,
165 NULL);
166 if (GNUNET_SYSERR == iret)
167 return EXIT_FAILURE;
168 if (GNUNET_NO == iret)
169 return EXIT_SUCCESS;
170 return global_ret;
171}
172
173
174/* 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:74
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 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.
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
void GNUNET_DHT_hello_get_cancel(struct GNUNET_DHT_HelloGetHandle *hgh)
Cancel hello get operation.
Definition: dht_api.c:1464
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_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:1053
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
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_NO
@ GNUNET_SYSERR
#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:400
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:566
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:1338
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define EXIT_NOTCONFIGURED
Definition: platform.h:269
Connection to the DHT service.
Definition: dht_api.c:235
Handle to get a HELLO URL from the DHT for manual bootstrapping.
Definition: dht_api.c:201
Definition of a command line option.