aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/cadet_api_list_peers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/cadet_api_list_peers.c')
-rw-r--r--src/cadet/cadet_api_list_peers.c126
1 files changed, 62 insertions, 64 deletions
diff --git a/src/cadet/cadet_api_list_peers.c b/src/cadet/cadet_api_list_peers.c
index 4dc6d02f5..65e9ad4da 100644
--- a/src/cadet/cadet_api_list_peers.c
+++ b/src/cadet/cadet_api_list_peers.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_peers.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
@@ -34,9 +34,7 @@
34/** 34/**
35 * Operation handle. 35 * Operation handle.
36 */ 36 */
37struct GNUNET_CADET_PeersLister 37struct GNUNET_CADET_PeersLister {
38{
39
40 /** 38 /**
41 * Monitor callback 39 * Monitor callback
42 */ 40 */
@@ -66,7 +64,6 @@ struct GNUNET_CADET_PeersLister
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,18 +74,18 @@ struct GNUNET_CADET_PeersLister
77 * @param info Message itself. 74 * @param info Message itself.
78 */ 75 */
79static void 76static void
80handle_get_peers (void *cls, 77handle_get_peers(void *cls,
81 const struct GNUNET_CADET_LocalInfoPeers *info) 78 const struct GNUNET_CADET_LocalInfoPeers *info)
82{ 79{
83 struct GNUNET_CADET_PeersLister *pl = cls; 80 struct GNUNET_CADET_PeersLister *pl = cls;
84 struct GNUNET_CADET_PeerListEntry ple; 81 struct GNUNET_CADET_PeerListEntry ple;
85 82
86 ple.peer = info->destination; 83 ple.peer = info->destination;
87 ple.have_tunnel = (int) ntohs (info->tunnel); 84 ple.have_tunnel = (int)ntohs(info->tunnel);
88 ple.n_paths = (unsigned int) ntohs (info->paths); 85 ple.n_paths = (unsigned int)ntohs(info->paths);
89 ple.best_path_length = (unsigned int) ntohl (info->best_path_length); 86 ple.best_path_length = (unsigned int)ntohl(info->best_path_length);
90 pl->peers_cb (pl->peers_cb_cls, 87 pl->peers_cb(pl->peers_cb_cls,
91 &ple); 88 &ple);
92} 89}
93 90
94 91
@@ -99,15 +96,16 @@ handle_get_peers (void *cls,
99 * @param msg Message itself. 96 * @param msg Message itself.
100 */ 97 */
101static void 98static void
102handle_get_peers_end (void *cls, 99handle_get_peers_end(void *cls,
103 const struct GNUNET_MessageHeader *msg) 100 const struct GNUNET_MessageHeader *msg)
104{ 101{
105 struct GNUNET_CADET_PeersLister *pl = cls; 102 struct GNUNET_CADET_PeersLister *pl = cls;
106 (void) msg;
107 103
108 pl->peers_cb (pl->peers_cb_cls, 104 (void)msg;
109 NULL); 105
110 GNUNET_CADET_list_peers_cancel (pl); 106 pl->peers_cb(pl->peers_cb_cls,
107 NULL);
108 GNUNET_CADET_list_peers_cancel(pl);
111} 109}
112 110
113 111
@@ -117,7 +115,7 @@ handle_get_peers_end (void *cls,
117 * @param cls a `struct GNUNET_CADET_PeersLister` operation 115 * @param cls a `struct GNUNET_CADET_PeersLister` operation
118 */ 116 */
119static void 117static void
120reconnect (void *cls); 118reconnect(void *cls);
121 119
122 120
123/** 121/**
@@ -127,18 +125,18 @@ reconnect (void *cls);
127 * @param error error code from MQ 125 * @param error error code from MQ
128 */ 126 */
129static void 127static void
130error_handler (void *cls, 128error_handler(void *cls,
131 enum GNUNET_MQ_Error error) 129 enum GNUNET_MQ_Error error)
132{ 130{
133 struct GNUNET_CADET_PeersLister *pl = cls; 131 struct GNUNET_CADET_PeersLister *pl = cls;
134 132
135 GNUNET_MQ_destroy (pl->mq); 133 GNUNET_MQ_destroy(pl->mq);
136 pl->mq = NULL; 134 pl->mq = NULL;
137 pl->backoff = GNUNET_TIME_randomized_backoff (pl->backoff, 135 pl->backoff = GNUNET_TIME_randomized_backoff(pl->backoff,
138 GNUNET_TIME_UNIT_MINUTES); 136 GNUNET_TIME_UNIT_MINUTES);
139 pl->reconnect_task = GNUNET_SCHEDULER_add_delayed (pl->backoff, 137 pl->reconnect_task = GNUNET_SCHEDULER_add_delayed(pl->backoff,
140 &reconnect, 138 &reconnect,
141 pl); 139 pl);
142} 140}
143 141
144 142
@@ -148,35 +146,35 @@ error_handler (void *cls,
148 * @param cls a `struct GNUNET_CADET_PeersLister` operation 146 * @param cls a `struct GNUNET_CADET_PeersLister` operation
149 */ 147 */
150static void 148static void
151reconnect (void *cls) 149reconnect(void *cls)
152{ 150{
153 struct GNUNET_CADET_PeersLister *pl = cls; 151 struct GNUNET_CADET_PeersLister *pl = cls;
154 struct GNUNET_MQ_MessageHandler handlers[] = { 152 struct GNUNET_MQ_MessageHandler handlers[] = {
155 GNUNET_MQ_hd_fixed_size (get_peers, 153 GNUNET_MQ_hd_fixed_size(get_peers,
156 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, 154 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS,
157 struct GNUNET_CADET_LocalInfoPeers, 155 struct GNUNET_CADET_LocalInfoPeers,
158 pl), 156 pl),
159 GNUNET_MQ_hd_fixed_size (get_peers_end, 157 GNUNET_MQ_hd_fixed_size(get_peers_end,
160 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END, 158 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END,
161 struct GNUNET_MessageHeader, 159 struct GNUNET_MessageHeader,
162 pl), 160 pl),
163 GNUNET_MQ_handler_end () 161 GNUNET_MQ_handler_end()
164 }; 162 };
165 struct GNUNET_MessageHeader *msg; 163 struct GNUNET_MessageHeader *msg;
166 struct GNUNET_MQ_Envelope *env; 164 struct GNUNET_MQ_Envelope *env;
167 165
168 pl->reconnect_task = NULL; 166 pl->reconnect_task = NULL;
169 pl->mq = GNUNET_CLIENT_connect (pl->cfg, 167 pl->mq = GNUNET_CLIENT_connect(pl->cfg,
170 "cadet", 168 "cadet",
171 handlers, 169 handlers,
172 &error_handler, 170 &error_handler,
173 pl); 171 pl);
174 if (NULL == pl->mq) 172 if (NULL == pl->mq)
175 return; 173 return;
176 env = GNUNET_MQ_msg (msg, 174 env = GNUNET_MQ_msg(msg,
177 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS); 175 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS);
178 GNUNET_MQ_send (pl->mq, 176 GNUNET_MQ_send(pl->mq,
179 env); 177 env);
180} 178}
181 179
182 180
@@ -191,27 +189,27 @@ reconnect (void *cls)
191 * @return NULL on error 189 * @return NULL on error
192 */ 190 */
193struct GNUNET_CADET_PeersLister * 191struct GNUNET_CADET_PeersLister *
194GNUNET_CADET_list_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, 192GNUNET_CADET_list_peers(const struct GNUNET_CONFIGURATION_Handle *cfg,
195 GNUNET_CADET_PeersCB callback, 193 GNUNET_CADET_PeersCB callback,
196 void *callback_cls) 194 void *callback_cls)
197{ 195{
198 struct GNUNET_CADET_PeersLister *pl; 196 struct GNUNET_CADET_PeersLister *pl;
199 197
200 if (NULL == callback) 198 if (NULL == callback)
201 { 199 {
202 GNUNET_break (0); 200 GNUNET_break(0);
203 return NULL; 201 return NULL;
204 } 202 }
205 pl = GNUNET_new (struct GNUNET_CADET_PeersLister); 203 pl = GNUNET_new(struct GNUNET_CADET_PeersLister);
206 pl->peers_cb = callback; 204 pl->peers_cb = callback;
207 pl->peers_cb_cls = callback_cls; 205 pl->peers_cb_cls = callback_cls;
208 pl->cfg = cfg; 206 pl->cfg = cfg;
209 reconnect (pl); 207 reconnect(pl);
210 if (NULL == pl->mq) 208 if (NULL == pl->mq)
211 { 209 {
212 GNUNET_free (pl); 210 GNUNET_free(pl);
213 return NULL; 211 return NULL;
214 } 212 }
215 return pl; 213 return pl;
216} 214}
217 215
@@ -223,15 +221,15 @@ GNUNET_CADET_list_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
223 * @return Closure given to GNUNET_CADET_get_peers(). 221 * @return Closure given to GNUNET_CADET_get_peers().
224 */ 222 */
225void * 223void *
226GNUNET_CADET_list_peers_cancel (struct GNUNET_CADET_PeersLister *pl) 224GNUNET_CADET_list_peers_cancel(struct GNUNET_CADET_PeersLister *pl)
227{ 225{
228 void *ret = pl->peers_cb_cls; 226 void *ret = pl->peers_cb_cls;
229 227
230 if (NULL != pl->mq) 228 if (NULL != pl->mq)
231 GNUNET_MQ_destroy (pl->mq); 229 GNUNET_MQ_destroy(pl->mq);
232 if (NULL != pl->reconnect_task) 230 if (NULL != pl->reconnect_task)
233 GNUNET_SCHEDULER_cancel (pl->reconnect_task); 231 GNUNET_SCHEDULER_cancel(pl->reconnect_task);
234 GNUNET_free (pl); 232 GNUNET_free(pl);
235 return ret; 233 return ret;
236} 234}
237 235