GNUnet debian-0.24.3-28-g4f2a77692
 
Loading...
Searching...
No Matches
gnunet-daemon-hostlist.c File Reference

code for bootstrapping via hostlist servers More...

Include dependency graph for gnunet-daemon-hostlist.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_HOSTLIST_ADV_Message
 A HOSTLIST_ADV message is used to exchange information about hostlist advertisements. More...
 

Functions

static void core_init (void *cls, const struct GNUNET_PeerIdentity *my_identity)
 Callback invoked once our connection to CORE service is up.
 
static int check_advertisement (void *cls, const struct GNUNET_MessageHeader *message)
 Core handler for p2p hostlist advertisements.
 
static void handle_advertisement (void *cls, const struct GNUNET_MessageHeader *message)
 Core handler for p2p hostlist advertisements.
 
static void * connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq, enum GNUNET_CORE_PeerClass class)
 Method called whenever a given peer connects.
 
static void disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
 Method called whenever a given peer disconnects.
 
static void cleaning_task (void *cls)
 Last task run during shutdown.
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run.
 
int main (int argc, char *const *argv)
 The main function for the hostlist daemon.
 

Variables

static int advertising
 Set if we are allowed to advertise our hostlist to others.
 
static int provide_hostlist
 Set if the user wants us to run a hostlist server.
 
static GNUNET_CORE_ConnectEventHandler server_ch
 Handle to hostlist server's connect handler.
 
static int bootstrapping
 Set if we are allowed to learn about peers by accessing hostlist servers.
 
static int learning
 Set if the user allows us to learn about new hostlists from the network.
 
static struct GNUNET_STATISTICS_Handlestats
 Statistics handle.
 
static struct GNUNET_CORE_Handlecore
 Handle to the core service (NULL until we've connected to it).
 
static GNUNET_HOSTLIST_UriHandler client_adv_handler
 Handle to the hostlist client's advertisement handler.
 
static GNUNET_CORE_ConnectEventHandler client_ch
 Handle to hostlist client's connect handler.
 
static GNUNET_CORE_DisconnectEventHandler client_dh
 Handle to hostlist client's disconnect handler.
 
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
 Our own peer identity.
 

Detailed Description

code for bootstrapping via hostlist servers

Author
Christian Grothoff

Definition in file gnunet-daemon-hostlist.c.

Function Documentation

◆ core_init()

static void core_init ( void *  cls,
const struct GNUNET_PeerIdentity my_identity 
)
static

Callback invoked once our connection to CORE service is up.

Parameters
clsNULL
my_identityour peer's identity

Definition at line 129 of file gnunet-daemon-hostlist.c.

131{
132 me = *my_identity;
133}
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.

References me, and my_identity.

Referenced by run().

Here is the caller graph for this function:

◆ check_advertisement()

static int check_advertisement ( void *  cls,
const struct GNUNET_MessageHeader message 
)
static

Core handler for p2p hostlist advertisements.

Parameters
clsclosure
messageadvertisement message we got
Returns
GNUNET_OK if message is well-formed

Definition at line 144 of file gnunet-daemon-hostlist.c.

146{
147 size_t size;
148 size_t uri_size;
149 const char *uri;
150
151 size = ntohs (message->size);
152 if (size <= sizeof(struct GNUNET_MessageHeader))
153 {
154 GNUNET_break_op (0);
155 return GNUNET_SYSERR;
156 }
157 uri = (const char *) &message[1];
158 uri_size = size - sizeof(struct GNUNET_MessageHeader);
159 if (uri[uri_size - 1] != '\0')
160 {
161 GNUNET_break_op (0);
162 return GNUNET_SYSERR;
163 }
164 return GNUNET_OK;
165}
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static unsigned int size
Size of the "table".
Definition peer.c:68
Header for all communications.

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, GNUNET_MessageHeader::size, size, and uri.

◆ handle_advertisement()

static void handle_advertisement ( void *  cls,
const struct GNUNET_MessageHeader message 
)
static

Core handler for p2p hostlist advertisements.

Parameters
clsclosure
messageadvertisement message we got
Returns
GNUNET_OK on success

Definition at line 176 of file gnunet-daemon-hostlist.c.

178{
179 const char *uri = (const char *) &message[1];
180
182 (void) (*client_adv_handler)(uri);
183}
static GNUNET_HOSTLIST_UriHandler client_adv_handler
Handle to the hostlist client's advertisement handler.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References client_adv_handler, GNUNET_assert, and uri.

◆ connect_handler()

static void * connect_handler ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq,
enum GNUNET_CORE_PeerClass  class 
)
static

