diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-01-27 04:05:12 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-01-27 04:05:12 +0100 |
commit | d3f013aba71486c121800d279cd1d3af4425c412 (patch) | |
tree | c86bfc9d800e04bda51e68b3041db1d954f43737 /src/cadet | |
parent | 20c42b92b71cb31bc5ed9cc4e4ff32efbd95aae4 (diff) | |
download | gnunet-d3f013aba71486c121800d279cd1d3af4425c412.tar.gz gnunet-d3f013aba71486c121800d279cd1d3af4425c412.zip |
more work towards fixing #5385
Diffstat (limited to 'src/cadet')
-rw-r--r-- | src/cadet/Makefile.am | 3 | ||||
-rw-r--r-- | src/cadet/cadet.h | 97 | ||||
-rw-r--r-- | src/cadet/cadet_api_get_channel.c | 90 | ||||
-rw-r--r-- | src/cadet/cadet_api_get_path.c (renamed from src/cadet/cadet_api_get_peer.c) | 135 | ||||
-rw-r--r-- | src/cadet/cadet_api_list_peers.c | 76 | ||||
-rw-r--r-- | src/cadet/gnunet-cadet.c | 123 | ||||
-rw-r--r-- | src/cadet/gnunet-service-cadet.c | 158 |
7 files changed, 325 insertions, 357 deletions
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am index 8f4cd20d4..80ad76737 100644 --- a/src/cadet/Makefile.am +++ b/src/cadet/Makefile.am | |||
@@ -34,7 +34,8 @@ lib_LTLIBRARIES = \ | |||
34 | 34 | ||
35 | libgnunetcadet_la_SOURCES = \ | 35 | libgnunetcadet_la_SOURCES = \ |
36 | cadet_api.c \ | 36 | cadet_api.c \ |
37 | cadet_api_get_peer.c \ | 37 | cadet_api_get_channel.c \ |
38 | cadet_api_get_path.c \ | ||
38 | cadet_api_get_tunnel.c \ | 39 | cadet_api_get_tunnel.c \ |
39 | cadet_api_list_peers.c \ | 40 | cadet_api_list_peers.c \ |
40 | cadet_api_list_tunnels.c \ | 41 | cadet_api_list_tunnels.c \ |
diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h index 226288284..51296ae50 100644 --- a/src/cadet/cadet.h +++ b/src/cadet/cadet.h | |||
@@ -249,24 +249,97 @@ struct GNUNET_CADET_LocalInfo | |||
249 | 249 | ||
250 | 250 | ||
251 | /** | 251 | /** |
252 | * Message to inform the client about one of the peers in the service. | 252 | * Message to inform the client about channels in the service. |
253 | * | ||
254 | * TODO: split into two messages! | ||
255 | */ | 253 | */ |
256 | struct GNUNET_CADET_LocalInfoPeer | 254 | struct GNUNET_CADET_RequestPathInfoMessage |
257 | { | 255 | { |
258 | /** | 256 | /** |
259 | * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER or | 257 | * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH |
260 | * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS | ||
261 | */ | 258 | */ |
262 | struct GNUNET_MessageHeader header; | 259 | struct GNUNET_MessageHeader header; |
263 | 260 | ||
261 | /** | ||
262 | * Always zero. | ||
263 | */ | ||
264 | uint32_t resered GNUNET_PACKED; | ||
265 | |||
266 | /** | ||
267 | * ID of the destination of the channel (can be local peer). | ||
268 | */ | ||
269 | struct GNUNET_PeerIdentity peer; | ||
270 | }; | ||
271 | |||
272 | |||
273 | /** | ||
274 | * Message to inform the client about channels in the service. | ||
275 | */ | ||
276 | struct GNUNET_CADET_ChannelInfoMessage | ||
277 | { | ||
278 | /** | ||
279 | * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL. | ||
280 | */ | ||
281 | struct GNUNET_MessageHeader header; | ||
282 | |||
264 | /** | 283 | /** |
265 | * Offset the peer has in the path this message is about. | 284 | * Root of the channel |
266 | */ | 285 | */ |
267 | uint16_t offset GNUNET_PACKED; | 286 | struct GNUNET_PeerIdentity root; |
268 | 287 | ||
269 | /** | 288 | /** |
289 | * Destination of the channel | ||
290 | */ | ||
291 | struct GNUNET_PeerIdentity dest; | ||
292 | |||
293 | /* FIXME: expand! */ | ||
294 | }; | ||
295 | |||
296 | |||
297 | /** | ||
298 | * Message to as the service about information on a channel. | ||
299 | */ | ||
300 | struct GNUNET_CADET_RequestChannelInfoMessage | ||
301 | { | ||
302 | /** | ||
303 | * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL. | ||
304 | */ | ||
305 | struct GNUNET_MessageHeader header; | ||
306 | |||
307 | /** | ||
308 | * Target of the channel. | ||
309 | */ | ||
310 | struct GNUNET_PeerIdentity target; | ||
311 | |||
312 | }; | ||
313 | |||
314 | |||
315 | /** | ||
316 | * Message to inform the client about one of the paths known to the service. | ||
317 | */ | ||
318 | struct GNUNET_CADET_LocalInfoPath | ||
319 | { | ||
320 | /** | ||
321 | * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH. | ||
322 | */ | ||
323 | struct GNUNET_MessageHeader header; | ||
324 | |||
325 | /** | ||
326 | * Zero. | ||
327 | */ | ||
328 | uint32_t reserved GNUNET_PACKED; | ||
329 | }; | ||
330 | |||
331 | |||
332 | /** | ||
333 | * Message to inform the client about one of the peers in the service. | ||
334 | */ | ||
335 | struct GNUNET_CADET_LocalInfoPeers | ||
336 | { | ||
337 | /** | ||
338 | * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS | ||
339 | */ | ||
340 | struct GNUNET_MessageHeader header; | ||
341 | |||
342 | /** | ||
270 | * Number of paths. | 343 | * Number of paths. |
271 | */ | 344 | */ |
272 | uint16_t paths GNUNET_PACKED; | 345 | uint16_t paths GNUNET_PACKED; |
@@ -277,17 +350,15 @@ struct GNUNET_CADET_LocalInfoPeer | |||
277 | int16_t tunnel GNUNET_PACKED; | 350 | int16_t tunnel GNUNET_PACKED; |
278 | 351 | ||
279 | /** | 352 | /** |
280 | * We are finished with the paths. | 353 | * Shortest known path. |
281 | */ | 354 | */ |
282 | uint16_t finished_with_paths; | 355 | uint32_t best_path_length GNUNET_PACKED; |
283 | 356 | ||
284 | /** | 357 | /** |
285 | * ID of the peer (can be local peer). | 358 | * ID of the peer (can be local peer). |
286 | */ | 359 | */ |
287 | struct GNUNET_PeerIdentity destination; | 360 | struct GNUNET_PeerIdentity destination; |
288 | 361 | ||
289 | /* If type == PEER (no 'S'): GNUNET_PeerIdentity paths[] | ||
290 | * (each path ends in destination) */ | ||
291 | }; | 362 | }; |
292 | 363 | ||
293 | 364 | ||
diff --git a/src/cadet/cadet_api_get_channel.c b/src/cadet/cadet_api_get_channel.c index 1249777c2..81f0691f1 100644 --- a/src/cadet/cadet_api_get_channel.c +++ b/src/cadet/cadet_api_get_channel.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 |
@@ -72,15 +72,67 @@ struct GNUNET_CADET_ChannelMonitor | |||
72 | */ | 72 | */ |
73 | struct GNUNET_PeerIdentity peer; | 73 | struct GNUNET_PeerIdentity peer; |
74 | 74 | ||
75 | /** | ||
76 | * Channel we want information about. | ||
77 | */ | ||
78 | uint32_t /* UGH */ channel_number; | ||
79 | |||
80 | }; | 75 | }; |
81 | 76 | ||
82 | 77 | ||
83 | /** | 78 | /** |
79 | * Check that message received from CADET service is well-formed. | ||
80 | * | ||
81 | * @param cls unused | ||
82 | * @param message the message we got | ||
83 | * @return #GNUNET_OK if the message is well-formed, | ||
84 | * #GNUNET_SYSERR otherwise | ||
85 | */ | ||
86 | static int | ||
87 | check_channel_info (void *cls, | ||
88 | const struct GNUNET_CADET_ChannelInfoMessage *message) | ||
89 | { | ||
90 | (void) cls; | ||
91 | |||
92 | return GNUNET_OK; | ||
93 | } | ||
94 | |||
95 | |||
96 | /** | ||
97 | * Process a local peer info reply, pass info to the user. | ||
98 | * | ||
99 | * @param cls Closure | ||
100 | * @param message Message itself. | ||
101 | */ | ||
102 | static void | ||
103 | handle_channel_info (void *cls, | ||
104 | const struct GNUNET_CADET_ChannelInfoMessage *message) | ||
105 | { | ||
106 | struct GNUNET_CADET_ChannelMonitor *cm = cls; | ||
107 | struct GNUNET_CADET_ChannelInternals ci; | ||
108 | |||
109 | ci.root = message->root; | ||
110 | ci.dest = message->dest; | ||
111 | cm->channel_cb (cm->channel_cb_cls, | ||
112 | &ci); | ||
113 | GNUNET_CADET_get_channel_cancel (cm); | ||
114 | } | ||
115 | |||
116 | |||
117 | /** | ||
118 | * Process a local peer info reply, pass info to the user. | ||
119 | * | ||
120 | * @param cls Closure | ||
121 | * @param message Message itself. | ||
122 | */ | ||
123 | static void | ||
124 | handle_channel_info_end (void *cls, | ||
125 | const struct GNUNET_MessageHeader *message) | ||
126 | { | ||
127 | struct GNUNET_CADET_ChannelMonitor *cm = cls; | ||
128 | |||
129 | cm->channel_cb (cm->channel_cb_cls, | ||
130 | NULL); | ||
131 | GNUNET_CADET_get_channel_cancel (cm); | ||
132 | } | ||
133 | |||
134 | |||
135 | /** | ||
84 | * Reconnect to the service and try again. | 136 | * Reconnect to the service and try again. |
85 | * | 137 | * |
86 | * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation | 138 | * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation |
@@ -120,11 +172,18 @@ static void | |||
120 | reconnect (void *cls) | 172 | reconnect (void *cls) |
121 | { | 173 | { |
122 | struct GNUNET_CADET_ChannelMonitor *cm = cls; | 174 | struct GNUNET_CADET_ChannelMonitor *cm = cls; |
123 | struct GNUNET_MQ_MessageHandler *handlers[] = { | 175 | struct GNUNET_MQ_MessageHandler handlers[] = { |
124 | FIXME, | 176 | GNUNET_MQ_hd_fixed_size (channel_info_end, |
177 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL_END, | ||
178 | struct GNUNET_MessageHeader, | ||
179 | cm), | ||
180 | GNUNET_MQ_hd_var_size (channel_info, | ||
181 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL, | ||
182 | struct GNUNET_CADET_ChannelInfoMessage, | ||
183 | cm), | ||
125 | GNUNET_MQ_handler_end () | 184 | GNUNET_MQ_handler_end () |
126 | }; | 185 | }; |
127 | struct GNUNET_MessageHeader *msg; | 186 | struct GNUNET_CADET_RequestChannelInfoMessage *msg; |
128 | struct GNUNET_MQ_Envelope *env; | 187 | struct GNUNET_MQ_Envelope *env; |
129 | 188 | ||
130 | cm->reconnect_task = NULL; | 189 | cm->reconnect_task = NULL; |
@@ -136,7 +195,8 @@ reconnect (void *cls) | |||
136 | if (NULL == cm->mq) | 195 | if (NULL == cm->mq) |
137 | return; | 196 | return; |
138 | env = GNUNET_MQ_msg (msg, | 197 | env = GNUNET_MQ_msg (msg, |
139 | type); | 198 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL); |
199 | msg->target = cm->peer; | ||
140 | GNUNET_MQ_send (cm->mq, | 200 | GNUNET_MQ_send (cm->mq, |
141 | env); | 201 | env); |
142 | } | 202 | } |
@@ -147,7 +207,6 @@ reconnect (void *cls) | |||
147 | * | 207 | * |
148 | * @param cfg configuration to use | 208 | * @param cfg configuration to use |
149 | * @param peer ID of the other end of the channel. | 209 | * @param peer ID of the other end of the channel. |
150 | * @param channel_number Channel number. | ||
151 | * @param callback Function to call with the requested data. | 210 | * @param callback Function to call with the requested data. |
152 | * @param callback_cls Closure for @c callback. | 211 | * @param callback_cls Closure for @c callback. |
153 | * @return NULL on error | 212 | * @return NULL on error |
@@ -155,7 +214,6 @@ reconnect (void *cls) | |||
155 | struct GNUNET_CADET_ChannelMonitor * | 214 | struct GNUNET_CADET_ChannelMonitor * |
156 | GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg, | 215 | GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg, |
157 | struct GNUNET_PeerIdentity *peer, | 216 | struct GNUNET_PeerIdentity *peer, |
158 | uint32_t /* UGH */ channel_number, | ||
159 | GNUNET_CADET_ChannelCB callback, | 217 | GNUNET_CADET_ChannelCB callback, |
160 | void *callback_cls) | 218 | void *callback_cls) |
161 | { | 219 | { |
@@ -167,10 +225,10 @@ GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
167 | return NULL; | 225 | return NULL; |
168 | } | 226 | } |
169 | cm = GNUNET_new (struct GNUNET_CADET_ChannelMonitor); | 227 | cm = GNUNET_new (struct GNUNET_CADET_ChannelMonitor); |
170 | cm->peer_cb = callback; | 228 | cm->channel_cb = callback; |
171 | cm->peer_cb_cls = callback_cls; | 229 | cm->channel_cb_cls = callback_cls; |
172 | cm->cfg = cfg; | 230 | cm->cfg = cfg; |
173 | cm->id = *id; | 231 | cm->peer = *peer; |
174 | reconnect (cm); | 232 | reconnect (cm); |
175 | if (NULL == cm->mq) | 233 | if (NULL == cm->mq) |
176 | { | 234 | { |
@@ -190,7 +248,7 @@ GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
190 | void * | 248 | void * |
191 | GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm) | 249 | GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm) |
192 | { | 250 | { |
193 | void *ret = cm->peer_cb_cls; | 251 | void *ret = cm->channel_cb_cls; |
194 | 252 | ||
195 | if (NULL != cm->mq) | 253 | if (NULL != cm->mq) |
196 | GNUNET_MQ_destroy (cm->mq); | 254 | GNUNET_MQ_destroy (cm->mq); |
diff --git a/src/cadet/cadet_api_get_peer.c b/src/cadet/cadet_api_get_path.c index 6276de3a4..2f35e365e 100644 --- a/src/cadet/cadet_api_get_peer.c +++ b/src/cadet/cadet_api_get_path.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_get_peer.c | 21 | * @file cadet/cadet_api_get_path.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 |
@@ -34,18 +34,18 @@ | |||
34 | /** | 34 | /** |
35 | * Operation handle. | 35 | * Operation handle. |
36 | */ | 36 | */ |
37 | struct GNUNET_CADET_GetPeer | 37 | struct GNUNET_CADET_GetPath |
38 | { | 38 | { |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Monitor callback | 41 | * Monitor callback |
42 | */ | 42 | */ |
43 | GNUNET_CADET_PeerCB peer_cb; | 43 | GNUNET_CADET_PathCB path_cb; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Closure for @c peer_cb. | 46 | * Closure for @c path_cb. |
47 | */ | 47 | */ |
48 | void *peer_cb_cls; | 48 | void *path_cb_cls; |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Message queue to talk to CADET service. | 51 | * Message queue to talk to CADET service. |
@@ -84,10 +84,10 @@ struct GNUNET_CADET_GetPeer | |||
84 | * #GNUNET_SYSERR otherwise | 84 | * #GNUNET_SYSERR otherwise |
85 | */ | 85 | */ |
86 | static int | 86 | static int |
87 | check_get_peer (void *cls, | 87 | check_get_path (void *cls, |
88 | const struct GNUNET_CADET_LocalInfoPeer *message) | 88 | const struct GNUNET_CADET_LocalInfoPath *message) |
89 | { | 89 | { |
90 | size_t msize = sizeof (struct GNUNET_CADET_LocalInfoPeer); | 90 | size_t msize = sizeof (struct GNUNET_CADET_LocalInfoPath); |
91 | size_t esize; | 91 | size_t esize; |
92 | 92 | ||
93 | (void) cls; | 93 | (void) cls; |
@@ -113,54 +113,44 @@ check_get_peer (void *cls, | |||
113 | * @param message Message itself. | 113 | * @param message Message itself. |
114 | */ | 114 | */ |
115 | static void | 115 | static void |
116 | handle_get_peer (void *cls, | 116 | handle_get_path (void *cls, |
117 | const struct GNUNET_CADET_LocalInfoPeer *message) | 117 | const struct GNUNET_CADET_LocalInfoPath *message) |
118 | { | 118 | { |
119 | struct GNUNET_CADET_GetPeer *gp = cls; | 119 | struct GNUNET_CADET_GetPath *gp = cls; |
120 | const struct GNUNET_PeerIdentity *paths_array; | 120 | struct GNUNET_CADET_PeerPathDetail ppd; |
121 | unsigned int paths; | 121 | |
122 | unsigned int path_length; | 122 | ppd.peer = gp->id; |
123 | int neighbor; | 123 | ppd.path = (const struct GNUNET_PeerIdentity *) &message[1]; |
124 | unsigned int peers; | 124 | ppd.path_length = (ntohs (message->header.size) - sizeof (*message)) |
125 | 125 | / sizeof (struct GNUNET_PeerIdentity); | |
126 | paths = ntohs (message->paths); | 126 | gp->path_cb (gp->path_cb_cls, |
127 | paths_array = (const struct GNUNET_PeerIdentity *) &message[1]; | 127 | &ppd); |
128 | peers = (ntohs (message->header.size) - sizeof (*message)) | 128 | } |
129 | / sizeof (struct GNUNET_PeerIdentity); | 129 | |
130 | path_length = 0; | 130 | |
131 | neighbor = GNUNET_NO; | 131 | /** |
132 | 132 | * Process a local peer info reply, pass info to the user. | |
133 | for (unsigned int i = 0; i < peers; i++) | 133 | * |
134 | { | 134 | * @param cls Closure |
135 | path_length++; | 135 | * @param message Message itself. |
136 | if (0 == memcmp (&paths_array[i], | 136 | */ |
137 | &message->destination, | 137 | static void |
138 | sizeof (struct GNUNET_PeerIdentity))) | 138 | handle_get_path_end (void *cls, |
139 | { | 139 | const struct GNUNET_MessageHeader *message) |
140 | if (1 == path_length) | 140 | { |
141 | neighbor = GNUNET_YES; | 141 | struct GNUNET_CADET_GetPath *gp = cls; |
142 | path_length = 0; | ||
143 | } | ||
144 | } | ||
145 | 142 | ||
146 | /* Call Callback with tunnel info */ | 143 | (void) message; |
147 | paths_array = (const struct GNUNET_PeerIdentity *) &message[1]; | 144 | gp->path_cb (gp->path_cb_cls, |
148 | gp->peer_cb (gp->peer_cb_cls, | 145 | NULL); |
149 | &message->destination, | 146 | GNUNET_CADET_get_path_cancel (gp); |
150 | (int) ntohs (message->tunnel), | ||
151 | neighbor, | ||
152 | paths, | ||
153 | paths_array, | ||
154 | (int) ntohs (message->offset), | ||
155 | (int) ntohs (message->finished_with_paths)); | ||
156 | GNUNET_CADET_get_peer_cancel (gp); | ||
157 | } | 147 | } |
158 | 148 | ||
159 | 149 | ||
160 | /** | 150 | /** |
161 | * Reconnect to the service and try again. | 151 | * Reconnect to the service and try again. |
162 | * | 152 | * |
163 | * @param cls a `struct GNUNET_CADET_GetPeer` operation | 153 | * @param cls a `struct GNUNET_CADET_GetPath` operation |
164 | */ | 154 | */ |
165 | static void | 155 | static void |
166 | reconnect (void *cls); | 156 | reconnect (void *cls); |
@@ -169,14 +159,14 @@ reconnect (void *cls); | |||
169 | /** | 159 | /** |
170 | * Function called on connection trouble. Reconnects. | 160 | * Function called on connection trouble. Reconnects. |
171 | * | 161 | * |
172 | * @param cls a `struct GNUNET_CADET_GetPeer` | 162 | * @param cls a `struct GNUNET_CADET_GetPath` |
173 | * @param error error code from MQ | 163 | * @param error error code from MQ |
174 | */ | 164 | */ |
175 | static void | 165 | static void |
176 | error_handler (void *cls, | 166 | error_handler (void *cls, |
177 | enum GNUNET_MQ_Error error) | 167 | enum GNUNET_MQ_Error error) |
178 | { | 168 | { |
179 | struct GNUNET_CADET_GetPeer *gp = cls; | 169 | struct GNUNET_CADET_GetPath *gp = cls; |
180 | 170 | ||
181 | GNUNET_MQ_destroy (gp->mq); | 171 | GNUNET_MQ_destroy (gp->mq); |
182 | gp->mq = NULL; | 172 | gp->mq = NULL; |
@@ -191,20 +181,24 @@ error_handler (void *cls, | |||
191 | /** | 181 | /** |
192 | * Reconnect to the service and try again. | 182 | * Reconnect to the service and try again. |
193 | * | 183 | * |
194 | * @param cls a `struct GNUNET_CADET_GetPeer` operation | 184 | * @param cls a `struct GNUNET_CADET_GetPath` operation |
195 | */ | 185 | */ |
196 | static void | 186 | static void |
197 | reconnect (void *cls) | 187 | reconnect (void *cls) |
198 | { | 188 | { |
199 | struct GNUNET_CADET_GetPeer *gp = cls; | 189 | struct GNUNET_CADET_GetPath *gp = cls; |
200 | struct GNUNET_MQ_MessageHandler handlers[] = { | 190 | struct GNUNET_MQ_MessageHandler handlers[] = { |
201 | GNUNET_MQ_hd_var_size (get_peer, | 191 | GNUNET_MQ_hd_var_size (get_path, |
202 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER, | 192 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH, |
203 | struct GNUNET_CADET_LocalInfoPeer, | 193 | struct GNUNET_CADET_LocalInfoPath, |
204 | gp), | 194 | gp), |
195 | GNUNET_MQ_hd_fixed_size (get_path_end, | ||
196 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END, | ||
197 | struct GNUNET_MessageHeader, | ||
198 | gp), | ||
205 | GNUNET_MQ_handler_end () | 199 | GNUNET_MQ_handler_end () |
206 | }; | 200 | }; |
207 | struct GNUNET_CADET_LocalInfo *msg; | 201 | struct GNUNET_CADET_RequestPathInfoMessage *msg; |
208 | struct GNUNET_MQ_Envelope *env; | 202 | struct GNUNET_MQ_Envelope *env; |
209 | 203 | ||
210 | gp->reconnect_task = NULL; | 204 | gp->reconnect_task = NULL; |
@@ -216,7 +210,7 @@ reconnect (void *cls) | |||
216 | if (NULL == gp->mq) | 210 | if (NULL == gp->mq) |
217 | return; | 211 | return; |
218 | env = GNUNET_MQ_msg (msg, | 212 | env = GNUNET_MQ_msg (msg, |
219 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); | 213 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH); |
220 | msg->peer = gp->id; | 214 | msg->peer = gp->id; |
221 | GNUNET_MQ_send (gp->mq, | 215 | GNUNET_MQ_send (gp->mq, |
222 | env); | 216 | env); |
@@ -224,31 +218,30 @@ reconnect (void *cls) | |||
224 | 218 | ||
225 | 219 | ||
226 | /** | 220 | /** |
227 | * Request information about a peer known to the running cadet peer. | 221 | * Request information about paths known to the running cadet peer. |
228 | * The callback will be called for the tunnel once. | ||
229 | * | 222 | * |
230 | * @param cfg configuration to use | 223 | * @param cfg configuration to use |
231 | * @param id Peer whose tunnel to examine. | 224 | * @param id Peer whose paths to examine. |
232 | * @param callback Function to call with the requested data. | 225 | * @param callback Function to call with the requested data. |
233 | * @param callback_cls Closure for @c callback. | 226 | * @param callback_cls Closure for @c callback. |
234 | * @return NULL on error | 227 | * @return NULL on error |
235 | */ | 228 | */ |
236 | struct GNUNET_CADET_GetPeer * | 229 | struct GNUNET_CADET_GetPath * |
237 | GNUNET_CADET_get_peer (const struct GNUNET_CONFIGURATION_Handle *cfg, | 230 | GNUNET_CADET_get_path (const struct GNUNET_CONFIGURATION_Handle *cfg, |
238 | const struct GNUNET_PeerIdentity *id, | 231 | const struct GNUNET_PeerIdentity *id, |
239 | GNUNET_CADET_PeerCB callback, | 232 | GNUNET_CADET_PathCB callback, |
240 | void *callback_cls) | 233 | void *callback_cls) |
241 | { | 234 | { |
242 | struct GNUNET_CADET_GetPeer *gp; | 235 | struct GNUNET_CADET_GetPath *gp; |
243 | 236 | ||
244 | if (NULL == callback) | 237 | if (NULL == callback) |
245 | { | 238 | { |
246 | GNUNET_break (0); | 239 | GNUNET_break (0); |
247 | return NULL; | 240 | return NULL; |
248 | } | 241 | } |
249 | gp = GNUNET_new (struct GNUNET_CADET_GetPeer); | 242 | gp = GNUNET_new (struct GNUNET_CADET_GetPath); |
250 | gp->peer_cb = callback; | 243 | gp->path_cb = callback; |
251 | gp->peer_cb_cls = callback_cls; | 244 | gp->path_cb_cls = callback_cls; |
252 | gp->cfg = cfg; | 245 | gp->cfg = cfg; |
253 | gp->id = *id; | 246 | gp->id = *id; |
254 | reconnect (gp); | 247 | reconnect (gp); |
@@ -265,12 +258,12 @@ GNUNET_CADET_get_peer (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
265 | * Cancel @a gp operation. | 258 | * Cancel @a gp operation. |
266 | * | 259 | * |
267 | * @param gp operation to cancel | 260 | * @param gp operation to cancel |
268 | * @return closure from #GNUNET_CADET_get_peer(). | 261 | * @return closure from #GNUNET_CADET_get_path(). |
269 | */ | 262 | */ |
270 | void * | 263 | void * |
271 | GNUNET_CADET_get_peer_cancel (struct GNUNET_CADET_GetPeer *gp) | 264 | GNUNET_CADET_get_path_cancel (struct GNUNET_CADET_GetPath *gp) |
272 | { | 265 | { |
273 | void *ret = gp->peer_cb_cls; | 266 | void *ret = gp->path_cb_cls; |
274 | 267 | ||
275 | if (NULL != gp->mq) | 268 | if (NULL != gp->mq) |
276 | GNUNET_MQ_destroy (gp->mq); | 269 | GNUNET_MQ_destroy (gp->mq); |
@@ -281,4 +274,4 @@ GNUNET_CADET_get_peer_cancel (struct GNUNET_CADET_GetPeer *gp) | |||
281 | } | 274 | } |
282 | 275 | ||
283 | 276 | ||
284 | /* end of cadet_api_get_peer.c */ | 277 | /* end of cadet_api_get_path.c */ |
diff --git a/src/cadet/cadet_api_list_peers.c b/src/cadet/cadet_api_list_peers.c index cc6948a36..4dc6d02f5 100644 --- a/src/cadet/cadet_api_list_peers.c +++ b/src/cadet/cadet_api_list_peers.c | |||
@@ -71,59 +71,43 @@ struct GNUNET_CADET_PeersLister | |||
71 | 71 | ||
72 | 72 | ||
73 | /** | 73 | /** |
74 | * Check that message received from CADET service is well-formed. | 74 | * Process a local reply about info on all tunnels, pass info to the user. |
75 | * | 75 | * |
76 | * @param cls the `struct GNUNET_CADET_PeersLister` | 76 | * @param cls a `struct GNUNET_CADET_PeersLister` |
77 | * @param message the message we got | 77 | * @param info Message itself. |
78 | * @return #GNUNET_OK if the message is well-formed, | ||
79 | * #GNUNET_SYSERR otherwise | ||
80 | */ | 78 | */ |
81 | static int | 79 | static void |
82 | check_get_peers (void *cls, | 80 | handle_get_peers (void *cls, |
83 | const struct GNUNET_MessageHeader *message) | 81 | const struct GNUNET_CADET_LocalInfoPeers *info) |
84 | { | 82 | { |
85 | size_t esize; | 83 | struct GNUNET_CADET_PeersLister *pl = cls; |
86 | 84 | struct GNUNET_CADET_PeerListEntry ple; | |
87 | (void) cls; | 85 | |
88 | esize = ntohs (message->size); | 86 | ple.peer = info->destination; |
89 | if (sizeof (struct GNUNET_CADET_LocalInfoPeer) == esize) | 87 | ple.have_tunnel = (int) ntohs (info->tunnel); |
90 | return GNUNET_OK; | 88 | ple.n_paths = (unsigned int) ntohs (info->paths); |
91 | if (sizeof (struct GNUNET_MessageHeader) == esize) | 89 | ple.best_path_length = (unsigned int) ntohl (info->best_path_length); |
92 | return GNUNET_OK; | 90 | pl->peers_cb (pl->peers_cb_cls, |
93 | return GNUNET_SYSERR; | 91 | &ple); |
94 | } | 92 | } |
95 | 93 | ||
96 | 94 | ||
97 | // FIXME: use two different message types instead of this mess! | ||
98 | /** | 95 | /** |
99 | * Process a local reply about info on all tunnels, pass info to the user. | 96 | * Process a end of list reply about info on all peers. |
100 | * | 97 | * |
101 | * @param cls a `struct GNUNET_CADET_PeersLister` | 98 | * @param cls a `struct GNUNET_CADET_PeersLister` |
102 | * @param msg Message itself. | 99 | * @param msg Message itself. |
103 | */ | 100 | */ |
104 | static void | 101 | static void |
105 | handle_get_peers (void *cls, | 102 | handle_get_peers_end (void *cls, |
106 | const struct GNUNET_MessageHeader *msg) | 103 | const struct GNUNET_MessageHeader *msg) |
107 | { | 104 | { |
108 | struct GNUNET_CADET_PeersLister *pl = cls; | 105 | struct GNUNET_CADET_PeersLister *pl = cls; |
109 | const struct GNUNET_CADET_LocalInfoPeer *info = | 106 | (void) msg; |
110 | (const struct GNUNET_CADET_LocalInfoPeer *) msg; | 107 | |
111 | 108 | pl->peers_cb (pl->peers_cb_cls, | |
112 | if (sizeof (struct GNUNET_CADET_LocalInfoPeer) == ntohs (msg->size)) | 109 | NULL); |
113 | pl->peers_cb (pl->peers_cb_cls, | 110 | GNUNET_CADET_list_peers_cancel (pl); |
114 | &info->destination, | ||
115 | (int) ntohs (info->tunnel), | ||
116 | (unsigned int) ntohs (info->paths), | ||
117 | 0); | ||
118 | else | ||
119 | { | ||
120 | pl->peers_cb (pl->peers_cb_cls, | ||
121 | NULL, | ||
122 | 0, | ||
123 | 0, | ||
124 | 0); | ||
125 | GNUNET_CADET_list_peers_cancel (pl); | ||
126 | } | ||
127 | } | 111 | } |
128 | 112 | ||
129 | 113 | ||
@@ -168,10 +152,14 @@ reconnect (void *cls) | |||
168 | { | 152 | { |
169 | struct GNUNET_CADET_PeersLister *pl = cls; | 153 | struct GNUNET_CADET_PeersLister *pl = cls; |
170 | struct GNUNET_MQ_MessageHandler handlers[] = { | 154 | struct GNUNET_MQ_MessageHandler handlers[] = { |
171 | GNUNET_MQ_hd_var_size (get_peers, | 155 | GNUNET_MQ_hd_fixed_size (get_peers, |
172 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, | 156 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, |
173 | struct GNUNET_MessageHeader, | 157 | struct GNUNET_CADET_LocalInfoPeers, |
174 | pl), | 158 | pl), |
159 | GNUNET_MQ_hd_fixed_size (get_peers_end, | ||
160 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END, | ||
161 | struct GNUNET_MessageHeader, | ||
162 | pl), | ||
175 | GNUNET_MQ_handler_end () | 163 | GNUNET_MQ_handler_end () |
176 | }; | 164 | }; |
177 | struct GNUNET_MessageHeader *msg; | 165 | struct GNUNET_MessageHeader *msg; |
@@ -186,7 +174,7 @@ reconnect (void *cls) | |||
186 | if (NULL == pl->mq) | 174 | if (NULL == pl->mq) |
187 | return; | 175 | return; |
188 | env = GNUNET_MQ_msg (msg, | 176 | env = GNUNET_MQ_msg (msg, |
189 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); | 177 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS); |
190 | GNUNET_MQ_send (pl->mq, | 178 | GNUNET_MQ_send (pl->mq, |
191 | env); | 179 | env); |
192 | } | 180 | } |
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c index b36113318..3386f7464 100644 --- a/src/cadet/gnunet-cadet.c +++ b/src/cadet/gnunet-cadet.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012, 2017 GNUnet e.V. | 3 | Copyright (C) 2012, 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 |
@@ -102,6 +102,16 @@ static struct GNUNET_CADET_Handle *mh; | |||
102 | static const struct GNUNET_CONFIGURATION_Handle *my_cfg; | 102 | static const struct GNUNET_CONFIGURATION_Handle *my_cfg; |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * Active get path operation. | ||
106 | */ | ||
107 | static struct GNUNET_CADET_GetPath *gpo; | ||
108 | |||
109 | /** | ||
110 | * Active peer listing operation. | ||
111 | */ | ||
112 | struct GNUNET_CADET_PeersLister *plo; | ||
113 | |||
114 | /** | ||
105 | * Channel handle. | 115 | * Channel handle. |
106 | */ | 116 | */ |
107 | static struct GNUNET_CADET_Channel *ch; | 117 | static struct GNUNET_CADET_Channel *ch; |
@@ -210,6 +220,16 @@ shutdown_task (void *cls) | |||
210 | { | 220 | { |
211 | GNUNET_CADET_channel_destroy (ch); | 221 | GNUNET_CADET_channel_destroy (ch); |
212 | ch = NULL; | 222 | ch = NULL; |
223 | } | ||
224 | if (NULL != gpo) | ||
225 | { | ||
226 | GNUNET_CADET_get_path_cancel (gpo); | ||
227 | gpo = NULL; | ||
228 | } | ||
229 | if (NULL != plo) | ||
230 | { | ||
231 | GNUNET_CADET_list_peers_cancel (plo); | ||
232 | plo = NULL; | ||
213 | } | 233 | } |
214 | if (NULL != mh) | 234 | if (NULL != mh) |
215 | { | 235 | { |
@@ -496,93 +516,52 @@ handle_data (void *cls, | |||
496 | * After last peer has been reported, an additional call with NULL is done. | 516 | * After last peer has been reported, an additional call with NULL is done. |
497 | * | 517 | * |
498 | * @param cls Closure. | 518 | * @param cls Closure. |
499 | * @param peer Peer, or NULL on "EOF". | 519 | * @param ple information about peer, or NULL on "EOF". |
500 | * @param tunnel Do we have a tunnel towards this peer? | ||
501 | * @param n_paths Number of known paths towards this peer. | ||
502 | * @param best_path How long is the best path? | ||
503 | * (0 = unknown, 1 = ourselves, 2 = neighbor) | ||
504 | */ | 520 | */ |
505 | static void | 521 | static void |
506 | peers_callback (void *cls, | 522 | peers_callback (void *cls, |
507 | const struct GNUNET_PeerIdentity *peer, | 523 | const struct GNUNET_CADET_PeerListEntry *ple) |
508 | int tunnel, | ||
509 | unsigned int n_paths, | ||
510 | unsigned int best_path) | ||
511 | { | 524 | { |
512 | if (NULL == peer) | 525 | if (NULL == ple) |
513 | { | 526 | { |
527 | plo = NULL; | ||
514 | GNUNET_SCHEDULER_shutdown(); | 528 | GNUNET_SCHEDULER_shutdown(); |
515 | return; | 529 | return; |
516 | } | 530 | } |
517 | FPRINTF (stdout, | 531 | FPRINTF (stdout, |
518 | "%s tunnel: %c, paths: %u\n", | 532 | "%s tunnel: %c, paths: %u\n", |
519 | GNUNET_i2s_full (peer), | 533 | GNUNET_i2s_full (&ple->peer), |
520 | tunnel ? 'Y' : 'N', | 534 | ple->have_tunnel ? 'Y' : 'N', |
521 | n_paths); | 535 | ple->n_paths); |
522 | } | 536 | } |
523 | 537 | ||
524 | 538 | ||
525 | /** | 539 | /** |
526 | * Method called to retrieve information about a specific peer | 540 | * Method called to retrieve information about paths to a specific peer |
527 | * known to the service. | 541 | * known to the service. |
528 | * | 542 | * |
529 | * @param cls Closure. | 543 | * @param cls Closure. |
530 | * @param peer Peer ID. | 544 | * @param ppd path detail |
531 | * @param tunnel Do we have a tunnel towards this peer? #GNUNET_YES/#GNUNET_NO | ||
532 | * @param neighbor Is this a direct neighbor? #GNUNET_YES/#GNUNET_NO | ||
533 | * @param n_paths Number of paths known towards peer. | ||
534 | * @param paths Array of PEER_IDs representing all paths to reach the peer. | ||
535 | * Each path starts with the local peer. | ||
536 | * Each path ends with the destination peer (given in @c peer). | ||
537 | */ | 545 | */ |
538 | static void | 546 | static void |
539 | peer_callback (void *cls, | 547 | path_callback (void *cls, |
540 | const struct GNUNET_PeerIdentity *peer, | 548 | const struct GNUNET_CADET_PeerPathDetail *ppd) |
541 | int tunnel, | ||
542 | int neighbor, | ||
543 | unsigned int n_paths, | ||
544 | const struct GNUNET_PeerIdentity *paths, | ||
545 | int offset, | ||
546 | int finished_with_paths) | ||
547 | { | 549 | { |
548 | unsigned int i; | 550 | if (NULL == ppd) |
549 | const struct GNUNET_PeerIdentity *p; | ||
550 | |||
551 | |||
552 | if (GNUNET_YES == finished_with_paths) | ||
553 | { | 551 | { |
552 | gpo = NULL; | ||
554 | GNUNET_SCHEDULER_shutdown(); | 553 | GNUNET_SCHEDULER_shutdown(); |
555 | return; | 554 | return; |
556 | } | 555 | } |
557 | 556 | FPRINTF (stdout, | |
558 | if (offset == 0){ | 557 | "Path of length %u: ", |
559 | FPRINTF (stdout, | 558 | ppd->path_length); |
560 | "%s [TUNNEL: %s, NEIGHBOR: %s, PATHS: %u]\n", | 559 | for (unsigned int i = 0; i < ppd->path_length; i++) |
561 | GNUNET_i2s_full (peer), | ||
562 | tunnel ? "Y" : "N", | ||
563 | neighbor ? "Y" : "N", | ||
564 | n_paths); | ||
565 | }else{ | ||
566 | p = paths; | ||
567 | FPRINTF (stdout, | ||
568 | "Indirekt path with offset %u: ", | ||
569 | offset); | ||
570 | for (i = 0; i <= offset && NULL != p;) | ||
571 | { | ||
572 | FPRINTF (stdout, | ||
573 | "%s ", | ||
574 | GNUNET_i2s (p)); | ||
575 | i++; | ||
576 | p++; | ||
577 | } | ||
578 | |||
579 | FPRINTF (stdout, | 560 | FPRINTF (stdout, |
580 | "\n"); | 561 | "%s ", |
581 | 562 | GNUNET_i2s (&ppd->path[i])); | |
582 | } | 563 | FPRINTF (stdout, |
583 | 564 | "\n"); | |
584 | |||
585 | |||
586 | } | 565 | } |
587 | 566 | ||
588 | 567 | ||
@@ -669,11 +648,9 @@ static void | |||
669 | get_peers (void *cls) | 648 | get_peers (void *cls) |
670 | { | 649 | { |
671 | job = NULL; | 650 | job = NULL; |
672 | #if FIXME5385 | 651 | plo = GNUNET_CADET_list_peers (my_cfg, |
673 | GNUNET_CADET_list_peers (my_cfg, | 652 | &peers_callback, |
674 | &peers_callback, | 653 | NULL); |
675 | NULL); | ||
676 | #endif | ||
677 | } | 654 | } |
678 | 655 | ||
679 | 656 | ||
@@ -699,12 +676,10 @@ show_peer (void *cls) | |||
699 | GNUNET_SCHEDULER_shutdown(); | 676 | GNUNET_SCHEDULER_shutdown(); |
700 | return; | 677 | return; |
701 | } | 678 | } |
702 | #if FIXME5385 | 679 | gpo = GNUNET_CADET_get_path (my_cfg, |
703 | GNUNET_CADET_get_peer (my_cfg, | 680 | &pid, |
704 | &pid, | 681 | &path_callback, |
705 | &peer_callback, | 682 | NULL); |
706 | NULL); | ||
707 | #endif | ||
708 | } | 683 | } |
709 | 684 | ||
710 | 685 | ||
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c index ae5d48943..a62ce4cb0 100644 --- a/src/cadet/gnunet-service-cadet.c +++ b/src/cadet/gnunet-service-cadet.c | |||
@@ -821,7 +821,7 @@ get_all_peers_iterator (void *cls, | |||
821 | struct CadetClient *c = cls; | 821 | struct CadetClient *c = cls; |
822 | struct CadetPeer *p = value; | 822 | struct CadetPeer *p = value; |
823 | struct GNUNET_MQ_Envelope *env; | 823 | struct GNUNET_MQ_Envelope *env; |
824 | struct GNUNET_CADET_LocalInfoPeer *msg; | 824 | struct GNUNET_CADET_LocalInfoPeers *msg; |
825 | 825 | ||
826 | env = GNUNET_MQ_msg (msg, | 826 | env = GNUNET_MQ_msg (msg, |
827 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); | 827 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); |
@@ -829,6 +829,7 @@ get_all_peers_iterator (void *cls, | |||
829 | msg->paths = htons (GCP_count_paths (p)); | 829 | msg->paths = htons (GCP_count_paths (p)); |
830 | msg->tunnel = htons (NULL != GCP_get_tunnel (p, | 830 | msg->tunnel = htons (NULL != GCP_get_tunnel (p, |
831 | GNUNET_NO)); | 831 | GNUNET_NO)); |
832 | msg->best_path_length = htonl (0); // FIXME: get length of shortest known path! | ||
832 | GNUNET_MQ_send (c->mq, | 833 | GNUNET_MQ_send (c->mq, |
833 | env); | 834 | env); |
834 | return GNUNET_YES; | 835 | return GNUNET_YES; |
@@ -852,7 +853,7 @@ handle_get_peers (void *cls, | |||
852 | GCP_iterate_all (&get_all_peers_iterator, | 853 | GCP_iterate_all (&get_all_peers_iterator, |
853 | c); | 854 | c); |
854 | env = GNUNET_MQ_msg (reply, | 855 | env = GNUNET_MQ_msg (reply, |
855 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); | 856 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END); |
856 | GNUNET_MQ_send (c->mq, | 857 | GNUNET_MQ_send (c->mq, |
857 | env); | 858 | env); |
858 | GNUNET_SERVICE_client_continue (c->client); | 859 | GNUNET_SERVICE_client_continue (c->client); |
@@ -876,10 +877,9 @@ path_info_iterator (void *cls, | |||
876 | { | 877 | { |
877 | struct GNUNET_MQ_Handle *mq = cls; | 878 | struct GNUNET_MQ_Handle *mq = cls; |
878 | struct GNUNET_MQ_Envelope *env; | 879 | struct GNUNET_MQ_Envelope *env; |
879 | struct GNUNET_CADET_LocalInfoPeer *resp; | 880 | struct GNUNET_CADET_LocalInfoPath *resp; |
880 | struct GNUNET_PeerIdentity *id; | 881 | struct GNUNET_PeerIdentity *id; |
881 | uint16_t path_size; | 882 | size_t path_size; |
882 | unsigned int i; | ||
883 | unsigned int path_length; | 883 | unsigned int path_length; |
884 | 884 | ||
885 | path_length = GCPP_get_length (path); | 885 | path_length = GCPP_get_length (path); |
@@ -893,18 +893,13 @@ path_info_iterator (void *cls, | |||
893 | } | 893 | } |
894 | env = GNUNET_MQ_msg_extra (resp, | 894 | env = GNUNET_MQ_msg_extra (resp, |
895 | path_size, | 895 | path_size, |
896 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); | 896 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH); |
897 | |||
898 | |||
899 | resp->offset = htons(off); | ||
900 | resp->finished_with_paths = htons(0); | ||
901 | |||
902 | id = (struct GNUNET_PeerIdentity *) &resp[1]; | 897 | id = (struct GNUNET_PeerIdentity *) &resp[1]; |
903 | 898 | ||
904 | /* Don't copy first peer. First peer is always the local one. Last | 899 | /* Don't copy first peer. First peer is always the local one. Last |
905 | * peer is always the destination (leave as 0, EOL). | 900 | * peer is always the destination (leave as 0, EOL). |
906 | */ | 901 | */ |
907 | for (i = 0; i <= off; i++) | 902 | for (unsigned int i = 0; i <= off; i++) |
908 | id[i] = *GCP_get_id (GCPP_get_peer_at_offset (path, | 903 | id[i] = *GCP_get_id (GCPP_get_peer_at_offset (path, |
909 | i)); | 904 | i)); |
910 | GNUNET_MQ_send (mq, | 905 | GNUNET_MQ_send (mq, |
@@ -912,70 +907,32 @@ path_info_iterator (void *cls, | |||
912 | return GNUNET_YES; | 907 | return GNUNET_YES; |
913 | } | 908 | } |
914 | 909 | ||
915 | /** | ||
916 | * Getting summary information about the number of paths and if a tunnel exists, | ||
917 | * and the indirect paths to a peer, if there are ones. | ||
918 | * | ||
919 | * @param cls Closure (). | ||
920 | * @param peer Peer ID (tunnel remote peer). | ||
921 | * @param value Peer info. | ||
922 | * @return #GNUNET_YES, to keep iterating. | ||
923 | */ | ||
924 | static void | ||
925 | get_peer_info (void *cls, | ||
926 | const struct GNUNET_PeerIdentity *peer, | ||
927 | struct CadetPeer *p) | ||
928 | { | ||
929 | struct CadetClient *c = cls; | ||
930 | struct GNUNET_MQ_Envelope *env; | ||
931 | struct GNUNET_CADET_LocalInfoPeer *msg; | ||
932 | |||
933 | env = GNUNET_MQ_msg (msg, | ||
934 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); | ||
935 | msg->offset = htons(0); | ||
936 | msg->destination = *peer; | ||
937 | msg->paths = htons (GCP_count_paths (p)); | ||
938 | msg->tunnel = htons (NULL != GCP_get_tunnel (p, | ||
939 | GNUNET_NO)); | ||
940 | msg->finished_with_paths = htons(0); | ||
941 | GNUNET_MQ_send (c->mq, | ||
942 | env); | ||
943 | GCP_iterate_indirect_paths (p, | ||
944 | &path_info_iterator, | ||
945 | c->mq); | ||
946 | } | ||
947 | |||
948 | 910 | ||
949 | /** | 911 | /** |
950 | * Handler for client's SHOW_PEER request. | 912 | * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH request. |
951 | * | 913 | * |
952 | * @param cls Identification of the client. | 914 | * @param cls Identification of the client. |
953 | * @param msg The actual message. | 915 | * @param msg The actual message. |
954 | */ | 916 | */ |
955 | static void | 917 | static void |
956 | handle_show_peer (void *cls, | 918 | handle_show_path (void *cls, |
957 | const struct GNUNET_CADET_LocalInfo *msg) | 919 | const struct GNUNET_CADET_RequestPathInfoMessage *msg) |
958 | { | 920 | { |
959 | struct CadetClient *c = cls; | 921 | struct CadetClient *c = cls; |
960 | struct CadetPeer *p; | 922 | struct CadetPeer *p; |
961 | struct GNUNET_MQ_Envelope *env; | 923 | struct GNUNET_MQ_Envelope *env; |
962 | struct GNUNET_CADET_LocalInfoPeer *resp; | 924 | struct GNUNET_MessageHeader *resp; |
963 | 925 | ||
964 | p = GCP_get (&msg->peer, | 926 | p = GCP_get (&msg->peer, |
965 | GNUNET_NO); | 927 | GNUNET_NO); |
966 | if (NULL != p){ | 928 | if (NULL != p) |
967 | get_peer_info(c, &(msg->peer), p); | 929 | GCP_iterate_indirect_paths (p, |
968 | } | 930 | &path_info_iterator, |
969 | 931 | c->mq); | |
970 | |||
971 | env = GNUNET_MQ_msg (resp, | 932 | env = GNUNET_MQ_msg (resp, |
972 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); | 933 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END); |
973 | resp->finished_with_paths = htons(1); | ||
974 | resp->destination = msg->peer; | ||
975 | |||
976 | GNUNET_MQ_send (c->mq, | 934 | GNUNET_MQ_send (c->mq, |
977 | env); | 935 | env); |
978 | |||
979 | GNUNET_SERVICE_client_continue (c->client); | 936 | GNUNET_SERVICE_client_continue (c->client); |
980 | } | 937 | } |
981 | 938 | ||
@@ -1144,77 +1101,6 @@ handle_info_tunnel (void *cls, | |||
1144 | 1101 | ||
1145 | 1102 | ||
1146 | /** | 1103 | /** |
1147 | * Iterator over all peers to dump info for each peer. | ||
1148 | * | ||
1149 | * @param cls Closure (unused). | ||
1150 | * @param peer Peer ID (tunnel remote peer). | ||
1151 | * @param value Peer info. | ||
1152 | * | ||
1153 | * @return #GNUNET_YES, to keep iterating. | ||
1154 | */ | ||
1155 | static int | ||
1156 | show_peer_iterator (void *cls, | ||
1157 | const struct GNUNET_PeerIdentity *peer, | ||
1158 | void *value) | ||
1159 | { | ||
1160 | struct CadetPeer *p = value; | ||
1161 | struct CadetTunnel *t; | ||
1162 | |||
1163 | t = GCP_get_tunnel (p, | ||
1164 | GNUNET_NO); | ||
1165 | if (NULL != t) | ||
1166 | GCT_debug (t, | ||
1167 | GNUNET_ERROR_TYPE_ERROR); | ||
1168 | LOG (GNUNET_ERROR_TYPE_ERROR, "\n"); | ||
1169 | return GNUNET_YES; | ||
1170 | } | ||
1171 | |||
1172 | |||
1173 | /** | ||
1174 | * Handler for client's INFO_DUMP request. | ||
1175 | * | ||
1176 | * @param cls Identification of the client. | ||
1177 | * @param message The actual message. | ||
1178 | */ | ||
1179 | static void | ||
1180 | handle_info_dump (void *cls, | ||
1181 | const struct GNUNET_MessageHeader *message) | ||
1182 | { | ||
1183 | struct CadetClient *c = cls; | ||
1184 | |||
1185 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1186 | "Received dump info request from client %u\n", | ||
1187 | c->id); | ||
1188 | |||
1189 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1190 | "*************************** DUMP START ***************************\n"); | ||
1191 | for (struct CadetClient *ci = clients_head; | ||
1192 | NULL != ci; | ||
1193 | ci = ci->next) | ||
1194 | { | ||
1195 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1196 | "Client %u (%p), handle: %p, ports: %u, channels: %u\n", | ||
1197 | ci->id, | ||
1198 | ci, | ||
1199 | ci->client, | ||
1200 | (NULL != c->ports) | ||
1201 | ? GNUNET_CONTAINER_multihashmap_size (ci->ports) | ||
1202 | : 0, | ||
1203 | GNUNET_CONTAINER_multihashmap32_size (ci->channels)); | ||
1204 | } | ||
1205 | LOG (GNUNET_ERROR_TYPE_ERROR, "***************************\n"); | ||
1206 | GCP_iterate_all (&show_peer_iterator, | ||
1207 | NULL); | ||
1208 | |||
1209 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1210 | "**************************** DUMP END ****************************\n"); | ||
1211 | |||
1212 | GNUNET_SERVICE_client_continue (c->client); | ||
1213 | } | ||
1214 | |||
1215 | |||
1216 | |||
1217 | /** | ||
1218 | * Callback called when a client connects to the service. | 1104 | * Callback called when a client connects to the service. |
1219 | * | 1105 | * |
1220 | * @param cls closure for the service | 1106 | * @param cls closure for the service |
@@ -1541,12 +1427,12 @@ GNUNET_SERVICE_MAIN | |||
1541 | struct GNUNET_CADET_LocalAck, | 1427 | struct GNUNET_CADET_LocalAck, |
1542 | NULL), | 1428 | NULL), |
1543 | GNUNET_MQ_hd_fixed_size (get_peers, | 1429 | GNUNET_MQ_hd_fixed_size (get_peers, |
1544 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, | 1430 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS, |
1545 | struct GNUNET_MessageHeader, | 1431 | struct GNUNET_MessageHeader, |
1546 | NULL), | 1432 | NULL), |
1547 | GNUNET_MQ_hd_fixed_size (show_peer, | 1433 | GNUNET_MQ_hd_fixed_size (show_path, |
1548 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER, | 1434 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH, |
1549 | struct GNUNET_CADET_LocalInfo, | 1435 | struct GNUNET_CADET_RequestPathInfoMessage, |
1550 | NULL), | 1436 | NULL), |
1551 | GNUNET_MQ_hd_fixed_size (info_tunnels, | 1437 | GNUNET_MQ_hd_fixed_size (info_tunnels, |
1552 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, | 1438 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, |
@@ -1556,10 +1442,6 @@ GNUNET_SERVICE_MAIN | |||
1556 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL, | 1442 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL, |
1557 | struct GNUNET_CADET_LocalInfo, | 1443 | struct GNUNET_CADET_LocalInfo, |
1558 | NULL), | 1444 | NULL), |
1559 | GNUNET_MQ_hd_fixed_size (info_dump, | ||
1560 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP, | ||
1561 | struct GNUNET_MessageHeader, | ||
1562 | NULL), | ||
1563 | GNUNET_MQ_handler_end ()); | 1445 | GNUNET_MQ_handler_end ()); |
1564 | 1446 | ||
1565 | /* end of gnunet-service-cadet-new.c */ | 1447 | /* end of gnunet-service-cadet-new.c */ |