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.

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 }
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
Message to inform the client about one of the paths known to the service.
Definition: cadet.h:408
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH.
Definition: cadet.h:412
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
The identity of the host (wraps the signing key of the peer).

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

◆ 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.

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 }
Operation handle.
GNUNET_CADET_PathCB path_cb
Monitor callback.
void * path_cb_cls
Closure for path_cb.
struct GNUNET_PeerIdentity id
Peer we want information about.
uint32_t off
Offset of the peer that was requested.
Definition: cadet.h:417
Detailed information we return per peer.
struct GNUNET_PeerIdentity peer
Peer this is about.

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.

◆ 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.

139 {
140  struct GNUNET_CADET_GetPath *gp = cls;
141 
142  (void) message;
143  gp->path_cb (gp->path_cb_cls,
144  NULL);
146 }
void * GNUNET_CADET_get_path_cancel(struct GNUNET_CADET_GetPath *gp)
Cancel gp operation.

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

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.

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 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
Function called on connection trouble.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
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:1064
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:355
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END
End of local information of service about a specific path.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH
Request local information of service about paths to specific peer.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH
Local information of service about a specific path.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect.
struct GNUNET_MQ_Handle * mq
Message queue to talk to CADET service.
Message to inform the client about channels in the service.
Definition: cadet.h:345
Message handler for a specific message type.
Header for all communications.

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(), handlers, GNUNET_CADET_GetPath::id, GNUNET_CADET_GetPath::mq, msg, and GNUNET_CADET_GetPath::reconnect_task.

Referenced by error_handler(), and GNUNET_CADET_get_path().

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.

167 {
168  struct GNUNET_CADET_GetPath *gp = cls;
169 
170  GNUNET_MQ_destroy (gp->mq);
171  gp->mq = NULL;
175  &reconnect,
176  gp);
177 }
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:837
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:1269
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,...
Definition: time.c:635
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_TIME_Relative backoff
Backoff for reconnect attempts.

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().

Here is the call graph for this function:
Here is the caller graph for this function: