aboutsummaryrefslogtreecommitdiff
path: root/src/ats/ats_api_scheduling.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/ats/ats_api_scheduling.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/ats/ats_api_scheduling.c')
-rw-r--r--src/ats/ats_api_scheduling.c582
1 files changed, 293 insertions, 289 deletions
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index f375be6a5..36162d12f 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -38,9 +38,10 @@
38/** 38/**
39 * How frequently do we scan the interfaces for changes to the addresses? 39 * How frequently do we scan the interfaces for changes to the addresses?
40 */ 40 */
41#define INTERFACE_PROCESSING_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) 41#define INTERFACE_PROCESSING_INTERVAL GNUNET_TIME_relative_multiply ( \
42 GNUNET_TIME_UNIT_MINUTES, 2)
42 43
43#define LOG(kind, ...) GNUNET_log_from(kind, "ats-scheduling-api", __VA_ARGS__) 44#define LOG(kind, ...) GNUNET_log_from (kind, "ats-scheduling-api", __VA_ARGS__)
44 45
45/** 46/**
46 * Session ID we use if there is no session / slot. 47 * Session ID we use if there is no session / slot.
@@ -53,7 +54,8 @@
53 * doesn't matter if we have a session, any address that ATS is 54 * doesn't matter if we have a session, any address that ATS is
54 * allowed to suggest right now should be tracked. 55 * allowed to suggest right now should be tracked.
55 */ 56 */
56struct GNUNET_ATS_AddressRecord { 57struct GNUNET_ATS_AddressRecord
58{
57 /** 59 /**
58 * Scheduling handle this address record belongs to. 60 * Scheduling handle this address record belongs to.
59 */ 61 */
@@ -97,7 +99,8 @@ struct GNUNET_ATS_AddressRecord {
97/** 99/**
98 * Handle to the ATS subsystem for bandwidth/transport scheduling information. 100 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
99 */ 101 */
100struct GNUNET_ATS_SchedulingHandle { 102struct GNUNET_ATS_SchedulingHandle
103{
101 /** 104 /**
102 * Our configuration. 105 * Our configuration.
103 */ 106 */
@@ -149,7 +152,7 @@ struct GNUNET_ATS_SchedulingHandle {
149 * @param sh handle to use to re-connect. 152 * @param sh handle to use to re-connect.
150 */ 153 */
151static void 154static void
152reconnect(struct GNUNET_ATS_SchedulingHandle *sh); 155reconnect (struct GNUNET_ATS_SchedulingHandle *sh);
153 156
154 157
155/** 158/**
@@ -158,12 +161,12 @@ reconnect(struct GNUNET_ATS_SchedulingHandle *sh);
158 * @param cls handle to use to re-connect. 161 * @param cls handle to use to re-connect.
159 */ 162 */
160static void 163static void
161reconnect_task(void *cls) 164reconnect_task (void *cls)
162{ 165{
163 struct GNUNET_ATS_SchedulingHandle *sh = cls; 166 struct GNUNET_ATS_SchedulingHandle *sh = cls;
164 167
165 sh->task = NULL; 168 sh->task = NULL;
166 reconnect(sh); 169 reconnect (sh);
167} 170}
168 171
169 172
@@ -173,21 +176,21 @@ reconnect_task(void *cls)
173 * @param sh our handle 176 * @param sh our handle
174 */ 177 */
175static void 178static void
176force_reconnect(struct GNUNET_ATS_SchedulingHandle *sh) 179force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
177{ 180{
178 if (NULL != sh->mq) 181 if (NULL != sh->mq)
179 { 182 {
180 GNUNET_MQ_destroy(sh->mq); 183 GNUNET_MQ_destroy (sh->mq);
181 sh->mq = NULL; 184 sh->mq = NULL;
182 } 185 }
183 sh->suggest_cb(sh->suggest_cb_cls, 186 sh->suggest_cb (sh->suggest_cb_cls,
184 NULL, NULL, NULL, 187 NULL, NULL, NULL,
185 GNUNET_BANDWIDTH_ZERO, 188 GNUNET_BANDWIDTH_ZERO,
186 GNUNET_BANDWIDTH_ZERO); 189 GNUNET_BANDWIDTH_ZERO);
187 sh->backoff = GNUNET_TIME_STD_BACKOFF(sh->backoff); 190 sh->backoff = GNUNET_TIME_STD_BACKOFF (sh->backoff);
188 sh->task = GNUNET_SCHEDULER_add_delayed(sh->backoff, 191 sh->task = GNUNET_SCHEDULER_add_delayed (sh->backoff,
189 &reconnect_task, 192 &reconnect_task,
190 sh); 193 sh);
191} 194}
192 195
193 196
@@ -200,37 +203,37 @@ force_reconnect(struct GNUNET_ATS_SchedulingHandle *sh)
200 * @return the session object (or NULL) 203 * @return the session object (or NULL)
201 */ 204 */
202static struct GNUNET_ATS_AddressRecord * 205static struct GNUNET_ATS_AddressRecord *
203find_session(struct GNUNET_ATS_SchedulingHandle *sh, 206find_session (struct GNUNET_ATS_SchedulingHandle *sh,
204 uint32_t session_id, 207 uint32_t session_id,
205 const struct GNUNET_PeerIdentity *peer) 208 const struct GNUNET_PeerIdentity *peer)
206{ 209{
207 struct GNUNET_ATS_AddressRecord *ar; 210 struct GNUNET_ATS_AddressRecord *ar;
208 211
209 if (session_id >= sh->session_array_size) 212 if (session_id >= sh->session_array_size)
210 { 213 {
211 GNUNET_break(0); 214 GNUNET_break (0);
212 return NULL; 215 return NULL;
213 } 216 }
214 if (0 == session_id) 217 if (0 == session_id)
215 return NULL; 218 return NULL;
216 ar = sh->session_array[session_id]; 219 ar = sh->session_array[session_id];
217 if (NULL == ar) 220 if (NULL == ar)
218 { 221 {
219 GNUNET_break(0); 222 GNUNET_break (0);
220 return NULL; 223 return NULL;
221 } 224 }
222 if (NULL == ar->address) 225 if (NULL == ar->address)
223 { 226 {
224 /* address was destroyed in the meantime, this can happen 227 /* address was destroyed in the meantime, this can happen
225 as we communicate asynchronously with the ATS service. */ 228 as we communicate asynchronously with the ATS service. */
226 return NULL; 229 return NULL;
227 } 230 }
228 if (0 != GNUNET_memcmp(peer, 231 if (0 != GNUNET_memcmp (peer,
229 &ar->address->peer)) 232 &ar->address->peer))
230 { 233 {
231 GNUNET_break(0); 234 GNUNET_break (0);
232 return NULL; 235 return NULL;
233 } 236 }
234 return ar; 237 return ar;
235} 238}
236 239
@@ -242,27 +245,27 @@ find_session(struct GNUNET_ATS_SchedulingHandle *sh,
242 * @return an unused slot, but never NOT_FOUND (0) 245 * @return an unused slot, but never NOT_FOUND (0)
243 */ 246 */
244static uint32_t 247static uint32_t
245find_empty_session_slot(struct GNUNET_ATS_SchedulingHandle *sh) 248find_empty_session_slot (struct GNUNET_ATS_SchedulingHandle *sh)
246{ 249{
247 static uint32_t off; 250 static uint32_t off;
248 uint32_t i; 251 uint32_t i;
249 252
250 GNUNET_assert(0 != sh->session_array_size); 253 GNUNET_assert (0 != sh->session_array_size);
251 i = 0; 254 i = 0;
252 while (((NOT_FOUND == off) || 255 while (((NOT_FOUND == off) ||
253 (NULL != sh->session_array[off % sh->session_array_size])) && 256 (NULL != sh->session_array[off % sh->session_array_size])) &&
254 (i < sh->session_array_size)) 257 (i < sh->session_array_size))
255 { 258 {
256 off++; 259 off++;
257 i++; 260 i++;
258 } 261 }
259 if ((NOT_FOUND != off % sh->session_array_size) && 262 if ((NOT_FOUND != off % sh->session_array_size) &&
260 (NULL == sh->session_array[off % sh->session_array_size])) 263 (NULL == sh->session_array[off % sh->session_array_size]))
261 return off; 264 return off;
262 i = sh->session_array_size; 265 i = sh->session_array_size;
263 GNUNET_array_grow(sh->session_array, 266 GNUNET_array_grow (sh->session_array,
264 sh->session_array_size, 267 sh->session_array_size,
265 sh->session_array_size * 2); 268 sh->session_array_size * 2);
266 return i; 269 return i;
267} 270}
268 271
@@ -276,26 +279,26 @@ find_empty_session_slot(struct GNUNET_ATS_SchedulingHandle *sh)
276 * @return the session id or NOT_FOUND for error 279 * @return the session id or NOT_FOUND for error
277 */ 280 */
278static uint32_t 281static uint32_t
279find_session_id(struct GNUNET_ATS_SchedulingHandle *sh, 282find_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
280 struct GNUNET_ATS_Session *session, 283 struct GNUNET_ATS_Session *session,
281 const struct GNUNET_HELLO_Address *address) 284 const struct GNUNET_HELLO_Address *address)
282{ 285{
283 uint32_t i; 286 uint32_t i;
284 287
285 if (NULL == address) 288 if (NULL == address)
286 { 289 {
287 GNUNET_break(0); 290 GNUNET_break (0);
288 return NOT_FOUND; 291 return NOT_FOUND;
289 } 292 }
290 for (i = 1; i < sh->session_array_size; i++) 293 for (i = 1; i < sh->session_array_size; i++)
291 if ((NULL != sh->session_array[i]) && 294 if ((NULL != sh->session_array[i]) &&
292 (GNUNET_NO == sh->session_array[i]->in_destroy) && 295 (GNUNET_NO == sh->session_array[i]->in_destroy) &&
293 ((session == sh->session_array[i]->session) || 296 ((session == sh->session_array[i]->session) ||
294 (NULL == sh->session_array[i]->session)) && 297 (NULL == sh->session_array[i]->session)) &&
295 (0 == GNUNET_memcmp(&address->peer, 298 (0 == GNUNET_memcmp (&address->peer,
296 &sh->session_array[i]->address->peer)) && 299 &sh->session_array[i]->address->peer)) &&
297 (0 == GNUNET_HELLO_address_cmp(address, 300 (0 == GNUNET_HELLO_address_cmp (address,
298 sh->session_array[i]->address))) 301 sh->session_array[i]->address)))
299 return i; 302 return i;
300 return NOT_FOUND; 303 return NOT_FOUND;
301} 304}
@@ -309,29 +312,29 @@ find_session_id(struct GNUNET_ATS_SchedulingHandle *sh,
309 * @param session_id identifies session that is no longer valid 312 * @param session_id identifies session that is no longer valid
310 */ 313 */
311static void 314static void
312release_session(struct GNUNET_ATS_SchedulingHandle *sh, 315release_session (struct GNUNET_ATS_SchedulingHandle *sh,
313 uint32_t session_id) 316 uint32_t session_id)
314{ 317{
315 struct GNUNET_ATS_AddressRecord *ar; 318 struct GNUNET_ATS_AddressRecord *ar;
316 319
317 if (NOT_FOUND == session_id) 320 if (NOT_FOUND == session_id)
318 return; 321 return;
319 if (session_id >= sh->session_array_size) 322 if (session_id >= sh->session_array_size)
320 { 323 {
321 GNUNET_break(0); 324 GNUNET_break (0);
322 force_reconnect(sh); 325 force_reconnect (sh);
323 return; 326 return;
324 } 327 }
325 /* this slot should have been removed from remove_session before */ 328 /* this slot should have been removed from remove_session before */
326 ar = sh->session_array[session_id]; 329 ar = sh->session_array[session_id];
327 if (NULL != ar->session) 330 if (NULL != ar->session)
328 { 331 {
329 GNUNET_break(0); 332 GNUNET_break (0);
330 force_reconnect(sh); 333 force_reconnect (sh);
331 return; 334 return;
332 } 335 }
333 GNUNET_HELLO_address_free(ar->address); 336 GNUNET_HELLO_address_free (ar->address);
334 GNUNET_free(ar); 337 GNUNET_free (ar);
335 sh->session_array[session_id] = NULL; 338 sh->session_array[session_id] = NULL;
336} 339}
337 340
@@ -344,15 +347,15 @@ release_session(struct GNUNET_ATS_SchedulingHandle *sh,
344 * @param srm message received 347 * @param srm message received
345 */ 348 */
346static void 349static void
347handle_ats_session_release(void *cls, 350handle_ats_session_release (void *cls,
348 const struct GNUNET_ATS_SessionReleaseMessage *srm) 351 const struct GNUNET_ATS_SessionReleaseMessage *srm)
349{ 352{
350 struct GNUNET_ATS_SchedulingHandle *sh = cls; 353 struct GNUNET_ATS_SchedulingHandle *sh = cls;
351 354
352 /* Note: peer field in srm not necessary right now, 355 /* Note: peer field in srm not necessary right now,
353 but might be good to have in the future */ 356 but might be good to have in the future */
354 release_session(sh, 357 release_session (sh,
355 ntohl(srm->session_id)); 358 ntohl (srm->session_id));
356} 359}
357 360
358 361
@@ -364,71 +367,71 @@ handle_ats_session_release(void *cls,
364 * @param m message received 367 * @param m message received
365 */ 368 */
366static void 369static void
367handle_ats_address_suggestion(void *cls, 370handle_ats_address_suggestion (void *cls,
368 const struct AddressSuggestionMessage *m) 371 const struct AddressSuggestionMessage *m)
369{ 372{
370 struct GNUNET_ATS_SchedulingHandle *sh = cls; 373 struct GNUNET_ATS_SchedulingHandle *sh = cls;
371 struct GNUNET_ATS_AddressRecord *ar; 374 struct GNUNET_ATS_AddressRecord *ar;
372 uint32_t session_id; 375 uint32_t session_id;
373 376
374 session_id = ntohl(m->session_id); 377 session_id = ntohl (m->session_id);
375 if (0 == session_id) 378 if (0 == session_id)
376 { 379 {
377 GNUNET_break(0); 380 GNUNET_break (0);
378 force_reconnect(sh); 381 force_reconnect (sh);
379 return; 382 return;
380 } 383 }
381 ar = find_session(sh, 384 ar = find_session (sh,
382 session_id, 385 session_id,
383 &m->peer); 386 &m->peer);
384 if (NULL == ar) 387 if (NULL == ar)
385 { 388 {
386 GNUNET_break(0); 389 GNUNET_break (0);
387 force_reconnect(sh); 390 force_reconnect (sh);
388 return; 391 return;
389 } 392 }
390 if (NULL == sh->suggest_cb) 393 if (NULL == sh->suggest_cb)
391 return; 394 return;
392 if (GNUNET_YES == ar->in_destroy) 395 if (GNUNET_YES == ar->in_destroy)
396 {
397 /* ignore suggestion, as this address is dying, unless BW is 0,
398 in that case signal 'disconnect' via BW 0 */
399 if ((0 == ntohl (m->bandwidth_out.value__)) &&
400 (0 == ntohl (m->bandwidth_in.value__)))
393 { 401 {
394 /* ignore suggestion, as this address is dying, unless BW is 0, 402 LOG (GNUNET_ERROR_TYPE_DEBUG,
395 in that case signal 'disconnect' via BW 0 */ 403 "ATS suggests disconnect from peer `%s' with BW %u/%u\n",
396 if ((0 == ntohl(m->bandwidth_out.value__)) && 404 GNUNET_i2s (&ar->address->peer),
397 (0 == ntohl(m->bandwidth_in.value__))) 405 (unsigned int) ntohl (m->bandwidth_out.value__),
398 { 406 (unsigned int) ntohl (m->bandwidth_in.value__));
399 LOG(GNUNET_ERROR_TYPE_DEBUG, 407 sh->suggest_cb (sh->suggest_cb_cls,
400 "ATS suggests disconnect from peer `%s' with BW %u/%u\n", 408 &m->peer,
401 GNUNET_i2s(&ar->address->peer), 409 NULL,
402 (unsigned int)ntohl(m->bandwidth_out.value__), 410 NULL,
403 (unsigned int)ntohl(m->bandwidth_in.value__)); 411 m->bandwidth_out,
404 sh->suggest_cb(sh->suggest_cb_cls, 412 m->bandwidth_in);
405 &m->peer,
406 NULL,
407 NULL,
408 m->bandwidth_out,
409 m->bandwidth_in);
410 }
411 return;
412 } 413 }
414 return;
415 }
413 if ((NULL == ar->session) && 416 if ((NULL == ar->session) &&
414 (GNUNET_HELLO_address_check_option(ar->address, 417 (GNUNET_HELLO_address_check_option (ar->address,
415 GNUNET_HELLO_ADDRESS_INFO_INBOUND))) 418 GNUNET_HELLO_ADDRESS_INFO_INBOUND)))
416 { 419 {
417 GNUNET_break(0); 420 GNUNET_break (0);
418 return; 421 return;
419 } 422 }
420 sh->backoff = GNUNET_TIME_UNIT_ZERO; 423 sh->backoff = GNUNET_TIME_UNIT_ZERO;
421 LOG(GNUNET_ERROR_TYPE_DEBUG, 424 LOG (GNUNET_ERROR_TYPE_DEBUG,
422 "ATS suggests address slot %u for peer `%s' using plugin %s\n", 425 "ATS suggests address slot %u for peer `%s' using plugin %s\n",
423 ar->slot, 426 ar->slot,
424 GNUNET_i2s(&ar->address->peer), 427 GNUNET_i2s (&ar->address->peer),
425 ar->address->transport_name); 428 ar->address->transport_name);
426 sh->suggest_cb(sh->suggest_cb_cls, 429 sh->suggest_cb (sh->suggest_cb_cls,
427 &m->peer, 430 &m->peer,
428 ar->address, 431 ar->address,
429 ar->session, 432 ar->session,
430 m->bandwidth_out, 433 m->bandwidth_out,
431 m->bandwidth_in); 434 m->bandwidth_in);
432} 435}
433 436
434 437
@@ -440,15 +443,15 @@ handle_ats_address_suggestion(void *cls,
440 * @param error details about the error 443 * @param error details about the error
441 */ 444 */
442static void 445static void
443error_handler(void *cls, 446error_handler (void *cls,
444 enum GNUNET_MQ_Error error) 447 enum GNUNET_MQ_Error error)
445{ 448{
446 struct GNUNET_ATS_SchedulingHandle *sh = cls; 449 struct GNUNET_ATS_SchedulingHandle *sh = cls;
447 450
448 LOG(GNUNET_ERROR_TYPE_DEBUG, 451 LOG (GNUNET_ERROR_TYPE_DEBUG,
449 "ATS connection died (code %d), reconnecting\n", 452 "ATS connection died (code %d), reconnecting\n",
450 (int)error); 453 (int) error);
451 force_reconnect(sh); 454 force_reconnect (sh);
452} 455}
453 456
454 457
@@ -460,8 +463,8 @@ error_handler(void *cls,
460 * @param ar the address to inform the ATS service about 463 * @param ar the address to inform the ATS service about
461 */ 464 */
462static void 465static void
463send_add_address_message(struct GNUNET_ATS_SchedulingHandle *sh, 466send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh,
464 const struct GNUNET_ATS_AddressRecord *ar) 467 const struct GNUNET_ATS_AddressRecord *ar)
465{ 468{
466 struct GNUNET_MQ_Envelope *ev; 469 struct GNUNET_MQ_Envelope *ev;
467 struct AddressAddMessage *m; 470 struct AddressAddMessage *m;
@@ -471,32 +474,32 @@ send_add_address_message(struct GNUNET_ATS_SchedulingHandle *sh,
471 474
472 if (NULL == sh->mq) 475 if (NULL == sh->mq)
473 return; /* disconnected, skip for now */ 476 return; /* disconnected, skip for now */
474 GNUNET_break(GNUNET_NT_UNSPECIFIED != ar->properties.scope); 477 GNUNET_break (GNUNET_NT_UNSPECIFIED != ar->properties.scope);
475 namelen = strlen(ar->address->transport_name) + 1; 478 namelen = strlen (ar->address->transport_name) + 1;
476 msize = ar->address->address_length + namelen; 479 msize = ar->address->address_length + namelen;
477 ev = GNUNET_MQ_msg_extra(m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD); 480 ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD);
478 m->peer = ar->address->peer; 481 m->peer = ar->address->peer;
479 m->address_length = htons(ar->address->address_length); 482 m->address_length = htons (ar->address->address_length);
480 m->address_local_info = htonl((uint32_t)ar->address->local_info); 483 m->address_local_info = htonl ((uint32_t) ar->address->local_info);
481 m->plugin_name_length = htons(namelen); 484 m->plugin_name_length = htons (namelen);
482 m->session_id = htonl(ar->slot); 485 m->session_id = htonl (ar->slot);
483 m->properties = ar->properties; 486 m->properties = ar->properties;
484 487
485 LOG(GNUNET_ERROR_TYPE_DEBUG, 488 LOG (GNUNET_ERROR_TYPE_DEBUG,
486 "Adding address for peer `%s', plugin `%s', session %p slot %u\n", 489 "Adding address for peer `%s', plugin `%s', session %p slot %u\n",
487 GNUNET_i2s(&ar->address->peer), 490 GNUNET_i2s (&ar->address->peer),
488 ar->address->transport_name, 491 ar->address->transport_name,
489 ar->session, 492 ar->session,
490 ar->slot); 493 ar->slot);
491 pm = (char *)&m[1]; 494 pm = (char *) &m[1];
492 GNUNET_memcpy(pm, 495 GNUNET_memcpy (pm,
493 ar->address->address, 496 ar->address->address,
494 ar->address->address_length); 497 ar->address->address_length);
495 if (NULL != ar->address->transport_name) 498 if (NULL != ar->address->transport_name)
496 GNUNET_memcpy(&pm[ar->address->address_length], 499 GNUNET_memcpy (&pm[ar->address->address_length],
497 ar->address->transport_name, 500 ar->address->transport_name,
498 namelen); 501 namelen);
499 GNUNET_MQ_send(sh->mq, ev); 502 GNUNET_MQ_send (sh->mq, ev);
500} 503}
501 504
502 505
@@ -506,51 +509,51 @@ send_add_address_message(struct GNUNET_ATS_SchedulingHandle *sh,
506 * @param sh handle to use to re-connect. 509 * @param sh handle to use to re-connect.
507 */ 510 */
508static void 511static void
509reconnect(struct GNUNET_ATS_SchedulingHandle *sh) 512reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
510{ 513{
511 struct GNUNET_MQ_MessageHandler handlers[] = { 514 struct GNUNET_MQ_MessageHandler handlers[] = {
512 GNUNET_MQ_hd_fixed_size(ats_session_release, 515 GNUNET_MQ_hd_fixed_size (ats_session_release,
513 GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE, 516 GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE,
514 struct GNUNET_ATS_SessionReleaseMessage, 517 struct GNUNET_ATS_SessionReleaseMessage,
515 sh), 518 sh),
516 GNUNET_MQ_hd_fixed_size(ats_address_suggestion, 519 GNUNET_MQ_hd_fixed_size (ats_address_suggestion,
517 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION, 520 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION,
518 struct AddressSuggestionMessage, 521 struct AddressSuggestionMessage,
519 sh), 522 sh),
520 GNUNET_MQ_handler_end() 523 GNUNET_MQ_handler_end ()
521 }; 524 };
522 struct GNUNET_MQ_Envelope *ev; 525 struct GNUNET_MQ_Envelope *ev;
523 struct ClientStartMessage *init; 526 struct ClientStartMessage *init;
524 unsigned int i; 527 unsigned int i;
525 struct GNUNET_ATS_AddressRecord *ar; 528 struct GNUNET_ATS_AddressRecord *ar;
526 529
527 GNUNET_assert(NULL == sh->mq); 530 GNUNET_assert (NULL == sh->mq);
528 sh->mq = GNUNET_CLIENT_connect(sh->cfg, 531 sh->mq = GNUNET_CLIENT_connect (sh->cfg,
529 "ats", 532 "ats",
530 handlers, 533 handlers,
531 &error_handler, 534 &error_handler,
532 sh); 535 sh);
533 if (NULL == sh->mq) 536 if (NULL == sh->mq)
534 { 537 {
535 GNUNET_break(0); 538 GNUNET_break (0);
536 force_reconnect(sh); 539 force_reconnect (sh);
537 return; 540 return;
538 } 541 }
539 ev = GNUNET_MQ_msg(init, 542 ev = GNUNET_MQ_msg (init,
540 GNUNET_MESSAGE_TYPE_ATS_START); 543 GNUNET_MESSAGE_TYPE_ATS_START);
541 init->start_flag = htonl(START_FLAG_SCHEDULING); 544 init->start_flag = htonl (START_FLAG_SCHEDULING);
542 GNUNET_MQ_send(sh->mq, ev); 545 GNUNET_MQ_send (sh->mq, ev);
543 if (NULL == sh->mq) 546 if (NULL == sh->mq)
544 return; 547 return;
545 for (i = 0; i < sh->session_array_size; i++) 548 for (i = 0; i < sh->session_array_size; i++)
546 { 549 {
547 ar = sh->session_array[i]; 550 ar = sh->session_array[i];
548 if (NULL == ar) 551 if (NULL == ar)
549 continue; 552 continue;
550 send_add_address_message(sh, ar); 553 send_add_address_message (sh, ar);
551 if (NULL == sh->mq) 554 if (NULL == sh->mq)
552 return; 555 return;
553 } 556 }
554} 557}
555 558
556 559
@@ -563,20 +566,20 @@ reconnect(struct GNUNET_ATS_SchedulingHandle *sh)
563 * @return ats context 566 * @return ats context
564 */ 567 */
565struct GNUNET_ATS_SchedulingHandle * 568struct GNUNET_ATS_SchedulingHandle *
566GNUNET_ATS_scheduling_init(const struct GNUNET_CONFIGURATION_Handle *cfg, 569GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
567 GNUNET_ATS_AddressSuggestionCallback suggest_cb, 570 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
568 void *suggest_cb_cls) 571 void *suggest_cb_cls)
569{ 572{
570 struct GNUNET_ATS_SchedulingHandle *sh; 573 struct GNUNET_ATS_SchedulingHandle *sh;
571 574
572 sh = GNUNET_new(struct GNUNET_ATS_SchedulingHandle); 575 sh = GNUNET_new (struct GNUNET_ATS_SchedulingHandle);
573 sh->cfg = cfg; 576 sh->cfg = cfg;
574 sh->suggest_cb = suggest_cb; 577 sh->suggest_cb = suggest_cb;
575 sh->suggest_cb_cls = suggest_cb_cls; 578 sh->suggest_cb_cls = suggest_cb_cls;
576 GNUNET_array_grow(sh->session_array, 579 GNUNET_array_grow (sh->session_array,
577 sh->session_array_size, 580 sh->session_array_size,
578 4); 581 4);
579 reconnect(sh); 582 reconnect (sh);
580 return sh; 583 return sh;
581} 584}
582 585
@@ -587,34 +590,34 @@ GNUNET_ATS_scheduling_init(const struct GNUNET_CONFIGURATION_Handle *cfg,
587 * @param sh handle to release 590 * @param sh handle to release
588 */ 591 */
589void 592void
590GNUNET_ATS_scheduling_done(struct GNUNET_ATS_SchedulingHandle *sh) 593GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
591{ 594{
592 struct GNUNET_ATS_AddressRecord *ar; 595 struct GNUNET_ATS_AddressRecord *ar;
593 unsigned int i; 596 unsigned int i;
594 597
595 if (NULL != sh->mq) 598 if (NULL != sh->mq)
596 { 599 {
597 GNUNET_MQ_destroy(sh->mq); 600 GNUNET_MQ_destroy (sh->mq);
598 sh->mq = NULL; 601 sh->mq = NULL;
599 } 602 }
600 if (NULL != sh->task) 603 if (NULL != sh->task)
601 { 604 {
602 GNUNET_SCHEDULER_cancel(sh->task); 605 GNUNET_SCHEDULER_cancel (sh->task);
603 sh->task = NULL; 606 sh->task = NULL;
604 } 607 }
605 for (i = 0; i < sh->session_array_size; i++) 608 for (i = 0; i < sh->session_array_size; i++)
609 {
610 if (NULL != (ar = sh->session_array[i]))
606 { 611 {
607 if (NULL != (ar = sh->session_array[i])) 612 GNUNET_HELLO_address_free (ar->address);
608 { 613 GNUNET_free (ar);
609 GNUNET_HELLO_address_free(ar->address); 614 sh->session_array[i] = NULL;
610 GNUNET_free(ar);
611 sh->session_array[i] = NULL;
612 }
613 } 615 }
614 GNUNET_array_grow(sh->session_array, 616 }
615 sh->session_array_size, 617 GNUNET_array_grow (sh->session_array,
616 0); 618 sh->session_array_size,
617 GNUNET_free(sh); 619 0);
620 GNUNET_free (sh);
618} 621}
619 622
620 623
@@ -631,10 +634,10 @@ GNUNET_ATS_scheduling_done(struct GNUNET_ATS_SchedulingHandle *sh)
631 * on error (i.e. ATS knows this exact address already) 634 * on error (i.e. ATS knows this exact address already)
632 */ 635 */
633struct GNUNET_ATS_AddressRecord * 636struct GNUNET_ATS_AddressRecord *
634GNUNET_ATS_address_add(struct GNUNET_ATS_SchedulingHandle *sh, 637GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
635 const struct GNUNET_HELLO_Address *address, 638 const struct GNUNET_HELLO_Address *address,
636 struct GNUNET_ATS_Session *session, 639 struct GNUNET_ATS_Session *session,
637 const struct GNUNET_ATS_Properties *prop) 640 const struct GNUNET_ATS_Properties *prop)
638{ 641{
639 struct GNUNET_ATS_AddressRecord *ar; 642 struct GNUNET_ATS_AddressRecord *ar;
640 size_t namelen; 643 size_t namelen;
@@ -642,42 +645,43 @@ GNUNET_ATS_address_add(struct GNUNET_ATS_SchedulingHandle *sh,
642 uint32_t s; 645 uint32_t s;
643 646
644 if (NULL == address) 647 if (NULL == address)
645 { 648 {
646 /* we need a valid address */ 649 /* we need a valid address */
647 GNUNET_break(0); 650 GNUNET_break (0);
648 return NULL; 651 return NULL;
649 } 652 }
650 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); 653 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
651 namelen = strlen(address->transport_name) + 1; 654 namelen = strlen (address->transport_name) + 1;
652 msize = address->address_length + namelen; 655 msize = address->address_length + namelen;
653 if ((msize + sizeof(struct AddressUpdateMessage) >= GNUNET_MAX_MESSAGE_SIZE) || 656 if ((msize + sizeof(struct AddressUpdateMessage) >=
657 GNUNET_MAX_MESSAGE_SIZE) ||
654 (address->address_length >= GNUNET_MAX_MESSAGE_SIZE) || 658 (address->address_length >= GNUNET_MAX_MESSAGE_SIZE) ||
655 (namelen >= GNUNET_MAX_MESSAGE_SIZE)) 659 (namelen >= GNUNET_MAX_MESSAGE_SIZE))
656 { 660 {
657 /* address too large for us, this should not happen */ 661 /* address too large for us, this should not happen */
658 GNUNET_break(0); 662 GNUNET_break (0);
659 return NULL; 663 return NULL;
660 } 664 }
661 665
662 if (NOT_FOUND != 666 if (NOT_FOUND !=
663 find_session_id(sh, 667 find_session_id (sh,
664 session, 668 session,
665 address)) 669 address))
666 { 670 {
667 /* Already existing, nothing todo, but this should not happen */ 671 /* Already existing, nothing todo, but this should not happen */
668 GNUNET_break(0); 672 GNUNET_break (0);
669 return NULL; 673 return NULL;
670 } 674 }
671 s = find_empty_session_slot(sh); 675 s = find_empty_session_slot (sh);
672 ar = GNUNET_new(struct GNUNET_ATS_AddressRecord); 676 ar = GNUNET_new (struct GNUNET_ATS_AddressRecord);
673 ar->sh = sh; 677 ar->sh = sh;
674 ar->slot = s; 678 ar->slot = s;
675 ar->session = session; 679 ar->session = session;
676 ar->address = GNUNET_HELLO_address_copy(address); 680 ar->address = GNUNET_HELLO_address_copy (address);
677 GNUNET_ATS_properties_hton(&ar->properties, 681 GNUNET_ATS_properties_hton (&ar->properties,
678 prop); 682 prop);
679 sh->session_array[s] = ar; 683 sh->session_array[s] = ar;
680 send_add_address_message(sh, ar); 684 send_add_address_message (sh, ar);
681 return ar; 685 return ar;
682} 686}
683 687
@@ -689,10 +693,10 @@ GNUNET_ATS_address_add(struct GNUNET_ATS_SchedulingHandle *sh,
689 * @param session session handle 693 * @param session session handle
690 */ 694 */
691void 695void
692GNUNET_ATS_address_add_session(struct GNUNET_ATS_AddressRecord *ar, 696GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar,
693 struct GNUNET_ATS_Session *session) 697 struct GNUNET_ATS_Session *session)
694{ 698{
695 GNUNET_break(NULL == ar->session); 699 GNUNET_break (NULL == ar->session);
696 ar->session = session; 700 ar->session = session;
697} 701}
698 702
@@ -710,17 +714,17 @@ GNUNET_ATS_address_add_session(struct GNUNET_ATS_AddressRecord *ar,
710 * use it still to establish a new session 714 * use it still to establish a new session
711 */ 715 */
712int 716int
713GNUNET_ATS_address_del_session(struct GNUNET_ATS_AddressRecord *ar, 717GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
714 struct GNUNET_ATS_Session *session) 718 struct GNUNET_ATS_Session *session)
715{ 719{
716 GNUNET_assert(session == ar->session); 720 GNUNET_assert (session == ar->session);
717 ar->session = NULL; 721 ar->session = NULL;
718 if (GNUNET_HELLO_address_check_option(ar->address, 722 if (GNUNET_HELLO_address_check_option (ar->address,
719 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 723 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
720 { 724 {
721 GNUNET_ATS_address_destroy(ar); 725 GNUNET_ATS_address_destroy (ar);
722 return GNUNET_YES; 726 return GNUNET_YES;
723 } 727 }
724 return GNUNET_NO; 728 return GNUNET_NO;
725} 729}
726 730
@@ -737,30 +741,30 @@ GNUNET_ATS_address_del_session(struct GNUNET_ATS_AddressRecord *ar,
737 * @param prop performance data for the address 741 * @param prop performance data for the address
738 */ 742 */
739void 743void
740GNUNET_ATS_address_update(struct GNUNET_ATS_AddressRecord *ar, 744GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
741 const struct GNUNET_ATS_Properties *prop) 745 const struct GNUNET_ATS_Properties *prop)
742{ 746{
743 struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; 747 struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
744 struct GNUNET_MQ_Envelope *ev; 748 struct GNUNET_MQ_Envelope *ev;
745 struct AddressUpdateMessage *m; 749 struct AddressUpdateMessage *m;
746 750
747 LOG(GNUNET_ERROR_TYPE_DEBUG, 751 LOG (GNUNET_ERROR_TYPE_DEBUG,
748 "Updating address for peer `%s', plugin `%s', session %p slot %u\n", 752 "Updating address for peer `%s', plugin `%s', session %p slot %u\n",
749 GNUNET_i2s(&ar->address->peer), 753 GNUNET_i2s (&ar->address->peer),
750 ar->address->transport_name, 754 ar->address->transport_name,
751 ar->session, 755 ar->session,
752 ar->slot); 756 ar->slot);
753 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); 757 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
754 GNUNET_ATS_properties_hton(&ar->properties, 758 GNUNET_ATS_properties_hton (&ar->properties,
755 prop); 759 prop);
756 if (NULL == sh->mq) 760 if (NULL == sh->mq)
757 return; /* disconnected, skip for now */ 761 return; /* disconnected, skip for now */
758 ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); 762 ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
759 m->session_id = htonl(ar->slot); 763 m->session_id = htonl (ar->slot);
760 m->peer = ar->address->peer; 764 m->peer = ar->address->peer;
761 m->properties = ar->properties; 765 m->properties = ar->properties;
762 GNUNET_MQ_send(sh->mq, 766 GNUNET_MQ_send (sh->mq,
763 ev); 767 ev);
764} 768}
765 769
766 770
@@ -770,27 +774,27 @@ GNUNET_ATS_address_update(struct GNUNET_ATS_AddressRecord *ar,
770 * @param ar address to destroy 774 * @param ar address to destroy
771 */ 775 */
772void 776void
773GNUNET_ATS_address_destroy(struct GNUNET_ATS_AddressRecord *ar) 777GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar)
774{ 778{
775 struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; 779 struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
776 struct GNUNET_MQ_Envelope *ev; 780 struct GNUNET_MQ_Envelope *ev;
777 struct AddressDestroyedMessage *m; 781 struct AddressDestroyedMessage *m;
778 782
779 LOG(GNUNET_ERROR_TYPE_DEBUG, 783 LOG (GNUNET_ERROR_TYPE_DEBUG,
780 "Deleting address for peer `%s', plugin `%s', slot %u session %p\n", 784 "Deleting address for peer `%s', plugin `%s', slot %u session %p\n",
781 GNUNET_i2s(&ar->address->peer), 785 GNUNET_i2s (&ar->address->peer),
782 ar->address->transport_name, 786 ar->address->transport_name,
783 ar->slot, 787 ar->slot,
784 ar->session); 788 ar->session);
785 GNUNET_break(NULL == ar->session); 789 GNUNET_break (NULL == ar->session);
786 ar->session = NULL; 790 ar->session = NULL;
787 ar->in_destroy = GNUNET_YES; 791 ar->in_destroy = GNUNET_YES;
788 if (NULL == sh->mq) 792 if (NULL == sh->mq)
789 return; 793 return;
790 ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED); 794 ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
791 m->session_id = htonl(ar->slot); 795 m->session_id = htonl (ar->slot);
792 m->peer = ar->address->peer; 796 m->peer = ar->address->peer;
793 GNUNET_MQ_send(sh->mq, ev); 797 GNUNET_MQ_send (sh->mq, ev);
794} 798}
795 799
796 800