diff options
Diffstat (limited to 'src/ats/ats_api_scheduling.c')
-rw-r--r-- | src/ats/ats_api_scheduling.c | 350 |
1 files changed, 197 insertions, 153 deletions
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index d2bf06c17..496a18b12 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010,2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2010-2015 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -164,12 +164,12 @@ struct GNUNET_ATS_SchedulingHandle | |||
164 | /** | 164 | /** |
165 | * Head of network list | 165 | * Head of network list |
166 | */ | 166 | */ |
167 | struct ATS_Network * net_head; | 167 | struct ATS_Network *net_head; |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * Tail of network list | 170 | * Tail of network list |
171 | */ | 171 | */ |
172 | struct ATS_Network * net_tail; | 172 | struct ATS_Network *net_tail; |
173 | 173 | ||
174 | /** | 174 | /** |
175 | * Array of session objects (we need to translate them to numbers and back | 175 | * Array of session objects (we need to translate them to numbers and back |
@@ -182,16 +182,15 @@ struct GNUNET_ATS_SchedulingHandle | |||
182 | /** | 182 | /** |
183 | * Task to trigger reconnect. | 183 | * Task to trigger reconnect. |
184 | */ | 184 | */ |
185 | struct GNUNET_SCHEDULER_Task * task; | 185 | struct GNUNET_SCHEDULER_Task *task; |
186 | 186 | ||
187 | /** | 187 | /** |
188 | * Task retrieving interfaces from the system | 188 | * Task retrieving interfaces from the system |
189 | */ | 189 | */ |
190 | struct GNUNET_SCHEDULER_Task * interface_task; | 190 | struct GNUNET_SCHEDULER_Task *interface_task; |
191 | |||
192 | 191 | ||
193 | /** | 192 | /** |
194 | * Size of the session array. | 193 | * Size of the @e session_array. |
195 | */ | 194 | */ |
196 | unsigned int session_array_size; | 195 | unsigned int session_array_size; |
197 | 196 | ||
@@ -218,7 +217,8 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh); | |||
218 | * @param tc scheduler context | 217 | * @param tc scheduler context |
219 | */ | 218 | */ |
220 | static void | 219 | static void |
221 | reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 220 | reconnect_task (void *cls, |
221 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
222 | { | 222 | { |
223 | struct GNUNET_ATS_SchedulingHandle *sh = cls; | 223 | struct GNUNET_ATS_SchedulingHandle *sh = cls; |
224 | 224 | ||
@@ -238,9 +238,9 @@ force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh) | |||
238 | sh->reconnect = GNUNET_NO; | 238 | sh->reconnect = GNUNET_NO; |
239 | GNUNET_CLIENT_disconnect (sh->client); | 239 | GNUNET_CLIENT_disconnect (sh->client); |
240 | sh->client = NULL; | 240 | sh->client = NULL; |
241 | sh->task = | 241 | sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
242 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task, | 242 | &reconnect_task, |
243 | sh); | 243 | sh); |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
@@ -258,23 +258,26 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh); | |||
258 | * Type of a function to call when we receive a message | 258 | * Type of a function to call when we receive a message |
259 | * from the service. | 259 | * from the service. |
260 | * | 260 | * |
261 | * @param cls the 'struct GNUNET_ATS_SchedulingHandle' | 261 | * @param cls the `struct GNUNET_ATS_SchedulingHandle` |
262 | * @param msg message received, NULL on timeout or fatal error | 262 | * @param msg message received, NULL on timeout or fatal error |
263 | */ | 263 | */ |
264 | static void | 264 | static void |
265 | process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg); | 265 | process_ats_message (void *cls, |
266 | const struct GNUNET_MessageHeader *msg); | ||
266 | 267 | ||
267 | 268 | ||
268 | /** | 269 | /** |
269 | * We can now transmit a message to ATS. Do it. | 270 | * We can now transmit a message to ATS. Do it. |
270 | * | 271 | * |
271 | * @param cls the 'struct GNUNET_ATS_SchedulingHandle' | 272 | * @param cls the `struct GNUNET_ATS_SchedulingHandle` |
272 | * @param size number of bytes we can transmit to ATS | 273 | * @param size number of bytes we can transmit to ATS |
273 | * @param buf where to copy the messages | 274 | * @param buf where to copy the messages |
274 | * @return number of bytes copied into buf | 275 | * @return number of bytes copied into @a buf |
275 | */ | 276 | */ |
276 | static size_t | 277 | static size_t |
277 | transmit_message_to_ats (void *cls, size_t size, void *buf) | 278 | transmit_message_to_ats (void *cls, |
279 | size_t size, | ||
280 | void *buf) | ||
278 | { | 281 | { |
279 | struct GNUNET_ATS_SchedulingHandle *sh = cls; | 282 | struct GNUNET_ATS_SchedulingHandle *sh = cls; |
280 | struct PendingMessage *p; | 283 | struct PendingMessage *p; |
@@ -282,7 +285,7 @@ transmit_message_to_ats (void *cls, size_t size, void *buf) | |||
282 | char *cbuf; | 285 | char *cbuf; |
283 | 286 | ||
284 | sh->th = NULL; | 287 | sh->th = NULL; |
285 | if ((size == 0) || (buf == NULL)) | 288 | if ((0 == size) || (NULL == buf)) |
286 | { | 289 | { |
287 | force_reconnect (sh); | 290 | force_reconnect (sh); |
288 | return 0; | 291 | return 0; |
@@ -291,10 +294,14 @@ transmit_message_to_ats (void *cls, size_t size, void *buf) | |||
291 | cbuf = buf; | 294 | cbuf = buf; |
292 | while ((NULL != (p = sh->pending_head)) && (p->size <= size)) | 295 | while ((NULL != (p = sh->pending_head)) && (p->size <= size)) |
293 | { | 296 | { |
294 | memcpy (&cbuf[ret], &p[1], p->size); | 297 | memcpy (&cbuf[ret], |
298 | &p[1], | ||
299 | p->size); | ||
295 | ret += p->size; | 300 | ret += p->size; |
296 | size -= p->size; | 301 | size -= p->size; |
297 | GNUNET_CONTAINER_DLL_remove (sh->pending_head, sh->pending_tail, p); | 302 | GNUNET_CONTAINER_DLL_remove (sh->pending_head, |
303 | sh->pending_tail, | ||
304 | p); | ||
298 | GNUNET_free (p); | 305 | GNUNET_free (p); |
299 | } | 306 | } |
300 | do_transmit (sh); | 307 | do_transmit (sh); |
@@ -336,10 +343,10 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh) | |||
336 | * @return the session object (or NULL) | 343 | * @return the session object (or NULL) |
337 | */ | 344 | */ |
338 | static struct Session * | 345 | static struct Session * |
339 | find_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id, | 346 | find_session (struct GNUNET_ATS_SchedulingHandle *sh, |
347 | uint32_t session_id, | ||
340 | const struct GNUNET_PeerIdentity *peer) | 348 | const struct GNUNET_PeerIdentity *peer) |
341 | { | 349 | { |
342 | |||
343 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-scheduling-api", | 350 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-scheduling-api", |
344 | "Find session %u from peer %s in %p\n", | 351 | "Find session %u from peer %s in %p\n", |
345 | (unsigned int) session_id, GNUNET_i2s (peer), sh); | 352 | (unsigned int) session_id, GNUNET_i2s (peer), sh); |
@@ -396,16 +403,19 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id, | |||
396 | * @return the session id | 403 | * @return the session id |
397 | */ | 404 | */ |
398 | static uint32_t | 405 | static uint32_t |
399 | find_empty_session_slot (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session, | 406 | find_empty_session_slot (struct GNUNET_ATS_SchedulingHandle *sh, |
400 | const struct GNUNET_PeerIdentity *peer) | 407 | struct Session *session, |
408 | const struct GNUNET_PeerIdentity *peer) | ||
401 | { | 409 | { |
402 | unsigned int i; | 410 | unsigned int i; |
403 | unsigned int f; | 411 | unsigned int f; |
404 | 412 | ||
405 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-scheduling-api", | 413 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
406 | "Get session ID for session %p from peer %s in %p\n", session, | 414 | "ats-scheduling-api", |
407 | GNUNET_i2s (peer), sh); | 415 | "Get session ID for session %p from peer %s in %p\n", |
408 | 416 | session, | |
417 | GNUNET_i2s (peer), | ||
418 | sh); | ||
409 | if (NULL == session) | 419 | if (NULL == session) |
410 | return NOT_FOUND; | 420 | return NOT_FOUND; |
411 | f = 0; | 421 | f = 0; |
@@ -442,8 +452,9 @@ find_empty_session_slot (struct GNUNET_ATS_SchedulingHandle *sh, struct Session | |||
442 | * @return the session id or NOT_FOUND for error | 452 | * @return the session id or NOT_FOUND for error |
443 | */ | 453 | */ |
444 | static uint32_t | 454 | static uint32_t |
445 | find_session_id (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session, | 455 | find_session_id (struct GNUNET_ATS_SchedulingHandle *sh, |
446 | const struct GNUNET_PeerIdentity *peer) | 456 | struct Session *session, |
457 | const struct GNUNET_PeerIdentity *peer) | ||
447 | { | 458 | { |
448 | unsigned int i; | 459 | unsigned int i; |
449 | char * p2; | 460 | char * p2; |
@@ -484,15 +495,16 @@ find_session_id (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session | |||
484 | * @param peer peer the session belongs to | 495 | * @param peer peer the session belongs to |
485 | */ | 496 | */ |
486 | static void | 497 | static void |
487 | remove_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id, | 498 | remove_session (struct GNUNET_ATS_SchedulingHandle *sh, |
499 | uint32_t session_id, | ||
488 | const struct GNUNET_PeerIdentity *peer) | 500 | const struct GNUNET_PeerIdentity *peer) |
489 | { | 501 | { |
490 | GNUNET_assert (peer != NULL); | 502 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
491 | GNUNET_assert (sh != NULL); | 503 | "ats-scheduling-api", |
492 | 504 | "Release sessionID %u from peer %s in %p\n", | |
493 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-scheduling-api", | 505 | (unsigned int) session_id, |
494 | "Release sessionID %u from peer %s in %p\n", | 506 | GNUNET_i2s (peer), |
495 | (unsigned int) session_id, GNUNET_i2s (peer), sh); | 507 | sh); |
496 | 508 | ||
497 | if (0 == session_id) | 509 | if (0 == session_id) |
498 | return; | 510 | return; |
@@ -508,7 +520,6 @@ remove_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id, | |||
508 | GNUNET_i2s (peer), | 520 | GNUNET_i2s (peer), |
509 | session_id); | 521 | session_id); |
510 | sh->session_array[session_id].session = NULL; | 522 | sh->session_array[session_id].session = NULL; |
511 | |||
512 | } | 523 | } |
513 | 524 | ||
514 | 525 | ||
@@ -521,7 +532,8 @@ remove_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id, | |||
521 | * @param peer peer the session belongs to | 532 | * @param peer peer the session belongs to |
522 | */ | 533 | */ |
523 | static void | 534 | static void |
524 | release_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id, | 535 | release_session (struct GNUNET_ATS_SchedulingHandle *sh, |
536 | uint32_t session_id, | ||
525 | const struct GNUNET_PeerIdentity *peer) | 537 | const struct GNUNET_PeerIdentity *peer) |
526 | { | 538 | { |
527 | 539 | ||
@@ -565,11 +577,12 @@ process_release_message (struct GNUNET_ATS_SchedulingHandle *sh, | |||
565 | * Type of a function to call when we receive a message | 577 | * Type of a function to call when we receive a message |
566 | * from the service. | 578 | * from the service. |
567 | * | 579 | * |
568 | * @param cls the 'struct GNUNET_ATS_SchedulingHandle' | 580 | * @param cls the `struct GNUNET_ATS_SchedulingHandle` |
569 | * @param msg message received, NULL on timeout or fatal error | 581 | * @param msg message received, NULL on timeout or fatal error |
570 | */ | 582 | */ |
571 | static void | 583 | static void |
572 | process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg) | 584 | process_ats_message (void *cls, |
585 | const struct GNUNET_MessageHeader *msg) | ||
573 | { | 586 | { |
574 | struct GNUNET_ATS_SchedulingHandle *sh = cls; | 587 | struct GNUNET_ATS_SchedulingHandle *sh = cls; |
575 | const struct AddressSuggestionMessage *m; | 588 | const struct AddressSuggestionMessage *m; |
@@ -688,9 +701,11 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh) | |||
688 | GNUNET_assert (NULL == sh->client); | 701 | GNUNET_assert (NULL == sh->client); |
689 | sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg); | 702 | sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg); |
690 | GNUNET_assert (NULL != sh->client); | 703 | GNUNET_assert (NULL != sh->client); |
691 | GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh, | 704 | GNUNET_CLIENT_receive (sh->client, |
692 | GNUNET_TIME_UNIT_FOREVER_REL); | 705 | &process_ats_message, sh, |
693 | if ((NULL == (p = sh->pending_head)) || (GNUNET_YES != p->is_init)) | 706 | GNUNET_TIME_UNIT_FOREVER_REL); |
707 | if ( (NULL == (p = sh->pending_head)) || | ||
708 | (GNUNET_YES != p->is_init) ) | ||
694 | { | 709 | { |
695 | p = GNUNET_malloc (sizeof (struct PendingMessage) + | 710 | p = GNUNET_malloc (sizeof (struct PendingMessage) + |
696 | sizeof (struct ClientStartMessage)); | 711 | sizeof (struct ClientStartMessage)); |
@@ -700,39 +715,44 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh) | |||
700 | init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); | 715 | init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); |
701 | init->header.size = htons (sizeof (struct ClientStartMessage)); | 716 | init->header.size = htons (sizeof (struct ClientStartMessage)); |
702 | init->start_flag = htonl (START_FLAG_SCHEDULING); | 717 | init->start_flag = htonl (START_FLAG_SCHEDULING); |
703 | GNUNET_CONTAINER_DLL_insert (sh->pending_head, sh->pending_tail, p); | 718 | GNUNET_CONTAINER_DLL_insert (sh->pending_head, |
719 | sh->pending_tail, | ||
720 | p); | ||
704 | } | 721 | } |
705 | do_transmit (sh); | 722 | do_transmit (sh); |
706 | } | 723 | } |
707 | 724 | ||
708 | 725 | ||
709 | /** | 726 | /** |
710 | * delete the current network list | 727 | * Delete the current network list. |
728 | * | ||
729 | * @param sh scheduling handle to clean up | ||
711 | */ | 730 | */ |
712 | static void | 731 | static void |
713 | delete_networks (struct GNUNET_ATS_SchedulingHandle *sh) | 732 | delete_networks (struct GNUNET_ATS_SchedulingHandle *sh) |
714 | { | 733 | { |
715 | struct ATS_Network * cur = sh->net_head; | 734 | struct ATS_Network *cur; |
716 | while (cur != NULL) | 735 | |
736 | while (NULL != (cur = sh->net_head)) | ||
717 | { | 737 | { |
718 | GNUNET_CONTAINER_DLL_remove(sh->net_head, sh->net_tail, cur); | 738 | GNUNET_CONTAINER_DLL_remove (sh->net_head, |
739 | sh->net_tail, | ||
740 | cur); | ||
719 | GNUNET_free (cur); | 741 | GNUNET_free (cur); |
720 | cur = sh->net_head; | ||
721 | } | 742 | } |
722 | } | 743 | } |
723 | 744 | ||
724 | 745 | ||
725 | static int | 746 | static int |
726 | interface_proc (void *cls, const char *name, | 747 | interface_proc (void *cls, |
748 | const char *name, | ||
727 | int isDefault, | 749 | int isDefault, |
728 | const struct sockaddr * | 750 | const struct sockaddr *addr, |
729 | addr, | 751 | const struct sockaddr *broadcast_addr, |
730 | const struct sockaddr * | 752 | const struct sockaddr *netmask, |
731 | broadcast_addr, | 753 | socklen_t addrlen) |
732 | const struct sockaddr * | ||
733 | netmask, socklen_t addrlen) | ||
734 | { | 754 | { |
735 | struct GNUNET_ATS_SchedulingHandle * sh = cls; | 755 | struct GNUNET_ATS_SchedulingHandle *sh = cls; |
736 | /* Calculate network */ | 756 | /* Calculate network */ |
737 | struct ATS_Network *net = NULL; | 757 | struct ATS_Network *net = NULL; |
738 | 758 | ||
@@ -822,19 +842,23 @@ interface_proc (void *cls, const char *name, | |||
822 | 842 | ||
823 | 843 | ||
824 | /** | 844 | /** |
825 | * Periodically get list of addresses | 845 | * Periodically get list of network addresses from our interfaces. |
846 | * | ||
826 | * @param cls closure | 847 | * @param cls closure |
827 | * @param tc Task context | 848 | * @param tc Task context |
828 | */ | 849 | */ |
829 | static void | 850 | static void |
830 | get_addresses (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 851 | get_addresses (void *cls, |
852 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
831 | { | 853 | { |
832 | struct GNUNET_ATS_SchedulingHandle * sh = cls; | 854 | struct GNUNET_ATS_SchedulingHandle *sh = cls; |
855 | |||
833 | sh->interface_task = NULL; | 856 | sh->interface_task = NULL; |
834 | delete_networks (sh); | 857 | delete_networks (sh); |
835 | GNUNET_OS_network_interfaces_list(interface_proc, sh); | 858 | GNUNET_OS_network_interfaces_list (&interface_proc, |
859 | sh); | ||
836 | sh->interface_task = GNUNET_SCHEDULER_add_delayed (INTERFACE_PROCESSING_INTERVALL, | 860 | sh->interface_task = GNUNET_SCHEDULER_add_delayed (INTERFACE_PROCESSING_INTERVALL, |
837 | get_addresses, | 861 | &get_addresses, |
838 | sh); | 862 | sh); |
839 | } | 863 | } |
840 | 864 | ||
@@ -913,37 +937,41 @@ GNUNET_ATS_print_property_type (enum GNUNET_ATS_Property type) | |||
913 | * @param sh the scheduling handle | 937 | * @param sh the scheduling handle |
914 | * @param addr address | 938 | * @param addr address |
915 | * @param addrlen address length | 939 | * @param addrlen address length |
916 | * @return location as GNUNET_ATS_Information | 940 | * @return type of the network the address belongs to |
917 | */ | 941 | */ |
918 | struct GNUNET_ATS_Information | 942 | enum GNUNET_ATS_Network_Type |
919 | GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle * sh, const struct sockaddr * addr, socklen_t addrlen) | 943 | GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh, |
944 | const struct sockaddr *addr, | ||
945 | socklen_t addrlen) | ||
920 | { | 946 | { |
921 | GNUNET_assert (sh != NULL); | 947 | struct ATS_Network *cur = sh->net_head; |
922 | struct ATS_Network * cur = sh->net_head; | 948 | enum GNUNET_ATS_NetworkType type = GNUNET_ATS_NET_UNSPECIFIED; |
923 | |||
924 | int type = GNUNET_ATS_NET_UNSPECIFIED; | ||
925 | struct GNUNET_ATS_Information ats; | ||
926 | 949 | ||
927 | if (addr->sa_family == AF_UNIX) | 950 | switch (addr->sa_family) |
928 | { | 951 | { |
929 | type = GNUNET_ATS_NET_LOOPBACK; | 952 | case AF_UNIX: |
930 | } | 953 | type = GNUNET_ATS_NET_LOOPBACK; |
954 | break; | ||
955 | case AF_INET: | ||
956 | { | ||
957 | const struct sockaddr_in *a4 = (const struct sockaddr_in *) addr; | ||
931 | 958 | ||
932 | /* IPv4 loopback check */ | 959 | if ((a4->sin_addr.s_addr & htonl(0xff000000)) == htonl (0x7f000000)) |
933 | if (addr->sa_family == AF_INET) | 960 | type = GNUNET_ATS_NET_LOOPBACK; |
934 | { | 961 | break; |
935 | struct sockaddr_in * a4 = (struct sockaddr_in *) addr; | 962 | } |
963 | case AF_INET6: | ||
964 | { | ||
965 | const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *) addr; | ||
936 | 966 | ||
937 | if ((a4->sin_addr.s_addr & htonl(0xff000000)) == htonl (0x7f000000)) | 967 | if (IN6_IS_ADDR_LOOPBACK (&a6->sin6_addr)) |
938 | type = GNUNET_ATS_NET_LOOPBACK; | 968 | type = GNUNET_ATS_NET_LOOPBACK; |
939 | } | 969 | break; |
940 | /* IPv6 loopback check */ | 970 | } |
941 | if (addr->sa_family == AF_INET6) | 971 | default: |
942 | { | 972 | GNUNET_break (0); |
943 | struct sockaddr_in6 * a6 = (struct sockaddr_in6 *) addr; | 973 | break; |
944 | if (IN6_IS_ADDR_LOOPBACK (&a6->sin6_addr)) | 974 | } |
945 | type = GNUNET_ATS_NET_LOOPBACK; | ||
946 | } | ||
947 | 975 | ||
948 | /* Check local networks */ | 976 | /* Check local networks */ |
949 | while ((cur != NULL) && (type == GNUNET_ATS_NET_UNSPECIFIED)) | 977 | while ((cur != NULL) && (type == GNUNET_ATS_NET_UNSPECIFIED)) |
@@ -953,7 +981,6 @@ GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle * sh, const stru | |||
953 | cur = cur->next; | 981 | cur = cur->next; |
954 | continue; | 982 | continue; |
955 | } | 983 | } |
956 | |||
957 | if (addr->sa_family == AF_INET) | 984 | if (addr->sa_family == AF_INET) |
958 | { | 985 | { |
959 | struct sockaddr_in * a4 = (struct sockaddr_in *) addr; | 986 | struct sockaddr_in * a4 = (struct sockaddr_in *) addr; |
@@ -987,14 +1014,13 @@ GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle * sh, const stru | |||
987 | /* no local network found for this address, default: WAN */ | 1014 | /* no local network found for this address, default: WAN */ |
988 | if (type == GNUNET_ATS_NET_UNSPECIFIED) | 1015 | if (type == GNUNET_ATS_NET_UNSPECIFIED) |
989 | type = GNUNET_ATS_NET_WAN; | 1016 | type = GNUNET_ATS_NET_WAN; |
990 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 1017 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
991 | ats.value = htonl (type); | 1018 | "ats-scheduling-api", |
992 | |||
993 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-scheduling-api", | ||
994 | "`%s' is in network `%s'\n", | 1019 | "`%s' is in network `%s'\n", |
995 | GNUNET_a2s ((const struct sockaddr *) addr, addrlen), | 1020 | GNUNET_a2s (addr, |
996 | GNUNET_ATS_print_network_type(type)); | 1021 | addrlen), |
997 | return ats; | 1022 | GNUNET_ATS_print_network_type (type)); |
1023 | return type; | ||
998 | } | 1024 | } |
999 | 1025 | ||
1000 | 1026 | ||
@@ -1003,7 +1029,7 @@ GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle * sh, const stru | |||
1003 | * | 1029 | * |
1004 | * @param cfg configuration to use | 1030 | * @param cfg configuration to use |
1005 | * @param suggest_cb notification to call whenever the suggestation changed | 1031 | * @param suggest_cb notification to call whenever the suggestation changed |
1006 | * @param suggest_cb_cls closure for 'suggest_cb' | 1032 | * @param suggest_cb_cls closure for @a suggest_cb |
1007 | * @return ats context | 1033 | * @return ats context |
1008 | */ | 1034 | */ |
1009 | struct GNUNET_ATS_SchedulingHandle * | 1035 | struct GNUNET_ATS_SchedulingHandle * |
@@ -1017,11 +1043,14 @@ GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1017 | sh->cfg = cfg; | 1043 | sh->cfg = cfg; |
1018 | sh->suggest_cb = suggest_cb; | 1044 | sh->suggest_cb = suggest_cb; |
1019 | sh->suggest_cb_cls = suggest_cb_cls; | 1045 | sh->suggest_cb_cls = suggest_cb_cls; |
1020 | GNUNET_array_grow (sh->session_array, sh->session_array_size, 4); | 1046 | GNUNET_array_grow (sh->session_array, |
1021 | GNUNET_OS_network_interfaces_list(interface_proc, sh); | 1047 | sh->session_array_size, |
1048 | 4); | ||
1049 | GNUNET_OS_network_interfaces_list (&interface_proc, | ||
1050 | sh); | ||
1022 | sh->interface_task = GNUNET_SCHEDULER_add_delayed (INTERFACE_PROCESSING_INTERVALL, | 1051 | sh->interface_task = GNUNET_SCHEDULER_add_delayed (INTERFACE_PROCESSING_INTERVALL, |
1023 | get_addresses, | 1052 | &get_addresses, |
1024 | sh); | 1053 | sh); |
1025 | reconnect (sh); | 1054 | reconnect (sh); |
1026 | return sh; | 1055 | return sh; |
1027 | } | 1056 | } |
@@ -1037,10 +1066,12 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh) | |||
1037 | { | 1066 | { |
1038 | struct PendingMessage *p; | 1067 | struct PendingMessage *p; |
1039 | struct GNUNET_ATS_SuggestHandle *cur; | 1068 | struct GNUNET_ATS_SuggestHandle *cur; |
1040 | struct GNUNET_ATS_SuggestHandle *next; | 1069 | |
1041 | while (NULL != (p = sh->pending_head)) | 1070 | while (NULL != (p = sh->pending_head)) |
1042 | { | 1071 | { |
1043 | GNUNET_CONTAINER_DLL_remove (sh->pending_head, sh->pending_tail, p); | 1072 | GNUNET_CONTAINER_DLL_remove (sh->pending_head, |
1073 | sh->pending_tail, | ||
1074 | p); | ||
1044 | GNUNET_free (p); | 1075 | GNUNET_free (p); |
1045 | } | 1076 | } |
1046 | if (NULL != sh->client) | 1077 | if (NULL != sh->client) |
@@ -1053,26 +1084,26 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh) | |||
1053 | GNUNET_SCHEDULER_cancel (sh->task); | 1084 | GNUNET_SCHEDULER_cancel (sh->task); |
1054 | sh->task = NULL; | 1085 | sh->task = NULL; |
1055 | } | 1086 | } |
1056 | 1087 | while (NULL != (cur = sh->sug_head)) | |
1057 | next = sh->sug_head; | ||
1058 | while (NULL != (cur = next)) | ||
1059 | { | 1088 | { |
1060 | next = cur->next; | 1089 | GNUNET_CONTAINER_DLL_remove (sh->sug_head, |
1061 | GNUNET_CONTAINER_DLL_remove (sh->sug_head, sh->sug_tail, cur); | 1090 | sh->sug_tail, |
1062 | GNUNET_free (cur); | 1091 | cur); |
1092 | GNUNET_free (cur); | ||
1063 | } | 1093 | } |
1064 | |||
1065 | delete_networks (sh); | 1094 | delete_networks (sh); |
1066 | if (sh->interface_task != NULL) | 1095 | if (NULL != sh->interface_task) |
1067 | { | 1096 | { |
1068 | GNUNET_SCHEDULER_cancel(sh->interface_task); | 1097 | GNUNET_SCHEDULER_cancel (sh->interface_task); |
1069 | sh->interface_task = NULL; | 1098 | sh->interface_task = NULL; |
1070 | } | 1099 | } |
1071 | GNUNET_array_grow (sh->session_array, sh->session_array_size, 0); | 1100 | GNUNET_array_grow (sh->session_array, |
1101 | sh->session_array_size, | ||
1102 | 0); | ||
1072 | GNUNET_free (sh); | 1103 | GNUNET_free (sh); |
1073 | sh = NULL; | ||
1074 | } | 1104 | } |
1075 | 1105 | ||
1106 | |||
1076 | /** | 1107 | /** |
1077 | * We would like to reset the address suggestion block time for this | 1108 | * We would like to reset the address suggestion block time for this |
1078 | * peer | 1109 | * peer |
@@ -1096,7 +1127,9 @@ GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1096 | m->header.size = htons (sizeof (struct ResetBackoffMessage)); | 1127 | m->header.size = htons (sizeof (struct ResetBackoffMessage)); |
1097 | m->reserved = htonl (0); | 1128 | m->reserved = htonl (0); |
1098 | m->peer = *peer; | 1129 | m->peer = *peer; |
1099 | GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p); | 1130 | GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, |
1131 | sh->pending_tail, | ||
1132 | p); | ||
1100 | do_transmit (sh); | 1133 | do_transmit (sh); |
1101 | } | 1134 | } |
1102 | 1135 | ||
@@ -1157,18 +1190,17 @@ GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1157 | struct GNUNET_ATS_SuggestHandle *s; | 1190 | struct GNUNET_ATS_SuggestHandle *s; |
1158 | 1191 | ||
1159 | for (s = sh->sug_head; NULL != s; s = s->next) | 1192 | for (s = sh->sug_head; NULL != s; s = s->next) |
1160 | if (0 == memcmp(peer, &s->id, sizeof (s->id))) | 1193 | if (0 == memcmp (peer, &s->id, sizeof (s->id))) |
1161 | break; | 1194 | break; |
1162 | if (NULL == s) | 1195 | if (NULL == s) |
1163 | { | 1196 | { |
1164 | GNUNET_break (0); | 1197 | GNUNET_break (0); |
1165 | return; | 1198 | return; |
1166 | } | ||
1167 | else | ||
1168 | { | ||
1169 | GNUNET_CONTAINER_DLL_remove (sh->sug_head, sh->sug_tail, s); | ||
1170 | GNUNET_free (s); | ||
1171 | } | 1199 | } |
1200 | GNUNET_CONTAINER_DLL_remove (sh->sug_head, | ||
1201 | sh->sug_tail, | ||
1202 | s); | ||
1203 | GNUNET_free (s); | ||
1172 | 1204 | ||
1173 | p = GNUNET_malloc (sizeof (struct PendingMessage) + | 1205 | p = GNUNET_malloc (sizeof (struct PendingMessage) + |
1174 | sizeof (struct RequestAddressMessage)); | 1206 | sizeof (struct RequestAddressMessage)); |
@@ -1179,7 +1211,9 @@ GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1179 | m->header.size = htons (sizeof (struct RequestAddressMessage)); | 1211 | m->header.size = htons (sizeof (struct RequestAddressMessage)); |
1180 | m->reserved = htonl (0); | 1212 | m->reserved = htonl (0); |
1181 | m->peer = *peer; | 1213 | m->peer = *peer; |
1182 | GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p); | 1214 | GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, |
1215 | sh->pending_tail, | ||
1216 | p); | ||
1183 | do_transmit (sh); | 1217 | do_transmit (sh); |
1184 | } | 1218 | } |
1185 | 1219 | ||
@@ -1190,26 +1224,23 @@ GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1190 | * @param sh the scheduling handle | 1224 | * @param sh the scheduling handle |
1191 | * @param address the address | 1225 | * @param address the address |
1192 | * @param session the session | 1226 | * @param session the session |
1193 | * @return GNUNET_YES or GNUNET_NO | 1227 | * @return #GNUNET_YES or #GNUNET_NO |
1194 | */ | 1228 | */ |
1195 | int | 1229 | int |
1196 | GNUNET_ATS_session_known (struct GNUNET_ATS_SchedulingHandle *sh, | 1230 | GNUNET_ATS_session_known (struct GNUNET_ATS_SchedulingHandle *sh, |
1197 | const struct GNUNET_HELLO_Address *address, | 1231 | const struct GNUNET_HELLO_Address *address, |
1198 | struct Session *session) | 1232 | struct Session *session) |
1199 | { | 1233 | { |
1200 | int s; | 1234 | if (NULL == session) |
1201 | if (NULL != session) | ||
1202 | { | ||
1203 | if (NOT_FOUND != (s = find_session_id (sh, session, &address->peer))) | ||
1204 | { | ||
1205 | /* Existing */ | ||
1206 | return GNUNET_YES; | ||
1207 | } | ||
1208 | return GNUNET_NO; | 1235 | return GNUNET_NO; |
1209 | } | 1236 | if (NOT_FOUND != find_session_id (sh, |
1237 | session, | ||
1238 | &address->peer)) | ||
1239 | return GNUNET_YES; /* Exists */ | ||
1210 | return GNUNET_NO; | 1240 | return GNUNET_NO; |
1211 | } | 1241 | } |
1212 | 1242 | ||
1243 | |||
1213 | /** | 1244 | /** |
1214 | * We have a new address ATS should know. Addresses have to be added with this | 1245 | * We have a new address ATS should know. Addresses have to be added with this |
1215 | * function before they can be: updated, set in use and destroyed | 1246 | * function before they can be: updated, set in use and destroyed |
@@ -1218,8 +1249,8 @@ GNUNET_ATS_session_known (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1218 | * @param address the address | 1249 | * @param address the address |
1219 | * @param session session handle, can be NULL | 1250 | * @param session session handle, can be NULL |
1220 | * @param ats performance data for the address | 1251 | * @param ats performance data for the address |
1221 | * @param ats_count number of performance records in 'ats' | 1252 | * @param ats_count number of performance records in @a ats |
1222 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 1253 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1223 | */ | 1254 | */ |
1224 | int | 1255 | int |
1225 | GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | 1256 | GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, |
@@ -1237,16 +1268,18 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1237 | size_t msize; | 1268 | size_t msize; |
1238 | uint32_t s = 0; | 1269 | uint32_t s = 0; |
1239 | 1270 | ||
1240 | if (address == NULL) | 1271 | if (NULL == address) |
1241 | { | 1272 | { |
1242 | GNUNET_break (0); | 1273 | GNUNET_break (0); |
1243 | return GNUNET_SYSERR; | 1274 | return GNUNET_SYSERR; |
1244 | } | 1275 | } |
1245 | 1276 | ||
1246 | namelen = (address->transport_name == NULL) ? 0 : strlen (address->transport_name) + 1; | 1277 | namelen = (NULL == address->transport_name) |
1278 | ? 0 | ||
1279 | : strlen (address->transport_name) + 1; | ||
1247 | 1280 | ||
1248 | msize = sizeof (struct AddressUpdateMessage) + address->address_length + | 1281 | msize = sizeof (struct AddressUpdateMessage) + address->address_length + |
1249 | ats_count * sizeof (struct GNUNET_ATS_Information) + namelen; | 1282 | ats_count * sizeof (struct GNUNET_ATS_Information) + namelen; |
1250 | if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || | 1283 | if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || |
1251 | (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || | 1284 | (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || |
1252 | (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || | 1285 | (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || |
@@ -1264,7 +1297,9 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1264 | /* Already existing, nothing todo */ | 1297 | /* Already existing, nothing todo */ |
1265 | return GNUNET_SYSERR; | 1298 | return GNUNET_SYSERR; |
1266 | } | 1299 | } |
1267 | s = find_empty_session_slot (sh, session, &address->peer); | 1300 | s = find_empty_session_slot (sh, |
1301 | session, | ||
1302 | &address->peer); | ||
1268 | GNUNET_break (NOT_FOUND != s); | 1303 | GNUNET_break (NOT_FOUND != s); |
1269 | } | 1304 | } |
1270 | 1305 | ||
@@ -1284,18 +1319,23 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1285 | "Adding address for peer `%s', plugin `%s', session %p id %u\n", | 1320 | "Adding address for peer `%s', plugin `%s', session %p id %u\n", |
1286 | GNUNET_i2s (&address->peer), | 1321 | GNUNET_i2s (&address->peer), |
1287 | address->transport_name, session, s); | 1322 | address->transport_name, |
1323 | session, | ||
1324 | s); | ||
1288 | 1325 | ||
1289 | am = (struct GNUNET_ATS_Information *) &m[1]; | 1326 | am = (struct GNUNET_ATS_Information *) &m[1]; |
1290 | memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); | 1327 | memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); |
1291 | pm = (char *) &am[ats_count]; | 1328 | pm = (char *) &am[ats_count]; |
1292 | memcpy (pm, address->address, address->address_length); | 1329 | memcpy (pm, address->address, address->address_length); |
1293 | if (NULL != address->transport_name) | 1330 | if (NULL != address->transport_name) |
1294 | memcpy (&pm[address->address_length], address->transport_name, namelen); | 1331 | memcpy (&pm[address->address_length], |
1295 | GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p); | 1332 | address->transport_name, |
1333 | namelen); | ||
1334 | GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, | ||
1335 | sh->pending_tail, | ||
1336 | p); | ||
1296 | do_transmit (sh); | 1337 | do_transmit (sh); |
1297 | return GNUNET_OK; | 1338 | return GNUNET_OK; |
1298 | |||
1299 | } | 1339 | } |
1300 | 1340 | ||
1301 | 1341 | ||
@@ -1380,10 +1420,14 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1380 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1381 | "Updating address for peer `%s', plugin `%s', session %p id %u\n", | 1421 | "Updating address for peer `%s', plugin `%s', session %p id %u\n", |
1382 | GNUNET_i2s (&address->peer), | 1422 | GNUNET_i2s (&address->peer), |
1383 | address->transport_name, session, s); | 1423 | address->transport_name, |
1424 | session, | ||
1425 | s); | ||
1384 | 1426 | ||
1385 | am = (struct GNUNET_ATS_Information *) &m[1]; | 1427 | am = (struct GNUNET_ATS_Information *) &m[1]; |
1386 | memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); | 1428 | memcpy (am, |
1429 | ats, | ||
1430 | ats_count * sizeof (struct GNUNET_ATS_Information)); | ||
1387 | pm = (char *) &am[ats_count]; | 1431 | pm = (char *) &am[ats_count]; |
1388 | memcpy (pm, address->address, address->address_length); | 1432 | memcpy (pm, address->address, address->address_length); |
1389 | memcpy (&pm[address->address_length], address->transport_name, namelen); | 1433 | memcpy (&pm[address->address_length], address->transport_name, namelen); |
@@ -1405,7 +1449,8 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1405 | void | 1449 | void |
1406 | GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, | 1450 | GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, |
1407 | const struct GNUNET_HELLO_Address *address, | 1451 | const struct GNUNET_HELLO_Address *address, |
1408 | struct Session *session, int in_use) | 1452 | struct Session *session, |
1453 | int in_use) | ||
1409 | { | 1454 | { |
1410 | struct PendingMessage *p; | 1455 | struct PendingMessage *p; |
1411 | struct AddressUseMessage *m; | 1456 | struct AddressUseMessage *m; |
@@ -1470,7 +1515,6 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1470 | memcpy (&pm[address->address_length], address->transport_name, namelen); | 1515 | memcpy (&pm[address->address_length], address->transport_name, namelen); |
1471 | GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p); | 1516 | GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p); |
1472 | do_transmit (sh); | 1517 | do_transmit (sh); |
1473 | return; | ||
1474 | } | 1518 | } |
1475 | 1519 | ||
1476 | 1520 | ||
@@ -1494,9 +1538,9 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1494 | char *pm; | 1538 | char *pm; |
1495 | size_t namelen; | 1539 | size_t namelen; |
1496 | size_t msize; | 1540 | size_t msize; |
1497 | uint32_t s = 0; | 1541 | uint32_t s; |
1498 | 1542 | ||
1499 | if (address == NULL) | 1543 | if (NULL == address) |
1500 | { | 1544 | { |
1501 | GNUNET_break (0); | 1545 | GNUNET_break (0); |
1502 | return; | 1546 | return; |