Method called whenever a given peer connects.

Wrapper to call both client's and server's functions

Parameters
clsclosure
peerpeer identity this notification is about
mqqueue for sending messages to peer
classclass of the connecting peer
Returns
peer

Definition at line 197 of file gnunet-daemon-hostlist.c.

201{
202 if (0 == GNUNET_memcmp (&me,
203 peer))
204 return NULL;
206 "A new peer connected, notifying client and server\n");
207 if (NULL != client_ch)
208 GNUNET_assert (NULL ==
209 (*client_ch)(cls,
210 peer,
211 mq,
212 class));
213 if (NULL != server_ch)
214 GNUNET_assert (NULL ==
215 (*server_ch)(cls,
216 peer,
217 mq,
218 class));
219 return (void *) peer;
220}
static GNUNET_CORE_ConnectEventHandler server_ch
Handle to hostlist server's connect handler.
static GNUNET_CORE_ConnectEventHandler client_ch
Handle to hostlist client's connect handler.
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
@ GNUNET_ERROR_TYPE_DEBUG
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.

References client_ch, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcmp, me, mq, and server_ch.

Referenced by run().

Here is the caller graph for this function:

◆ disconnect_handler()

static void disconnect_handler ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  internal_cls 
)
static

Method called whenever a given peer disconnects.

Wrapper to call both client's and server's functions

Parameters
clsclosure
peerpeer identity this notification is about

Definition at line 231 of file gnunet-daemon-hostlist.c.

234{
235 if (0 == GNUNET_memcmp (&me,
236 peer))
237 return;
238 /* call hostlist client disconnect handler */
239 if (NULL != client_dh)
240 (*client_dh)(cls,
241 peer,
242 NULL);
243}
static GNUNET_CORE_DisconnectEventHandler client_dh
Handle to hostlist client's disconnect handler.

References client_dh, GNUNET_memcmp, and me.

Referenced by run().

Here is the caller graph for this function:

◆ cleaning_task()

static void cleaning_task ( void *  cls)
static

Last task run during shutdown.

Disconnects us from the other services.

Parameters
clsNULL

Definition at line 253 of file gnunet-daemon-hostlist.c.

254{
256 "Hostlist daemon is shutting down\n");
257 if (NULL != core)
258 {
260 core = NULL;
261 }
262 if (bootstrapping)
263 {
265 }
267 {
269 }
270 if (NULL != stats)
271 {
273 GNUNET_NO);
274 stats = NULL;
275 }
276}
static struct GNUNET_CORE_Handle * core
Handle to the core service (NULL until we've connected to it).
static struct GNUNET_STATISTICS_Handle * stats
Statistics handle.
static int bootstrapping
Set if we are allowed to learn about peers by accessing hostlist servers.
static int provide_hostlist
Set if the user wants us to run a hostlist server.
void GNUNET_HOSTLIST_client_stop()
Stop downloading hostlists from hostlist servers as necessary.
void GNUNET_HOSTLIST_server_stop()
Stop server offering our hostlist.
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition core_api.c:744
@ GNUNET_NO
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).

References bootstrapping, core, GNUNET_CORE_disconnect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_HOSTLIST_client_stop(), GNUNET_HOSTLIST_server_stop(), GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_destroy(), provide_hostlist, and stats.

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.

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

Definition at line 288 of file gnunet-daemon-hostlist.c.

