diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-28 22:59:45 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-28 22:59:45 +0000 |
commit | 577cc81d8aec03978a54e220c39c755373ce7467 (patch) | |
tree | 97fe455575d45611e2edb83c5b680a29c33119f1 /src | |
parent | 8aea89ec78662e1dd4ae34c3165612e9e0960a91 (diff) | |
download | gnunet-577cc81d8aec03978a54e220c39c755373ce7467.tar.gz gnunet-577cc81d8aec03978a54e220c39c755373ce7467.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 59 | ||||
-rw-r--r-- | src/transport/test_transport_api_udp_peer1.conf | 3 |
2 files changed, 36 insertions, 26 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 5ef974942..70c60c387 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -347,6 +347,10 @@ struct Plugin | |||
347 | */ | 347 | */ |
348 | struct GNUNET_NETWORK_FDSet *broadcast_rs; | 348 | struct GNUNET_NETWORK_FDSet *broadcast_rs; |
349 | 349 | ||
350 | /** | ||
351 | * Broadcast interval | ||
352 | */ | ||
353 | struct GNUNET_TIME_Relative broadcast_interval; | ||
350 | 354 | ||
351 | /** | 355 | /** |
352 | * expected delay for ACKs | 356 | * expected delay for ACKs |
@@ -1430,7 +1434,7 @@ udp_broadcast_send (void *cls, | |||
1430 | 1434 | ||
1431 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1435 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1432 | "Sent broadcast with %i bytes\n", sent); | 1436 | "Sent broadcast with %i bytes\n", sent); |
1433 | plugin->send_broadcast_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &udp_broadcast_send, plugin); | 1437 | plugin->send_broadcast_task = GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval, &udp_broadcast_send, plugin); |
1434 | 1438 | ||
1435 | } | 1439 | } |
1436 | 1440 | ||
@@ -1776,6 +1780,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1776 | struct Plugin *plugin; | 1780 | struct Plugin *plugin; |
1777 | int sockets_created; | 1781 | int sockets_created; |
1778 | int broadcast; | 1782 | int broadcast; |
1783 | struct GNUNET_TIME_Relative interval; | ||
1779 | struct sockaddr_in serverAddrv4; | 1784 | struct sockaddr_in serverAddrv4; |
1780 | struct sockaddr_in6 serverAddrv6; | 1785 | struct sockaddr_in6 serverAddrv6; |
1781 | struct sockaddr *serverAddr; | 1786 | struct sockaddr *serverAddr; |
@@ -1794,6 +1799,9 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1794 | if (broadcast == GNUNET_SYSERR) | 1799 | if (broadcast == GNUNET_SYSERR) |
1795 | broadcast = GNUNET_NO; | 1800 | broadcast = GNUNET_NO; |
1796 | 1801 | ||
1802 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-udp", "BROADCAST_INTERVAL", &interval)) | ||
1803 | interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10); | ||
1804 | |||
1797 | if (GNUNET_OK != | 1805 | if (GNUNET_OK != |
1798 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "BROADCAST_PORT", | 1806 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "BROADCAST_PORT", |
1799 | &bport)) | 1807 | &bport)) |
@@ -1827,6 +1835,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1827 | plugin->broadcast_port = bport; | 1835 | plugin->broadcast_port = bport; |
1828 | plugin->broadcast = broadcast; | 1836 | plugin->broadcast = broadcast; |
1829 | plugin->env = env; | 1837 | plugin->env = env; |
1838 | plugin->broadcast_interval = interval; | ||
1830 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 1839 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); |
1831 | api->cls = plugin; | 1840 | api->cls = plugin; |
1832 | 1841 | ||
@@ -2015,43 +2024,41 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2015 | LOG (GNUNET_ERROR_TYPE_ERROR, "Binding Broadcast to IPv4 port %d\n", | 2024 | LOG (GNUNET_ERROR_TYPE_ERROR, "Binding Broadcast to IPv4 port %d\n", |
2016 | ntohs (serverAddrv4.sin_port)); | 2025 | ntohs (serverAddrv4.sin_port)); |
2017 | 2026 | ||
2018 | tries = 0; | 2027 | if (GNUNET_NETWORK_socket_bind (plugin->sockv4_broadcast, serverAddr, addrlen) != GNUNET_OK) |
2019 | while (GNUNET_NETWORK_socket_bind (plugin->sockv4_broadcast, serverAddr, addrlen) != GNUNET_OK) | ||
2020 | { | 2028 | { |
2021 | serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ | ||
2022 | #if DEBUG_UDP | ||
2023 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2024 | "IPv4 Binding failed, trying new port %d\n", | ||
2025 | ntohs (serverAddrv4.sin_port)); | ||
2026 | #endif | ||
2027 | tries++; | ||
2028 | if (tries > 10) | ||
2029 | { | ||
2030 | GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast); | 2029 | GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast); |
2031 | plugin->sockv4_broadcast = NULL; | 2030 | plugin->sockv4_broadcast = NULL; |
2032 | break; | ||
2033 | } | ||
2034 | } | 2031 | } |
2035 | if (plugin->sockv4_broadcast != NULL) | 2032 | if (plugin->sockv4_broadcast != NULL) |
2036 | { | 2033 | { |
2037 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("UDP Broadcast sockets on port %u \n"), bport); | 2034 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("UDP Broadcast sockets on port %u \n"), bport); |
2038 | int yes = 1; | 2035 | int yes = 1; |
2039 | if (GNUNET_NETWORK_socket_setsockopt (plugin->sockv4_broadcast, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(int)) != GNUNET_OK) | 2036 | if (GNUNET_NETWORK_socket_setsockopt (plugin->sockv4_broadcast, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(int)) != GNUNET_OK) |
2040 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "BROAD CASD socket"); | 2037 | { |
2038 | GNUNET_NETWORK_socket_close(plugin->sockv4_broadcast); | ||
2039 | plugin->sockv4_broadcast = NULL; | ||
2040 | } | ||
2041 | else | ||
2042 | { | ||
2043 | plugin->broadcast_rs = GNUNET_NETWORK_fdset_create (); | ||
2044 | GNUNET_NETWORK_fdset_set (plugin->broadcast_rs, plugin->sockv4_broadcast); | ||
2045 | } | ||
2041 | } | 2046 | } |
2042 | } | 2047 | } |
2043 | 2048 | ||
2044 | plugin->broadcast_rs = GNUNET_NETWORK_fdset_create (); | 2049 | if (plugin->sockv4_broadcast != NULL) |
2045 | if (NULL != plugin->sockv4_broadcast) | 2050 | { |
2046 | GNUNET_NETWORK_fdset_set (plugin->broadcast_rs, plugin->sockv4_broadcast); | 2051 | plugin->broadcast = GNUNET_YES; |
2047 | 2052 | plugin->select_broadcast_task = | |
2048 | plugin->select_broadcast_task = | 2053 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
2049 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 2054 | GNUNET_SCHEDULER_NO_TASK, |
2050 | GNUNET_SCHEDULER_NO_TASK, | 2055 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->broadcast_rs, |
2051 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->broadcast_rs, | 2056 | NULL, &udp_plugin_broadcast_select, plugin); |
2052 | NULL, &udp_plugin_broadcast_select, plugin); | 2057 | |
2053 | 2058 | plugin->send_broadcast_task = GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval, &udp_broadcast_send, plugin); | |
2054 | plugin->send_broadcast_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &udp_broadcast_send, plugin); | 2059 | } |
2060 | else | ||
2061 | plugin->broadcast = GNUNET_NO; | ||
2055 | } | 2062 | } |
2056 | 2063 | ||
2057 | if (sockets_created == 0) | 2064 | if (sockets_created == 0) |
diff --git a/src/transport/test_transport_api_udp_peer1.conf b/src/transport/test_transport_api_udp_peer1.conf index 19e4688a3..d0007d6cb 100644 --- a/src/transport/test_transport_api_udp_peer1.conf +++ b/src/transport/test_transport_api_udp_peer1.conf | |||
@@ -5,6 +5,9 @@ DEFAULTCONFIG = test_transport_api_udp_peer1.conf | |||
5 | 5 | ||
6 | [transport-udp] | 6 | [transport-udp] |
7 | PORT = 12040 | 7 | PORT = 12040 |
8 | #BROADCAST = YES | ||
9 | #BROADCAST_PORT = 20089 | ||
10 | #BROADCAST_INTERVAL = 30000 | ||
8 | MAX_BPS = 50000000 | 11 | MAX_BPS = 50000000 |
9 | 12 | ||
10 | [arm] | 13 | [arm] |