diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/dns/dns_api.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/dns/dns_api.c')
-rw-r--r-- | src/dns/dns_api.c | 225 |
1 files changed, 110 insertions, 115 deletions
diff --git a/src/dns/dns_api.c b/src/dns/dns_api.c index e34f02ef0..4dc8e00dd 100644 --- a/src/dns/dns_api.c +++ b/src/dns/dns_api.c | |||
@@ -11,7 +11,7 @@ | |||
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 | ||
@@ -31,9 +31,7 @@ | |||
31 | /** | 31 | /** |
32 | * Handle to identify an individual DNS request. | 32 | * Handle to identify an individual DNS request. |
33 | */ | 33 | */ |
34 | struct GNUNET_DNS_RequestHandle | 34 | struct GNUNET_DNS_RequestHandle { |
35 | { | ||
36 | |||
37 | /** | 35 | /** |
38 | * Handle to DNS API. | 36 | * Handle to DNS API. |
39 | */ | 37 | */ |
@@ -48,16 +46,13 @@ struct GNUNET_DNS_RequestHandle | |||
48 | * Re-connect counter, to make sure we did not reconnect in the meantime. | 46 | * Re-connect counter, to make sure we did not reconnect in the meantime. |
49 | */ | 47 | */ |
50 | uint32_t generation; | 48 | uint32_t generation; |
51 | |||
52 | }; | 49 | }; |
53 | 50 | ||
54 | 51 | ||
55 | /** | 52 | /** |
56 | * DNS handle | 53 | * DNS handle |
57 | */ | 54 | */ |
58 | struct GNUNET_DNS_Handle | 55 | struct GNUNET_DNS_Handle { |
59 | { | ||
60 | |||
61 | /** | 56 | /** |
62 | * Connection to DNS service, or NULL. | 57 | * Connection to DNS service, or NULL. |
63 | */ | 58 | */ |
@@ -108,7 +103,7 @@ struct GNUNET_DNS_Handle | |||
108 | * @param tc scheduler context (unused) | 103 | * @param tc scheduler context (unused) |
109 | */ | 104 | */ |
110 | static void | 105 | static void |
111 | reconnect (void *cls); | 106 | reconnect(void *cls); |
112 | 107 | ||
113 | 108 | ||
114 | /** | 109 | /** |
@@ -117,17 +112,17 @@ reconnect (void *cls); | |||
117 | * @param dh handle with the connection | 112 | * @param dh handle with the connection |
118 | */ | 113 | */ |
119 | static void | 114 | static void |
120 | force_reconnect (struct GNUNET_DNS_Handle *dh) | 115 | force_reconnect(struct GNUNET_DNS_Handle *dh) |
121 | { | 116 | { |
122 | if (NULL != dh->mq) | 117 | if (NULL != dh->mq) |
123 | { | 118 | { |
124 | GNUNET_MQ_destroy (dh->mq); | 119 | GNUNET_MQ_destroy(dh->mq); |
125 | dh->mq = NULL; | 120 | dh->mq = NULL; |
126 | } | 121 | } |
127 | dh->reconnect_task = | 122 | dh->reconnect_task = |
128 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 123 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
129 | &reconnect, | 124 | &reconnect, |
130 | dh); | 125 | dh); |
131 | } | 126 | } |
132 | 127 | ||
133 | 128 | ||
@@ -140,12 +135,12 @@ force_reconnect (struct GNUNET_DNS_Handle *dh) | |||
140 | * @param error error code | 135 | * @param error error code |
141 | */ | 136 | */ |
142 | static void | 137 | static void |
143 | mq_error_handler (void *cls, | 138 | mq_error_handler(void *cls, |
144 | enum GNUNET_MQ_Error error) | 139 | enum GNUNET_MQ_Error error) |
145 | { | 140 | { |
146 | struct GNUNET_DNS_Handle *dh = cls; | 141 | struct GNUNET_DNS_Handle *dh = cls; |
147 | 142 | ||
148 | force_reconnect (dh); | 143 | force_reconnect(dh); |
149 | } | 144 | } |
150 | 145 | ||
151 | 146 | ||
@@ -158,14 +153,14 @@ mq_error_handler (void *cls, | |||
158 | * @param req message from the service (request) | 153 | * @param req message from the service (request) |
159 | */ | 154 | */ |
160 | static int | 155 | static int |
161 | check_request (void *cls, | 156 | check_request(void *cls, |
162 | const struct GNUNET_DNS_Request *req) | 157 | const struct GNUNET_DNS_Request *req) |
163 | { | 158 | { |
164 | if (0 != ntohl (req->reserved)) | 159 | if (0 != ntohl(req->reserved)) |
165 | { | 160 | { |
166 | GNUNET_break (0); | 161 | GNUNET_break(0); |
167 | return GNUNET_SYSERR; | 162 | return GNUNET_SYSERR; |
168 | } | 163 | } |
169 | return GNUNET_OK; | 164 | return GNUNET_OK; |
170 | } | 165 | } |
171 | 166 | ||
@@ -178,22 +173,22 @@ check_request (void *cls, | |||
178 | * @param msg message from the service (request) | 173 | * @param msg message from the service (request) |
179 | */ | 174 | */ |
180 | static void | 175 | static void |
181 | handle_request (void *cls, | 176 | handle_request(void *cls, |
182 | const struct GNUNET_DNS_Request *req) | 177 | const struct GNUNET_DNS_Request *req) |
183 | { | 178 | { |
184 | struct GNUNET_DNS_Handle *dh = cls; | 179 | struct GNUNET_DNS_Handle *dh = cls; |
185 | size_t payload_length = ntohs (req->header.size) - sizeof (*req); | 180 | size_t payload_length = ntohs(req->header.size) - sizeof(*req); |
186 | struct GNUNET_DNS_RequestHandle *rh; | 181 | struct GNUNET_DNS_RequestHandle *rh; |
187 | 182 | ||
188 | rh = GNUNET_new (struct GNUNET_DNS_RequestHandle); | 183 | rh = GNUNET_new(struct GNUNET_DNS_RequestHandle); |
189 | rh->dh =dh; | 184 | rh->dh = dh; |
190 | rh->request_id = req->request_id; | 185 | rh->request_id = req->request_id; |
191 | rh->generation = dh->generation; | 186 | rh->generation = dh->generation; |
192 | dh->pending_requests++; | 187 | dh->pending_requests++; |
193 | dh->rh (dh->rh_cls, | 188 | dh->rh(dh->rh_cls, |
194 | rh, | 189 | rh, |
195 | payload_length, | 190 | payload_length, |
196 | (const char*) &req[1]); | 191 | (const char*)&req[1]); |
197 | } | 192 | } |
198 | 193 | ||
199 | 194 | ||
@@ -203,33 +198,33 @@ handle_request (void *cls, | |||
203 | * @param cls handle with the connection to connect | 198 | * @param cls handle with the connection to connect |
204 | */ | 199 | */ |
205 | static void | 200 | static void |
206 | reconnect (void *cls) | 201 | reconnect(void *cls) |
207 | { | 202 | { |
208 | struct GNUNET_DNS_Handle *dh = cls; | 203 | struct GNUNET_DNS_Handle *dh = cls; |
209 | struct GNUNET_MQ_MessageHandler handlers[] = { | 204 | struct GNUNET_MQ_MessageHandler handlers[] = { |
210 | GNUNET_MQ_hd_var_size (request, | 205 | GNUNET_MQ_hd_var_size(request, |
211 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST, | 206 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST, |
212 | struct GNUNET_DNS_Request, | 207 | struct GNUNET_DNS_Request, |
213 | dh), | 208 | dh), |
214 | GNUNET_MQ_handler_end () | 209 | GNUNET_MQ_handler_end() |
215 | }; | 210 | }; |
216 | struct GNUNET_MQ_Envelope *env; | 211 | struct GNUNET_MQ_Envelope *env; |
217 | struct GNUNET_DNS_Register *msg; | 212 | struct GNUNET_DNS_Register *msg; |
218 | 213 | ||
219 | dh->reconnect_task = NULL; | 214 | dh->reconnect_task = NULL; |
220 | dh->mq = GNUNET_CLIENT_connect (dh->cfg, | 215 | dh->mq = GNUNET_CLIENT_connect(dh->cfg, |
221 | "dns", | 216 | "dns", |
222 | handlers, | 217 | handlers, |
223 | &mq_error_handler, | 218 | &mq_error_handler, |
224 | dh); | 219 | dh); |
225 | if (NULL == dh->mq) | 220 | if (NULL == dh->mq) |
226 | return; | 221 | return; |
227 | dh->generation++; | 222 | dh->generation++; |
228 | env = GNUNET_MQ_msg (msg, | 223 | env = GNUNET_MQ_msg(msg, |
229 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT); | 224 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT); |
230 | msg->flags = htonl (dh->flags); | 225 | msg->flags = htonl(dh->flags); |
231 | GNUNET_MQ_send (dh->mq, | 226 | GNUNET_MQ_send(dh->mq, |
232 | env); | 227 | env); |
233 | } | 228 | } |
234 | 229 | ||
235 | 230 | ||
@@ -244,24 +239,24 @@ reconnect (void *cls) | |||
244 | * @param rh request that should now be forwarded | 239 | * @param rh request that should now be forwarded |
245 | */ | 240 | */ |
246 | void | 241 | void |
247 | GNUNET_DNS_request_forward (struct GNUNET_DNS_RequestHandle *rh) | 242 | GNUNET_DNS_request_forward(struct GNUNET_DNS_RequestHandle *rh) |
248 | { | 243 | { |
249 | struct GNUNET_MQ_Envelope *env; | 244 | struct GNUNET_MQ_Envelope *env; |
250 | struct GNUNET_DNS_Response *resp; | 245 | struct GNUNET_DNS_Response *resp; |
251 | 246 | ||
252 | GNUNET_assert (0 < rh->dh->pending_requests--); | 247 | GNUNET_assert(0 < rh->dh->pending_requests--); |
253 | if (rh->generation != rh->dh->generation) | 248 | if (rh->generation != rh->dh->generation) |
254 | { | 249 | { |
255 | GNUNET_free (rh); | 250 | GNUNET_free(rh); |
256 | return; | 251 | return; |
257 | } | 252 | } |
258 | env = GNUNET_MQ_msg (resp, | 253 | env = GNUNET_MQ_msg(resp, |
259 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); | 254 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); |
260 | resp->drop_flag = htonl (1); | 255 | resp->drop_flag = htonl(1); |
261 | resp->request_id = rh->request_id; | 256 | resp->request_id = rh->request_id; |
262 | GNUNET_MQ_send (rh->dh->mq, | 257 | GNUNET_MQ_send(rh->dh->mq, |
263 | env); | 258 | env); |
264 | GNUNET_free (rh); | 259 | GNUNET_free(rh); |
265 | } | 260 | } |
266 | 261 | ||
267 | 262 | ||
@@ -272,24 +267,24 @@ GNUNET_DNS_request_forward (struct GNUNET_DNS_RequestHandle *rh) | |||
272 | * @param rh request that should now be dropped | 267 | * @param rh request that should now be dropped |
273 | */ | 268 | */ |
274 | void | 269 | void |
275 | GNUNET_DNS_request_drop (struct GNUNET_DNS_RequestHandle *rh) | 270 | GNUNET_DNS_request_drop(struct GNUNET_DNS_RequestHandle *rh) |
276 | { | 271 | { |
277 | struct GNUNET_MQ_Envelope *env; | 272 | struct GNUNET_MQ_Envelope *env; |
278 | struct GNUNET_DNS_Response *resp; | 273 | struct GNUNET_DNS_Response *resp; |
279 | 274 | ||
280 | GNUNET_assert (0 < rh->dh->pending_requests--); | 275 | GNUNET_assert(0 < rh->dh->pending_requests--); |
281 | if (rh->generation != rh->dh->generation) | 276 | if (rh->generation != rh->dh->generation) |
282 | { | 277 | { |
283 | GNUNET_free (rh); | 278 | GNUNET_free(rh); |
284 | return; | 279 | return; |
285 | } | 280 | } |
286 | env = GNUNET_MQ_msg (resp, | 281 | env = GNUNET_MQ_msg(resp, |
287 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); | 282 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); |
288 | resp->request_id = rh->request_id; | 283 | resp->request_id = rh->request_id; |
289 | resp->drop_flag = htonl (0); | 284 | resp->drop_flag = htonl(0); |
290 | GNUNET_MQ_send (rh->dh->mq, | 285 | GNUNET_MQ_send(rh->dh->mq, |
291 | env); | 286 | env); |
292 | GNUNET_free (rh); | 287 | GNUNET_free(rh); |
293 | } | 288 | } |
294 | 289 | ||
295 | 290 | ||
@@ -303,37 +298,37 @@ GNUNET_DNS_request_drop (struct GNUNET_DNS_RequestHandle *rh) | |||
303 | * @param reply reply data | 298 | * @param reply reply data |
304 | */ | 299 | */ |
305 | void | 300 | void |
306 | GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh, | 301 | GNUNET_DNS_request_answer(struct GNUNET_DNS_RequestHandle *rh, |
307 | uint16_t reply_length, | 302 | uint16_t reply_length, |
308 | const char *reply) | 303 | const char *reply) |
309 | { | 304 | { |
310 | struct GNUNET_MQ_Envelope *env; | 305 | struct GNUNET_MQ_Envelope *env; |
311 | struct GNUNET_DNS_Response *resp; | 306 | struct GNUNET_DNS_Response *resp; |
312 | 307 | ||
313 | GNUNET_assert (0 < rh->dh->pending_requests--); | 308 | GNUNET_assert(0 < rh->dh->pending_requests--); |
314 | if (rh->generation != rh->dh->generation) | 309 | if (rh->generation != rh->dh->generation) |
315 | { | 310 | { |
316 | GNUNET_free (rh); | 311 | GNUNET_free(rh); |
317 | return; | 312 | return; |
318 | } | 313 | } |
319 | if (reply_length + sizeof (struct GNUNET_DNS_Response) | 314 | if (reply_length + sizeof(struct GNUNET_DNS_Response) |
320 | >= GNUNET_MAX_MESSAGE_SIZE) | 315 | >= GNUNET_MAX_MESSAGE_SIZE) |
321 | { | 316 | { |
322 | GNUNET_break (0); | 317 | GNUNET_break(0); |
323 | GNUNET_free (rh); | 318 | GNUNET_free(rh); |
324 | return; | 319 | return; |
325 | } | 320 | } |
326 | env = GNUNET_MQ_msg_extra (resp, | 321 | env = GNUNET_MQ_msg_extra(resp, |
327 | reply_length, | 322 | reply_length, |
328 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); | 323 | GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); |
329 | resp->drop_flag = htonl (2); | 324 | resp->drop_flag = htonl(2); |
330 | resp->request_id = rh->request_id; | 325 | resp->request_id = rh->request_id; |
331 | GNUNET_memcpy (&resp[1], | 326 | GNUNET_memcpy(&resp[1], |
332 | reply, | 327 | reply, |
333 | reply_length); | 328 | reply_length); |
334 | GNUNET_MQ_send (rh->dh->mq, | 329 | GNUNET_MQ_send(rh->dh->mq, |
335 | env); | 330 | env); |
336 | GNUNET_free (rh); | 331 | GNUNET_free(rh); |
337 | } | 332 | } |
338 | 333 | ||
339 | 334 | ||
@@ -347,19 +342,19 @@ GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh, | |||
347 | * @return DNS handle | 342 | * @return DNS handle |
348 | */ | 343 | */ |
349 | struct GNUNET_DNS_Handle * | 344 | struct GNUNET_DNS_Handle * |
350 | GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 345 | GNUNET_DNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, |
351 | enum GNUNET_DNS_Flags flags, | 346 | enum GNUNET_DNS_Flags flags, |
352 | GNUNET_DNS_RequestHandler rh, | 347 | GNUNET_DNS_RequestHandler rh, |
353 | void *rh_cls) | 348 | void *rh_cls) |
354 | { | 349 | { |
355 | struct GNUNET_DNS_Handle *dh; | 350 | struct GNUNET_DNS_Handle *dh; |
356 | 351 | ||
357 | dh = GNUNET_new (struct GNUNET_DNS_Handle); | 352 | dh = GNUNET_new(struct GNUNET_DNS_Handle); |
358 | dh->cfg = cfg; | 353 | dh->cfg = cfg; |
359 | dh->flags = flags; | 354 | dh->flags = flags; |
360 | dh->rh = rh; | 355 | dh->rh = rh; |
361 | dh->rh_cls = rh_cls; | 356 | dh->rh_cls = rh_cls; |
362 | dh->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, dh); | 357 | dh->reconnect_task = GNUNET_SCHEDULER_add_now(&reconnect, dh); |
363 | return dh; | 358 | return dh; |
364 | } | 359 | } |
365 | 360 | ||
@@ -370,21 +365,21 @@ GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
370 | * @param dh DNS handle | 365 | * @param dh DNS handle |
371 | */ | 366 | */ |
372 | void | 367 | void |
373 | GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *dh) | 368 | GNUNET_DNS_disconnect(struct GNUNET_DNS_Handle *dh) |
374 | { | 369 | { |
375 | if (NULL != dh->mq) | 370 | if (NULL != dh->mq) |
376 | { | 371 | { |
377 | GNUNET_MQ_destroy (dh->mq); | 372 | GNUNET_MQ_destroy(dh->mq); |
378 | dh->mq = NULL; | 373 | dh->mq = NULL; |
379 | } | 374 | } |
380 | if (NULL != dh->reconnect_task) | 375 | if (NULL != dh->reconnect_task) |
381 | { | 376 | { |
382 | GNUNET_SCHEDULER_cancel (dh->reconnect_task); | 377 | GNUNET_SCHEDULER_cancel(dh->reconnect_task); |
383 | dh->reconnect_task = NULL; | 378 | dh->reconnect_task = NULL; |
384 | } | 379 | } |
385 | /* make sure client has no pending requests left over! */ | 380 | /* make sure client has no pending requests left over! */ |
386 | GNUNET_break (0 == dh->pending_requests); | 381 | GNUNET_break(0 == dh->pending_requests); |
387 | GNUNET_free (dh); | 382 | GNUNET_free(dh); |
388 | } | 383 | } |
389 | 384 | ||
390 | /* end of dns_api.c */ | 385 | /* end of dns_api.c */ |