[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r28665 - in gnunet/src: include testing
From: |
gnunet |
Subject: |
[GNUnet-SVN] r28665 - in gnunet/src: include testing |
Date: |
Thu, 15 Aug 2013 18:27:27 +0200 |
Author: harsha
Date: 2013-08-15 18:27:27 +0200 (Thu, 15 Aug 2013)
New Revision: 28665
Removed:
gnunet/src/testing/bindfail.c
gnunet/src/testing/bindok.c
Modified:
gnunet/src/include/gnunet_testing_lib.h
gnunet/src/testing/Makefile.am
gnunet/src/testing/test_testing_portreservation.c
gnunet/src/testing/testing.c
Log:
- make no distinction between TCP and UDP port while reserving them
Modified: gnunet/src/include/gnunet_testing_lib.h
===================================================================
--- gnunet/src/include/gnunet_testing_lib.h 2013-08-15 15:46:39 UTC (rev
28664)
+++ gnunet/src/include/gnunet_testing_lib.h 2013-08-15 16:27:27 UTC (rev
28665)
@@ -181,15 +181,13 @@
/**
- * Reserve a TCP or UDP port for a peer.
+ * Reserve a port for a peer.
*
* @param system system to use for reservation tracking
- * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP
* @return 0 if no free port was available
*/
uint16_t
-GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system,
- int is_tcp);
+GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system);
/**
@@ -197,12 +195,10 @@
* (used during GNUNET_TESTING_peer_destroy).
*
* @param system system to use for reservation tracking
- * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP
* @param port reserved port to release
*/
void
GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
- int is_tcp,
uint16_t port);
Modified: gnunet/src/testing/Makefile.am
===================================================================
--- gnunet/src/testing/Makefile.am 2013-08-15 15:46:39 UTC (rev 28664)
+++ gnunet/src/testing/Makefile.am 2013-08-15 16:27:27 UTC (rev 28665)
@@ -97,17 +97,6 @@
$(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/util/libgnunetutil.la
-
-
EXTRA_DIST = \
test_testing_defaults.conf
-
-noinst_PROGRAMS = \
- bindfail bindok
-
-bindok_SOURCES = bindok.c
-
-bindfail_SOURCES = bindfail.c
-bindfail_LDADD = $(top_builddir)/src/util/libgnunetutil.la
-
Deleted: gnunet/src/testing/bindfail.c
===================================================================
--- gnunet/src/testing/bindfail.c 2013-08-15 15:46:39 UTC (rev 28664)
+++ gnunet/src/testing/bindfail.c 2013-08-15 16:27:27 UTC (rev 28665)
@@ -1,37 +0,0 @@
-#include "platform.h"
-#include "gnunet_util_lib.h"
-
-int main()
-{
- uint16_t port = 12035;
- struct GNUNET_NETWORK_Handle *sock1;
- struct GNUNET_NETWORK_Handle *sock2;
- struct sockaddr_in addr;
- int proto;
-
- proto = SOCK_STREAM;
- (void) memset (&addr, 0, sizeof (struct sockaddr_in));
- sock1 = GNUNET_NETWORK_socket_create (AF_INET, proto, 0);
- sock2 = GNUNET_NETWORK_socket_create (AF_INET, proto, 0);
-
- addr.sin_port = htons (port);
- addr.sin_addr.s_addr = INADDR_ANY;
-
- if (GNUNET_SYSERR ==
- GNUNET_NETWORK_socket_bind (sock1, (const struct sockaddr *) &addr,
- sizeof (addr), 0))
- {
- fprintf (stderr, "first bind failed. check port\n");
- return 1;
- }
- if (GNUNET_SYSERR ==
- GNUNET_NETWORK_socket_bind (sock2, (const struct sockaddr *) &addr,
- sizeof (addr), 0))
- {
- printf ("All OK\n");
- return 0;
- }
- fprintf (stderr, "Second bind succeeded! WTF!!\n");
- fgetc (stdin);
- return 1;
-}
Deleted: gnunet/src/testing/bindok.c
===================================================================
--- gnunet/src/testing/bindok.c 2013-08-15 15:46:39 UTC (rev 28664)
+++ gnunet/src/testing/bindok.c 2013-08-15 16:27:27 UTC (rev 28665)
@@ -1,30 +0,0 @@
-#include "platform.h"
-
-int main()
-{
- uint16_t port = 12035;
- int sock1;
- int sock2;
- struct sockaddr_in addr;
-
- (void) memset (&addr, 0, sizeof (struct sockaddr_in));
- sock1 = socket (AF_INET, SOCK_DGRAM, 0);
- sock2 = socket (AF_INET, SOCK_DGRAM, 0);
-
- addr.sin_port = htons (port);
- addr.sin_addr.s_addr = INADDR_ANY;
-
- if (0 != bind (sock1, (const struct sockaddr *) &addr, sizeof (addr)))
- {
- perror ("bind");
- return 1;
- }
- if (0 != bind (sock2, (const struct sockaddr *) &addr, sizeof (addr)))
- {
- printf ("All OK\n");
- return 0;
- }
- fprintf (stderr, "Second bind succeeded! WTF!!\n");
- fgetc (stdin);
- return 1;
-}
Modified: gnunet/src/testing/test_testing_portreservation.c
===================================================================
--- gnunet/src/testing/test_testing_portreservation.c 2013-08-15 15:46:39 UTC
(rev 28664)
+++ gnunet/src/testing/test_testing_portreservation.c 2013-08-15 16:27:27 UTC
(rev 28665)
@@ -52,27 +52,27 @@
system = GNUNET_TESTING_system_create ("/tmp/gnunet-testing-new",
"localhost", NULL, NULL);
GNUNET_assert (NULL != system);
- new_port1 = GNUNET_TESTING_reserve_port (system, GNUNET_YES);
+ new_port1 = GNUNET_TESTING_reserve_port (system);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Reserved TCP port %u\n", new_port1);
if (0 == new_port1)
goto end;
- new_port2 = GNUNET_TESTING_reserve_port (system, GNUNET_YES);
+ new_port2 = GNUNET_TESTING_reserve_port (system);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Reserved TCP port %u\n", new_port2);
if (0 == new_port2)
goto end;
GNUNET_assert (new_port1 != new_port2);
- GNUNET_TESTING_release_port (system, GNUNET_YES, new_port1);
+ GNUNET_TESTING_release_port (system, new_port1);
old_port1 = new_port1;
new_port1 = 0;
- new_port1 = GNUNET_TESTING_reserve_port (system, GNUNET_YES);
+ new_port1 = GNUNET_TESTING_reserve_port (system);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Reserved TCP port %u\n", new_port1);
GNUNET_assert (0 != new_port1);
GNUNET_assert (old_port1 == new_port1);
- GNUNET_TESTING_release_port (system, GNUNET_YES, new_port1);
- GNUNET_TESTING_release_port (system, GNUNET_YES, new_port2);
+ GNUNET_TESTING_release_port (system, new_port1);
+ GNUNET_TESTING_release_port (system, new_port2);
status = GNUNET_OK;
end:
Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c 2013-08-15 15:46:39 UTC (rev 28664)
+++ gnunet/src/testing/testing.c 2013-08-15 16:27:27 UTC (rev 28665)
@@ -132,28 +132,16 @@
unsigned int n_shared_services;
/**
- * Bitmap where each TCP port that has already been reserved for
- * some GNUnet peer is recorded. Note that we additionally need to
- * test if a port is already in use by non-GNUnet components before
- * assigning it to a peer/service. If we detect that a port is
- * already in use, we also mark it in this bitmap. So all the bits
- * that are zero merely indicate ports that MIGHT be available for
- * peers.
+ * Bitmap where each port that has already been reserved for some GNUnet peer
+ * is recorded. Note that we make no distinction between TCP and UDP ports
+ * and test if a port is already in use before assigning it to a
peer/service.
+ * If we detect that a port is already in use, we also mark it in this
bitmap.
+ * So all the bits that are zero merely indicate ports that MIGHT be
available
+ * for peers.
*/
- uint32_t reserved_tcp_ports[65536 / 32];
+ uint32_t reserved_ports[65536 / 32];
/**
- * Bitmap where each UDP port that has already been reserved for
- * some GNUnet peer is recorded. Note that we additionally need to
- * test if a port is already in use by non-GNUnet components before
- * assigning it to a peer/service. If we detect that a port is
- * already in use, we also mark it in this bitmap. So all the bits
- * that are zero merely indicate ports that MIGHT be available for
- * peers.
- */
- uint32_t reserved_udp_ports[65536 / 32];
-
- /**
* Counter we use to make service home paths unique on this system;
* the full path consists of the tmppath and this number. Each
* UNIXPATH for a peer is also modified to include the respective
@@ -568,12 +556,10 @@
* Reserve a TCP or UDP port for a peer.
*
* @param system system to use for reservation tracking
- * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP
* @return 0 if no free port was available
*/
uint16_t
-GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system,
- int is_tcp)
+GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
{
struct GNUNET_NETWORK_Handle *socket;
struct addrinfo hint;
@@ -597,15 +583,14 @@
open in the respective address family
*/
hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
- hint.ai_socktype = (GNUNET_YES == is_tcp)? SOCK_STREAM : SOCK_DGRAM;
+ hint.ai_socktype = 0;
hint.ai_protocol = 0;
hint.ai_addrlen = 0;
hint.ai_addr = NULL;
hint.ai_canonname = NULL;
hint.ai_next = NULL;
hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
- port_buckets = (GNUNET_YES == is_tcp) ?
- system->reserved_tcp_ports : system->reserved_udp_ports;
+ port_buckets = system->reserved_ports;
for (index = (system->lowport / 32) + 1; index < (system->highport / 32);
index++)
{
xor_image = (UINT32_MAX ^ port_buckets[index]);
@@ -629,10 +614,7 @@
bind_status = GNUNET_NO;
for (ai = ret; NULL != ai; ai = ai->ai_next)
{
- socket = GNUNET_NETWORK_socket_create (ai->ai_family,
- (GNUNET_YES == is_tcp) ?
- SOCK_STREAM : SOCK_DGRAM,
- 0);
+ socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0);
if (NULL == socket)
continue;
bind_status = GNUNET_NETWORK_socket_bind (socket,
@@ -642,6 +624,16 @@
GNUNET_NETWORK_socket_close (socket);
if (GNUNET_OK != bind_status)
break;
+ socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0);
+ if (NULL == socket)
+ continue;
+ bind_status = GNUNET_NETWORK_socket_bind (socket,
+ ai->ai_addr,
+ ai->ai_addrlen,
+ 0);
+ GNUNET_NETWORK_socket_close (socket);
+ if (GNUNET_OK != bind_status)
+ break;
}
port_buckets[index] |= (1U << pos); /* Set the port bit */
freeaddrinfo (ret);
@@ -663,20 +655,17 @@
* (used during GNUNET_TESTING_peer_destroy).
*
* @param system system to use for reservation tracking
- * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP
* @param port reserved port to release
*/
void
GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
- int is_tcp,
uint16_t port)
{
uint32_t *port_buckets;
uint16_t bucket;
uint16_t pos;
- port_buckets = (GNUNET_YES == is_tcp) ?
- system->reserved_tcp_ports : system->reserved_udp_ports;
+ port_buckets = system->reserved_ports;
bucket = port / 32;
pos = port % 32;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port);
@@ -819,8 +808,7 @@
GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing",
single_variable)))
{
- /* FIXME: What about UDP? */
- new_port = GNUNET_TESTING_reserve_port (uc->system, GNUNET_YES);
+ new_port = GNUNET_TESTING_reserve_port (uc->system);
if (0 == new_port)
{
uc->status = GNUNET_SYSERR;
@@ -998,7 +986,7 @@
(void) GNUNET_asprintf (&service_home, "%s/shared/%s/%u",
system->tmppath, ss->sname, ss->n_instances);
(void) GNUNET_asprintf (&i->unix_sock, "%s/sock", service_home);
- port = GNUNET_TESTING_reserve_port (system, GNUNET_YES);
+ port = GNUNET_TESTING_reserve_port (system);
if (0 == port)
{
GNUNET_free (service_home);
@@ -1589,9 +1577,7 @@
if (NULL != peer->ports)
{
for (cnt = 0; cnt < peer->nports; cnt++)
- GNUNET_TESTING_release_port (peer->system,
- GNUNET_YES,
- peer->ports[cnt]);
+ GNUNET_TESTING_release_port (peer->system, peer->ports[cnt]);
GNUNET_free (peer->ports);
}
GNUNET_free (peer);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r28665 - in gnunet/src: include testing,
gnunet <=