diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-17 22:20:18 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-17 22:20:18 +0000 |
commit | 81b92caa24a83620032438df9c5ee3ea51663a02 (patch) | |
tree | 2b2df659c94e1ead5bbdb5082e50018c39e68796 | |
parent | 4756cb0779daf3e4c33b6e876dce956de7ee6dd8 (diff) | |
download | gnunet-81b92caa24a83620032438df9c5ee3ea51663a02.tar.gz gnunet-81b92caa24a83620032438df9c5ee3ea51663a02.zip |
simplify ATS API and plugin API by returning the network type, instead of an ATS_Information struct
-rw-r--r-- | src/ats/ats_api_scheduling.c | 350 | ||||
-rw-r--r-- | src/include/gnunet_ats_service.h | 16 | ||||
-rw-r--r-- | src/include/gnunet_transport_plugin.h | 8 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport.c | 27 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 23 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_server.c | 18 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 14 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp.c | 20 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp_broadcasting.c | 29 | ||||
-rw-r--r-- | src/transport/plugin_transport_unix.c | 5 |
10 files changed, 282 insertions, 228 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; |
diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index 7be2e4758..e09dc5d75 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h | |||
@@ -35,11 +35,6 @@ | |||
35 | */ | 35 | */ |
36 | #define GNUNET_ATS_NetworkTypeCount 6 | 36 | #define GNUNET_ATS_NetworkTypeCount 6 |
37 | 37 | ||
38 | /** | ||
39 | * ATS network types as array initializer | ||
40 | */ | ||
41 | #define GNUNET_ATS_NetworkType { GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN, GNUNET_ATS_NET_BT } | ||
42 | |||
43 | 38 | ||
44 | /** | 39 | /** |
45 | * Types of networks (with separate quotas) we support. | 40 | * Types of networks (with separate quotas) we support. |
@@ -79,6 +74,13 @@ enum GNUNET_ATS_Network_Type | |||
79 | 74 | ||
80 | 75 | ||
81 | /** | 76 | /** |
77 | * ATS network types as array initializer | ||
78 | */ | ||
79 | #define GNUNET_ATS_NetworkType { GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN, GNUNET_ATS_NET_BT } | ||
80 | |||
81 | |||
82 | |||
83 | /** | ||
82 | * Default bandwidth assigned to a network : 64 KB/s | 84 | * Default bandwidth assigned to a network : 64 KB/s |
83 | */ | 85 | */ |
84 | #define GNUNET_ATS_DefaultBandwidth 65536 | 86 | #define GNUNET_ATS_DefaultBandwidth 65536 |
@@ -430,9 +432,9 @@ GNUNET_ATS_print_network_type (enum GNUNET_ATS_Network_Type net); | |||
430 | * @param sh the `struct GNUNET_ATS_SchedulingHandle` handle | 432 | * @param sh the `struct GNUNET_ATS_SchedulingHandle` handle |
431 | * @param addr address | 433 | * @param addr address |
432 | * @param addrlen address length | 434 | * @param addrlen address length |
433 | * @return location as `struct GNUNET_ATS_Information` | 435 | * @return type of the network the address belongs to |
434 | */ | 436 | */ |
435 | struct GNUNET_ATS_Information | 437 | enum GNUNET_ATS_Network_Type |
436 | GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh, | 438 | GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh, |
437 | const struct sockaddr *addr, | 439 | const struct sockaddr *addr, |
438 | socklen_t addrlen); | 440 | socklen_t addrlen); |
diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h index 17333551c..90d6ed2c6 100644 --- a/src/include/gnunet_transport_plugin.h +++ b/src/include/gnunet_transport_plugin.h | |||
@@ -120,15 +120,15 @@ typedef struct GNUNET_TIME_Relative | |||
120 | 120 | ||
121 | 121 | ||
122 | /** | 122 | /** |
123 | * Function that will be called to figure if an address is an loopback, | 123 | * Function that will be called to figure if an address is an |
124 | * LAN, WAN etc. address | 124 | * loopback, LAN, WAN etc. address |
125 | * | 125 | * |
126 | * @param cls closure | 126 | * @param cls closure |
127 | * @param addr binary address | 127 | * @param addr binary address |
128 | * @param addrlen length of the @a addr | 128 | * @param addrlen length of the @a addr |
129 | * @return ATS Information containing the network type | 129 | * @return type of the network the address belongs to |
130 | */ | 130 | */ |
131 | typedef struct GNUNET_ATS_Information | 131 | typedef enum GNUNET_ATS_Network_Type |
132 | (*GNUNET_TRANSPORT_AddressToType) (void *cls, | 132 | (*GNUNET_TRANSPORT_AddressToType) (void *cls, |
133 | const struct sockaddr *addr, | 133 | const struct sockaddr *addr, |
134 | size_t addrlen); | 134 | size_t addrlen); |
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 03fbc95db..2d2c0db46 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -633,36 +633,33 @@ plugin_env_session_end (void *cls, const struct GNUNET_HELLO_Address *address, | |||
633 | * | 633 | * |
634 | * @param cls closure | 634 | * @param cls closure |
635 | * @param addr binary address | 635 | * @param addr binary address |
636 | * @param addrlen length of the address | 636 | * @param addrlen length of the @a addr |
637 | * @return ATS Information containing the network type | 637 | * @return type of the network @a addr belongs to |
638 | */ | 638 | */ |
639 | static struct GNUNET_ATS_Information | 639 | static enum GNUNET_ATS_Network_Type |
640 | plugin_env_address_to_type (void *cls, const struct sockaddr *addr, | 640 | plugin_env_address_to_type (void *cls, |
641 | size_t addrlen) | 641 | const struct sockaddr *addr, |
642 | size_t addrlen) | ||
642 | { | 643 | { |
643 | struct GNUNET_ATS_Information ats; | ||
644 | |||
645 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
646 | ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED); | ||
647 | if (NULL == GST_ats) | 644 | if (NULL == GST_ats) |
648 | { | 645 | { |
649 | GNUNET_break(0); | 646 | GNUNET_break(0); |
650 | return ats; | 647 | return GNUNET_ATS_NET_UNSPECIFIED; |
651 | } | 648 | } |
652 | if (((addr->sa_family != AF_INET) && (addrlen != sizeof(struct sockaddr_in))) | 649 | if (((addr->sa_family != AF_INET) && (addrlen != sizeof(struct sockaddr_in))) |
653 | && ((addr->sa_family != AF_INET6) | 650 | && ((addr->sa_family != AF_INET6) |
654 | && (addrlen != sizeof(struct sockaddr_in6))) | 651 | && (addrlen != sizeof(struct sockaddr_in6))) |
655 | && (addr->sa_family != AF_UNIX)) | 652 | && (addr->sa_family != AF_UNIX)) |
656 | { | 653 | { |
657 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
658 | "Malformed address with length %u `%s'\n", addrlen, | ||
659 | GNUNET_a2s (addr, addrlen)); | ||
660 | GNUNET_break(0); | 654 | GNUNET_break(0); |
661 | return ats; | 655 | return GNUNET_ATS_NET_UNSPECIFIED; |
662 | } | 656 | } |
663 | return GNUNET_ATS_address_get_type (GST_ats, addr, addrlen); | 657 | return GNUNET_ATS_address_get_type (GST_ats, |
658 | addr, | ||
659 | addrlen); | ||
664 | } | 660 | } |
665 | 661 | ||
662 | |||
666 | /** | 663 | /** |
667 | * Notify ATS about the new address including the network this address is | 664 | * Notify ATS about the new address including the network this address is |
668 | * located in. | 665 | * located in. |
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index cc1f39e9a..9c9af57ad 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -262,9 +262,9 @@ struct Session | |||
262 | unsigned int msgs_in_queue; | 262 | unsigned int msgs_in_queue; |
263 | 263 | ||
264 | /** | 264 | /** |
265 | * ATS network type in NBO | 265 | * ATS network type. |
266 | */ | 266 | */ |
267 | uint32_t ats_address_network_type; | 267 | enum GNUNET_ATS_Network_Type ats_address_network_type; |
268 | }; | 268 | }; |
269 | 269 | ||
270 | 270 | ||
@@ -1173,9 +1173,9 @@ client_receive_mst_cb (void *cls, | |||
1173 | char *stat_txt; | 1173 | char *stat_txt; |
1174 | 1174 | ||
1175 | plugin = s->plugin; | 1175 | plugin = s->plugin; |
1176 | GNUNET_break (s->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); | ||
1176 | atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 1177 | atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
1177 | atsi.value = s->ats_address_network_type; | 1178 | atsi.value = htonl (s->ats_address_network_type); |
1178 | GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED)); | ||
1179 | 1179 | ||
1180 | delay = s->plugin->env->receive (plugin->env->cls, | 1180 | delay = s->plugin->env->receive (plugin->env->cls, |
1181 | s->address, | 1181 | s->address, |
@@ -1941,7 +1941,7 @@ static enum GNUNET_ATS_Network_Type | |||
1941 | http_client_plugin_get_network (void *cls, | 1941 | http_client_plugin_get_network (void *cls, |
1942 | struct Session *session) | 1942 | struct Session *session) |
1943 | { | 1943 | { |
1944 | return ntohl (session->ats_address_network_type); | 1944 | return session->ats_address_network_type; |
1945 | } | 1945 | } |
1946 | 1946 | ||
1947 | 1947 | ||
@@ -1998,7 +1998,7 @@ http_client_plugin_get_session (void *cls, | |||
1998 | struct HTTP_Client_Plugin *plugin = cls; | 1998 | struct HTTP_Client_Plugin *plugin = cls; |
1999 | struct Session *s; | 1999 | struct Session *s; |
2000 | struct sockaddr *sa; | 2000 | struct sockaddr *sa; |
2001 | struct GNUNET_ATS_Information ats; | 2001 | enum GNUNET_ATS_Network_Type net_type; |
2002 | size_t salen = 0; | 2002 | size_t salen = 0; |
2003 | int res; | 2003 | int res; |
2004 | 2004 | ||
@@ -2021,8 +2021,7 @@ http_client_plugin_get_session (void *cls, | |||
2021 | } | 2021 | } |
2022 | 2022 | ||
2023 | /* Determine network location */ | 2023 | /* Determine network location */ |
2024 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 2024 | net_type = GNUNET_ATS_NET_UNSPECIFIED; |
2025 | ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED); | ||
2026 | sa = http_common_socket_from_address (address->address, | 2025 | sa = http_common_socket_from_address (address->address, |
2027 | address->address_length, | 2026 | address->address_length, |
2028 | &res); | 2027 | &res); |
@@ -2039,15 +2038,15 @@ http_client_plugin_get_session (void *cls, | |||
2039 | { | 2038 | { |
2040 | salen = sizeof (struct sockaddr_in6); | 2039 | salen = sizeof (struct sockaddr_in6); |
2041 | } | 2040 | } |
2042 | ats = plugin->env->get_address_type (plugin->env->cls, sa, salen); | 2041 | net_type = plugin->env->get_address_type (plugin->env->cls, sa, salen); |
2043 | GNUNET_free (sa); | 2042 | GNUNET_free (sa); |
2044 | } | 2043 | } |
2045 | else if (GNUNET_NO == res) | 2044 | else if (GNUNET_NO == res) |
2046 | { | 2045 | { |
2047 | /* Cannot convert to sockaddr -> is external hostname */ | 2046 | /* Cannot convert to sockaddr -> is external hostname */ |
2048 | ats.value = htonl (GNUNET_ATS_NET_WAN); | 2047 | net_type = GNUNET_ATS_NET_WAN; |
2049 | } | 2048 | } |
2050 | if (GNUNET_ATS_NET_UNSPECIFIED == ntohl (ats.value)) | 2049 | if (GNUNET_ATS_NET_UNSPECIFIED == net_type) |
2051 | { | 2050 | { |
2052 | GNUNET_break (0); | 2051 | GNUNET_break (0); |
2053 | return NULL; | 2052 | return NULL; |
@@ -2056,7 +2055,7 @@ http_client_plugin_get_session (void *cls, | |||
2056 | s = GNUNET_new (struct Session); | 2055 | s = GNUNET_new (struct Session); |
2057 | s->plugin = plugin; | 2056 | s->plugin = plugin; |
2058 | s->address = GNUNET_HELLO_address_copy (address); | 2057 | s->address = GNUNET_HELLO_address_copy (address); |
2059 | s->ats_address_network_type = ats.value; | 2058 | s->ats_address_network_type = net_type; |
2060 | 2059 | ||
2061 | s->put.state = H_NOT_CONNECTED; | 2060 | s->put.state = H_NOT_CONNECTED; |
2062 | s->timeout = GNUNET_TIME_relative_to_absolute (HTTP_CLIENT_SESSION_TIMEOUT); | 2061 | s->timeout = GNUNET_TIME_relative_to_absolute (HTTP_CLIENT_SESSION_TIMEOUT); |
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index aaa17b2cf..c7c145328 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -1423,23 +1423,25 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, | |||
1423 | conn_info->client_addr, | 1423 | conn_info->client_addr, |
1424 | sizeof (struct sockaddr_in)); | 1424 | sizeof (struct sockaddr_in)); |
1425 | addr_len = http_common_address_get_size (addr); | 1425 | addr_len = http_common_address_get_size (addr); |
1426 | ats = plugin->env->get_address_type (plugin->env->cls, | 1426 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
1427 | conn_info->client_addr, | 1427 | ats.value = htonl (plugin->env->get_address_type (plugin->env->cls, |
1428 | sizeof (struct sockaddr_in)); | 1428 | conn_info->client_addr, |
1429 | sizeof (struct sockaddr_in))); | ||
1429 | break; | 1430 | break; |
1430 | case (AF_INET6): | 1431 | case (AF_INET6): |
1431 | addr = http_common_address_from_socket (plugin->protocol, | 1432 | addr = http_common_address_from_socket (plugin->protocol, |
1432 | conn_info->client_addr, | 1433 | conn_info->client_addr, |
1433 | sizeof (struct sockaddr_in6)); | 1434 | sizeof (struct sockaddr_in6)); |
1434 | addr_len = http_common_address_get_size (addr); | 1435 | addr_len = http_common_address_get_size (addr); |
1435 | ats = plugin->env->get_address_type (plugin->env->cls, | 1436 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
1436 | conn_info->client_addr, | 1437 | ats.value = htonl (plugin->env->get_address_type (plugin->env->cls, |
1437 | sizeof (struct sockaddr_in6)); | 1438 | conn_info->client_addr, |
1439 | sizeof (struct sockaddr_in6))); | ||
1438 | break; | 1440 | break; |
1439 | default: | 1441 | default: |
1440 | /* external host name */ | 1442 | /* external host name */ |
1441 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 1443 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
1442 | ats.type = htonl (GNUNET_ATS_NET_WAN); | 1444 | ats.value = htonl (GNUNET_ATS_NET_WAN); |
1443 | return NULL; | 1445 | return NULL; |
1444 | } | 1446 | } |
1445 | s = GNUNET_new (struct Session); | 1447 | s = GNUNET_new (struct Session); |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 4f7b57641..01a4eade8 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -1521,7 +1521,7 @@ tcp_plugin_get_session (void *cls, | |||
1521 | const struct IPv4TcpAddress *t4; | 1521 | const struct IPv4TcpAddress *t4; |
1522 | const struct IPv6TcpAddress *t6; | 1522 | const struct IPv6TcpAddress *t6; |
1523 | unsigned int options; | 1523 | unsigned int options; |
1524 | struct GNUNET_ATS_Information ats; | 1524 | enum GNUNET_ATS_Network_Type net_type; |
1525 | unsigned int is_natd = GNUNET_NO; | 1525 | unsigned int is_natd = GNUNET_NO; |
1526 | size_t addrlen; | 1526 | size_t addrlen; |
1527 | #ifdef TCP_STEALTH | 1527 | #ifdef TCP_STEALTH |
@@ -1612,7 +1612,8 @@ tcp_plugin_get_session (void *cls, | |||
1612 | return NULL; | 1612 | return NULL; |
1613 | } | 1613 | } |
1614 | 1614 | ||
1615 | ats = plugin->env->get_address_type (plugin->env->cls, sb, sbs); | 1615 | net_type = plugin->env->get_address_type (plugin->env->cls, sb, sbs); |
1616 | |||
1616 | 1617 | ||
1617 | if ((is_natd == GNUNET_YES) && (addrlen == sizeof(struct IPv6TcpAddress))) | 1618 | if ((is_natd == GNUNET_YES) && (addrlen == sizeof(struct IPv6TcpAddress))) |
1618 | { | 1619 | { |
@@ -1645,7 +1646,7 @@ tcp_plugin_get_session (void *cls, | |||
1645 | address, | 1646 | address, |
1646 | NULL, | 1647 | NULL, |
1647 | GNUNET_YES); | 1648 | GNUNET_YES); |
1648 | session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value); | 1649 | session->ats_address_network_type = net_type; |
1649 | GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); | 1650 | GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); |
1650 | session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, | 1651 | session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, |
1651 | &nat_connect_timeout, | 1652 | &nat_connect_timeout, |
@@ -1742,7 +1743,7 @@ tcp_plugin_get_session (void *cls, | |||
1742 | address, | 1743 | address, |
1743 | GNUNET_SERVER_connect_socket (plugin->server, sa), | 1744 | GNUNET_SERVER_connect_socket (plugin->server, sa), |
1744 | GNUNET_NO); | 1745 | GNUNET_NO); |
1745 | session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value); | 1746 | session->ats_address_network_type = net_type; |
1746 | GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); | 1747 | GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); |
1747 | GNUNET_SERVER_client_set_user_context(session->client, session); | 1748 | GNUNET_SERVER_client_set_user_context(session->client, session); |
1748 | GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, | 1749 | GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, |
@@ -2333,8 +2334,9 @@ handle_tcp_welcome (void *cls, | |||
2333 | } | 2334 | } |
2334 | session = create_session (plugin, address, client, GNUNET_NO); | 2335 | session = create_session (plugin, address, client, GNUNET_NO); |
2335 | GNUNET_HELLO_address_free (address); | 2336 | GNUNET_HELLO_address_free (address); |
2336 | ats = plugin->env->get_address_type (plugin->env->cls, vaddr, alen); | 2337 | session->ats_address_network_type = plugin->env->get_address_type (plugin->env->cls, vaddr, alen); |
2337 | session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value); | 2338 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
2339 | ats.value = htonl (session->ats_address_network_type); | ||
2338 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2340 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2339 | "Creating new%s session %p for peer `%s' client %p \n", | 2341 | "Creating new%s session %p for peer `%s' client %p \n", |
2340 | GNUNET_HELLO_address_check_option (session->address, | 2342 | GNUNET_HELLO_address_check_option (session->address, |
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 48535f28b..76c9dfdec 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -1799,6 +1799,7 @@ udp_plugin_create_session (void *cls, | |||
1799 | if (sizeof (struct IPv4UdpAddress) == address->address_length) | 1799 | if (sizeof (struct IPv4UdpAddress) == address->address_length) |
1800 | { | 1800 | { |
1801 | struct sockaddr_in v4; | 1801 | struct sockaddr_in v4; |
1802 | |||
1802 | udp_v4 = (struct IPv4UdpAddress *) address->address; | 1803 | udp_v4 = (struct IPv4UdpAddress *) address->address; |
1803 | memset (&v4, '\0', sizeof (v4)); | 1804 | memset (&v4, '\0', sizeof (v4)); |
1804 | v4.sin_family = AF_INET; | 1805 | v4.sin_family = AF_INET; |
@@ -1807,9 +1808,10 @@ udp_plugin_create_session (void *cls, | |||
1807 | #endif | 1808 | #endif |
1808 | v4.sin_port = udp_v4->u4_port; | 1809 | v4.sin_port = udp_v4->u4_port; |
1809 | v4.sin_addr.s_addr = udp_v4->ipv4_addr; | 1810 | v4.sin_addr.s_addr = udp_v4->ipv4_addr; |
1810 | s->ats = plugin->env->get_address_type (plugin->env->cls, | 1811 | s->ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
1811 | (const struct sockaddr *) &v4, | 1812 | s->ats.value = htonl (plugin->env->get_address_type (plugin->env->cls, |
1812 | sizeof (v4)); | 1813 | (const struct sockaddr *) &v4, |
1814 | sizeof (v4))); | ||
1813 | } | 1815 | } |
1814 | else if (sizeof (struct IPv6UdpAddress) == address->address_length) | 1816 | else if (sizeof (struct IPv6UdpAddress) == address->address_length) |
1815 | { | 1817 | { |
@@ -1822,8 +1824,10 @@ udp_plugin_create_session (void *cls, | |||
1822 | #endif | 1824 | #endif |
1823 | v6.sin6_port = udp_v6->u6_port; | 1825 | v6.sin6_port = udp_v6->u6_port; |
1824 | v6.sin6_addr = udp_v6->ipv6_addr; | 1826 | v6.sin6_addr = udp_v6->ipv6_addr; |
1825 | s->ats = plugin->env->get_address_type (plugin->env->cls, | 1827 | s->ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
1826 | (const struct sockaddr *) &v6, sizeof (v6)); | 1828 | s->ats.value = htonl (plugin->env->get_address_type (plugin->env->cls, |
1829 | (const struct sockaddr *) &v6, | ||
1830 | sizeof (v6))); | ||
1827 | } | 1831 | } |
1828 | 1832 | ||
1829 | if (NULL == s) | 1833 | if (NULL == s) |
@@ -2871,11 +2875,11 @@ analyze_send_error (struct Plugin *plugin, | |||
2871 | const struct sockaddr *sa, | 2875 | const struct sockaddr *sa, |
2872 | socklen_t slen, int error) | 2876 | socklen_t slen, int error) |
2873 | { | 2877 | { |
2874 | struct GNUNET_ATS_Information type; | 2878 | enum GNUNET_ATS_Network_Type type; |
2875 | 2879 | ||
2876 | type = plugin->env->get_address_type (plugin->env->cls, sa, slen); | 2880 | type = plugin->env->get_address_type (plugin->env->cls, sa, slen); |
2877 | if (((GNUNET_ATS_NET_LAN == ntohl (type.value)) | 2881 | if (((GNUNET_ATS_NET_LAN == type) |
2878 | || (GNUNET_ATS_NET_WAN == ntohl (type.value))) | 2882 | || (GNUNET_ATS_NET_WAN == type)) |
2879 | && ((ENETUNREACH == errno)|| (ENETDOWN == errno))) | 2883 | && ((ENETUNREACH == errno)|| (ENETDOWN == errno))) |
2880 | { | 2884 | { |
2881 | if (slen == sizeof (struct sockaddr_in)) | 2885 | if (slen == sizeof (struct sockaddr_in)) |
diff --git a/src/transport/plugin_transport_udp_broadcasting.c b/src/transport/plugin_transport_udp_broadcasting.c index 6566245cd..3ef9ecaaf 100644 --- a/src/transport/plugin_transport_udp_broadcasting.c +++ b/src/transport/plugin_transport_udp_broadcasting.c | |||
@@ -111,21 +111,24 @@ struct Mstv4Context | |||
111 | struct Plugin *plugin; | 111 | struct Plugin *plugin; |
112 | 112 | ||
113 | struct IPv4UdpAddress addr; | 113 | struct IPv4UdpAddress addr; |
114 | |||
114 | /** | 115 | /** |
115 | * ATS network type in NBO | 116 | * ATS network type. |
116 | */ | 117 | */ |
117 | uint32_t ats_address_network_type; | 118 | enum GNUNET_ATS_Network_Type ats_address_network_type; |
118 | }; | 119 | }; |
119 | 120 | ||
121 | |||
120 | struct Mstv6Context | 122 | struct Mstv6Context |
121 | { | 123 | { |
122 | struct Plugin *plugin; | 124 | struct Plugin *plugin; |
123 | 125 | ||
124 | struct IPv6UdpAddress addr; | 126 | struct IPv6UdpAddress addr; |
127 | |||
125 | /** | 128 | /** |
126 | * ATS network type in NBO | 129 | * ATS network type. |
127 | */ | 130 | */ |
128 | uint32_t ats_address_network_type; | 131 | enum GNUNET_ATS_Network_Type ats_address_network_type; |
129 | }; | 132 | }; |
130 | 133 | ||
131 | 134 | ||
@@ -152,7 +155,7 @@ broadcast_ipv6_mst_cb (void *cls, void *client, | |||
152 | 155 | ||
153 | /* setup ATS */ | 156 | /* setup ATS */ |
154 | atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 157 | atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
155 | atsi.value = mc->ats_address_network_type; | 158 | atsi.value = htonl (mc->ats_address_network_type); |
156 | GNUNET_break (ntohl(mc->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED); | 159 | GNUNET_break (ntohl(mc->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED); |
157 | 160 | ||
158 | hello = (struct GNUNET_MessageHeader *) &msg[1]; | 161 | hello = (struct GNUNET_MessageHeader *) &msg[1]; |
@@ -195,7 +198,7 @@ broadcast_ipv4_mst_cb (void *cls, void *client, | |||
195 | 198 | ||
196 | /* setup ATS */ | 199 | /* setup ATS */ |
197 | atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 200 | atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
198 | atsi.value = mc->ats_address_network_type; | 201 | atsi.value = htonl (mc->ats_address_network_type); |
199 | GNUNET_break (ntohl(mc->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED); | 202 | GNUNET_break (ntohl(mc->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED); |
200 | 203 | ||
201 | hello = (struct GNUNET_MessageHeader *) &msg[1]; | 204 | hello = (struct GNUNET_MessageHeader *) &msg[1]; |
@@ -221,8 +224,6 @@ udp_broadcast_receive (struct Plugin *plugin, | |||
221 | const struct sockaddr *addr, | 224 | const struct sockaddr *addr, |
222 | size_t addrlen) | 225 | size_t addrlen) |
223 | { | 226 | { |
224 | struct GNUNET_ATS_Information ats; | ||
225 | |||
226 | if (addrlen == sizeof (struct sockaddr_in)) | 227 | if (addrlen == sizeof (struct sockaddr_in)) |
227 | { | 228 | { |
228 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 229 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -235,8 +236,9 @@ udp_broadcast_receive (struct Plugin *plugin, | |||
235 | 236 | ||
236 | mc->addr.ipv4_addr = av4->sin_addr.s_addr; | 237 | mc->addr.ipv4_addr = av4->sin_addr.s_addr; |
237 | mc->addr.u4_port = av4->sin_port; | 238 | mc->addr.u4_port = av4->sin_port; |
238 | ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) addr, addrlen); | 239 | mc->ats_address_network_type = plugin->env->get_address_type (plugin->env->cls, |
239 | mc->ats_address_network_type = ats.value; | 240 | (const struct sockaddr *) addr, |
241 | addrlen); | ||
240 | 242 | ||
241 | GNUNET_assert (NULL != plugin->broadcast_ipv4_mst); | 243 | GNUNET_assert (NULL != plugin->broadcast_ipv4_mst); |
242 | if (GNUNET_OK != | 244 | if (GNUNET_OK != |
@@ -256,8 +258,7 @@ udp_broadcast_receive (struct Plugin *plugin, | |||
256 | 258 | ||
257 | mc->addr.ipv6_addr = av6->sin6_addr; | 259 | mc->addr.ipv6_addr = av6->sin6_addr; |
258 | mc->addr.u6_port = av6->sin6_port; | 260 | mc->addr.u6_port = av6->sin6_port; |
259 | ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) addr, addrlen); | 261 | mc->ats_address_network_type = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) addr, addrlen); |
260 | mc->ats_address_network_type = ats.value; | ||
261 | GNUNET_assert (NULL != plugin->broadcast_ipv4_mst); | 262 | GNUNET_assert (NULL != plugin->broadcast_ipv4_mst); |
262 | if (GNUNET_OK != | 263 | if (GNUNET_OK != |
263 | GNUNET_SERVER_mst_receive (plugin->broadcast_ipv6_mst, mc, buf, size, | 264 | GNUNET_SERVER_mst_receive (plugin->broadcast_ipv6_mst, mc, buf, size, |
@@ -473,7 +474,7 @@ iface_proc (void *cls, | |||
473 | { | 474 | { |
474 | struct Plugin *plugin = cls; | 475 | struct Plugin *plugin = cls; |
475 | struct BroadcastAddress *ba; | 476 | struct BroadcastAddress *ba; |
476 | struct GNUNET_ATS_Information network; | 477 | enum GNUNET_ATS_Network_Type network; |
477 | 478 | ||
478 | if (NULL == addr) | 479 | if (NULL == addr) |
479 | return GNUNET_OK; | 480 | return GNUNET_OK; |
@@ -489,7 +490,7 @@ iface_proc (void *cls, | |||
489 | GNUNET_a2s (netmask, addrlen), name, netmask); | 490 | GNUNET_a2s (netmask, addrlen), name, netmask); |
490 | 491 | ||
491 | network = plugin->env->get_address_type (plugin->env->cls, broadcast_addr, addrlen); | 492 | network = plugin->env->get_address_type (plugin->env->cls, broadcast_addr, addrlen); |
492 | if (GNUNET_ATS_NET_LOOPBACK == ntohl(network.value)) | 493 | if (GNUNET_ATS_NET_LOOPBACK == network) |
493 | { | 494 | { |
494 | /* Broadcasting on loopback does not make sense */ | 495 | /* Broadcasting on loopback does not make sense */ |
495 | return GNUNET_YES; | 496 | return GNUNET_YES; |
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 460869181..112f15d09 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -1387,7 +1387,10 @@ unix_transport_server_start (void *cls) | |||
1387 | plugin->unix_socket_path[0] = '@'; | 1387 | plugin->unix_socket_path[0] = '@'; |
1388 | un->sun_path[0] = '\0'; | 1388 | un->sun_path[0] = '\0'; |
1389 | } | 1389 | } |
1390 | plugin->ats_network = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) un, un_len); | 1390 | plugin->ats_network.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
1391 | plugin->ats_network.value = htonl (plugin->env->get_address_type (plugin->env->cls, | ||
1392 | (const struct sockaddr *) un, | ||
1393 | un_len)); | ||
1391 | plugin->unix_sock.desc = | 1394 | plugin->unix_sock.desc = |
1392 | GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); | 1395 | GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); |
1393 | if (NULL == plugin->unix_sock.desc) | 1396 | if (NULL == plugin->unix_sock.desc) |