GNUnet  0.11.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 85 of file cadet_api_get_path.c.

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

87 {
88  size_t msize = sizeof(struct GNUNET_CADET_LocalInfoPath);
89  size_t esize;
90 
91  (void) cls;
92  esize = ntohs (message->header.size);
93  if (esize < msize)
94  {
95  GNUNET_break (0);
96  return GNUNET_SYSERR;
97  }
98  if (0 != ((esize - msize) % sizeof(struct GNUNET_PeerIdentity)))
99  {
100  GNUNET_break (0);
101  return GNUNET_SYSERR;
102  }
103  return GNUNET_OK;
104 }
#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: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: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 114 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.

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

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

187 {
188  struct GNUNET_CADET_GetPath *gp = cls;
190  GNUNET_MQ_hd_var_size (get_path,
193  gp),
194  GNUNET_MQ_hd_fixed_size (get_path_end,
196  struct GNUNET_MessageHeader,
197  gp),
199  };
201  struct GNUNET_MQ_Envelope *env;
202 
203  gp->reconnect_task = NULL;
204  gp->mq = GNUNET_CLIENT_connect (gp->cfg,
205  "cadet",
206  handlers,
207  &error_handler,
208  gp);
209  if (NULL == gp->mq)
210  return;
211  env = GNUNET_MQ_msg (msg,
213  msg->peer = gp->id;
214  GNUNET_MQ_send (gp->mq,
215  env);
216 }
#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:1057
#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 165 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().

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