292{
293 struct GNUNET_MQ_MessageHandler learn_handlers[] = {
294 GNUNET_MQ_hd_var_size (advertisement,
297 NULL),
299 };
300 struct GNUNET_MQ_MessageHandler no_learn_handlers[] = {
302 };
303 const struct GNUNET_CORE_ServiceInfo service_info =
304 {
306 .version = { 1, 0 },
307 .version_max = { 1, 0 },
308 .version_min = { 1, 0 },
309 };
310
311 if ((! bootstrapping) && (! learning)
312 && (! provide_hostlist)
313 )
314 {
316 _ (
317 "None of the functions for the hostlist daemon were enabled. I have no reason to run!\n"));
318 return;
319 }
320 stats = GNUNET_STATISTICS_create ("hostlist", cfg);
321 if (NULL == stats)
322 {
323 GNUNET_break (0);
324 return;
325 }
326 if (bootstrapping)
328 stats,
329 &client_ch,
330 &client_dh,
332 learning);
333 core =
335 NULL,
336 &core_init,
339 learning ? learn_handlers : no_learn_handlers,
340 &service_info);
341
342
345 stats,
346 core,
347 &server_ch,
350 NULL);
351
352 if (NULL == core)
353 {
355 _ ("Failed to connect to `%s' service.\n"), "core");
357 return;
358 }
359}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static void * connect_handler(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq, enum GNUNET_CORE_PeerClass class)
Method called whenever a given peer connects.
static void cleaning_task(void *cls)
Last task run during shutdown.
static int advertising
Set if we are allowed to advertise our hostlist to others.
static int learning
Set if the user allows us to learn about new hostlists from the network.
static void disconnect_handler(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a given peer disconnects.
static void core_init(void *cls, const struct GNUNET_PeerIdentity *my_identity)
Callback invoked once our connection to CORE service is up.
int GNUNET_HOSTLIST_client_start(const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_STATISTICS_Handle *st, GNUNET_CORE_ConnectEventHandler *ch, GNUNET_CORE_DisconnectEventHandler *dh, GNUNET_HOSTLIST_UriHandler *msgh, int learn)
Start downloading hostlists from hostlist servers as necessary.
int GNUNET_HOSTLIST_server_start(const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_STATISTICS_Handle *st, struct GNUNET_CORE_Handle *co, GNUNET_CORE_ConnectEventHandler *server_ch, int advertise)
Start server offering our hostlist.
struct GNUNET_CORE_Handle * GNUNET_CORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, GNUNET_CORE_StartupCallback init, GNUNET_CORE_ConnectEventHandler connects, GNUNET_CORE_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers, struct GNUNET_CORE_ServiceInfo *service_info)
Connect to the core service.
Definition core_api.c:698
@ GNUNET_CORE_SERVICE_HOSTLIST
Identifier for hostlist service.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT
Hostlist advertisement message.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:567
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
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
#define _(String)
GNU gettext support macro.
Definition platform.h:179
Gnunet service info - identifying compatibility with a range of version of a service communicating ov...
enum GNUNET_CORE_Service service
Identifier of the service on top of CORE.
Message handler for a specific message type.

References _, advertising, bootstrapping, cfg, cleaning_task(), client_adv_handler, client_ch, client_dh, connect_handler(), core, core_init(), disconnect_handler(), GNUNET_break, GNUNET_CORE_connect(), GNUNET_CORE_SERVICE_HOSTLIST, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_HOSTLIST_client_start(), GNUNET_HOSTLIST_server_start(), GNUNET_log, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), learning, provide_hostlist, server_ch, GNUNET_CORE_ServiceInfo::service, and stats.

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 
)

The main function for the hostlist daemon.

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

Definition at line 370 of file gnunet-daemon-hostlist.c.

371{
374 "advertise",
376 "advertise our hostlist to other peers"),
377 &advertising),
379 "bootstrap",
381 "bootstrap using hostlists (it is highly recommended that you always use this option)"),
384 "enable-learning",
386 "enable learning about hostlist servers from other peers"),
387 &learning),
389 "provide-hostlist",
390 gettext_noop ("provide a hostlist server"),
393 };
394
395 int ret;
396
397 GNUNET_log_setup ("hostlist", "WARNING", NULL);
398 ret =
399 (GNUNET_OK ==
401 argc, argv,
402 "hostlist",
403 _ ("GNUnet hostlist server and client"),
404 options,
405 &run, NULL)) ? 0 : 1;
406 return ret;
407}
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
#define gettext_noop(String)
Definition gettext.h:74
static int ret
Final status code.
Definition gnunet-arm.c:93
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
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.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
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 _, advertising, bootstrapping, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_log_setup(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), learning, options, provide_hostlist, ret, and run().

Here is the call graph for this function:

Variable Documentation

◆ advertising

int advertising
static

Set if we are allowed to advertise our hostlist to others.

Definition at line 38 of file gnunet-daemon-hostlist.c.

Referenced by main(), and run().

◆ provide_hostlist

int provide_hostlist
static

Set if the user wants us to run a hostlist server.

Definition at line 43 of file gnunet-daemon-hostlist.c.

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

◆ server_ch

Handle to hostlist server's connect handler.

Definition at line 48 of file gnunet-daemon-hostlist.c.

Referenced by connect_handler(), GNUNET_HOSTLIST_server_start(), and run().

◆ bootstrapping

int bootstrapping
static

Set if we are allowed to learn about peers by accessing hostlist servers.

Definition at line 54 of file gnunet-daemon-hostlist.c.

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

◆ learning

int learning
static

Set if the user allows us to learn about new hostlists from the network.

Definition at line 60 of file gnunet-daemon-hostlist.c.

Referenced by main(), and run().

◆ stats

struct GNUNET_STATISTICS_Handle* stats
static

Statistics handle.

Definition at line 65 of file gnunet-daemon-hostlist.c.

Referenced by cleaning_task(), and run().

◆ core

struct GNUNET_CORE_Handle* core
static

Handle to the core service (NULL until we've connected to it).

Definition at line 70 of file gnunet-daemon-hostlist.c.

Referenced by cleaning_task(), and run().

◆ client_adv_handler

GNUNET_HOSTLIST_UriHandler client_adv_handler
static

Handle to the hostlist client's advertisement handler.

Definition at line 75 of file gnunet-daemon-hostlist.c.

Referenced by handle_advertisement(), and run().

◆ client_ch

Handle to hostlist client's connect handler.

Definition at line 80 of file gnunet-daemon-hostlist.c.

Referenced by connect_handler(), and run().

◆ client_dh

Handle to hostlist client's disconnect handler.

Definition at line 85 of file gnunet-daemon-hostlist.c.

Referenced by disconnect_handler(), and run().

◆ me

Our own peer identity.

Definition at line 119 of file gnunet-daemon-hostlist.c.

Referenced by connect_handler(), construct_task_graph(), construct_task_graph_gradecast(), core_init(), disconnect_handler(), free_queue(), GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_contains_value(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_CONTAINER_multihashmap_get_random(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CONTAINER_multihashmap_remove_all(), GNUNET_CONTAINER_multipeermap_contains(), GNUNET_CONTAINER_multipeermap_contains_value(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_CONTAINER_multipeermap_get_random(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_remove_all(), GNUNET_CONTAINER_multishortmap_contains(), GNUNET_CONTAINER_multishortmap_contains_value(), GNUNET_CONTAINER_multishortmap_destroy(), GNUNET_CONTAINER_multishortmap_get(), GNUNET_CONTAINER_multishortmap_get_multiple(), GNUNET_CONTAINER_multishortmap_get_random(), GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_CONTAINER_multishortmap_put(), GNUNET_CONTAINER_multishortmap_remove(), GNUNET_CONTAINER_multishortmap_remove_all(), GNUNET_CONTAINER_multiuuidmap_contains(), GNUNET_CONTAINER_multiuuidmap_contains_value(), GNUNET_CONTAINER_multiuuidmap_destroy(), GNUNET_CONTAINER_multiuuidmap_get(), GNUNET_CONTAINER_multiuuidmap_get_multiple(), GNUNET_CONTAINER_multiuuidmap_get_random(), GNUNET_CONTAINER_multiuuidmap_iterate(), GNUNET_CONTAINER_multiuuidmap_put(), GNUNET_CONTAINER_multiuuidmap_remove(), GNUNET_CONTAINER_multiuuidmap_remove_all(), GNUNET_DHT_verify_path(), GNUNET_TRANSPORT_TESTING_log_connect(), GNUNET_TRANSPORT_TESTING_log_disconnect(), handle_add_queue_message(), notify_client_queues(), notify_monitor(), notify_monitors(), task_other_peer(), and update_next_cache().