aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-01-27 00:36:47 +0100
committerChristian Grothoff <christian@grothoff.org>2019-01-27 00:36:47 +0100
commit65b339b7ce68fcbaec9df6f66e8ed45e60b39ce1 (patch)
treefff17cdb219935617877a5504bb8435712b80a61 /src/cadet
parent8f884f001a70fee622fff0c0ac8c38a0634df789 (diff)
downloadgnunet-65b339b7ce68fcbaec9df6f66e8ed45e60b39ce1.tar.gz
gnunet-65b339b7ce68fcbaec9df6f66e8ed45e60b39ce1.zip
more work on #5385
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/Makefile.am2
-rw-r--r--src/cadet/cadet_api_get_channel.c98
-rw-r--r--src/cadet/cadet_api_get_peer.c101
-rw-r--r--src/cadet/cadet_api_list_peers.c179
-rw-r--r--src/cadet/cadet_api_list_tunnels.c26
5 files changed, 310 insertions, 96 deletions
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am
index bccaf2cd9..62eaad38c 100644
--- a/src/cadet/Makefile.am
+++ b/src/cadet/Makefile.am
@@ -34,6 +34,8 @@ lib_LTLIBRARIES = \
34 34
35libgnunetcadet_la_SOURCES = \ 35libgnunetcadet_la_SOURCES = \
36 cadet_api.c \ 36 cadet_api.c \
37 cadet_api_get_peer.c \
38 cadet_api_list_peers.c \
37 cadet_api_helper.c 39 cadet_api_helper.c
38libgnunetcadet_la_LIBADD = \ 40libgnunetcadet_la_LIBADD = \
39 $(top_builddir)/src/util/libgnunetutil.la \ 41 $(top_builddir)/src/util/libgnunetutil.la \
diff --git a/src/cadet/cadet_api_get_channel.c b/src/cadet/cadet_api_get_channel.c
index cd90f5b78..d41337522 100644
--- a/src/cadet/cadet_api_get_channel.c
+++ b/src/cadet/cadet_api_get_channel.c
@@ -31,9 +31,8 @@
31#include "cadet_protocol.h" 31#include "cadet_protocol.h"
32 32
33 33
34
35/** 34/**
36 * Ugly legacy hack. 35 * Operation handle.
37 */ 36 */
38struct GNUNET_CADET_ChannelMonitor 37struct GNUNET_CADET_ChannelMonitor
39{ 38{
@@ -48,23 +47,81 @@ struct GNUNET_CADET_ChannelMonitor
48 */ 47 */
49 void *channel_cb_cls; 48 void *channel_cb_cls;
50 49
50 /**
51 * Configuration we use.
52 */
51 const struct GNUNET_CONFIGURATION_Handle *cfg; 53 const struct GNUNET_CONFIGURATION_Handle *cfg;
52 54
55 /**
56 * Message queue to talk to CADET service.
57 */
53 struct GNUNET_MQ_Handle *mq; 58 struct GNUNET_MQ_Handle *mq;
54 59
60 /**
61 * Task to reconnect.
62 */
63 struct GNUNET_SCHEDULER_Task *reconnect_task;
64
65 /**
66 * Backoff for reconnect attempts.
67 */
68 struct GNUNET_TIME_Relative backoff;
69
70 /**
71 * Peer we want information about.
72 */
55 struct GNUNET_PeerIdentity peer; 73 struct GNUNET_PeerIdentity peer;
56 74
75 /**
76 * Channel we want information about.
77 */
57 uint32_t /* UGH */ channel_number; 78 uint32_t /* UGH */ channel_number;
58 79
59}; 80};
60 81
61 82
83/**
84 * Reconnect to the service and try again.
85 *
86 * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation
87 */
88static void
89reconnect (void *cls);
90
91
92/**
93 * Function called on connection trouble. Reconnects.
94 *
95 * @param cls a `struct GNUNET_CADET_ChannelMonitor``
96 * @param error error code from MQ
97 */
98static void
99error_handler (void *cls,
100 enum GNUNET_MQ_Error error)
101{
102 struct GNUNET_CADET_ChannelMonitor *cm = cls;
103
104 GNUNET_MQ_destroy (cm->mq);
105 cm->mq = NULL;
106 cm->backoff = GNUNET_TIME_randomized_backoff (cm->backoff,
107 GNUNET_TIME_UNIT_MINUTES);
108 cm->reconnect_task = GNUNET_SCHEDULER_add_delayed (cm->backoff,
109 &reconnect,
110 cm);
111}
112
62 113
114/**
115 * Reconnect to the service and try again.
116 *
117 * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation
118 */
63static void 119static void
64reconnect (void *cls) 120reconnect (void *cls)
65{ 121{
66 struct GNUNET_CADET_ChannelMonitor *cm = cls; 122 struct GNUNET_CADET_ChannelMonitor *cm = cls;
67 struct GNUNET_MQ_MessageHandler *handlers[] = { 123 struct GNUNET_MQ_MessageHandler *handlers[] = {
124 FIXME
68 } 125 }
69 struct GNUNET_MessageHeader *msg; 126 struct GNUNET_MessageHeader *msg;
70 struct GNUNET_MQ_Envelope *env; 127 struct GNUNET_MQ_Envelope *env;
@@ -100,10 +157,45 @@ GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg,
100 GNUNET_CADET_ChannelCB callback, 157 GNUNET_CADET_ChannelCB callback,
101 void *callback_cls) 158 void *callback_cls)
102{ 159{
160 struct GNUNET_CADET_ChannelMonitor *cm;
161
162 if (NULL == callback)
163 {
164 GNUNET_break (0);
165 return NULL;
166 }
167 cm = GNUNET_new (struct GNUNET_CADET_ChannelMonitor);
168 cm->peer_cb = callback;
169 cm->peer_cb_cls = callback_cls;
170 cm->cfg = cfg;
171 cm->id = *id;
172 reconnect (cm);
173 if (NULL == cm->mq)
174 {
175 GNUNET_free (cm);
176 return NULL;
177 }
178 return cm;
103} 179}
104 180
105 181
182/**
183 * Cancel a channel monitor request. The callback will not be called (anymore).
184 *
185 * @param h Cadet handle.
186 * @return Closure that was given to #GNUNET_CADET_get_channel().
187 */
106void * 188void *
107GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm) 189GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm)
108{ 190{
191 void *ret = cm->peer_cb_cls;
192
193 if (NULL != cm->mq)
194 GNUNET_MQ_destroy (cm->mq);
195 if (NULL != cm->reconnect_task)
196 GNUNET_SCHEDULER_cancel (cm->reconnect_task);
197 GNUNET_free (cm);
198 return ret;
109} 199}
200
201/* end of cadet_api_get_channel.c */
diff --git a/src/cadet/cadet_api_get_peer.c b/src/cadet/cadet_api_get_peer.c
index c7d6e324b..e86c1567c 100644
--- a/src/cadet/cadet_api_get_peer.c
+++ b/src/cadet/cadet_api_get_peer.c
@@ -32,7 +32,7 @@
32 32
33 33
34/** 34/**
35 * 35 * Operation handle.
36 */ 36 */
37struct GNUNET_CADET_GetPeer 37struct GNUNET_CADET_GetPeer
38{ 38{
@@ -43,15 +43,35 @@ struct GNUNET_CADET_GetPeer
43 GNUNET_CADET_PeerCB peer_cb; 43 GNUNET_CADET_PeerCB peer_cb;
44 44
45 /** 45 /**
46 * Info callback closure for @c info_cb. 46 * Closure for @c peer_cb.
47 */ 47 */
48 void *peer_cb_cls; 48 void *peer_cb_cls;
49 49
50 struct GNUNET_PeerIdentity id; 50 /**
51 51 * Message queue to talk to CADET service.
52 */
52 struct GNUNET_MQ_Handle *mq; 53 struct GNUNET_MQ_Handle *mq;
53 54
55 /**
56 * Configuration we use.
57 */
54 const struct GNUNET_CONFIGURATION_Handle *cfg; 58 const struct GNUNET_CONFIGURATION_Handle *cfg;
59
60 /**
61 * Task to reconnect.
62 */
63 struct GNUNET_SCHEDULER_Task *reconnect_task;
64
65 /**
66 * Backoff for reconnect attempts.
67 */
68 struct GNUNET_TIME_Relative backoff;
69
70 /**
71 * Peer we want information about.
72 */
73 struct GNUNET_PeerIdentity id;
74
55}; 75};
56 76
57 77
@@ -103,11 +123,6 @@ handle_get_peer (void *cls,
103 int neighbor; 123 int neighbor;
104 unsigned int peers; 124 unsigned int peers;
105 125
106
107 LOG (GNUNET_ERROR_TYPE_DEBUG,
108 "number of paths %u\n",
109 ntohs (message->paths));
110
111 paths = ntohs (message->paths); 126 paths = ntohs (message->paths);
112 paths_array = (const struct GNUNET_PeerIdentity *) &message[1]; 127 paths_array = (const struct GNUNET_PeerIdentity *) &message[1];
113 peers = (ntohs (message->header.size) - sizeof (*message)) 128 peers = (ntohs (message->header.size) - sizeof (*message))
@@ -117,11 +132,9 @@ handle_get_peer (void *cls,
117 132
118 for (unsigned int i = 0; i < peers; i++) 133 for (unsigned int i = 0; i < peers; i++)
119 { 134 {
120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
121 " %s\n",
122 GNUNET_i2s (&paths_array[i]));
123 path_length++; 135 path_length++;
124 if (0 == memcmp (&paths_array[i], &message->destination, 136 if (0 == memcmp (&paths_array[i],
137 &message->destination,
125 sizeof (struct GNUNET_PeerIdentity))) 138 sizeof (struct GNUNET_PeerIdentity)))
126 { 139 {
127 if (1 == path_length) 140 if (1 == path_length)
@@ -130,7 +143,7 @@ handle_get_peer (void *cls,
130 } 143 }
131 } 144 }
132 145
133 /* Call Callback with tunnel info. */ 146 /* Call Callback with tunnel info */
134 paths_array = (const struct GNUNET_PeerIdentity *) &message[1]; 147 paths_array = (const struct GNUNET_PeerIdentity *) &message[1];
135 gp->peer_cb (gp->peer_cb_cls, 148 gp->peer_cb (gp->peer_cb_cls,
136 &message->destination, 149 &message->destination,
@@ -144,20 +157,57 @@ handle_get_peer (void *cls,
144} 157}
145 158
146 159
160/**
161 * Reconnect to the service and try again.
162 *
163 * @param cls a `struct GNUNET_CADET_GetPeer` operation
164 */
165static void
166reconnect (void *cls);
167
168
169/**
170 * Function called on connection trouble. Reconnects.
171 *
172 * @param cls a `struct GNUNET_CADET_GetPeer`
173 * @param error error code from MQ
174 */
175static void
176error_handler (void *cls,
177 enum GNUNET_MQ_Error error)
178{
179 struct GNUNET_CADET_GetPeer *gp = cls;
180
181 GNUNET_MQ_destroy (gp->mq);
182 gp->mq = NULL;
183 gp->backoff = GNUNET_TIME_randomized_backoff (gp->backoff,
184 GNUNET_TIME_UNIT_MINUTES);
185 gp->reconnect_task = GNUNET_SCHEDULER_add_delayed (gp->backoff,
186 &reconnect,
187 gp);
188}
189
190
191/**
192 * Reconnect to the service and try again.
193 *
194 * @param cls a `struct GNUNET_CADET_GetPeer` operation
195 */
147static void 196static void
148reconnect (void *cls) 197reconnect (void *cls)
149{ 198{
150 struct GNUNET_CADET_GetPeer *gp = cls; 199 struct GNUNET_CADET_GetPeer *gp = cls;
151 struct GNUNET_MQ_MessageHandler *handlers[] = { 200 struct GNUNET_MQ_MessageHandler handlers[] = {
152 GNUNET_MQ_hd_var_size (get_peer, 201 GNUNET_MQ_hd_var_size (get_peer,
153 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER, 202 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER,
154 struct GNUNET_CADET_LocalInfoPeer, 203 struct GNUNET_CADET_LocalInfoPeer,
155 h), 204 gp),
156 GNUNET_MQ_handler_end () 205 GNUNET_MQ_handler_end ()
157 } 206 };
158 struct GNUNET_CADET_LocalInfo *msg; 207 struct GNUNET_CADET_LocalInfo *msg;
159 struct GNUNET_MQ_Envelope *env; 208 struct GNUNET_MQ_Envelope *env;
160 209
210 gp->reconnect_task = NULL;
161 gp->mq = GNUNET_CLIENT_connect (gp->cfg, 211 gp->mq = GNUNET_CLIENT_connect (gp->cfg,
162 "cadet", 212 "cadet",
163 handlers, 213 handlers,
@@ -168,7 +218,7 @@ reconnect (void *cls)
168 env = GNUNET_MQ_msg (msg, 218 env = GNUNET_MQ_msg (msg,
169 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); 219 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER);
170 msg->peer = gp->id; 220 msg->peer = gp->id;
171 GNUNET_MQ_send (lt->mq, 221 GNUNET_MQ_send (gp->mq,
172 env); 222 env);
173} 223}
174 224
@@ -211,15 +261,24 @@ GNUNET_CADET_get_peer (const struct GNUNET_CONFIGURATION_Handle *cfg,
211} 261}
212 262
213 263
214 264/**
265 * Cancel @a gp operation.
266 *
267 * @param gp operation to cancel
268 * @return closure from #GNUNET_CADET_get_peer().
269 */
215void * 270void *
216GNUNET_CADET_get_peer_cancel (struct GNUNET_CADET_GetPeer *gp) 271GNUNET_CADET_get_peer_cancel (struct GNUNET_CADET_GetPeer *gp)
217{ 272{
218 void *ret = gp->peer_cb_cls; 273 void *ret = gp->peer_cb_cls;
219 274
220 GNUNET_MQ_disconnect (gp->mq); 275 if (NULL != gp->mq)
276 GNUNET_MQ_destroy (gp->mq);
277 if (NULL != gp->reconnect_task)
278 GNUNET_SCHEDULER_cancel (gp->reconnect_task);
221 GNUNET_free (gp); 279 GNUNET_free (gp);
222 return ret; 280 return ret;
223} 281}
224 282
225 283
284/* end of cadet_api_get_peer.c */
diff --git a/src/cadet/cadet_api_list_peers.c b/src/cadet/cadet_api_list_peers.c
index f6563a290..d53bcf65d 100644
--- a/src/cadet/cadet_api_list_peers.c
+++ b/src/cadet/cadet_api_list_peers.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
@@ -18,7 +18,7 @@
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.c 21 * @file cadet/cadet_api_list_peers.c
22 * @brief cadet api: client implementation of cadet service 22 * @brief cadet api: client implementation of cadet service
23 * @author Bartlomiej Polot 23 * @author Bartlomiej Polot
24 * @author Christian Grothoff 24 * @author Christian Grothoff
@@ -31,9 +31,8 @@
31#include "cadet_protocol.h" 31#include "cadet_protocol.h"
32 32
33 33
34
35/** 34/**
36 * Ugly legacy hack. 35 * Operation handle.
37 */ 36 */
38struct GNUNET_CADET_PeersLister 37struct GNUNET_CADET_PeersLister
39{ 38{
@@ -47,33 +46,34 @@ struct GNUNET_CADET_PeersLister
47 * Info callback closure for @c info_cb. 46 * Info callback closure for @c info_cb.
48 */ 47 */
49 void *peers_cb_cls; 48 void *peers_cb_cls;
50};
51 49
50 /**
51 * Message queue to talk to CADET service.
52 */
53 struct GNUNET_MQ_Handle *mq;
52 54
53/** 55 /**
54 * Send message of @a type to CADET service of @a h 56 * Configuration we use.
55 * 57 */
56 * @param h handle to CADET service 58 const struct GNUNET_CONFIGURATION_Handle *cfg;
57 * @param type message type of trivial information request to send
58 */
59static void
60send_info_request (struct GNUNET_CADET_Handle *h,
61 uint16_t type)
62{
63 struct GNUNET_MessageHeader *msg;
64 struct GNUNET_MQ_Envelope *env;
65 59
66 env = GNUNET_MQ_msg (msg, 60 /**
67 type); 61 * Task to reconnect.
68 GNUNET_MQ_send (h->mq, 62 */
69 env); 63 struct GNUNET_SCHEDULER_Task *reconnect_task;
70} 64
65 /**
66 * Backoff for reconnect attempts.
67 */
68 struct GNUNET_TIME_Relative backoff;
69
70};
71 71
72 72
73/** 73/**
74 * Check that message received from CADET service is well-formed. 74 * Check that message received from CADET service is well-formed.
75 * 75 *
76 * @param cls the `struct GNUNET_CADET_Handle` 76 * @param cls the `struct GNUNET_CADET_PeersLister`
77 * @param message the message we got 77 * @param message the message we got
78 * @return #GNUNET_OK if the message is well-formed, 78 * @return #GNUNET_OK if the message is well-formed,
79 * #GNUNET_SYSERR otherwise 79 * #GNUNET_SYSERR otherwise
@@ -94,60 +94,97 @@ check_get_peers (void *cls,
94} 94}
95 95
96 96
97// FIXME: use two different message types instead of this mess!
97/** 98/**
98 * Process a local reply about info on all tunnels, pass info to the user. 99 * Process a local reply about info on all tunnels, pass info to the user.
99 * 100 *
100 * @param cls Closure (Cadet handle). 101 * @param cls a `struct GNUNET_CADET_PeersLister`
101 * @param msg Message itself. 102 * @param msg Message itself.
102 */ 103 */
103static void 104static void
104handle_get_peers (void *cls, 105handle_get_peers (void *cls,
105 const struct GNUNET_MessageHeader *msg) 106 const struct GNUNET_MessageHeader *msg)
106{ 107{
107 struct GNUNET_CADET_Handle *h = cls; 108 struct GNUNET_CADET_PeersLister *pl = cls;
108 const struct GNUNET_CADET_LocalInfoPeer *info = 109 const struct GNUNET_CADET_LocalInfoPeer *info =
109 (const struct GNUNET_CADET_LocalInfoPeer *) msg; 110 (const struct GNUNET_CADET_LocalInfoPeer *) msg;
110 111
111 if (NULL == h->info_cb.peers_cb)
112 return;
113 if (sizeof (struct GNUNET_CADET_LocalInfoPeer) == ntohs (msg->size)) 112 if (sizeof (struct GNUNET_CADET_LocalInfoPeer) == ntohs (msg->size))
114 h->info_cb.peers_cb (h->info_cls, 113 pl->peers_cb (pl->peers_cb_cls,
115 &info->destination, 114 &info->destination,
116 (int) ntohs (info->tunnel), 115 (int) ntohs (info->tunnel),
117 (unsigned int) ntohs (info->paths), 116 (unsigned int) ntohs (info->paths),
118 0); 117 0);
119 else 118 else
120 h->info_cb.peers_cb (h->info_cls, 119 {
121 NULL, 120 pl->peers_cb (pl->peers_cb_cls,
122 0, 121 NULL,
123 0, 122 0,
124 0); 123 0,
124 0);
125 GNUNET_CADET_list_peers_cancel (pl);
126 }
127}
128
129
130/**
131 * Reconnect to the service and try again.
132 *
133 * @param cls a `struct GNUNET_CADET_PeersLister` operation
134 */
135static void
136reconnect (void *cls);
137
138
139/**
140 * Function called on connection trouble. Reconnects.
141 *
142 * @param cls a `struct GNUNET_CADET_PeersLister`
143 * @param error error code from MQ
144 */
145static void
146error_handler (void *cls,
147 enum GNUNET_MQ_Error error)
148{
149 struct GNUNET_CADET_PeersLister *pl = cls;
150
151 GNUNET_MQ_destroy (pl->mq);
152 pl->mq = NULL;
153 pl->backoff = GNUNET_TIME_randomized_backoff (pl->backoff,
154 GNUNET_TIME_UNIT_MINUTES);
155 pl->reconnect_task = GNUNET_SCHEDULER_add_delayed (pl->backoff,
156 &reconnect,
157 pl);
125} 158}
126 159
127 160
161/**
162 * Reconnect to the service and try again.
163 *
164 * @param cls a `struct GNUNET_CADET_PeersLister` operation
165 */
128static void 166static void
129reconnect (void *cls) 167reconnect (void *cls)
130{ 168{
131 struct GNUNET_CADET_ListTunnels *lt = cls; 169 struct GNUNET_CADET_PeersLister *pl = cls;
132 struct GNUNET_MQ_MessageHandler *handlers[] = { 170 struct GNUNET_MQ_MessageHandler handlers[] = {
133 GNUNET_MQ_hd_var_size (get_peers, 171 GNUNET_MQ_hd_var_size (get_peers,
134 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, 172 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS,
135 struct GNUNET_MessageHeader, 173 struct GNUNET_MessageHeader,
136 h), 174 pl),
137 GNUNET_MQ_handler_end () 175 GNUNET_MQ_handler_end ()
138 } 176 };
139 struct GNUNET_MessageHeader *msg; 177 struct GNUNET_MessageHeader *msg;
140 struct GNUNET_MQ_Envelope *env; 178 struct GNUNET_MQ_Envelope *env;
141 179
142 cm->mq = GNUNET_CLIENT_connect (cm->cfg, 180 pl->mq = GNUNET_CLIENT_connect (pl->cfg,
143 "cadet", 181 "cadet",
144 handlers, 182 handlers,
145 &error_handler, 183 &error_handler,
146 cm); 184 pl);
147
148 env = GNUNET_MQ_msg (msg, 185 env = GNUNET_MQ_msg (msg,
149 type); 186 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS);
150 GNUNET_MQ_send (cm->mq, 187 GNUNET_MQ_send (pl->mq,
151 env); 188 env);
152} 189}
153 190
@@ -157,50 +194,54 @@ reconnect (void *cls)
157 * The callback will be called for every peer known to the service. 194 * The callback will be called for every peer known to the service.
158 * Only one info request (of any kind) can be active at once. 195 * Only one info request (of any kind) can be active at once.
159 * 196 *
160 * WARNING: unstable API, likely to change in the future!
161 *
162 * @param h Handle to the cadet peer. 197 * @param h Handle to the cadet peer.
163 * @param callback Function to call with the requested data. 198 * @param callback Function to call with the requested data.
164 * @param callback_cls Closure for @c callback. 199 * @param callback_cls Closure for @c callback.
165 * @return #GNUNET_OK / #GNUNET_SYSERR 200 * @return NULL on error
166 */ 201 */
167struct GNUNET_CADET_PeersLister * 202struct GNUNET_CADET_PeersLister *
168GNUNET_CADET_list_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, 203GNUNET_CADET_list_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
169 GNUNET_CADET_PeersCB callback, 204 GNUNET_CADET_PeersCB callback,
170 void *callback_cls) 205 void *callback_cls)
171{ 206{
172 if (NULL != h->info_cb.peers_cb) 207 struct GNUNET_CADET_PeersLister *pl;
208
209 if (NULL == callback)
173 { 210 {
174 GNUNET_break (0); 211 GNUNET_break (0);
175 return GNUNET_SYSERR; 212 return NULL;
213 }
214 pl = GNUNET_new (struct GNUNET_CADET_PeersLister);
215 pl->peers_cb = callback;
216 pl->peers_cb_cls = callback_cls;
217 pl->cfg = cfg;
218 reconnect (pl);
219 if (NULL == pl->mq)
220 {
221 GNUNET_free (pl);
222 return NULL;
176 } 223 }
177 send_info_request (h, 224 return pl;
178 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS);
179 h->info_cb.peers_cb = callback;
180 h->info_cls = callback_cls;
181 return GNUNET_OK;
182} 225}
183 226
184 227
185/** 228/**
186 * Cancel a peer info request. The callback will not be called (anymore). 229 * Cancel a peer info request. The callback will not be called (anymore).
187 * 230 *
188 * WARNING: unstable API, likely to change in the future! 231 * @param pl operation handle
189 *
190 * @param h Cadet handle.
191 * @return Closure given to GNUNET_CADET_get_peers(). 232 * @return Closure given to GNUNET_CADET_get_peers().
192 */ 233 */
193void * 234void *
194GNUNET_CADET_list_peers_cancel (struct GNUNET_CADET_PeersLister *pl) 235GNUNET_CADET_list_peers_cancel (struct GNUNET_CADET_PeersLister *pl)
195{ 236{
196 void *cls = h->info_cls; 237 void *ret = pl->peers_cb_cls;
197 238
198 h->info_cb.peers_cb = NULL; 239 if (NULL != pl->mq)
199 h->info_cls = NULL; 240 GNUNET_MQ_destroy (pl->mq);
200 return cls; 241 if (NULL != pl->reconnect_task)
242 GNUNET_SCHEDULER_cancel (pl->reconnect_task);
243 GNUNET_free (pl);
244 return ret;
201} 245}
202 246
203 247/* end of cadet_api_list_peers.c */
204
205
206
diff --git a/src/cadet/cadet_api_list_tunnels.c b/src/cadet/cadet_api_list_tunnels.c
index 96343bf4d..7d0534e41 100644
--- a/src/cadet/cadet_api_list_tunnels.c
+++ b/src/cadet/cadet_api_list_tunnels.c
@@ -18,7 +18,7 @@
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.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
23 * @author Bartlomiej Polot 23 * @author Bartlomiej Polot
24 * @author Christian Grothoff 24 * @author Christian Grothoff
@@ -31,9 +31,8 @@
31#include "cadet_protocol.h" 31#include "cadet_protocol.h"
32 32
33 33
34
35/** 34/**
36 * Ugly legacy hack. 35 * Operation handle.
37 */ 36 */
38struct GNUNET_CADET_ListTunnels 37struct GNUNET_CADET_ListTunnels
39{ 38{
@@ -47,6 +46,27 @@ struct GNUNET_CADET_ListTunnels
47 * Info callback closure for @c tunnels_cb. 46 * Info callback closure for @c tunnels_cb.
48 */ 47 */
49 void *tunnels_cb_cls; 48 void *tunnels_cb_cls;
49
50 /**
51 * Message queue to talk to CADET service.
52 */
53 struct GNUNET_MQ_Handle *mq;
54
55 /**
56 * Configuration we use.
57 */
58 const struct GNUNET_CONFIGURATION_Handle *cfg;
59
60 /**
61 * Task to reconnect.
62 */
63 struct GNUNET_SCHEDULER_Task *reconnect_task;
64
65 /**
66 * Backoff for reconnect attempts.
67 */
68 struct GNUNET_TIME_Relative backoff;
69
50}; 70};
51 71
52 72