GNUnet  0.10.x
Data Structures | Functions
cadet_api_get_path.c File Reference

cadet api: client implementation of cadet service More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_cadet_service.h"
#include "cadet.h"
#include "cadet_protocol.h"
Include dependency graph for cadet_api_get_path.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_CADET_GetPath
 Operation handle. More...
 

Functions

static int check_get_path (void *cls, const struct GNUNET_CADET_LocalInfoPath *message)
 Check that message received from CADET service is well-formed. More...
 
static void handle_get_path (void *cls, const struct GNUNET_CADET_LocalInfoPath *message)
 Process a local peer info reply, pass info to the user. More...
 
static void handle_get_path_end (void *cls, const struct GNUNET_MessageHeader *message)
 Process a local peer info reply, pass info to the user. More...
 
static void reconnect (void *cls)
 Reconnect to the service and try again. More...
 
static void error_handler (void *cls, enum GNUNET_MQ_Error error)
 Function called on connection trouble. More...
 
struct GNUNET_CADET_GetPathGNUNET_CADET_get_path (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *id, GNUNET_CADET_PathCB callback, void *callback_cls)
 Request information about paths known to the running cadet peer. More...
 
void * GNUNET_CADET_get_path_cancel (struct GNUNET_CADET_GetPath *gp)
 Cancel gp operation. More...
 

Detailed Description

cadet api: client implementation of cadet service

Author
Bartlomiej Polot
Christian Grothoff

Definition in file cadet_api_get_path.c.

Function Documentation

◆ check_get_path()

static int check_get_path ( void *  cls,
const struct GNUNET_CADET_LocalInfoPath message 
)
static

Check that message received from CADET service is well-formed.

Parameters
clsunused
messagethe message we got
Returns
GNUNET_OK if the message is well-formed, GNUNET_SYSERR otherwise

Definition at line 87 of file cadet_api_get_path.c.

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_CADET_LocalInfoPath::header, and GNUNET_MessageHeader::size.

89 {
90  size_t msize = sizeof (struct GNUNET_CADET_LocalInfoPath);
91  size_t esize;
92 
93  (void) cls;
94  esize = ntohs (message->header.size);
95  if (esize < msize)
96  {
97  GNUNET_break (0);
98  return GNUNET_SYSERR;
99  }
100  if (0 != ((esize - msize) % sizeof (struct GNUNET_PeerIdentity)))
101  {
102  GNUNET_break (0);
103  return GNUNET_SYSERR;
104  }
105  return GNUNET_OK;
106 }
#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: GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH.
Definition: cadet.h:327
Message to inform the client about one of the paths known to the service.
Definition: cadet.h:322
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
The identity of the host (wraps the signing key of the peer).

◆ handle_get_path()

static void handle_get_path ( void *  cls,
const struct GNUNET_CADET_LocalInfoPath message 
)
static

Process a local peer info reply, pass info to the user.

Parameters
clsClosure
messageMessage itself.

Definition at line 116 of file cadet_api_get_path.c.

References GNUNET_CADET_LocalInfoPath::header, GNUNET_CADET_GetPath::id, GNUNET_CADET_LocalInfoPath::off, GNUNET_CADET_PeerPathDetail::path, GNUNET_CADET_GetPath::path_cb, GNUNET_CADET_GetPath::path_cb_cls, GNUNET_CADET_PeerPathDetail::path_length, GNUNET_CADET_PeerPathDetail::peer, GNUNET_MessageHeader::size, and GNUNET_CADET_PeerPathDetail::target_offset.

118 {
119  struct GNUNET_CADET_GetPath *gp = cls;
120  struct GNUNET_CADET_PeerPathDetail ppd;
121 
122  ppd.peer = gp->id;
123  ppd.path = (const struct GNUNET_PeerIdentity *) &message[1];
124  ppd.target_offset = ntohl (message->off);
125  ppd.path_length = (ntohs (message->header.size) - sizeof (*message))
126  / sizeof (struct GNUNET_PeerIdentity);
127  gp->path_cb (gp->path_cb_cls,
128  &ppd);
129 }
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH.
Definition: cadet.h:327
void * path_cb_cls
Closure for path_cb.
GNUNET_CADET_PathCB path_cb
Monitor callback.
uint32_t off
Offset of the peer that was requested.
Definition: cadet.h:332
Operation handle.
struct GNUNET_PeerIdentity peer
Peer this is about.
struct GNUNET_PeerIdentity id
Peer we want information about.
The identity of the host (wraps the signing key of the peer).
Detailed information we return per peer.

