diff options
Diffstat (limited to 'src/cadet/cadet_api_get_path.c')
-rw-r--r-- | src/cadet/cadet_api_get_path.c | 155 |
1 files changed, 76 insertions, 79 deletions
diff --git a/src/cadet/cadet_api_get_path.c b/src/cadet/cadet_api_get_path.c index fcc79c3d5..0f18014c3 100644 --- a/src/cadet/cadet_api_get_path.c +++ b/src/cadet/cadet_api_get_path.c | |||
@@ -16,7 +16,7 @@ | |||
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_get_path.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 |
@@ -34,9 +34,7 @@ | |||
34 | /** | 34 | /** |
35 | * Operation handle. | 35 | * Operation handle. |
36 | */ | 36 | */ |
37 | struct GNUNET_CADET_GetPath | 37 | struct GNUNET_CADET_GetPath { |
38 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * Monitor callback | 39 | * Monitor callback |
42 | */ | 40 | */ |
@@ -71,7 +69,6 @@ struct GNUNET_CADET_GetPath | |||
71 | * Peer we want information about. | 69 | * Peer we want information about. |
72 | */ | 70 | */ |
73 | struct GNUNET_PeerIdentity id; | 71 | struct GNUNET_PeerIdentity id; |
74 | |||
75 | }; | 72 | }; |
76 | 73 | ||
77 | 74 | ||
@@ -84,24 +81,24 @@ struct GNUNET_CADET_GetPath | |||
84 | * #GNUNET_SYSERR otherwise | 81 | * #GNUNET_SYSERR otherwise |
85 | */ | 82 | */ |
86 | static int | 83 | static int |
87 | check_get_path (void *cls, | 84 | check_get_path(void *cls, |
88 | const struct GNUNET_CADET_LocalInfoPath *message) | 85 | const struct GNUNET_CADET_LocalInfoPath *message) |
89 | { | 86 | { |
90 | size_t msize = sizeof (struct GNUNET_CADET_LocalInfoPath); | 87 | size_t msize = sizeof(struct GNUNET_CADET_LocalInfoPath); |
91 | size_t esize; | 88 | size_t esize; |
92 | 89 | ||
93 | (void) cls; | 90 | (void)cls; |
94 | esize = ntohs (message->header.size); | 91 | esize = ntohs(message->header.size); |
95 | if (esize < msize) | 92 | if (esize < msize) |
96 | { | 93 | { |
97 | GNUNET_break (0); | 94 | GNUNET_break(0); |
98 | return GNUNET_SYSERR; | 95 | return GNUNET_SYSERR; |
99 | } | 96 | } |
100 | if (0 != ((esize - msize) % sizeof (struct GNUNET_PeerIdentity))) | 97 | if (0 != ((esize - msize) % sizeof(struct GNUNET_PeerIdentity))) |
101 | { | 98 | { |
102 | GNUNET_break (0); | 99 | GNUNET_break(0); |
103 | return GNUNET_SYSERR; | 100 | return GNUNET_SYSERR; |
104 | } | 101 | } |
105 | return GNUNET_OK; | 102 | return GNUNET_OK; |
106 | } | 103 | } |
107 | 104 | ||
@@ -113,19 +110,19 @@ check_get_path (void *cls, | |||
113 | * @param message Message itself. | 110 | * @param message Message itself. |
114 | */ | 111 | */ |
115 | static void | 112 | static void |
116 | handle_get_path (void *cls, | 113 | handle_get_path(void *cls, |
117 | const struct GNUNET_CADET_LocalInfoPath *message) | 114 | const struct GNUNET_CADET_LocalInfoPath *message) |
118 | { | 115 | { |
119 | struct GNUNET_CADET_GetPath *gp = cls; | 116 | struct GNUNET_CADET_GetPath *gp = cls; |
120 | struct GNUNET_CADET_PeerPathDetail ppd; | 117 | struct GNUNET_CADET_PeerPathDetail ppd; |
121 | 118 | ||
122 | ppd.peer = gp->id; | 119 | ppd.peer = gp->id; |
123 | ppd.path = (const struct GNUNET_PeerIdentity *) &message[1]; | 120 | ppd.path = (const struct GNUNET_PeerIdentity *)&message[1]; |
124 | ppd.target_offset = ntohl (message->off); | 121 | ppd.target_offset = ntohl(message->off); |
125 | ppd.path_length = (ntohs (message->header.size) - sizeof (*message)) | 122 | ppd.path_length = (ntohs(message->header.size) - sizeof(*message)) |
126 | / sizeof (struct GNUNET_PeerIdentity); | 123 | / sizeof(struct GNUNET_PeerIdentity); |
127 | gp->path_cb (gp->path_cb_cls, | 124 | gp->path_cb(gp->path_cb_cls, |
128 | &ppd); | 125 | &ppd); |
129 | } | 126 | } |
130 | 127 | ||
131 | 128 | ||
@@ -136,15 +133,15 @@ handle_get_path (void *cls, | |||
136 | * @param message Message itself. | 133 | * @param message Message itself. |
137 | */ | 134 | */ |
138 | static void | 135 | static void |
139 | handle_get_path_end (void *cls, | 136 | handle_get_path_end(void *cls, |
140 | const struct GNUNET_MessageHeader *message) | 137 | const struct GNUNET_MessageHeader *message) |
141 | { | 138 | { |
142 | struct GNUNET_CADET_GetPath *gp = cls; | 139 | struct GNUNET_CADET_GetPath *gp = cls; |
143 | 140 | ||
144 | (void) message; | 141 | (void)message; |
145 | gp->path_cb (gp->path_cb_cls, | 142 | gp->path_cb(gp->path_cb_cls, |
146 | NULL); | 143 | NULL); |
147 | GNUNET_CADET_get_path_cancel (gp); | 144 | GNUNET_CADET_get_path_cancel(gp); |
148 | } | 145 | } |
149 | 146 | ||
150 | 147 | ||
@@ -154,7 +151,7 @@ handle_get_path_end (void *cls, | |||
154 | * @param cls a `struct GNUNET_CADET_GetPath` operation | 151 | * @param cls a `struct GNUNET_CADET_GetPath` operation |
155 | */ | 152 | */ |
156 | static void | 153 | static void |
157 | reconnect (void *cls); | 154 | reconnect(void *cls); |
158 | 155 | ||
159 | 156 | ||
160 | /** | 157 | /** |
@@ -164,18 +161,18 @@ reconnect (void *cls); | |||
164 | * @param error error code from MQ | 161 | * @param error error code from MQ |
165 | */ | 162 | */ |
166 | static void | 163 | static void |
167 | error_handler (void *cls, | 164 | error_handler(void *cls, |
168 | enum GNUNET_MQ_Error error) | 165 | enum GNUNET_MQ_Error error) |
169 | { | 166 | { |
170 | struct GNUNET_CADET_GetPath *gp = cls; | 167 | struct GNUNET_CADET_GetPath *gp = cls; |
171 | 168 | ||
172 | GNUNET_MQ_destroy (gp->mq); | 169 | GNUNET_MQ_destroy(gp->mq); |
173 | gp->mq = NULL; | 170 | gp->mq = NULL; |
174 | gp->backoff = GNUNET_TIME_randomized_backoff (gp->backoff, | 171 | gp->backoff = GNUNET_TIME_randomized_backoff(gp->backoff, |
175 | GNUNET_TIME_UNIT_MINUTES); | 172 | GNUNET_TIME_UNIT_MINUTES); |
176 | gp->reconnect_task = GNUNET_SCHEDULER_add_delayed (gp->backoff, | 173 | gp->reconnect_task = GNUNET_SCHEDULER_add_delayed(gp->backoff, |
177 | &reconnect, | 174 | &reconnect, |
178 | gp); | 175 | gp); |
179 | } | 176 | } |
180 | 177 | ||
181 | 178 | ||
@@ -185,36 +182,36 @@ error_handler (void *cls, | |||
185 | * @param cls a `struct GNUNET_CADET_GetPath` operation | 182 | * @param cls a `struct GNUNET_CADET_GetPath` operation |
186 | */ | 183 | */ |
187 | static void | 184 | static void |
188 | reconnect (void *cls) | 185 | reconnect(void *cls) |
189 | { | 186 | { |
190 | struct GNUNET_CADET_GetPath *gp = cls; | 187 | struct GNUNET_CADET_GetPath *gp = cls; |
191 | struct GNUNET_MQ_MessageHandler handlers[] = { | 188 | struct GNUNET_MQ_MessageHandler handlers[] = { |
192 | GNUNET_MQ_hd_var_size (get_path, | 189 | GNUNET_MQ_hd_var_size(get_path, |
193 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH, | 190 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH, |
194 | struct GNUNET_CADET_LocalInfoPath, | 191 | struct GNUNET_CADET_LocalInfoPath, |
195 | gp), | 192 | gp), |
196 | GNUNET_MQ_hd_fixed_size (get_path_end, | 193 | GNUNET_MQ_hd_fixed_size(get_path_end, |
197 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END, | 194 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END, |
198 | struct GNUNET_MessageHeader, | 195 | struct GNUNET_MessageHeader, |
199 | gp), | 196 | gp), |
200 | GNUNET_MQ_handler_end () | 197 | GNUNET_MQ_handler_end() |
201 | }; | 198 | }; |
202 | struct GNUNET_CADET_RequestPathInfoMessage *msg; | 199 | struct GNUNET_CADET_RequestPathInfoMessage *msg; |
203 | struct GNUNET_MQ_Envelope *env; | 200 | struct GNUNET_MQ_Envelope *env; |
204 | 201 | ||
205 | gp->reconnect_task = NULL; | 202 | gp->reconnect_task = NULL; |
206 | gp->mq = GNUNET_CLIENT_connect (gp->cfg, | 203 | gp->mq = GNUNET_CLIENT_connect(gp->cfg, |
207 | "cadet", | 204 | "cadet", |
208 | handlers, | 205 | handlers, |
209 | &error_handler, | 206 | &error_handler, |
210 | gp); | 207 | gp); |
211 | if (NULL == gp->mq) | 208 | if (NULL == gp->mq) |
212 | return; | 209 | return; |
213 | env = GNUNET_MQ_msg (msg, | 210 | env = GNUNET_MQ_msg(msg, |
214 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH); | 211 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH); |
215 | msg->peer = gp->id; | 212 | msg->peer = gp->id; |
216 | GNUNET_MQ_send (gp->mq, | 213 | GNUNET_MQ_send(gp->mq, |
217 | env); | 214 | env); |
218 | } | 215 | } |
219 | 216 | ||
220 | 217 | ||
@@ -228,29 +225,29 @@ reconnect (void *cls) | |||
228 | * @return NULL on error | 225 | * @return NULL on error |
229 | */ | 226 | */ |
230 | struct GNUNET_CADET_GetPath * | 227 | struct GNUNET_CADET_GetPath * |
231 | GNUNET_CADET_get_path (const struct GNUNET_CONFIGURATION_Handle *cfg, | 228 | GNUNET_CADET_get_path(const struct GNUNET_CONFIGURATION_Handle *cfg, |
232 | const struct GNUNET_PeerIdentity *id, | 229 | const struct GNUNET_PeerIdentity *id, |
233 | GNUNET_CADET_PathCB callback, | 230 | GNUNET_CADET_PathCB callback, |
234 | void *callback_cls) | 231 | void *callback_cls) |
235 | { | 232 | { |
236 | struct GNUNET_CADET_GetPath *gp; | 233 | struct GNUNET_CADET_GetPath *gp; |
237 | 234 | ||
238 | if (NULL == callback) | 235 | if (NULL == callback) |
239 | { | 236 | { |
240 | GNUNET_break (0); | 237 | GNUNET_break(0); |
241 | return NULL; | 238 | return NULL; |
242 | } | 239 | } |
243 | gp = GNUNET_new (struct GNUNET_CADET_GetPath); | 240 | gp = GNUNET_new(struct GNUNET_CADET_GetPath); |
244 | gp->path_cb = callback; | 241 | gp->path_cb = callback; |
245 | gp->path_cb_cls = callback_cls; | 242 | gp->path_cb_cls = callback_cls; |
246 | gp->cfg = cfg; | 243 | gp->cfg = cfg; |
247 | gp->id = *id; | 244 | gp->id = *id; |
248 | reconnect (gp); | 245 | reconnect(gp); |
249 | if (NULL == gp->mq) | 246 | if (NULL == gp->mq) |
250 | { | 247 | { |
251 | GNUNET_free (gp); | 248 | GNUNET_free(gp); |
252 | return NULL; | 249 | return NULL; |
253 | } | 250 | } |
254 | return gp; | 251 | return gp; |
255 | } | 252 | } |
256 | 253 | ||
@@ -262,15 +259,15 @@ GNUNET_CADET_get_path (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
262 | * @return closure from #GNUNET_CADET_get_path(). | 259 | * @return closure from #GNUNET_CADET_get_path(). |
263 | */ | 260 | */ |
264 | void * | 261 | void * |
265 | GNUNET_CADET_get_path_cancel (struct GNUNET_CADET_GetPath *gp) | 262 | GNUNET_CADET_get_path_cancel(struct GNUNET_CADET_GetPath *gp) |
266 | { | 263 | { |
267 | void *ret = gp->path_cb_cls; | 264 | void *ret = gp->path_cb_cls; |
268 | 265 | ||
269 | if (NULL != gp->mq) | 266 | if (NULL != gp->mq) |
270 | GNUNET_MQ_destroy (gp->mq); | 267 | GNUNET_MQ_destroy(gp->mq); |
271 | if (NULL != gp->reconnect_task) | 268 | if (NULL != gp->reconnect_task) |
272 | GNUNET_SCHEDULER_cancel (gp->reconnect_task); | 269 | GNUNET_SCHEDULER_cancel(gp->reconnect_task); |
273 | GNUNET_free (gp); | 270 | GNUNET_free(gp); |
274 | return ret; | 271 | return ret; |
275 | } | 272 | } |
276 | 273 | ||