GNUnet  0.10.x
cadet_api_list_tunnels.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2011, 2017, 2019 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19 */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_cadet_service.h"
30 #include "cadet.h"
31 #include "cadet_protocol.h"
32 
33 
38 {
39 
44 
49 
54 
59 
64 
69 
70 };
71 
72 
79 static void
80 handle_get_tunnels (void *cls,
81  const struct GNUNET_CADET_LocalInfoTunnel *info)
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 }
94 
95 
102 static void
104  const struct GNUNET_MessageHeader *msg)
105 {
106  struct GNUNET_CADET_ListTunnels *lt = cls;
107  (void) msg;
108 
109  lt->tunnels_cb (lt->tunnels_cb_cls,
110  NULL);
112 }
113 
114 
120 static void
121 reconnect (void *cls);
122 
123 
130 static void
131 error_handler (void *cls,
132  enum GNUNET_MQ_Error error)
133 {
134  struct GNUNET_CADET_ListTunnels *lt = cls;
135 
136  GNUNET_MQ_destroy (lt->mq);
137  lt->mq = NULL;
141  &reconnect,
142  lt);
143 }
144 
145 
151 static void
152 reconnect (void *cls)
153 {
154  struct GNUNET_CADET_ListTunnels *lt = cls;
155  struct GNUNET_MQ_MessageHandler handlers[] = {
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 }
182 
183 
196  GNUNET_CADET_TunnelsCB callback,
197  void *callback_cls)
198 {
199  struct GNUNET_CADET_ListTunnels *lt;
200 
201  if (NULL == callback)
202  {
203  GNUNET_break (0);
204  return NULL;
205  }
206  lt = GNUNET_new (struct GNUNET_CADET_ListTunnels);
207  lt->tunnels_cb = callback;
208  lt->tunnels_cb_cls = callback_cls;
209  lt->cfg = cfg;
210  reconnect (lt);
211  if (NULL == lt->mq)
212  {
213  GNUNET_free (lt);
214  return NULL;
215  }
216  return lt;
217 }
218 
219 
226 void *
228 {
229  void *ret = lt->tunnels_cb_cls;
230 
231  if (NULL != lt->mq)
232  GNUNET_MQ_destroy (lt->mq);
233  if (NULL != lt->reconnect_task)
235  GNUNET_free (lt);
236  return ret;
237 }
238 
239 
240 /* end of cadet_api_list_tunnels.c */
uint16_t cstate
Connection state.
Definition: cadet.h:404
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
void * GNUNET_CADET_list_tunnels_cancel(struct GNUNET_CADET_ListTunnels *lt)
Cancel a monitor request.
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.
GNUNET_MQ_Error
Error codes for the queue.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
void(* GNUNET_CADET_TunnelsCB)(void *cls, const struct GNUNET_CADET_TunnelDetails *td)
Method called to retrieve information about all tunnels in CADET, called once per tunnel...
static void get_tunnels(void *cls)
Call CADET&#39;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.
struct GNUNET_PeerIdentity destination
ID of the destination of the tunnel (can be local peer).
Definition: cadet.h:389
uint16_t cstate
What is our connectivity state?
#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_new(type)
Allocate a struct or union of the given type.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS
Local information about all tunnels of service.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_PeerIdentity peer
Target of the tunnel.
Details about a tunnel managed by CADET.
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
void * tunnels_cb_cls
Info callback closure for tunnels_cb.
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.
uint32_t channels
How many channels use the tunnel.
Message to inform the client about one of the tunnels in the service.
Definition: cadet.h:373
Message handler for a specific message type.
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.
#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
uint32_t connections
Number of connections.
Definition: cadet.h:394
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.
P2P messages used by CADET.
uint32_t channels
Number of channels.
Definition: cadet.h:384
Handle to a message queue.
Definition: mq.c:85
uint16_t estate
What is our encryption state?
struct GNUNET_CADET_ListTunnels * GNUNET_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.
uint16_t estate
Encryption state.
Definition: cadet.h:399
struct GNUNET_TIME_Relative backoff
Backoff for reconnect attempts.
static void reconnect(void *cls)
Reconnect to the service and try again.
configuration data
Definition: configuration.c:85
Entry in list of pending tasks.
Definition: scheduler.c:134
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect.
uint32_t connections
How many connections support the tunnel.
Header for all communications.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
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
GNUNET_CADET_TunnelsCB tunnels_cb
Monitor callback.
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
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965