◆ handle_get_path_end()

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

Process a local peer info reply, pass info to the user.

Parameters
clsClosure
messageMessage itself.

Definition at line 139 of file cadet_api_get_path.c.

References GNUNET_CADET_get_path_cancel(), GNUNET_CADET_GetPath::path_cb, GNUNET_CADET_GetPath::path_cb_cls, and reconnect().

141 {
142  struct GNUNET_CADET_GetPath *gp = cls;
143 
144  (void) message;
145  gp->path_cb (gp->path_cb_cls,
146  NULL);
148 }
void * path_cb_cls
Closure for path_cb.
GNUNET_CADET_PathCB path_cb
Monitor callback.
void * GNUNET_CADET_get_path_cancel(struct GNUNET_CADET_GetPath *gp)
Cancel gp operation.
Operation handle.
Here is the call graph for this function:

◆ reconnect()

static void reconnect ( void *  cls)
static

Reconnect to the service and try again.

Parameters
clsa struct GNUNET_CADET_GetPath operation

Definition at line 188 of file cadet_api_get_path.c.

References GNUNET_CADET_GetPath::cfg, env, error_handler(), GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END, GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_CADET_GetPath::id, GNUNET_CADET_GetPath::mq, msg, GNUNET_CADET_RequestPathInfoMessage::peer, and GNUNET_CADET_GetPath::reconnect_task.

Referenced by error_handler(), GNUNET_CADET_get_path(), and handle_get_path_end().

189 {
190  struct GNUNET_CADET_GetPath *gp = cls;
192  GNUNET_MQ_hd_var_size (get_path,
195  gp),
196  GNUNET_MQ_hd_fixed_size (get_path_end,
198  struct GNUNET_MessageHeader,
199  gp),
201  };
203  struct GNUNET_MQ_Envelope *env;
204 
205  gp->reconnect_task = NULL;
206  gp->mq = GNUNET_CLIENT_connect (gp->cfg,
207  "cadet",
208  handlers,
209  &error_handler,
210  gp);
211  if (NULL == gp->mq)
212  return;
213  env = GNUNET_MQ_msg (msg,
215  msg->peer = gp->id;
216  GNUNET_MQ_send (gp->mq,
217  env);
218 }
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH
Local information of service about a specific path.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
Message to inform the client about channels in the service.
Definition: cadet.h:259
struct GNUNET_PeerIdentity peer
ID of the destination of the channel (can be local peer).
Definition: cadet.h:274
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect.
Message to inform the client about one of the paths known to the service.
Definition: cadet.h:322
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH
Request local information of service about paths to specific peer.
struct GNUNET_MQ_Handle * mq
Message queue to talk to CADET service.
Message handler for a specific message type.
Operation handle.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_PeerIdentity id
Peer we want information about.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END
End of local information of service about a specific path.
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
Function called on connection trouble.
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_MQ_handler_end()
End-marker for the handlers array.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ error_handler()

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

Function called on connection trouble.

Reconnects.

Parameters
clsa struct GNUNET_CADET_GetPath
errorerror code from MQ

Definition at line 167 of file cadet_api_get_path.c.

References GNUNET_CADET_GetPath::backoff, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_randomized_backoff(), GNUNET_TIME_UNIT_MINUTES, GNUNET_CADET_GetPath::mq, reconnect(), and GNUNET_CADET_GetPath::reconnect_task.

Referenced by reconnect().

169 {
170  struct GNUNET_CADET_GetPath *gp = cls;
171 
172  GNUNET_MQ_destroy (gp->mq);
173  gp->mq = NULL;
177  &reconnect,
178  gp);
179 }
struct GNUNET_TIME_Relative backoff
Backoff for reconnect attempts.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
struct GNUNET_MQ_Handle * mq
Message queue to talk to CADET service.
Operation handle.
static void reconnect(void *cls)
Reconnect to the service and try again.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
struct GNUNET_TIME_Relative GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIME_Relative threshold)
Randomized exponential back-off, starting at 1 ms and going up by a factor of 2+r, where 0 <= r <= 0.5, up to a maximum of the given threshold.
Definition: time.c:759
Here is the call graph for this function:
Here is the caller graph for this function: