GNUnet  0.11.x
Typedefs | Functions
Peer Info service

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

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 117 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).
Parameters
cfgconfiguration to use
Returns
NULL on error (configuration related, actual connection establishment may happen asynchronously).

Definition at line 130 of file peerinfo_api.c.

131 {
132  struct GNUNET_PEERINFO_Handle *h;
133 
135  h->cfg = cfg;
136  reconnect (h);
137  if (NULL == h->mq)
138  {
139  GNUNET_free (h);
140  return NULL;
141  }
142  return h;
143 }
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:436
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 156 of file peerinfo_api.c.

157 {
159 
160  while (NULL != (ic = h->ic_head))
161  {
162  GNUNET_CONTAINER_DLL_remove (h->ic_head,
163  h->ic_tail,
164  ic);
165  GNUNET_free (ic);
166  }
167  if (NULL != h->mq)
168  {
170  h->mq = NULL;
171  }
172  if (NULL != h->r_task)
173  {
174  GNUNET_SCHEDULER_cancel (h->r_task);
175  h->r_task = NULL;
176  }
177  GNUNET_free (h);
178 }
#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:837
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
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 553 of file peerinfo_api.c.

557 {
558  struct GNUNET_MQ_Envelope *env;
559  struct GNUNET_PeerIdentity peer;
560 
561  if (NULL == h->mq)
562  return NULL;
564  GNUNET_HELLO_get_id (hello,
565  &peer));
567  "Adding peer `%s' to PEERINFO database\n",
568  GNUNET_i2s (&peer));
569  env = GNUNET_MQ_msg_copy ((const struct GNUNET_MessageHeader *) hello);
570  if (NULL != cont)
572  cont,
573  cont_cls);
574  GNUNET_MQ_send (h->mq,
575  env);
576  return env;
577 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
@ GNUNET_OK
Definition: gnunet_common.h:95
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:671
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:355
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:787
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:666
#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)
timeouthow long to wait until timing out
callbackthe method to call for each peer
callback_clsclosure for callback
Returns
iterator context

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 487 of file peerinfo_api.c.

492 {
494 
496  ic->h = h;
498  ic->callback = callback;
500  if (NULL != peer)
501  {
502  ic->have_peer = GNUNET_YES;
503  ic->peer = *peer;
504  }
506  h->ic_tail,
507  ic);
508  if (h->ic_head == ic)
509  send_ic_request (h);
510  return ic;
511 }
static int include_friend_only
Option '-f'.
@ GNUNET_YES
Definition: gnunet_common.h:97
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
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:351
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 520 of file peerinfo_api.c.

521 {
522  struct GNUNET_PEERINFO_Handle *h = ic->h;
523 
524  ic->callback = NULL;
525  if (ic == h->ic_head)
526  return;
527  GNUNET_CONTAINER_DLL_remove (h->ic_head,
528  h->ic_tail,
529  ic);
530  GNUNET_free (ic);
531 }

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(), GDS_HELLO_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(), GDS_HELLO_done(), 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: