GNUnet  0.10.x
Data Structures | Macros | Functions
peerinfo_api_notify.c File Reference

notify API to access peerinfo service More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_peerinfo_service.h"
#include "gnunet_protocols.h"
#include "peerinfo.h"
Include dependency graph for peerinfo_api_notify.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_PEERINFO_NotifyContext
 Context for the info handler. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "peerinfo-api",__VA_ARGS__)
 

Functions

static void reconnect (void *cls)
 Task to re-try connecting to peerinfo. More...
 
static void do_reconnect (struct GNUNET_PEERINFO_NotifyContext *nc)
 We encountered an error, reconnect to the service. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 We got a disconnect after asking regex to do the announcement. More...
 
static int check_notification (void *cls, const struct InfoMessage *im)
 Check that a peerinfo information message is well-formed. More...
 
static void handle_notification (void *cls, const struct InfoMessage *im)
 Receive a peerinfo information message, process it. More...
 
static void handle_end_iteration (void *cls, const struct GNUNET_MessageHeader *msg)
 Type of a function to call when we receive a message from the service. 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

notify API to access peerinfo service

Author
Christian Grothoff

Definition in file peerinfo_api_notify.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "peerinfo-api",__VA_ARGS__)

Definition at line 32 of file peerinfo_api_notify.c.

Referenced by GNUNET_PEERINFO_notify(), and handle_notification().

Function Documentation

◆ reconnect()

static void reconnect ( void *  cls)
static

Task to re-try connecting to peerinfo.

Parameters
clsthe struct GNUNET_PEERINFO_NotifyContext *

Definition at line 197 of file peerinfo_api_notify.c.

References GNUNET_PEERINFO_NotifyContext::cfg, env, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_PEERINFO_INFO, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END, GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_PEERINFO_NotifyContext::include_friend_only, NotifyMessage::include_friend_only, GNUNET_PEERINFO_NotifyContext::mq, mq_error_handler(), nc, and GNUNET_PEERINFO_NotifyContext::task.

Referenced by do_reconnect(), and GNUNET_PEERINFO_notify().

198 {
199  struct GNUNET_PEERINFO_NotifyContext *nc = cls;
201  GNUNET_MQ_hd_var_size (notification,
203  struct InfoMessage,
204  nc),
205  GNUNET_MQ_hd_fixed_size (end_iteration,
207  struct GNUNET_MessageHeader,
208  nc),
210  };
211  struct GNUNET_MQ_Envelope *env;
212  struct NotifyMessage *nm;
213 
214  nc->task = NULL;
215  nc->mq = GNUNET_CLIENT_connect (nc->cfg,
216  "peerinfo",
217  handlers,
219  nc);
220  if (NULL == nc->mq)
221  return;
222  env = GNUNET_MQ_msg (nm,
224  nm->include_friend_only = htonl (nc->include_friend_only);
225  GNUNET_MQ_send (nc->mq,
226  env);
227 }
uint32_t include_friend_only
Include friend only HELLOs and peers in callbacks.
Definition: peerinfo.h:95
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:901
Context for the info handler.
Message used to inform the client about a particular peer; this message is optionally followed by a H...
Definition: peerinfo.h:107
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
We got a disconnect after asking regex to do the announcement.
#define GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY
Start notifying this client about all changes to the known peers until it disconnects.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
int include_friend_only
Include friend only HELLOs in callbacks.
struct GNUNET_MQ_Handle * mq
Our connection to the PEERINFO service.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
Message handler for a specific message type.
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MESSAGE_TYPE_PEERINFO_INFO
Information about one of the peers.
struct GNUNET_SCHEDULER_Task * task
Tasked used for delayed re-connection attempt.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration.
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:353
#define GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END
End of information about other peers.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Header for all communications.
Definition: peerinfo.h:85
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_reconnect()

static void do_reconnect ( struct GNUNET_PEERINFO_NotifyContext nc)
static

We encountered an error, reconnect to the service.

Parameters
nccontext to reconnect

Definition at line 87 of file peerinfo_api_notify.c.

References GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_now(), GNUNET_PEERINFO_NotifyContext::mq, reconnect(), and GNUNET_PEERINFO_NotifyContext::task.

Referenced by mq_error_handler().

88 {
89  GNUNET_MQ_destroy (nc->mq);
90  nc->mq = NULL;
92  nc);
93 }
static void reconnect(void *cls)
Task to re-try connecting to peerinfo.
struct GNUNET_MQ_Handle * mq
Our connection to the PEERINFO service.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
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:824
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

We got a disconnect after asking regex to do the announcement.

Retry.

Parameters
clsthe struct GNUNET_PEERINFO_NotifyContext to retry
errorerror code

Definition at line 104 of file peerinfo_api_notify.c.

References do_reconnect(), and nc.

Referenced by reconnect().

106 {
107  struct GNUNET_PEERINFO_NotifyContext *nc = cls;
108 
109  do_reconnect (nc);
110 }
static void do_reconnect(struct GNUNET_PEERINFO_NotifyContext *nc)
We encountered an error, reconnect to the service.
Context for the info handler.
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_notification()

static int check_notification ( void *  cls,
const struct InfoMessage im 
)
static

Check that a peerinfo information message is well-formed.

Parameters
clsclosure
immessage received
Returns
GNUNET_OK if the message is well-formed

Definition at line 121 of file peerinfo_api_notify.c.

References GNUNET_break, GNUNET_HELLO_size(), GNUNET_OK, GNUNET_SYSERR, InfoMessage::header, and GNUNET_MessageHeader::size.

123 {
124  uint16_t ms = ntohs (im->header.size) - sizeof (*im);
125 
126  if (ms >= sizeof (struct GNUNET_MessageHeader))
127  {
128  const struct GNUNET_HELLO_Message *hello;
129 
130  hello = (const struct GNUNET_HELLO_Message *) &im[1];
131  if (ms != GNUNET_HELLO_size (hello))
132  {
133  GNUNET_break (0);
134  return GNUNET_SYSERR;
135  }
136  return GNUNET_OK;
137  }
138  if (0 != ms)
139  {
140  GNUNET_break (0);
141  return GNUNET_SYSERR;
142  }
143  return GNUNET_OK; /* odd... */
144 }
A HELLO message is used to exchange information about transports with other peers.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_PEERINFO_INFO.
Definition: peerinfo.h:113
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:649
Header for all communications.
Here is the call graph for this function:

◆ handle_notification()

static void handle_notification ( void *  cls,
const struct InfoMessage im 
)
static

Receive a peerinfo information message, process it.

Parameters
clsclosure
immessage received

Definition at line 154 of file peerinfo_api_notify.c.

References GNUNET_PEERINFO_NotifyContext::callback, GNUNET_PEERINFO_NotifyContext::callback_cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), InfoMessage::header, LOG, nc, InfoMessage::peer, and GNUNET_MessageHeader::size.

156 {
157  struct GNUNET_PEERINFO_NotifyContext *nc = cls;
158  const struct GNUNET_HELLO_Message *hello;
159  uint16_t ms = ntohs (im->header.size) - sizeof (struct InfoMessage);
160 
161  if (0 == ms)
162  return;
163  hello = (const struct GNUNET_HELLO_Message *) &im[1];
165  "Received information about peer `%s' from peerinfo database\n",
166  GNUNET_i2s (&im->peer));
167  nc->callback (nc->callback_cls,
168  &im->peer,
169  hello,
170  NULL);
171 }
A HELLO message is used to exchange information about transports with other peers.
Context for the info handler.
Message used to inform the client about a particular peer; this message is optionally followed by a H...
Definition: peerinfo.h:107
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void * callback_cls
Closure for callback.
struct GNUNET_PeerIdentity peer
About which peer are we talking here?
Definition: peerinfo.h:123
#define LOG(kind,...)
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_PEERINFO_INFO.
Definition: peerinfo.h:113
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
GNUNET_PEERINFO_Processor callback
Function to call with information.
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:

◆ handle_end_iteration()

static void handle_end_iteration ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Type of a function to call when we receive a message from the service.

Call the iterator with the result and (if applicable) continue to receive more messages or trigger processing the next event (if applicable).

Parameters
clsclosure
msgmessage received, NULL on timeout or fatal error

Definition at line 184 of file peerinfo_api_notify.c.

186 {
187  /* these are ignored by the notify API */
188 }