GNUnet  0.18.1
Peer Info service

Maintain the list of currently known hosts. More...

Collaboration diagram for Peer Info service:

Typedefs

typedef void(* GNUNET_PEERINFO_Processor) (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
 Type of an iterator over the hosts. More...
 

Functions

struct GNUNET_PEERINFO_HandleGNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Connect to the peerinfo service. More...
 
void GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h)
 Disconnect from the peerinfo service. More...
 
struct GNUNET_MQ_EnvelopeGNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h, const struct GNUNET_HELLO_Message *hello, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
 Add a host to the persistent list. More...
 
struct GNUNET_PEERINFO_IteratorContextGNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, int include_friend_only, const struct GNUNET_PeerIdentity *peer, GNUNET_PEERINFO_Processor callback, void *callback_cls)
 Call a method for each known matching host. More...
 
void GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic)
 Cancel an iteration over peer information. More...
 
struct GNUNET_PEERINFO_NotifyContextGNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg, int include_friend_only, GNUNET_PEERINFO_Processor callback, void *callback_cls)
 Call a method whenever our known information about peers changes. More...
 
void GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc)
 Stop notifying about changes. More...
 

Detailed Description

Maintain the list of currently known hosts.

Holds an in-memory structure of data/hosts.

See also
Documentation

Typedef Documentation

◆ GNUNET_PEERINFO_Processor

typedef void(* GNUNET_PEERINFO_Processor) (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)

Type of an iterator over the hosts.

Note that each host will be called with each available protocol.

Parameters
clsclosure
peerid of the peer, NULL for last call
hellohello message for the peer (can be NULL)
errormessage

Definition at line 120 of file gnunet_peerinfo_service.h.

Function Documentation

◆ GNUNET_PEERINFO_connect()

struct GNUNET_PEERINFO_Handle* GNUNET_PEERINFO_connect ( const struct GNUNET_CONFIGURATION_Handle cfg)

Connect to the peerinfo service.

Parameters
cfgconfiguration to use
Returns
NULL on error (configuration related, actual connection etablishment may happen asynchronously).

Definition at line 123 of file peerinfo_api.c.

124 {
125  struct GNUNET_PEERINFO_Handle *h;
126 
128  h->cfg = cfg;
129  reconnect (h);
130  if (NULL == h->mq)
131  {
132  GNUNET_free (h);
133  return NULL;
134  }
135  return h;
136 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
static void reconnect(struct GNUNET_PEERINFO_Handle *h)
Close the existing connection to PEERINFO and reconnect.
Definition: peerinfo_api.c:429
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
Handle to the peerinfo service.
Definition: peerinfo_api.c:85

References cfg, GNUNET_ARM_Handle::cfg, GNUNET_free, GNUNET_new, h, GNUNET_ARM_Handle::mq, and reconnect().

Referenced by GCH_init(), GNUNET_HOSTLIST_client_start(), GNUNET_HOSTLIST_server_start(), libgnunet_plugin_rest_peerinfo_init(), and run().

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

◆ GNUNET_PEERINFO_disconnect()

void GNUNET_PEERINFO_disconnect ( struct GNUNET_PEERINFO_Handle h)

Disconnect from the peerinfo service.

Note that all iterators must have completed or have been cancelled by the time this function is called (otherwise, calling this function is a serious error). Furthermore, if GNUNET_PEERINFO_add_peer() operations are still pending, they will be cancelled silently on disconnect.

Parameters
hhandle to disconnect

Definition at line 149 of file peerinfo_api.c.

150 {
152 
153  while (NULL != (ic = h->ic_head))
154  {
155  GNUNET_CONTAINER_DLL_remove (h->ic_head,
156  h->ic_tail,
157  ic);
158  GNUNET_free (ic);
159  }
160  if (NULL != h->mq)
161  {
163  h->mq = NULL;
164  }
165  if (NULL != h->r_task)
166  {
167  GNUNET_SCHEDULER_cancel (h->r_task);
168  h->r_task = NULL;
169  }
170  GNUNET_free (h);
171 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:687
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:944
Context for an iteration request.
Definition: peerinfo_api.c:38

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), h, and GNUNET_ARM_Handle::mq.

Referenced by cleaning_task(), cleanup_handle(), GCH_shutdown(), GNUNET_HOSTLIST_client_stop(), GNUNET_HOSTLIST_server_stop(), libgnunet_plugin_rest_peerinfo_done(), and shutdown_task().

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

◆ GNUNET_PEERINFO_add_peer()

struct GNUNET_MQ_Envelope* GNUNET_PEERINFO_add_peer ( struct GNUNET_PEERINFO_Handle h,
const struct GNUNET_HELLO_Message hello,
GNUNET_SCHEDULER_TaskCallback  cont,
void *  cont_cls 
)

Add a host to the persistent list.

This method operates in semi-reliable mode: if the transmission is not completed by the time GNUNET_PEERINFO_disconnect() is called, it will be aborted. Furthermore, if a second HELLO is added for the same peer before the first one was transmitted, PEERINFO may merge the two HELLOs prior to transmission to the service.

Parameters
hhandle to the peerinfo service
hellothe verified (!) HELLO message
contcontinuation to call when done, NULL is allowed
cont_clsclosure for cont
Returns
handle to cancel add operation; all pending 'add' operations will be cancelled automatically on disconnect, so it is not necessary to keep this handle (unless cont is non-NULL and at some point calling cont must be prevented)

This method operates in semi-reliable mode: if the transmission is not completed by the time GNUNET_PEERINFO_disconnect() is called, it will be aborted. Furthermore, if a second HELLO is added for the same peer before the first one was transmitted, PEERINFO may merge the two HELLOs prior to transmission to the service.

Parameters
hhandle to the peerinfo service
hellothe verified (!) HELLO message
contcontinuation to call when done, NULL is allowed
cont_clsclosure for cont
Returns
handle to cancel add operation; all pending 'add' operations will be cancelled automatically on disconnect, so it is not necessary to keep this handle (unless cont is NULL and at some point calling cont must be prevented)

Definition at line 530 of file peerinfo_api.c.

534 {
535  struct GNUNET_MQ_Envelope *env;
536  struct GNUNET_PeerIdentity peer;
537 
538  if (NULL == h->mq)
539  return NULL;
541  GNUNET_HELLO_get_id (hello,
542  &peer));
544  "Adding peer `%s' to PEERINFO database\n",
545  GNUNET_i2s (&peer));
546  env = GNUNET_MQ_msg_copy ((const struct GNUNET_MessageHeader *) hello);
547  if (NULL != cont)
549  cont,
550  cont_cls);
551  GNUNET_MQ_send (h->mq,
552  env);
553  return env;
554 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
int GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
Get the peer identity from a HELLO message.
Definition: hello.c:649
@ GNUNET_OK
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition: mq.c:642
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition: mq.c:537
#define LOG(kind,...)
Definition: peerinfo_api.c:31
Header for all communications.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.

References env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_get_id(), GNUNET_i2s(), GNUNET_MQ_msg_copy(), GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_OK, h, LOG, GNUNET_ARM_Handle::mq, and peer.

Referenced by callback_download(), GST_validation_handle_pong(), handle_hello(), parse_hello_uri(), and refresh_hello_task().

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

◆ GNUNET_PEERINFO_iterate()

struct GNUNET_PEERINFO_IteratorContext* GNUNET_PEERINFO_iterate ( struct GNUNET_PEERINFO_Handle h,
int  include_friend_only,
const struct GNUNET_PeerIdentity peer,
GNUNET_PEERINFO_Processor  callback,
void *  callback_cls 
)

Call a method for each known matching host.

The callback method will be invoked once for each matching host and then finally once with a NULL pointer. After that final invocation, the iterator context must no longer be used.

Instead of calling this function with peer == NULL it is often better to use GNUNET_PEERINFO_notify().

Parameters
hhandle to the peerinfo service
include_friend_onlyinclude HELLO messages for friends only
peerrestrict iteration to this peer only (can be NULL)
callbackthe method to call for each peer
callback_clsclosure for callback
Returns
iterator context

Definition at line 464 of file peerinfo_api.c.

469 {
471 
473  ic->h = h;
475  ic->callback = callback;
477  if (NULL != peer)
478  {
479  ic->have_peer = GNUNET_YES;
480  ic->peer = *peer;
481  }
483  h->ic_tail,
484  ic);
485  if (h->ic_head == ic)
486  send_ic_request (h);
487  return ic;
488 }
static int include_friend_only
Option '-f'.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
@ GNUNET_YES
static void send_ic_request(struct GNUNET_PEERINFO_Handle *h)
Send the next IC request at the head of the queue.
Definition: peerinfo_api.c:344
void * callback_cls
Closure for callback.
Definition: peerinfo_api.c:62
struct GNUNET_PeerIdentity peer
Peer we are interested in (only valid if iteration was restricted to one peer).
Definition: peerinfo_api.c:67
GNUNET_PEERINFO_Processor callback
Function to call with the results.
Definition: peerinfo_api.c:57
int include_friend_only
Only include friends in reply?
Definition: peerinfo_api.c:77
struct GNUNET_PEERINFO_Handle * h
Handle to the PEERINFO service.
Definition: peerinfo_api.c:52

References GNUNET_PEERINFO_IteratorContext::callback, GNUNET_PEERINFO_IteratorContext::callback_cls, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_new, GNUNET_YES, h, GNUNET_PEERINFO_IteratorContext::h, GNUNET_PEERINFO_IteratorContext::have_peer, include_friend_only, GNUNET_PEERINFO_IteratorContext::include_friend_only, GNUNET_PEERINFO_IteratorContext::peer, peer, and send_ic_request().

Referenced by peerinfo_get(), process_notify(), and state_machine().

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

◆ GNUNET_PEERINFO_iterate_cancel()

void GNUNET_PEERINFO_iterate_cancel ( struct GNUNET_PEERINFO_IteratorContext ic)

Cancel an iteration over peer information.

Parameters
iccontext of the iterator to cancel

Definition at line 497 of file peerinfo_api.c.

498 {
499  struct GNUNET_PEERINFO_Handle *h = ic->h;
500 
501  ic->callback = NULL;
502  if (ic == h->ic_head)
503  return;
504  GNUNET_CONTAINER_DLL_remove (h->ic_head,
505  h->ic_tail,
506  ic);
507  GNUNET_free (ic);
508 }

References GNUNET_PEERINFO_IteratorContext::callback, GNUNET_CONTAINER_DLL_remove, GNUNET_free, h, and GNUNET_PEERINFO_IteratorContext::h.

Referenced by cleanup_handle(), GNUNET_HOSTLIST_server_stop(), process_notify(), and shutdown_task().

Here is the caller graph for this function:

◆ GNUNET_PEERINFO_notify()

struct GNUNET_PEERINFO_NotifyContext* GNUNET_PEERINFO_notify ( const struct GNUNET_CONFIGURATION_Handle cfg,
int  include_friend_only,
GNUNET_PEERINFO_Processor  callback,
void *  callback_cls 
)

Call a method whenever our known information about peers changes.

Initially calls the given function for all known peers and then only signals changes.

If include_friend_only is set to GNUNET_YES peerinfo will include HELLO messages which are intended for friend to friend mode and which do not have to be gossiped. Otherwise these messages are skipped.

Parameters
cfgconfiguration to use
include_friend_onlyinclude HELLO messages for friends only
callbackthe method to call for each peer
callback_clsclosure for callback
Returns
NULL on error

Definition at line 245 of file peerinfo_api_notify.c.

249 {
251 
253  nc->cfg = cfg;
254  nc->callback = callback;
257  reconnect (nc);
258  if (NULL == nc->mq)
259  {
261  "Could not connect to PEERINFO service.\n");
262  GNUNET_free (nc);
263  return NULL;
264  }
265  return nc;
266 }
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
@ GNUNET_ERROR_TYPE_WARNING
static void reconnect(void *cls)
Task to re-try connecting to peerinfo.
#define LOG(kind,...)
Context for the info handler.
struct GNUNET_MQ_Handle * mq
Our connection to the PEERINFO service.
void * callback_cls
Closure for callback.
int include_friend_only
Include friend only HELLOs in callbacks.
GNUNET_PEERINFO_Processor callback
Function to call with information.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration.

References GNUNET_PEERINFO_NotifyContext::callback, GNUNET_PEERINFO_NotifyContext::callback_cls, cfg, GNUNET_PEERINFO_NotifyContext::cfg, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_new, include_friend_only, GNUNET_PEERINFO_NotifyContext::include_friend_only, LOG, GNUNET_PEERINFO_NotifyContext::mq, nc, and reconnect().

Referenced by core_init(), core_init_cb(), GCH_init(), GNUNET_HOSTLIST_server_start(), GST_validation_start(), process_peer(), and run().

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

◆ GNUNET_PEERINFO_notify_cancel()

void GNUNET_PEERINFO_notify_cancel ( struct GNUNET_PEERINFO_NotifyContext nc)

Stop notifying about changes.

Parameters
nccontext to stop notifying

Definition at line 275 of file peerinfo_api_notify.c.

276 {
277  if (NULL != nc->mq)
278  {
280  nc->mq = NULL;
281  }
282  if (NULL != nc->task)
283  {
285  nc->task = NULL;
286  }
287  GNUNET_free (nc);
288 }
struct GNUNET_SCHEDULER_Task * task
Tasked used for delayed re-connection attempt.

References GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_PEERINFO_NotifyContext::mq, nc, and GNUNET_PEERINFO_NotifyContext::task.

Referenced by cleaning_task(), GCH_shutdown(), GNUNET_HOSTLIST_server_stop(), GST_validation_stop(), libgnunet_plugin_dhtu_gnunet_done(), process_peer(), and shutdown_task().

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