aboutsummaryrefslogtreecommitdiff
path: root/src/ats/ats_api2_transport.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/ats/ats_api2_transport.c
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/ats/ats_api2_transport.c')
-rw-r--r--src/ats/ats_api2_transport.c435
1 files changed, 215 insertions, 220 deletions
diff --git a/src/ats/ats_api2_transport.c b/src/ats/ats_api2_transport.c
index e73b2daa8..441e7c8c2 100644
--- a/src/ats/ats_api2_transport.c
+++ b/src/ats/ats_api2_transport.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 ats/ats_api2_transport.c 21 * @file ats/ats_api2_transport.c
22 * @brief address suggestions and bandwidth allocation 22 * @brief address suggestions and bandwidth allocation
@@ -27,7 +27,7 @@
27#include "gnunet_ats_transport_service.h" 27#include "gnunet_ats_transport_service.h"
28#include "ats2.h" 28#include "ats2.h"
29 29
30#define LOG(kind,...) GNUNET_log_from(kind, "ats-transport-api", __VA_ARGS__) 30#define LOG(kind, ...) GNUNET_log_from(kind, "ats-transport-api", __VA_ARGS__)
31 31
32 32
33/** 33/**
@@ -35,9 +35,7 @@
35 * doesn't matter if we have a session, any session that ATS is 35 * doesn't matter if we have a session, any session that ATS is
36 * allowed to suggest right now should be tracked. 36 * allowed to suggest right now should be tracked.
37 */ 37 */
38struct GNUNET_ATS_SessionRecord 38struct GNUNET_ATS_SessionRecord {
39{
40
41 /** 39 /**
42 * Transport handle this session record belongs to. 40 * Transport handle this session record belongs to.
43 */ 41 */
@@ -75,16 +73,13 @@ struct GNUNET_ATS_SessionRecord
75 * messages. 73 * messages.
76 */ 74 */
77 uint32_t slot; 75 uint32_t slot;
78
79}; 76};
80 77
81 78
82/** 79/**
83 * Handle to the ATS subsystem for bandwidth/transport transport information. 80 * Handle to the ATS subsystem for bandwidth/transport transport information.
84 */ 81 */
85struct GNUNET_ATS_TransportHandle 82struct GNUNET_ATS_TransportHandle {
86{
87
88 /** 83 /**
89 * Our configuration. 84 * Our configuration.
90 */ 85 */
@@ -129,7 +124,6 @@ struct GNUNET_ATS_TransportHandle
129 * Reconnect backoff delay. 124 * Reconnect backoff delay.
130 */ 125 */
131 struct GNUNET_TIME_Relative backoff; 126 struct GNUNET_TIME_Relative backoff;
132
133}; 127};
134 128
135 129
@@ -141,18 +135,18 @@ struct GNUNET_ATS_TransportHandle
141 * @param hbo value read 135 * @param hbo value read
142 */ 136 */
143static void 137static void
144properties_hton (struct PropertiesNBO *nbo, 138properties_hton(struct PropertiesNBO *nbo,
145 const struct GNUNET_ATS_Properties *hbo) 139 const struct GNUNET_ATS_Properties *hbo)
146{ 140{
147 nbo->delay = GNUNET_TIME_relative_hton (hbo->delay); 141 nbo->delay = GNUNET_TIME_relative_hton(hbo->delay);
148 nbo->goodput_out = htonl (hbo->goodput_out); 142 nbo->goodput_out = htonl(hbo->goodput_out);
149 nbo->goodput_in = htonl (hbo->goodput_in); 143 nbo->goodput_in = htonl(hbo->goodput_in);
150 nbo->utilization_out = htonl (hbo->utilization_out); 144 nbo->utilization_out = htonl(hbo->utilization_out);
151 nbo->utilization_in = htonl (hbo->utilization_in); 145 nbo->utilization_in = htonl(hbo->utilization_in);
152 nbo->distance = htonl (hbo->distance); 146 nbo->distance = htonl(hbo->distance);
153 nbo->mtu = htonl (hbo->mtu); 147 nbo->mtu = htonl(hbo->mtu);
154 nbo->nt = htonl ((uint32_t) hbo->nt); 148 nbo->nt = htonl((uint32_t)hbo->nt);
155 nbo->cc = htonl ((uint32_t) hbo->cc); 149 nbo->cc = htonl((uint32_t)hbo->cc);
156} 150}
157 151
158 152
@@ -162,7 +156,7 @@ properties_hton (struct PropertiesNBO *nbo,
162 * @param sh handle to use to re-connect. 156 * @param sh handle to use to re-connect.
163 */ 157 */
164static void 158static void
165reconnect (struct GNUNET_ATS_TransportHandle *ath); 159reconnect(struct GNUNET_ATS_TransportHandle *ath);
166 160
167 161
168/** 162/**
@@ -171,12 +165,12 @@ reconnect (struct GNUNET_ATS_TransportHandle *ath);
171 * @param cls handle to use to re-connect. 165 * @param cls handle to use to re-connect.
172 */ 166 */
173static void 167static void
174reconnect_task (void *cls) 168reconnect_task(void *cls)
175{ 169{
176 struct GNUNET_ATS_TransportHandle *ath = cls; 170 struct GNUNET_ATS_TransportHandle *ath = cls;
177 171
178 ath->task = NULL; 172 ath->task = NULL;
179 reconnect (ath); 173 reconnect(ath);
180} 174}
181 175
182 176
@@ -186,20 +180,20 @@ reconnect_task (void *cls)
186 * @param ath our handle 180 * @param ath our handle
187 */ 181 */
188static void 182static void
189force_reconnect (struct GNUNET_ATS_TransportHandle *ath) 183force_reconnect(struct GNUNET_ATS_TransportHandle *ath)
190{ 184{
191 if (NULL != ath->mq) 185 if (NULL != ath->mq)
192 { 186 {
193 GNUNET_MQ_destroy (ath->mq); 187 GNUNET_MQ_destroy(ath->mq);
194 ath->mq = NULL; 188 ath->mq = NULL;
195 } 189 }
196 /* FIXME: do we tell transport service about disconnect events? CON: 190 /* FIXME: do we tell transport service about disconnect events? CON:
197 initially ATS will have a really screwed picture of the world and 191 initially ATS will have a really screwed picture of the world and
198 the rapid change would be bad. PRO: if we don't, ATS and 192 the rapid change would be bad. PRO: if we don't, ATS and
199 transport may disagree about the allocation for a while... 193 transport may disagree about the allocation for a while...
200 For now: lazy: do nothing. */ 194 For now: lazy: do nothing. */
201 ath->backoff = GNUNET_TIME_STD_BACKOFF (ath->backoff); 195 ath->backoff = GNUNET_TIME_STD_BACKOFF(ath->backoff);
202 ath->task = GNUNET_SCHEDULER_add_delayed (ath->backoff, 196 ath->task = GNUNET_SCHEDULER_add_delayed(ath->backoff,
203 &reconnect_task, 197 &reconnect_task,
204 ath); 198 ath);
205} 199}
@@ -212,11 +206,11 @@ force_reconnect (struct GNUNET_ATS_TransportHandle *ath)
212 * @param m message received 206 * @param m message received
213 */ 207 */
214static int 208static int
215check_ats_address_suggestion (void *cls, 209check_ats_address_suggestion(void *cls,
216 const struct AddressSuggestionMessage *m) 210 const struct AddressSuggestionMessage *m)
217{ 211{
218 (void) cls; 212 (void)cls;
219 GNUNET_MQ_check_zero_termination (m); 213 GNUNET_MQ_check_zero_termination(m);
220 return GNUNET_SYSERR; 214 return GNUNET_SYSERR;
221} 215}
222 216
@@ -228,13 +222,13 @@ check_ats_address_suggestion (void *cls,
228 * @param m message received 222 * @param m message received
229 */ 223 */
230static void 224static void
231handle_ats_address_suggestion (void *cls, 225handle_ats_address_suggestion(void *cls,
232 const struct AddressSuggestionMessage *m) 226 const struct AddressSuggestionMessage *m)
233{ 227{
234 struct GNUNET_ATS_TransportHandle *ath = cls; 228 struct GNUNET_ATS_TransportHandle *ath = cls;
235 const char *address = (const char *) &m[1]; 229 const char *address = (const char *)&m[1];
236 230
237 ath->suggest_cb (ath->suggest_cb_cls, 231 ath->suggest_cb(ath->suggest_cb_cls,
238 &m->peer, 232 &m->peer,
239 address); 233 address);
240} 234}
@@ -243,8 +237,7 @@ handle_ats_address_suggestion (void *cls,
243/** 237/**
244 * Closure for #match_session_cb. 238 * Closure for #match_session_cb.
245 */ 239 */
246struct FindContext 240struct FindContext {
247{
248 /** 241 /**
249 * Key to look for. 242 * Key to look for.
250 */ 243 */
@@ -266,19 +259,19 @@ struct FindContext
266 * @return #GNUNET_NO if match found, #GNUNET_YES to continue searching 259 * @return #GNUNET_NO if match found, #GNUNET_YES to continue searching
267 */ 260 */
268static int 261static int
269match_session_cb (void *cls, 262match_session_cb(void *cls,
270 const struct GNUNET_PeerIdentity *pid, 263 const struct GNUNET_PeerIdentity *pid,
271 void *value) 264 void *value)
272{ 265{
273 struct FindContext *fc = cls; 266 struct FindContext *fc = cls;
274 struct GNUNET_ATS_SessionRecord *sr = value; 267 struct GNUNET_ATS_SessionRecord *sr = value;
275 268
276 (void) pid; 269 (void)pid;
277 if (fc->session_id == sr->slot) 270 if (fc->session_id == sr->slot)
278 { 271 {
279 fc->sr = sr; 272 fc->sr = sr;
280 return GNUNET_NO; 273 return GNUNET_NO;
281 } 274 }
282 return GNUNET_YES; 275 return GNUNET_YES;
283} 276}
284 277
@@ -293,18 +286,19 @@ match_session_cb (void *cls,
293 * @return NULL if no such record exists 286 * @return NULL if no such record exists
294 */ 287 */
295static struct GNUNET_ATS_SessionRecord * 288static struct GNUNET_ATS_SessionRecord *
296find_session (struct GNUNET_ATS_TransportHandle *ath, 289find_session(struct GNUNET_ATS_TransportHandle *ath,
297 uint32_t session_id, 290 uint32_t session_id,
298 const struct GNUNET_PeerIdentity *pid) 291 const struct GNUNET_PeerIdentity *pid)
299{ 292{
300 struct FindContext fc = { 293 struct FindContext fc = {
301 .session_id = session_id, 294 .session_id = session_id,
302 .sr = NULL 295 .sr = NULL
303 }; 296 };
304 GNUNET_CONTAINER_multipeermap_get_multiple (ath->records, 297
305 pid, 298 GNUNET_CONTAINER_multipeermap_get_multiple(ath->records,
306 &match_session_cb, 299 pid,
307 &fc); 300 &match_session_cb,
301 &fc);
308 return fc.sr; 302 return fc.sr;
309} 303}
310 304
@@ -316,34 +310,34 @@ find_session (struct GNUNET_ATS_TransportHandle *ath,
316 * @param m message received 310 * @param m message received
317 */ 311 */
318static void 312static void
319handle_ats_session_allocation (void *cls, 313handle_ats_session_allocation(void *cls,
320 const struct SessionAllocationMessage *m) 314 const struct SessionAllocationMessage *m)
321{ 315{
322 struct GNUNET_ATS_TransportHandle *ath = cls; 316 struct GNUNET_ATS_TransportHandle *ath = cls;
323 struct GNUNET_ATS_SessionRecord *ar; 317 struct GNUNET_ATS_SessionRecord *ar;
324 uint32_t session_id; 318 uint32_t session_id;
325 319
326 session_id = ntohl (m->session_id); 320 session_id = ntohl(m->session_id);
327 ar = find_session (ath, 321 ar = find_session(ath,
328 session_id, 322 session_id,
329 &m->peer); 323 &m->peer);
330 if (NULL == ar) 324 if (NULL == ar)
331 { 325 {
332 /* this can (rarely) happen if ATS changes an sessiones allocation 326 /* this can (rarely) happen if ATS changes an sessiones allocation
333 just when the transport service deleted it */ 327 just when the transport service deleted it */
334 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 328 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
335 "Allocation ignored, session unknown\n"); 329 "Allocation ignored, session unknown\n");
336 return; 330 return;
337 } 331 }
338 ath->backoff = GNUNET_TIME_UNIT_ZERO; 332 ath->backoff = GNUNET_TIME_UNIT_ZERO;
339 LOG (GNUNET_ERROR_TYPE_DEBUG, 333 LOG(GNUNET_ERROR_TYPE_DEBUG,
340 "ATS allocates bandwidth for peer `%s' using address %s\n", 334 "ATS allocates bandwidth for peer `%s' using address %s\n",
341 GNUNET_i2s (&ar->pid), 335 GNUNET_i2s(&ar->pid),
342 ar->address); 336 ar->address);
343 ath->alloc_cb (ath->alloc_cb_cls, 337 ath->alloc_cb(ath->alloc_cb_cls,
344 ar->session, 338 ar->session,
345 m->bandwidth_out, 339 m->bandwidth_out,
346 m->bandwidth_in); 340 m->bandwidth_in);
347} 341}
348 342
349 343
@@ -355,15 +349,15 @@ handle_ats_session_allocation (void *cls,
355 * @param error details about the error 349 * @param error details about the error
356 */ 350 */
357static void 351static void
358error_handler (void *cls, 352error_handler(void *cls,
359 enum GNUNET_MQ_Error error) 353 enum GNUNET_MQ_Error error)
360{ 354{
361 struct GNUNET_ATS_TransportHandle *ath = cls; 355 struct GNUNET_ATS_TransportHandle *ath = cls;
362 356
363 LOG (GNUNET_ERROR_TYPE_DEBUG, 357 LOG(GNUNET_ERROR_TYPE_DEBUG,
364 "ATS connection died (code %d), reconnecting\n", 358 "ATS connection died (code %d), reconnecting\n",
365 (int) error); 359 (int)error);
366 force_reconnect (ath); 360 force_reconnect(ath);
367} 361}
368 362
369 363
@@ -374,7 +368,7 @@ error_handler (void *cls,
374 * @param ar the session to inform the ATS service about 368 * @param ar the session to inform the ATS service about
375 */ 369 */
376static void 370static void
377send_add_session_message (const struct GNUNET_ATS_SessionRecord *ar) 371send_add_session_message(const struct GNUNET_ATS_SessionRecord *ar)
378{ 372{
379 struct GNUNET_ATS_TransportHandle *ath = ar->ath; 373 struct GNUNET_ATS_TransportHandle *ath = ar->ath;
380 struct GNUNET_MQ_Envelope *ev; 374 struct GNUNET_MQ_Envelope *ev;
@@ -383,26 +377,26 @@ send_add_session_message (const struct GNUNET_ATS_SessionRecord *ar)
383 377
384 if (NULL == ath->mq) 378 if (NULL == ath->mq)
385 return; /* disconnected, skip for now */ 379 return; /* disconnected, skip for now */
386 alen = strlen (ar->address) + 1; 380 alen = strlen(ar->address) + 1;
387 ev = GNUNET_MQ_msg_extra (m, 381 ev = GNUNET_MQ_msg_extra(m,
388 alen, 382 alen,
389 (NULL == ar->session) 383 (NULL == ar->session)
390 ? GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY 384 ? GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY
391 : GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD); 385 : GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD);
392 m->peer = ar->pid; 386 m->peer = ar->pid;
393 m->session_id = htonl (ar->slot); 387 m->session_id = htonl(ar->slot);
394 properties_hton (&m->properties, 388 properties_hton(&m->properties,
395 &ar->properties); 389 &ar->properties);
396 GNUNET_memcpy (&m[1], 390 GNUNET_memcpy(&m[1],
397 ar->address, 391 ar->address,
398 alen); 392 alen);
399 393
400 LOG (GNUNET_ERROR_TYPE_DEBUG, 394 LOG(GNUNET_ERROR_TYPE_DEBUG,
401 "Adding address `%s' for peer `%s'\n", 395 "Adding address `%s' for peer `%s'\n",
402 ar->address, 396 ar->address,
403 GNUNET_i2s (&ar->pid)); 397 GNUNET_i2s(&ar->pid));
404 GNUNET_MQ_send (ath->mq, 398 GNUNET_MQ_send(ath->mq,
405 ev); 399 ev);
406} 400}
407 401
408 402
@@ -415,15 +409,15 @@ send_add_session_message (const struct GNUNET_ATS_SessionRecord *ar)
415 * @return #GNUNET_OK 409 * @return #GNUNET_OK
416 */ 410 */
417static int 411static int
418send_add_session_cb (void *cls, 412send_add_session_cb(void *cls,
419 const struct GNUNET_PeerIdentity *pid, 413 const struct GNUNET_PeerIdentity *pid,
420 void *value) 414 void *value)
421{ 415{
422 struct GNUNET_ATS_SessionRecord *ar = value; 416 struct GNUNET_ATS_SessionRecord *ar = value;
423 417
424 (void) cls; 418 (void)cls;
425 (void) pid; 419 (void)pid;
426 send_add_session_message (ar); 420 send_add_session_message(ar);
427 return GNUNET_OK; 421 return GNUNET_OK;
428} 422}
429 423
@@ -434,43 +428,43 @@ send_add_session_cb (void *cls,
434 * @param ath handle to use to re-connect. 428 * @param ath handle to use to re-connect.
435 */ 429 */
436static void 430static void
437reconnect (struct GNUNET_ATS_TransportHandle *ath) 431reconnect(struct GNUNET_ATS_TransportHandle *ath)
438{ 432{
439 struct GNUNET_MQ_MessageHandler handlers[] = { 433 struct GNUNET_MQ_MessageHandler handlers[] = {
440 GNUNET_MQ_hd_var_size (ats_address_suggestion, 434 GNUNET_MQ_hd_var_size(ats_address_suggestion,
441 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION, 435 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION,
442 struct AddressSuggestionMessage, 436 struct AddressSuggestionMessage,
443 ath), 437 ath),
444 GNUNET_MQ_hd_fixed_size (ats_session_allocation, 438 GNUNET_MQ_hd_fixed_size(ats_session_allocation,
445 GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION, 439 GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION,
446 struct SessionAllocationMessage, 440 struct SessionAllocationMessage,
447 ath), 441 ath),
448 GNUNET_MQ_handler_end () 442 GNUNET_MQ_handler_end()
449 }; 443 };
450 struct GNUNET_MQ_Envelope *ev; 444 struct GNUNET_MQ_Envelope *ev;
451 struct GNUNET_MessageHeader *init; 445 struct GNUNET_MessageHeader *init;
452 446
453 GNUNET_assert (NULL == ath->mq); 447 GNUNET_assert(NULL == ath->mq);
454 ath->mq = GNUNET_CLIENT_connect (ath->cfg, 448 ath->mq = GNUNET_CLIENT_connect(ath->cfg,
455 "ats", 449 "ats",
456 handlers, 450 handlers,
457 &error_handler, 451 &error_handler,
458 ath); 452 ath);
459 if (NULL == ath->mq) 453 if (NULL == ath->mq)
460 { 454 {
461 GNUNET_break (0); 455 GNUNET_break(0);
462 force_reconnect (ath); 456 force_reconnect(ath);
463 return; 457 return;
464 } 458 }
465 ev = GNUNET_MQ_msg (init, 459 ev = GNUNET_MQ_msg(init,
466 GNUNET_MESSAGE_TYPE_ATS_START); 460 GNUNET_MESSAGE_TYPE_ATS_START);
467 GNUNET_MQ_send (ath->mq, 461 GNUNET_MQ_send(ath->mq,
468 ev); 462 ev);
469 if (NULL == ath->mq) 463 if (NULL == ath->mq)
470 return; 464 return;
471 GNUNET_CONTAINER_multipeermap_iterate (ath->records, 465 GNUNET_CONTAINER_multipeermap_iterate(ath->records,
472 &send_add_session_cb, 466 &send_add_session_cb,
473 ath); 467 ath);
474} 468}
475 469
476 470
@@ -485,23 +479,23 @@ reconnect (struct GNUNET_ATS_TransportHandle *ath)
485 * @return ats context 479 * @return ats context
486 */ 480 */
487struct GNUNET_ATS_TransportHandle * 481struct GNUNET_ATS_TransportHandle *
488GNUNET_ATS_transport_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 482GNUNET_ATS_transport_init(const struct GNUNET_CONFIGURATION_Handle *cfg,
489 GNUNET_ATS_AllocationCallback alloc_cb, 483 GNUNET_ATS_AllocationCallback alloc_cb,
490 void *alloc_cb_cls, 484 void *alloc_cb_cls,
491 GNUNET_ATS_SuggestionCallback suggest_cb, 485 GNUNET_ATS_SuggestionCallback suggest_cb,
492 void *suggest_cb_cls) 486 void *suggest_cb_cls)
493{ 487{
494 struct GNUNET_ATS_TransportHandle *ath; 488 struct GNUNET_ATS_TransportHandle *ath;
495 489
496 ath = GNUNET_new (struct GNUNET_ATS_TransportHandle); 490 ath = GNUNET_new(struct GNUNET_ATS_TransportHandle);
497 ath->cfg = cfg; 491 ath->cfg = cfg;
498 ath->suggest_cb = suggest_cb; 492 ath->suggest_cb = suggest_cb;
499 ath->suggest_cb_cls = suggest_cb_cls; 493 ath->suggest_cb_cls = suggest_cb_cls;
500 ath->alloc_cb = alloc_cb; 494 ath->alloc_cb = alloc_cb;
501 ath->alloc_cb_cls = alloc_cb_cls; 495 ath->alloc_cb_cls = alloc_cb_cls;
502 ath->records = GNUNET_CONTAINER_multipeermap_create (128, 496 ath->records = GNUNET_CONTAINER_multipeermap_create(128,
503 GNUNET_YES); 497 GNUNET_YES);
504 reconnect (ath); 498 reconnect(ath);
505 return ath; 499 return ath;
506} 500}
507 501
@@ -515,15 +509,15 @@ GNUNET_ATS_transport_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
515 * @return #GNUNET_OK 509 * @return #GNUNET_OK
516 */ 510 */
517static int 511static int
518free_record (void *cls, 512free_record(void *cls,
519 const struct GNUNET_PeerIdentity *pid, 513 const struct GNUNET_PeerIdentity *pid,
520 void *value) 514 void *value)
521{ 515{
522 struct GNUNET_ATS_SessionRecord *ar = value; 516 struct GNUNET_ATS_SessionRecord *ar = value;
523 517
524 (void) cls; 518 (void)cls;
525 (void) pid; 519 (void)pid;
526 GNUNET_free (ar); 520 GNUNET_free(ar);
527 return GNUNET_OK; 521 return GNUNET_OK;
528} 522}
529 523
@@ -534,23 +528,23 @@ free_record (void *cls,
534 * @param ath handle to release 528 * @param ath handle to release
535 */ 529 */
536void 530void
537GNUNET_ATS_transport_done (struct GNUNET_ATS_TransportHandle *ath) 531GNUNET_ATS_transport_done(struct GNUNET_ATS_TransportHandle *ath)
538{ 532{
539 if (NULL != ath->mq) 533 if (NULL != ath->mq)
540 { 534 {
541 GNUNET_MQ_destroy (ath->mq); 535 GNUNET_MQ_destroy(ath->mq);
542 ath->mq = NULL; 536 ath->mq = NULL;
543 } 537 }
544 if (NULL != ath->task) 538 if (NULL != ath->task)
545 { 539 {
546 GNUNET_SCHEDULER_cancel (ath->task); 540 GNUNET_SCHEDULER_cancel(ath->task);
547 ath->task = NULL; 541 ath->task = NULL;
548 } 542 }
549 GNUNET_CONTAINER_multipeermap_iterate (ath->records, 543 GNUNET_CONTAINER_multipeermap_iterate(ath->records,
550 &free_record, 544 &free_record,
551 NULL); 545 NULL);
552 GNUNET_CONTAINER_multipeermap_destroy (ath->records); 546 GNUNET_CONTAINER_multipeermap_destroy(ath->records);
553 GNUNET_free (ath); 547 GNUNET_free(ath);
554} 548}
555 549
556 550
@@ -569,55 +563,56 @@ GNUNET_ATS_transport_done (struct GNUNET_ATS_TransportHandle *ath)
569 * on error (i.e. ATS knows this exact session already) 563 * on error (i.e. ATS knows this exact session already)
570 */ 564 */
571struct GNUNET_ATS_SessionRecord * 565struct GNUNET_ATS_SessionRecord *
572GNUNET_ATS_session_add (struct GNUNET_ATS_TransportHandle *ath, 566GNUNET_ATS_session_add(struct GNUNET_ATS_TransportHandle *ath,
573 const struct GNUNET_PeerIdentity *pid, 567 const struct GNUNET_PeerIdentity *pid,
574 const char *address, 568 const char *address,
575 struct GNUNET_ATS_Session *session, 569 struct GNUNET_ATS_Session *session,
576 const struct GNUNET_ATS_Properties *prop) 570 const struct GNUNET_ATS_Properties *prop)
577{ 571{
578 struct GNUNET_ATS_SessionRecord *ar; 572 struct GNUNET_ATS_SessionRecord *ar;
579 uint32_t s; 573 uint32_t s;
580 size_t alen; 574 size_t alen;
581 575
582 if (NULL == address) 576 if (NULL == address)
583 { 577 {
584 /* we need a valid address */ 578 /* we need a valid address */
585 GNUNET_break (0); 579 GNUNET_break(0);
586 return NULL; 580 return NULL;
587 } 581 }
588 alen = strlen (address) + 1; 582 alen = strlen(address) + 1;
589 if ( (alen + sizeof (struct SessionAddMessage) >= GNUNET_MAX_MESSAGE_SIZE) || 583 if ((alen + sizeof(struct SessionAddMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
590 (alen >= GNUNET_MAX_MESSAGE_SIZE) ) 584 (alen >= GNUNET_MAX_MESSAGE_SIZE))
591 { 585 {
592 /* address too large for us, this should not happen */ 586 /* address too large for us, this should not happen */
593 GNUNET_break (0); 587 GNUNET_break(0);
594 return NULL; 588 return NULL;
595 } 589 }
596 590
597 /* Spin 's' until we find an unused session ID for this pid */ 591 /* Spin 's' until we find an unused session ID for this pid */
598 for (s = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 592 for (s = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
599 UINT32_MAX); 593 UINT32_MAX);
600 NULL != find_session (ath, 594 NULL != find_session(ath,
601 s, 595 s,
602 pid); 596 pid);
603 s++) ; 597 s++)
604 598 ;
605 alen = strlen (address) + 1; 599
606 ar = GNUNET_malloc (sizeof (struct GNUNET_ATS_SessionRecord) + alen); 600 alen = strlen(address) + 1;
601 ar = GNUNET_malloc(sizeof(struct GNUNET_ATS_SessionRecord) + alen);
607 ar->ath = ath; 602 ar->ath = ath;
608 ar->slot = s; 603 ar->slot = s;
609 ar->session = session; 604 ar->session = session;
610 ar->address = (const char *) &ar[1]; 605 ar->address = (const char *)&ar[1];
611 ar->pid = *pid; 606 ar->pid = *pid;
612 ar->properties = *prop; 607 ar->properties = *prop;
613 memcpy (&ar[1], 608 memcpy(&ar[1],
614 address, 609 address,
615 alen); 610 alen);
616 (void) GNUNET_CONTAINER_multipeermap_put (ath->records, 611 (void)GNUNET_CONTAINER_multipeermap_put(ath->records,
617 &ar->pid, 612 &ar->pid,
618 ar, 613 ar,
619 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 614 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
620 send_add_session_message (ar); 615 send_add_session_message(ar);
621 return ar; 616 return ar;
622} 617}
623 618
@@ -634,28 +629,28 @@ GNUNET_ATS_session_add (struct GNUNET_ATS_TransportHandle *ath,
634 * @param prop performance data for the session 629 * @param prop performance data for the session
635 */ 630 */
636void 631void
637GNUNET_ATS_session_update (struct GNUNET_ATS_SessionRecord *ar, 632GNUNET_ATS_session_update(struct GNUNET_ATS_SessionRecord *ar,
638 const struct GNUNET_ATS_Properties *prop) 633 const struct GNUNET_ATS_Properties *prop)
639{ 634{
640 struct GNUNET_ATS_TransportHandle *ath = ar->ath; 635 struct GNUNET_ATS_TransportHandle *ath = ar->ath;
641 struct GNUNET_MQ_Envelope *ev; 636 struct GNUNET_MQ_Envelope *ev;
642 struct SessionUpdateMessage *m; 637 struct SessionUpdateMessage *m;
643 638
644 LOG (GNUNET_ERROR_TYPE_DEBUG, 639 LOG(GNUNET_ERROR_TYPE_DEBUG,
645 "Updating address `%s' for peer `%s'\n", 640 "Updating address `%s' for peer `%s'\n",
646 ar->address, 641 ar->address,
647 GNUNET_i2s (&ar->pid)); 642 GNUNET_i2s(&ar->pid));
648 ar->properties = *prop; 643 ar->properties = *prop;
649 if (NULL == ath->mq) 644 if (NULL == ath->mq)
650 return; /* disconnected, skip for now */ 645 return; /* disconnected, skip for now */
651 ev = GNUNET_MQ_msg (m, 646 ev = GNUNET_MQ_msg(m,
652 GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE); 647 GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE);
653 m->session_id = htonl (ar->slot); 648 m->session_id = htonl(ar->slot);
654 m->peer = ar->pid; 649 m->peer = ar->pid;
655 properties_hton (&m->properties, 650 properties_hton(&m->properties,
656 &ar->properties); 651 &ar->properties);
657 GNUNET_MQ_send (ath->mq, 652 GNUNET_MQ_send(ath->mq,
658 ev); 653 ev);
659} 654}
660 655
661 656
@@ -667,24 +662,24 @@ GNUNET_ATS_session_update (struct GNUNET_ATS_SessionRecord *ar,
667 * @param ar session record to drop 662 * @param ar session record to drop
668 */ 663 */
669void 664void
670GNUNET_ATS_session_del (struct GNUNET_ATS_SessionRecord *ar) 665GNUNET_ATS_session_del(struct GNUNET_ATS_SessionRecord *ar)
671{ 666{
672 struct GNUNET_ATS_TransportHandle *ath = ar->ath; 667 struct GNUNET_ATS_TransportHandle *ath = ar->ath;
673 struct GNUNET_MQ_Envelope *ev; 668 struct GNUNET_MQ_Envelope *ev;
674 struct SessionDelMessage *m; 669 struct SessionDelMessage *m;
675 670
676 LOG (GNUNET_ERROR_TYPE_DEBUG, 671 LOG(GNUNET_ERROR_TYPE_DEBUG,
677 "Deleting address `%s' for peer `%s'\n", 672 "Deleting address `%s' for peer `%s'\n",
678 ar->address, 673 ar->address,
679 GNUNET_i2s (&ar->pid)); 674 GNUNET_i2s(&ar->pid));
680 if (NULL == ath->mq) 675 if (NULL == ath->mq)
681 return; 676 return;
682 ev = GNUNET_MQ_msg (m, 677 ev = GNUNET_MQ_msg(m,
683 GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL); 678 GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL);
684 m->session_id = htonl (ar->slot); 679 m->session_id = htonl(ar->slot);
685 m->peer = ar->pid; 680 m->peer = ar->pid;
686 GNUNET_MQ_send (ath->mq, 681 GNUNET_MQ_send(ath->mq,
687 ev); 682 ev);
688} 683}
689 684
690 685