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

79 {
80  struct GNUNET_CADET_ListTunnels *lt = cls;
82 
83  td.peer = info->destination;
84  td.channels = ntohl(info->channels);
85  td.connections = ntohl(info->connections);
86  td.estate = ntohs(info->estate);
87  td.cstate = ntohs(info->cstate);
88  lt->tunnels_cb(lt->tunnels_cb_cls,
89  &td);
90 }
uint16_t cstate
Connection state.
Definition: cadet.h:391
struct GNUNET_PeerIdentity destination
ID of the destination of the tunnel (can be local peer).
Definition: cadet.h:376
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:381
uint32_t channels
Number of channels.
Definition: cadet.h:371
uint16_t estate
Encryption state.
Definition: cadet.h:386
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 100 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.

102 {
103  struct GNUNET_CADET_ListTunnels *lt = cls;
104 
105  (void)msg;
106 
107  lt->tunnels_cb(lt->tunnels_cb_cls,
108  NULL);
110 }
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 150 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().

151 {
152  struct GNUNET_CADET_ListTunnels *lt = cls;
157  lt),
158  GNUNET_MQ_hd_fixed_size(get_tunnels_end,
160  struct GNUNET_MessageHeader,
161  lt),
163  };
164  struct GNUNET_MessageHeader *msg;
165  struct GNUNET_MQ_Envelope *env;
166 
167  lt->reconnect_task = NULL;
168  lt->mq = GNUNET_CLIENT_connect(lt->cfg,
169  "cadet",
170  handlers,
171  &error_handler,
172  lt);
173  if (NULL == lt->mq)
174  return;
175  env = GNUNET_MQ_msg(msg,
177  GNUNET_MQ_send(lt->mq,
178  env);
179 }
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
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:619
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:361
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:351
#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 129 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().

131 {
132  struct GNUNET_CADET_ListTunnels *lt = cls;
133 
134  GNUNET_MQ_destroy(lt->mq);
135  lt->mq = NULL;
139  &reconnect,
140  lt);
141 }
#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:1237
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: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
Here is the call graph for this function:
Here is the caller graph for this function: