aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/cadet_api_list_tunnels.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/cadet_api_list_tunnels.c')
-rw-r--r--src/cadet/cadet_api_list_tunnels.c134
1 files changed, 66 insertions, 68 deletions
diff --git a/src/cadet/cadet_api_list_tunnels.c b/src/cadet/cadet_api_list_tunnels.c
index a2ba65993..2ea8cf26c 100644
--- a/src/cadet/cadet_api_list_tunnels.c
+++ b/src/cadet/cadet_api_list_tunnels.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file cadet/cadet_api_list_tunnels.c 21 * @file cadet/cadet_api_list_tunnels.c
22 * @brief cadet api: client implementation of cadet service 22 * @brief cadet api: client implementation of cadet service
@@ -34,9 +34,7 @@
34/** 34/**
35 * Operation handle. 35 * Operation handle.
36 */ 36 */
37struct GNUNET_CADET_ListTunnels 37struct GNUNET_CADET_ListTunnels {
38{
39
40 /** 38 /**
41 * Monitor callback 39 * Monitor callback
42 */ 40 */
@@ -46,7 +44,7 @@ struct GNUNET_CADET_ListTunnels
46 * Info callback closure for @c tunnels_cb. 44 * Info callback closure for @c tunnels_cb.
47 */ 45 */
48 void *tunnels_cb_cls; 46 void *tunnels_cb_cls;
49 47
50 /** 48 /**
51 * Message queue to talk to CADET service. 49 * Message queue to talk to CADET service.
52 */ 50 */
@@ -66,7 +64,6 @@ struct GNUNET_CADET_ListTunnels
66 * Backoff for reconnect attempts. 64 * Backoff for reconnect attempts.
67 */ 65 */
68 struct GNUNET_TIME_Relative backoff; 66 struct GNUNET_TIME_Relative backoff;
69
70}; 67};
71 68
72 69
@@ -77,19 +74,19 @@ struct GNUNET_CADET_ListTunnels
77 * @param info Message itself. 74 * @param info Message itself.
78 */ 75 */
79static void 76static void
80handle_get_tunnels (void *cls, 77handle_get_tunnels(void *cls,
81 const struct GNUNET_CADET_LocalInfoTunnel *info) 78 const struct GNUNET_CADET_LocalInfoTunnel *info)
82{ 79{
83 struct GNUNET_CADET_ListTunnels *lt = cls; 80 struct GNUNET_CADET_ListTunnels *lt = cls;
84 struct GNUNET_CADET_TunnelDetails td; 81 struct GNUNET_CADET_TunnelDetails td;
85 82
86 td.peer = info->destination; 83 td.peer = info->destination;
87 td.channels = ntohl (info->channels); 84 td.channels = ntohl(info->channels);
88 td.connections = ntohl (info->connections); 85 td.connections = ntohl(info->connections);
89 td.estate = ntohs (info->estate); 86 td.estate = ntohs(info->estate);
90 td.cstate = ntohs (info->cstate); 87 td.cstate = ntohs(info->cstate);
91 lt->tunnels_cb (lt->tunnels_cb_cls, 88 lt->tunnels_cb(lt->tunnels_cb_cls,
92 &td); 89 &td);
93} 90}
94 91
95 92
@@ -100,15 +97,16 @@ handle_get_tunnels (void *cls,
100 * @param message Message itself. 97 * @param message Message itself.
101 */ 98 */
102static void 99static void
103handle_get_tunnels_end (void *cls, 100handle_get_tunnels_end(void *cls,
104 const struct GNUNET_MessageHeader *msg) 101 const struct GNUNET_MessageHeader *msg)
105{ 102{
106 struct GNUNET_CADET_ListTunnels *lt = cls; 103 struct GNUNET_CADET_ListTunnels *lt = cls;
107 (void) msg; 104
108 105 (void)msg;
109 lt->tunnels_cb (lt->tunnels_cb_cls, 106
110 NULL); 107 lt->tunnels_cb(lt->tunnels_cb_cls,
111 GNUNET_CADET_list_tunnels_cancel (lt); 108 NULL);
109 GNUNET_CADET_list_tunnels_cancel(lt);
112} 110}
113 111
114 112
@@ -118,7 +116,7 @@ handle_get_tunnels_end (void *cls,
118 * @param cls a `struct GNUNET_CADET_ListTunnels` operation 116 * @param cls a `struct GNUNET_CADET_ListTunnels` operation
119 */ 117 */
120static void 118static void
121reconnect (void *cls); 119reconnect(void *cls);
122 120
123 121
124/** 122/**
@@ -128,18 +126,18 @@ reconnect (void *cls);
128 * @param error error code from MQ 126 * @param error error code from MQ
129 */ 127 */
130static void 128static void
131error_handler (void *cls, 129error_handler(void *cls,
132 enum GNUNET_MQ_Error error) 130 enum GNUNET_MQ_Error error)
133{ 131{
134 struct GNUNET_CADET_ListTunnels *lt = cls; 132 struct GNUNET_CADET_ListTunnels *lt = cls;
135 133
136 GNUNET_MQ_destroy (lt->mq); 134 GNUNET_MQ_destroy(lt->mq);
137 lt->mq = NULL; 135 lt->mq = NULL;
138 lt->backoff = GNUNET_TIME_randomized_backoff (lt->backoff, 136 lt->backoff = GNUNET_TIME_randomized_backoff(lt->backoff,
139 GNUNET_TIME_UNIT_MINUTES); 137 GNUNET_TIME_UNIT_MINUTES);
140 lt->reconnect_task = GNUNET_SCHEDULER_add_delayed (lt->backoff, 138 lt->reconnect_task = GNUNET_SCHEDULER_add_delayed(lt->backoff,
141 &reconnect, 139 &reconnect,
142 lt); 140 lt);
143} 141}
144 142
145 143
@@ -149,35 +147,35 @@ error_handler (void *cls,
149 * @param cls a `struct GNUNET_CADET_ListTunnels` operation 147 * @param cls a `struct GNUNET_CADET_ListTunnels` operation
150 */ 148 */
151static void 149static void
152reconnect (void *cls) 150reconnect(void *cls)
153{ 151{
154 struct GNUNET_CADET_ListTunnels *lt = cls; 152 struct GNUNET_CADET_ListTunnels *lt = cls;
155 struct GNUNET_MQ_MessageHandler handlers[] = { 153 struct GNUNET_MQ_MessageHandler handlers[] = {
156 GNUNET_MQ_hd_fixed_size (get_tunnels, 154 GNUNET_MQ_hd_fixed_size(get_tunnels,
157 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, 155 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
158 struct GNUNET_CADET_LocalInfoTunnel, 156 struct GNUNET_CADET_LocalInfoTunnel,
159 lt), 157 lt),
160 GNUNET_MQ_hd_fixed_size (get_tunnels_end, 158 GNUNET_MQ_hd_fixed_size(get_tunnels_end,
161 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END, 159 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END,
162 struct GNUNET_MessageHeader, 160 struct GNUNET_MessageHeader,
163 lt), 161 lt),
164 GNUNET_MQ_handler_end () 162 GNUNET_MQ_handler_end()
165 }; 163 };
166 struct GNUNET_MessageHeader *msg; 164 struct GNUNET_MessageHeader *msg;
167 struct GNUNET_MQ_Envelope *env; 165 struct GNUNET_MQ_Envelope *env;
168 166
169 lt->reconnect_task = NULL; 167 lt->reconnect_task = NULL;
170 lt->mq = GNUNET_CLIENT_connect (lt->cfg, 168 lt->mq = GNUNET_CLIENT_connect(lt->cfg,
171 "cadet", 169 "cadet",
172 handlers, 170 handlers,
173 &error_handler, 171 &error_handler,
174 lt); 172 lt);
175 if (NULL == lt->mq) 173 if (NULL == lt->mq)
176 return; 174 return;
177 env = GNUNET_MQ_msg (msg, 175 env = GNUNET_MQ_msg(msg,
178 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS); 176 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS);
179 GNUNET_MQ_send (lt->mq, 177 GNUNET_MQ_send(lt->mq,
180 env); 178 env);
181} 179}
182 180
183 181
@@ -192,27 +190,27 @@ reconnect (void *cls)
192 * @return NULL on error 190 * @return NULL on error
193 */ 191 */
194struct GNUNET_CADET_ListTunnels * 192struct GNUNET_CADET_ListTunnels *
195GNUNET_CADET_list_tunnels (const struct GNUNET_CONFIGURATION_Handle *cfg, 193GNUNET_CADET_list_tunnels(const struct GNUNET_CONFIGURATION_Handle *cfg,
196 GNUNET_CADET_TunnelsCB callback, 194 GNUNET_CADET_TunnelsCB callback,
197 void *callback_cls) 195 void *callback_cls)
198{ 196{
199 struct GNUNET_CADET_ListTunnels *lt; 197 struct GNUNET_CADET_ListTunnels *lt;
200 198
201 if (NULL == callback) 199 if (NULL == callback)
202 { 200 {
203 GNUNET_break (0); 201 GNUNET_break(0);
204 return NULL; 202 return NULL;
205 } 203 }
206 lt = GNUNET_new (struct GNUNET_CADET_ListTunnels); 204 lt = GNUNET_new(struct GNUNET_CADET_ListTunnels);
207 lt->tunnels_cb = callback; 205 lt->tunnels_cb = callback;
208 lt->tunnels_cb_cls = callback_cls; 206 lt->tunnels_cb_cls = callback_cls;
209 lt->cfg = cfg; 207 lt->cfg = cfg;
210 reconnect (lt); 208 reconnect(lt);
211 if (NULL == lt->mq) 209 if (NULL == lt->mq)
212 { 210 {
213 GNUNET_free (lt); 211 GNUNET_free(lt);
214 return NULL; 212 return NULL;
215 } 213 }
216 return lt; 214 return lt;
217} 215}
218 216
@@ -224,15 +222,15 @@ GNUNET_CADET_list_tunnels (const struct GNUNET_CONFIGURATION_Handle *cfg,
224 * @return Closure given to GNUNET_CADET_list_tunnels(). 222 * @return Closure given to GNUNET_CADET_list_tunnels().
225 */ 223 */
226void * 224void *
227GNUNET_CADET_list_tunnels_cancel (struct GNUNET_CADET_ListTunnels *lt) 225GNUNET_CADET_list_tunnels_cancel(struct GNUNET_CADET_ListTunnels *lt)
228{ 226{
229 void *ret = lt->tunnels_cb_cls; 227 void *ret = lt->tunnels_cb_cls;
230 228
231 if (NULL != lt->mq) 229 if (NULL != lt->mq)
232 GNUNET_MQ_destroy (lt->mq); 230 GNUNET_MQ_destroy(lt->mq);
233 if (NULL != lt->reconnect_task) 231 if (NULL != lt->reconnect_task)
234 GNUNET_SCHEDULER_cancel (lt->reconnect_task); 232 GNUNET_SCHEDULER_cancel(lt->reconnect_task);
235 GNUNET_free (lt); 233 GNUNET_free(lt);
236 return ret; 234 return ret;
237} 235}
238 236