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 84 of file cadet_api_get_path.c.

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

86 {
87  size_t msize = sizeof(struct GNUNET_CADET_LocalInfoPath);
88  size_t esize;
89 
90  (void)cls;
91  esize = ntohs(message->header.size);
92  if (esize < msize)
93  {
94  GNUNET_break(0);
95  return GNUNET_SYSERR;
96  }
97  if (0 != ((esize - msize) % sizeof(struct GNUNET_PeerIdentity)))
98  {
99  GNUNET_break(0);
100  return GNUNET_SYSERR;
101  }
102  return GNUNET_OK;
103 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:316
Message to inform the client about one of the paths known to the service.
Definition: cadet.h:312
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 113 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.

115 {
116  struct GNUNET_CADET_GetPath *gp = cls;
117  struct GNUNET_CADET_PeerPathDetail ppd;
118 
119  ppd.peer = gp->id;
120  ppd.path = (const struct GNUNET_PeerIdentity *)&message[1];
121  ppd.target_offset = ntohl(message->off);
122  ppd.path_length = (ntohs(message->header.size) - sizeof(*message))
123  / sizeof(struct GNUNET_PeerIdentity);
124  gp->path_cb(gp->path_cb_cls,
125  &ppd);
126 }
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:316
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:321
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 136 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().

138 {
139  struct GNUNET_CADET_GetPath *gp = cls;
140 
141  (void)message;
142  gp->path_cb(gp->path_cb_cls,
143  NULL);
145 }
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 185 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().

186 {
187  struct GNUNET_CADET_GetPath *gp = cls;
189  GNUNET_MQ_hd_var_size(get_path,
192  gp),
193  GNUNET_MQ_hd_fixed_size(get_path_end,
195  struct GNUNET_MessageHeader,
196  gp),
198  };
200  struct GNUNET_MQ_Envelope *env;
201 
202  gp->reconnect_task = NULL;
203  gp->mq = GNUNET_CLIENT_connect(gp->cfg,
204  "cadet",
205  handlers,
206  &error_handler,
207  gp);
208  if (NULL == gp->mq)
209  return;
210  env = GNUNET_MQ_msg(msg,
212  msg->peer = gp->id;
213  GNUNET_MQ_send(gp->mq,
214  env);
215 }
#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:900
#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:252
struct GNUNET_PeerIdentity peer
ID of the destination of the channel (can be local peer).
Definition: cadet.h:266
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:312
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:351
#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 164 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().

166 {
167  struct GNUNET_CADET_GetPath *gp = cls;
168 
169  GNUNET_MQ_destroy(gp->mq);
170  gp->mq = NULL;
174  &reconnect,
175  gp);
176 }
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:1237
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:821
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:758
Here is the call graph for this function:
Here is the caller graph for this function: