GNUnet  0.10.x
Data Structures | Functions
cadet_api_get_channel.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_channel.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_CADET_ChannelMonitor
 Operation handle. More...
 

Functions

static int check_channel_info (void *cls, const struct GNUNET_CADET_ChannelInfoMessage *message)
 Check that message received from CADET service is well-formed. More...
 
static void handle_channel_info (void *cls, const struct GNUNET_CADET_ChannelInfoMessage *message)
 Process a local peer info reply, pass info to the user. More...
 
static void handle_channel_info_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_ChannelMonitorGNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_PeerIdentity *peer, GNUNET_CADET_ChannelCB callback, void *callback_cls)
 Request information about a specific channel of the running cadet peer. More...
 
void * GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm)
 Cancel a channel monitor request. More...
 

Detailed Description

cadet api: client implementation of cadet service

Author
Bartlomiej Polot
Christian Grothoff

Definition in file cadet_api_get_channel.c.

Function Documentation

◆ check_channel_info()

static int check_channel_info ( void *  cls,
const struct GNUNET_CADET_ChannelInfoMessage 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_channel.c.

References GNUNET_OK.

86 {
87  (void)cls;
88 
89  return GNUNET_OK;
90 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void * cls
Closure for handler.
Definition: cadet_api.c:157

◆ handle_channel_info()

static void handle_channel_info ( void *  cls,
const struct GNUNET_CADET_ChannelInfoMessage message 
)
static

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

Parameters
clsClosure
messageMessage itself.

Definition at line 100 of file cadet_api_get_channel.c.

References GNUNET_CADET_ChannelMonitor::channel_cb, GNUNET_CADET_ChannelMonitor::channel_cb_cls, GNUNET_CADET_ChannelInfoMessage::dest, GNUNET_CADET_ChannelInternals::dest, GNUNET_CADET_get_channel_cancel(), GNUNET_CADET_ChannelInfoMessage::root, and GNUNET_CADET_ChannelInternals::root.

102 {
103  struct GNUNET_CADET_ChannelMonitor *cm = cls;
105 
106  ci.root = message->root;
107  ci.dest = message->dest;
108  cm->channel_cb(cm->channel_cb_cls,
109  &ci);
111 }
struct GNUNET_PeerIdentity root
Root of the channel.
Internal details about a channel.
void * channel_cb_cls
Info callback closure for channel_cb.
struct GNUNET_PeerIdentity dest
Destination of the channel.
Definition: cadet.h:287
GNUNET_CADET_ChannelCB channel_cb
Channel callback.
void * GNUNET_CADET_get_channel_cancel(struct GNUNET_CADET_ChannelMonitor *cm)
Cancel a channel monitor request.
struct GNUNET_PeerIdentity root
Root of the channel.
Definition: cadet.h:282
Here is the call graph for this function:

◆ handle_channel_info_end()

static void handle_channel_info_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 121 of file cadet_api_get_channel.c.

References GNUNET_CADET_ChannelMonitor::channel_cb, GNUNET_CADET_ChannelMonitor::channel_cb_cls, GNUNET_CADET_get_channel_cancel(), and reconnect().

123 {
124  struct GNUNET_CADET_ChannelMonitor *cm = cls;
125 
126  cm->channel_cb(cm->channel_cb_cls,
127  NULL);
129 }
void * channel_cb_cls
Info callback closure for channel_cb.
GNUNET_CADET_ChannelCB channel_cb
Channel callback.
void * GNUNET_CADET_get_channel_cancel(struct GNUNET_CADET_ChannelMonitor *cm)
Cancel a channel monitor request.
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_ChannelMonitor operation

Definition at line 169 of file cadet_api_get_channel.c.

References GNUNET_CADET_ChannelMonitor::cfg, env, error_handler(), GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL_END, GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_CADET_ChannelMonitor::mq, msg, GNUNET_CADET_ChannelMonitor::peer, GNUNET_CADET_ChannelMonitor::reconnect_task, and GNUNET_CADET_RequestChannelInfoMessage::target.

Referenced by error_handler(), GNUNET_CADET_get_channel(), and handle_channel_info_end().

170 {
171  struct GNUNET_CADET_ChannelMonitor *cm = cls;
173  GNUNET_MQ_hd_fixed_size(channel_info_end,
175  struct GNUNET_MessageHeader,
176  cm),
177  GNUNET_MQ_hd_var_size(channel_info,
180  cm),
182  };
184  struct GNUNET_MQ_Envelope *env;
185 
186  cm->reconnect_task = NULL;
187  cm->mq = GNUNET_CLIENT_connect(cm->cfg,
188  "cadet",
189  handlers,
190  &error_handler,
191  cm);
192  if (NULL == cm->mq)
193  return;
194  env = GNUNET_MQ_msg(msg,
196  msg->target = cm->peer;
197  GNUNET_MQ_send(cm->mq,
198  env);
199 }
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL
Local information of service about a specific channel.
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:273
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
struct GNUNET_PeerIdentity peer
Peer we want information about.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
Message to as the service about information on a channel.
Definition: cadet.h:296
struct GNUNET_MQ_Handle * mq
Message queue to talk to CADET service.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL
Local information about all channels of service.
Message handler for a specific message type.
struct GNUNET_PeerIdentity target
Target of the channel.
Definition: cadet.h:305
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.
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_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL_END
End of local information of service about channels.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect.
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_ChannelMonitor`
errorerror code from MQ

Definition at line 148 of file cadet_api_get_channel.c.

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

Referenced by reconnect().

150 {
151  struct GNUNET_CADET_ChannelMonitor *cm = cls;
152 
153  GNUNET_MQ_destroy(cm->mq);
154  cm->mq = NULL;
158  &reconnect,
159  cm);
160 }
static void reconnect(void *cls)
Reconnect to the service and try again.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
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_TIME_Relative backoff
Backoff for reconnect attempts.
struct GNUNET_MQ_Handle * mq
Message queue to talk to CADET service.
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
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect.
Here is the call graph for this function:
Here is the caller graph for this function: