GNUnet 0.22.2
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 85 of file cadet_api_get_channel.c.

87{
88 (void) cls;
89
90 return GNUNET_OK;
91}
@ GNUNET_OK

References GNUNET_OK.

◆ 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 101 of file cadet_api_get_channel.c.

103{
104 struct GNUNET_CADET_ChannelMonitor *cm = cls;
106
107 ci.root = message->root;
108 ci.dest = message->dest;
109 cm->channel_cb (cm->channel_cb_cls,
110 &ci);
112}
void * GNUNET_CADET_get_channel_cancel(struct GNUNET_CADET_ChannelMonitor *cm)
Cancel a channel monitor request.
struct GNUNET_PeerIdentity dest
Destination of the channel.
Definition: cadet.h:380
struct GNUNET_PeerIdentity root
Root of the channel.
Definition: cadet.h:375
Internal details about a channel.
struct GNUNET_PeerIdentity root
Root of the channel.
void * channel_cb_cls
Info callback closure for channel_cb.
GNUNET_CADET_ChannelCB channel_cb
Channel callback.

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

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 122 of file cadet_api_get_channel.c.

124{
125 struct GNUNET_CADET_ChannelMonitor *cm = cls;
126
127 cm->channel_cb (cm->channel_cb_cls,
128 NULL);
130}

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

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 170 of file cadet_api_get_channel.c.

171{
172 struct GNUNET_CADET_ChannelMonitor *cm = cls;
174 GNUNET_MQ_hd_fixed_size (channel_info_end,
177 cm),
178 GNUNET_MQ_hd_var_size (channel_info,
181 cm),
183 };
185 struct GNUNET_MQ_Envelope *env;
186
187 cm->reconnect_task = NULL;
188 cm->mq = GNUNET_CLIENT_connect (cm->cfg,
189 "cadet",
190 handlers,
192 cm);
193 if (NULL == cm->mq)
194 return;
197 msg->target = cm->peer;
198 GNUNET_MQ_send (cm->mq,
199 env);
200}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
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.
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:1060
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:305
#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:76
#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_CHANNEL_END
End of local information of service about channels.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL
Local information of service about a specific channel.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL
Local information about all channels of service.
Message to inform the client about channels in the service.
Definition: cadet.h:366
struct GNUNET_PeerIdentity peer
Peer we want information about.
struct GNUNET_MQ_Handle * mq
Message queue to talk to CADET service.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Message to as the service about information on a channel.
Definition: cadet.h:390
Message handler for a specific message type.
Header for all communications.

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

Referenced by error_handler(), and GNUNET_CADET_get_channel().

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 149 of file cadet_api_get_channel.c.

151{
152 struct GNUNET_CADET_ChannelMonitor *cm = cls;
153
154 GNUNET_MQ_destroy (cm->mq);
155 cm->mq = NULL;
159 &reconnect,
160 cm);
161}
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:700
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:1277
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:834
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_TIME_Relative backoff
Backoff for reconnect attempts.

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 GNUNET_CLIENT_connect(), GNUNET_MQ_queue_for_callbacks(), and reconnect().

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