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

Go to the source code of this file.

Data Structures

struct  GNUNET_CADET_ListTunnels
 Operation handle. More...
 

Functions

static void handle_get_tunnels (void *cls, const struct GNUNET_CADET_LocalInfoTunnel *info)
 Process a local reply about info on all tunnels, pass info to the user. More...
 
static void handle_get_tunnels_end (void *cls, const struct GNUNET_MessageHeader *msg)
 Process a local reply about info on all tunnels, 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_ListTunnelsGNUNET_CADET_list_tunnels (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CADET_TunnelsCB callback, void *callback_cls)
 Request information about tunnels of the running cadet peer. More...
 
void * GNUNET_CADET_list_tunnels_cancel (struct GNUNET_CADET_ListTunnels *lt)
 Cancel a monitor request. More...
 

Detailed Description

cadet api: client implementation of cadet service

Author
Bartlomiej Polot
Christian Grothoff

Definition in file cadet_api_list_tunnels.c.

Function Documentation

◆ handle_get_tunnels()

static void handle_get_tunnels ( void *  cls,
const struct GNUNET_CADET_LocalInfoTunnel info 
)
static

Process a local reply about info on all tunnels, pass info to the user.

Parameters
clsa struct GNUNET_CADET_ListTunnels *
infoMessage itself.

Definition at line 80 of file cadet_api_list_tunnels.c.

References GNUNET_CADET_LocalInfoTunnel::channels, GNUNET_CADET_TunnelDetails::channels, GNUNET_CADET_LocalInfoTunnel::connections, GNUNET_CADET_TunnelDetails::connections, GNUNET_CADET_LocalInfoTunnel::cstate, GNUNET_CADET_TunnelDetails::cstate, GNUNET_CADET_LocalInfoTunnel::destination, GNUNET_CADET_LocalInfoTunnel::estate, GNUNET_CADET_TunnelDetails::estate, GNUNET_CADET_TunnelDetails::peer, GNUNET_CADET_ListTunnels::tunnels_cb, and GNUNET_CADET_ListTunnels::tunnels_cb_cls.

82 {
83  struct GNUNET_CADET_ListTunnels *lt = cls;
85 
86  td.peer = info->destination;
87  td.channels = ntohl (info->channels);
88  td.connections = ntohl (info->connections);
89  td.estate = ntohs (info->estate);
90  td.cstate = ntohs (info->cstate);
91  lt->tunnels_cb (lt->tunnels_cb_cls,
92  &td);
93 }
uint16_t cstate
Connection state.
Definition: cadet.h:404
struct GNUNET_PeerIdentity destination
ID of the destination of the tunnel (can be local peer).
Definition: cadet.h:389
struct GNUNET_PeerIdentity peer
Target of the tunnel.
Details about a tunnel managed by CADET.
void * tunnels_cb_cls
Info callback closure for tunnels_cb.
uint32_t connections
Number of connections.
Definition: cadet.h:394
uint32_t channels
Number of channels.
Definition: cadet.h:384
uint16_t estate
Encryption state.
Definition: cadet.h:399
GNUNET_CADET_TunnelsCB tunnels_cb
Monitor callback.

◆ handle_get_tunnels_end()

static void handle_get_tunnels_end ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Process a local reply about info on all tunnels, pass info to the user.

Parameters
clsa struct GNUNET_CADET_ListTunnels *
messageMessage itself.

Definition at line 103 of file cadet_api_list_tunnels.c.

References GNUNET_CADET_list_tunnels_cancel(), reconnect(), GNUNET_CADET_ListTunnels::tunnels_cb, and GNUNET_CADET_ListTunnels::tunnels_cb_cls.

105 {
106  struct GNUNET_CADET_ListTunnels *lt = cls;
107  (void) msg;
108 
109  lt->tunnels_cb (lt->tunnels_cb_cls,
110  NULL);
112 }
void * GNUNET_CADET_list_tunnels_cancel(struct GNUNET_CADET_ListTunnels *lt)
Cancel a monitor request.
void * tunnels_cb_cls
Info callback closure for tunnels_cb.
GNUNET_CADET_TunnelsCB tunnels_cb
Monitor callback.
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_ListTunnels operation

Definition at line 152 of file cadet_api_list_tunnels.c.

References GNUNET_CADET_ListTunnels::cfg, env, error_handler(), get_tunnels(), GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END, GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_CADET_ListTunnels::mq, msg, and GNUNET_CADET_ListTunnels::reconnect_task.

Referenced by error_handler(), GNUNET_CADET_list_tunnels(), and handle_get_tunnels_end().

153 {
154  struct GNUNET_CADET_ListTunnels *lt = cls;
159  lt),
160  GNUNET_MQ_hd_fixed_size (get_tunnels_end,
162  struct GNUNET_MessageHeader,
163  lt),
165  };
166  struct GNUNET_MessageHeader *msg;
167  struct GNUNET_MQ_Envelope *env;
168 
169  lt->reconnect_task = NULL;
170  lt->mq = GNUNET_CLIENT_connect (lt->cfg,
171  "cadet",
172  handlers,
173  &error_handler,
174  lt);
175  if (NULL == lt->mq)
176  return;
177  env = GNUNET_MQ_msg (msg,
179  GNUNET_MQ_send (lt->mq,
180  env);
181 }
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:901
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
Function called on connection trouble.
static void get_tunnels(void *cls)
Call CADET's meta API, get all tunnels known to a peer.
Definition: gnunet-cadet.c:649
struct GNUNET_MQ_Handle * mq
Message queue to talk to CADET service.
#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
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS
Local information about all tunnels of service.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
Message to inform the client about one of the tunnels in the service.
Definition: cadet.h:373
Message handler for a specific message type.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END
End of local information about all tunnels of service.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS
Request local information about all tunnels of service.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect.
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_ListTunnels
errorerror code from MQ

Definition at line 131 of file cadet_api_list_tunnels.c.

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

Referenced by reconnect().

133 {
134  struct GNUNET_CADET_ListTunnels *lt = cls;
135 
136  GNUNET_MQ_destroy (lt->mq);
137  lt->mq = NULL;
141  &reconnect,
142  lt);
143 }
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_MQ_Handle * mq
Message queue to talk to CADET service.
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:1246
struct GNUNET_TIME_Relative backoff
Backoff for reconnect attempts.
static void reconnect(void *cls)
Reconnect to the service and try again.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect.
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:759
Here is the call graph for this function:
Here is the caller graph for this function: