aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-01-27 01:16:00 +0100
committerChristian Grothoff <christian@grothoff.org>2019-01-27 01:16:00 +0100
commit20c42b92b71cb31bc5ed9cc4e4ff32efbd95aae4 (patch)
tree5d2bc239e847974b2c57fefb8b88e9e8e593b50d /src/cadet
parentb22c452796ec17a0d596dc2d2a2636ee00e12d68 (diff)
downloadgnunet-20c42b92b71cb31bc5ed9cc4e4ff32efbd95aae4.tar.gz
gnunet-20c42b92b71cb31bc5ed9cc4e4ff32efbd95aae4.zip
more work on #5385
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/Makefile.am1
-rw-r--r--src/cadet/cadet_api_get_peer.c2
-rw-r--r--src/cadet/cadet_api_get_tunnel.c1
-rw-r--r--src/cadet/cadet_api_list_tunnels.c149
4 files changed, 93 insertions, 60 deletions
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am
index 57a716f29..8f4cd20d4 100644
--- a/src/cadet/Makefile.am
+++ b/src/cadet/Makefile.am
@@ -37,6 +37,7 @@ libgnunetcadet_la_SOURCES = \
37 cadet_api_get_peer.c \ 37 cadet_api_get_peer.c \
38 cadet_api_get_tunnel.c \ 38 cadet_api_get_tunnel.c \
39 cadet_api_list_peers.c \ 39 cadet_api_list_peers.c \
40 cadet_api_list_tunnels.c \
40 cadet_api_helper.c 41 cadet_api_helper.c
41libgnunetcadet_la_LIBADD = \ 42libgnunetcadet_la_LIBADD = \
42 $(top_builddir)/src/util/libgnunetutil.la \ 43 $(top_builddir)/src/util/libgnunetutil.la \
diff --git a/src/cadet/cadet_api_get_peer.c b/src/cadet/cadet_api_get_peer.c
index bfac8d583..6276de3a4 100644
--- a/src/cadet/cadet_api_get_peer.c
+++ b/src/cadet/cadet_api_get_peer.c
@@ -231,7 +231,7 @@ reconnect (void *cls)
231 * @param id Peer whose tunnel to examine. 231 * @param id Peer whose tunnel to examine.
232 * @param callback Function to call with the requested data. 232 * @param callback Function to call with the requested data.
233 * @param callback_cls Closure for @c callback. 233 * @param callback_cls Closure for @c callback.
234 * @return #GNUNET_OK / #GNUNET_SYSERR 234 * @return NULL on error
235 */ 235 */
236struct GNUNET_CADET_GetPeer * 236struct GNUNET_CADET_GetPeer *
237GNUNET_CADET_get_peer (const struct GNUNET_CONFIGURATION_Handle *cfg, 237GNUNET_CADET_get_peer (const struct GNUNET_CONFIGURATION_Handle *cfg,
diff --git a/src/cadet/cadet_api_get_tunnel.c b/src/cadet/cadet_api_get_tunnel.c
index 3b489dd82..1d2776352 100644
--- a/src/cadet/cadet_api_get_tunnel.c
+++ b/src/cadet/cadet_api_get_tunnel.c
@@ -150,6 +150,7 @@ handle_get_tunnel (void *cls,
150 conns, 150 conns,
151 ntohs (msg->estate), 151 ntohs (msg->estate),
152 ntohs (msg->cstate)); 152 ntohs (msg->cstate));
153 GNUNET_CADET_get_tunnel_cancel (gt);
153} 154}
154 155
155 156
diff --git a/src/cadet/cadet_api_list_tunnels.c b/src/cadet/cadet_api_list_tunnels.c
index 7d0534e41..631b321b7 100644
--- a/src/cadet/cadet_api_list_tunnels.c
+++ b/src/cadet/cadet_api_list_tunnels.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011, 2017 GNUnet e.V. 3 Copyright (C) 2011, 2017, 2019 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -71,26 +71,6 @@ struct GNUNET_CADET_ListTunnels
71 71
72 72
73/** 73/**
74 * Send message of @a type to CADET service of @a h
75 *
76 * @param h handle to CADET service
77 * @param type message type of trivial information request to send
78 */
79static void
80send_info_request (struct GNUNET_CADET_Handle *h,
81 uint16_t type)
82{
83 struct GNUNET_MessageHeader *msg;
84 struct GNUNET_MQ_Envelope *env;
85
86 env = GNUNET_MQ_msg (msg,
87 type);
88 GNUNET_MQ_send (h->mq,
89 env);
90}
91
92
93/**
94 * Check that message received from CADET service is well-formed. 74 * Check that message received from CADET service is well-formed.
95 * 75 *
96 * @param cls the `struct GNUNET_CADET_Handle` 76 * @param cls the `struct GNUNET_CADET_Handle`
@@ -117,59 +97,99 @@ check_get_tunnels (void *cls,
117/** 97/**
118 * Process a local reply about info on all tunnels, pass info to the user. 98 * Process a local reply about info on all tunnels, pass info to the user.
119 * 99 *
120 * @param cls Closure (Cadet handle). 100 * @param cls a `struct GNUNET_CADET_ListTunnels *`
121 * @param message Message itself. 101 * @param message Message itself.
122 */ 102 */
123static void 103static void
124handle_get_tunnels (void *cls, 104handle_get_tunnels (void *cls,
125 const struct GNUNET_MessageHeader *msg) 105 const struct GNUNET_MessageHeader *msg)
126{ 106{
127 struct GNUNET_CADET_Handle *h = cls; 107 struct GNUNET_CADET_ListTunnels *lt = cls;
128 const struct GNUNET_CADET_LocalInfoTunnel *info = 108 const struct GNUNET_CADET_LocalInfoTunnel *info =
129 (const struct GNUNET_CADET_LocalInfoTunnel *) msg; 109 (const struct GNUNET_CADET_LocalInfoTunnel *) msg;
130 110
131 if (NULL == h->info_cb.tunnels_cb) 111 // FIXME: use two message types!
132 return;
133 if (sizeof (struct GNUNET_CADET_LocalInfoTunnel) == ntohs (msg->size)) 112 if (sizeof (struct GNUNET_CADET_LocalInfoTunnel) == ntohs (msg->size))
134 h->info_cb.tunnels_cb (h->info_cls, 113 lt->tunnels_cb (lt->tunnels_cb_cls,
135 &info->destination, 114 &info->destination,
136 ntohl (info->channels), 115 ntohl (info->channels),
137 ntohl (info->connections), 116 ntohl (info->connections),
138 ntohs (info->estate), 117 ntohs (info->estate),
139 ntohs (info->cstate)); 118 ntohs (info->cstate));
140 else 119 else
141 h->info_cb.tunnels_cb (h->info_cls, 120 {
142 NULL, 121 lt->tunnels_cb (lt->tunnels_cb_cls,
143 0, 122 NULL,
144 0, 123 0,
145 0, 124 0,
146 0); 125 0,
126 0);
127 GNUNET_CADET_list_tunnels_cancel (lt);
128 }
147} 129}
148 130
149 131
132/**
133 * Reconnect to the service and try again.
134 *
135 * @param cls a `struct GNUNET_CADET_ListTunnels` operation
136 */
137static void
138reconnect (void *cls);
139
140
141/**
142 * Function called on connection trouble. Reconnects.
143 *
144 * @param cls a `struct GNUNET_CADET_ListTunnels`
145 * @param error error code from MQ
146 */
147static void
148error_handler (void *cls,
149 enum GNUNET_MQ_Error error)
150{
151 struct GNUNET_CADET_ListTunnels *lt = cls;
152
153 GNUNET_MQ_destroy (lt->mq);
154 lt->mq = NULL;
155 lt->backoff = GNUNET_TIME_randomized_backoff (lt->backoff,
156 GNUNET_TIME_UNIT_MINUTES);
157 lt->reconnect_task = GNUNET_SCHEDULER_add_delayed (lt->backoff,
158 &reconnect,
159 lt);
160}
161
162
163/**
164 * Reconnect to the service and try again.
165 *
166 * @param cls a `struct GNUNET_CADET_ListTunnels` operation
167 */
150static void 168static void
151reconnect (void *cls) 169reconnect (void *cls)
152{ 170{
153 struct GNUNET_CADET_ListTunnels *lt = cls; 171 struct GNUNET_CADET_ListTunnels *lt = cls;
154 struct GNUNET_MQ_MessageHandler *handlers[] = { 172 struct GNUNET_MQ_MessageHandler handlers[] = {
155 GNUNET_MQ_hd_var_size (get_tunnels, 173 GNUNET_MQ_hd_var_size (get_tunnels,
156 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, 174 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
157 struct GNUNET_MessageHeader, 175 struct GNUNET_MessageHeader,
158 h), 176 lt),
159 GNUNET_MQ_handler_end () 177 GNUNET_MQ_handler_end ()
160 } 178 };
161 struct GNUNET_MessageHeader *msg; 179 struct GNUNET_MessageHeader *msg;
162 struct GNUNET_MQ_Envelope *env; 180 struct GNUNET_MQ_Envelope *env;
163 181
164 cm->mq = GNUNET_CLIENT_connect (cm->cfg, 182 lt->reconnect_task = NULL;
183 lt->mq = GNUNET_CLIENT_connect (lt->cfg,
165 "cadet", 184 "cadet",
166 handlers, 185 handlers,
167 &error_handler, 186 &error_handler,
168 cm); 187 lt);
169 188 if (NULL == lt->mq)
189 return;
170 env = GNUNET_MQ_msg (msg, 190 env = GNUNET_MQ_msg (msg,
171 type); 191 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS);
172 GNUNET_MQ_send (cm->mq, 192 GNUNET_MQ_send (lt->mq,
173 env); 193 env);
174} 194}
175 195
@@ -184,41 +204,52 @@ reconnect (void *cls)
184 * @param h Handle to the cadet peer. 204 * @param h Handle to the cadet peer.
185 * @param callback Function to call with the requested data. 205 * @param callback Function to call with the requested data.
186 * @param callback_cls Closure for @c callback. 206 * @param callback_cls Closure for @c callback.
187 * @return #GNUNET_OK / #GNUNET_SYSERR 207 * @return NULL on error
188 */ 208 */
189struct GNUNET_CADET_ListTunnels * 209struct GNUNET_CADET_ListTunnels *
190GNUNET_CADET_list_tunnels (const struct GNUNET_CONFIGURATION_Handle *cfg, 210GNUNET_CADET_list_tunnels (const struct GNUNET_CONFIGURATION_Handle *cfg,
191 GNUNET_CADET_TunnelsCB callback, 211 GNUNET_CADET_TunnelsCB callback,
192 void *callback_cls) 212 void *callback_cls)
193{ 213{
214 struct GNUNET_CADET_ListTunnels *lt;
194 215
195 if (NULL != h->info_cb.tunnels_cb) 216 if (NULL == callback)
196 { 217 {
197 GNUNET_break (0); 218 GNUNET_break (0);
198 return GNUNET_SYSERR; 219 return NULL;
199 } 220 }
200 send_info_request (h, 221 lt = GNUNET_new (struct GNUNET_CADET_ListTunnels);
201 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS); 222 lt->tunnels_cb = callback;
202 h->info_cb.tunnels_cb = callback; 223 lt->tunnels_cb_cls = callback_cls;
203 h->info_cls = callback_cls; 224 lt->cfg = cfg;
204 return GNUNET_OK; 225 reconnect (lt);
226 if (NULL == lt->mq)
227 {
228 GNUNET_free (lt);
229 return NULL;
230 }
231 return lt;
205} 232}
206 233
207 234
208/** 235/**
209 * Cancel a monitor request. The monitor callback will not be called. 236 * Cancel a monitor request. The monitor callback will not be called.
210 * 237 *
211 * @param h Cadet handle. 238 * @param lt operation handle
212 * @return Closure given to GNUNET_CADET_list_tunnels(). 239 * @return Closure given to GNUNET_CADET_list_tunnels().
213 */ 240 */
214void * 241void *
215GNUNET_CADET_list_tunnels_cancel (struct GNUNET_CADET_ListTunnels *lt) 242GNUNET_CADET_list_tunnels_cancel (struct GNUNET_CADET_ListTunnels *lt)
216{ 243{
217 void *cls = h->info_cls; 244 void *ret = lt->tunnels_cb_cls;
218 245
219 h->info_cb.tunnels_cb = NULL; 246 if (NULL != lt->mq)
220 h->info_cls = NULL; 247 GNUNET_MQ_destroy (lt->mq);
221 return cls; 248 if (NULL != lt->reconnect_task)
249 GNUNET_SCHEDULER_cancel (lt->reconnect_task);
250 GNUNET_free (lt);
251 return ret;
222} 252}
223 253
224 254
255/* end of cadet_api_list_tunnels.c */