GNUnet  0.10.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 118 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 128 of file peerinfo_api.c.

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

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

129 {
130  struct GNUNET_PEERINFO_Handle *h;
131 
133  h->cfg = cfg;
134  reconnect(h);
135  if (NULL == h->mq)
136  {
137  GNUNET_free(h);
138  return NULL;
139  }
140  return h;
141 }
struct GNUNET_MQ_Handle * mq
Connection to the service.
Definition: peerinfo_api.c:92
Handle to the peerinfo service.
Definition: peerinfo_api.c:83
static void reconnect(struct GNUNET_PEERINFO_Handle *h)
Close the existing connection to PEERINFO and reconnect.
Definition: peerinfo_api.c:435
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: peerinfo_api.c:87
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
#define GNUNET_free(ptr)
Wrapper around free.
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 154 of file peerinfo_api.c.

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_PEERINFO_Handle::ic_head, GNUNET_PEERINFO_Handle::ic_tail, GNUNET_PEERINFO_Handle::mq, and GNUNET_PEERINFO_Handle::r_task.

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

155 {
157 
158  while (NULL != (ic = h->ic_head))
159  {
161  h->ic_tail,
162  ic);
163  GNUNET_free(ic);
164  }
165  if (NULL != h->mq)
166  {
167  GNUNET_MQ_destroy(h->mq);
168  h->mq = NULL;
169  }
170  if (NULL != h->r_task)
171  {
173  h->r_task = NULL;
174  }
175  GNUNET_free(h);
176 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MQ_Handle * mq
Connection to the service.
Definition: peerinfo_api.c:92
struct GNUNET_PEERINFO_IteratorContext * ic_tail
Tail of iterator DLL.
Definition: peerinfo_api.c:102
struct GNUNET_PEERINFO_IteratorContext * ic_head
Head of iterator DLL.
Definition: peerinfo_api.c:97
Context for an iteration request.
Definition: peerinfo_api.c:37
struct GNUNET_SCHEDULER_Task * r_task
ID for a reconnect task.
Definition: peerinfo_api.c:107
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 552 of file peerinfo_api.c.

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, LOG, and GNUNET_PEERINFO_Handle::mq.

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

556 {
557  struct GNUNET_MQ_Envelope *env;
558  struct GNUNET_PeerIdentity peer;
559 
560  if (NULL == h->mq)
561  return NULL;
563  GNUNET_HELLO_get_id(hello,
564  &peer));
566  "Adding peer `%s' to PEERINFO database\n",
567  GNUNET_i2s(&peer));
568  env = GNUNET_MQ_msg_copy((const struct GNUNET_MessageHeader *)hello);
569  if (NULL != cont)
571  cont,
572  cont_cls);
573  GNUNET_MQ_send(h->mq,
574  env);
575  return env;
576 }
struct GNUNET_MQ_Handle * mq
Connection to the service.
Definition: peerinfo_api.c:92
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:662
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:651
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define LOG(kind,...)
Definition: peerinfo_api.c:31
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:772
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
The identity of the host (wraps the signing key of the peer).
Header for all communications.
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:351
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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 486 of file peerinfo_api.c.

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

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

491 {
493 
495  ic->h = h;
497  ic->callback = callback;
499  if (NULL != peer)
500  {
501  ic->have_peer = GNUNET_YES;
502  ic->peer = *peer;
503  }
505  h->ic_tail,
506  ic);
507  if (h->ic_head == ic)
508  send_ic_request(h);
509  return ic;
510 }
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:350
struct GNUNET_PEERINFO_IteratorContext * ic_tail
Tail of iterator DLL.
Definition: peerinfo_api.c:102
struct GNUNET_PEERINFO_IteratorContext * ic_head
Head of iterator DLL.
Definition: peerinfo_api.c:97
static int include_friend_only
Option '-f'.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Context for an iteration request.
Definition: peerinfo_api.c:37
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
void * callback_cls
Closure for callback.
Definition: peerinfo_api.c:61
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
GNUNET_PEERINFO_Processor callback
Function to call with the results.
Definition: peerinfo_api.c:56
int include_friend_only
Only include friends in reply?
Definition: peerinfo_api.c:76
struct GNUNET_PeerIdentity peer
Peer we are interested in (only valid if iteration was restricted to one peer).
Definition: peerinfo_api.c:66
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_PEERINFO_Handle * h
Handle to the PEERINFO service.
Definition: peerinfo_api.c:51
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 519 of file peerinfo_api.c.

References GNUNET_PEERINFO_IteratorContext::callback, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_PEERINFO_IteratorContext::h, GNUNET_PEERINFO_Handle::ic_head, and GNUNET_PEERINFO_Handle::ic_tail.

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

520 {
521  struct GNUNET_PEERINFO_Handle *h = ic->h;
522 
523  ic->callback = NULL;
524  if (ic == h->ic_head)
525  return;
527  h->ic_tail,
528  ic);
529  GNUNET_free(ic);
530 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
Handle to the peerinfo service.
Definition: peerinfo_api.c:83
struct GNUNET_PEERINFO_IteratorContext * ic_tail
Tail of iterator DLL.
Definition: peerinfo_api.c:102
struct GNUNET_PEERINFO_IteratorContext * ic_head
Head of iterator DLL.
Definition: peerinfo_api.c:97
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
GNUNET_PEERINFO_Processor callback
Function to call with the results.
Definition: peerinfo_api.c:56
struct GNUNET_PEERINFO_Handle * h
Handle to the PEERINFO service.
Definition: peerinfo_api.c:51
#define GNUNET_free(ptr)
Wrapper around free.
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 244 of file peerinfo_api_notify.c.

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

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

248 {
250 
252  nc->cfg = cfg;
253  nc->callback = callback;
256  reconnect(nc);
257  if (NULL == nc->mq)
258  {
260  "Could not connect to PEERINFO service.\n");
261  GNUNET_free(nc);
262  return NULL;
263  }
264  return nc;
265 }
Context for the info handler.
static void reconnect(void *cls)
Task to re-try connecting to peerinfo.
int include_friend_only
Include friend only HELLOs in callbacks.
struct GNUNET_MQ_Handle * mq
Our connection to the PEERINFO service.
static int include_friend_only
Option '-f'.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void * callback_cls
Closure for callback.
#define LOG(kind,...)
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration.
GNUNET_PEERINFO_Processor callback
Function to call with information.
#define GNUNET_free(ptr)
Wrapper around free.
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 274 of file peerinfo_api_notify.c.

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

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

275 {
276  if (NULL != nc->mq)
277  {
278  GNUNET_MQ_destroy(nc->mq);
279  nc->mq = NULL;
280  }
281  if (NULL != nc->task)
282  {
284  nc->task = NULL;
285  }
286  GNUNET_free(nc);
287 }
struct GNUNET_MQ_Handle * mq
Our connection to the PEERINFO service.
struct GNUNET_SCHEDULER_Task * task
Tasked used for delayed re-connection attempt.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function: