diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-08-15 16:27:27 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-08-15 16:27:27 +0000 |
commit | 356d73f3e59d50ab3aeee64d6e5384089428747b (patch) | |
tree | b683d79727fa4074b2877d1efd50b53fd454253b /src/testing/testing.c | |
parent | 2f540d8a505ee8842ea322513b381d7f3b48362d (diff) | |
download | gnunet-356d73f3e59d50ab3aeee64d6e5384089428747b.tar.gz gnunet-356d73f3e59d50ab3aeee64d6e5384089428747b.zip |
- make no distinction between TCP and UDP port while reserving them
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r-- | src/testing/testing.c | 64 |
1 files changed, 25 insertions, 39 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c index 70eebc3cc..9e193bd9c 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -132,26 +132,14 @@ struct GNUNET_TESTING_System | |||
132 | unsigned int n_shared_services; | 132 | unsigned int n_shared_services; |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * Bitmap where each TCP port that has already been reserved for | 135 | * Bitmap where each port that has already been reserved for some GNUnet peer |
136 | * some GNUnet peer is recorded. Note that we additionally need to | 136 | * is recorded. Note that we make no distinction between TCP and UDP ports |
137 | * test if a port is already in use by non-GNUnet components before | 137 | * and test if a port is already in use before assigning it to a peer/service. |
138 | * assigning it to a peer/service. If we detect that a port is | 138 | * If we detect that a port is already in use, we also mark it in this bitmap. |
139 | * already in use, we also mark it in this bitmap. So all the bits | 139 | * So all the bits that are zero merely indicate ports that MIGHT be available |
140 | * that are zero merely indicate ports that MIGHT be available for | 140 | * for peers. |
141 | * peers. | ||
142 | */ | 141 | */ |
143 | uint32_t reserved_tcp_ports[65536 / 32]; | 142 | uint32_t reserved_ports[65536 / 32]; |
144 | |||
145 | /** | ||
146 | * Bitmap where each UDP port that has already been reserved for | ||
147 | * some GNUnet peer is recorded. Note that we additionally need to | ||
148 | * test if a port is already in use by non-GNUnet components before | ||
149 | * assigning it to a peer/service. If we detect that a port is | ||
150 | * already in use, we also mark it in this bitmap. So all the bits | ||
151 | * that are zero merely indicate ports that MIGHT be available for | ||
152 | * peers. | ||
153 | */ | ||
154 | uint32_t reserved_udp_ports[65536 / 32]; | ||
155 | 143 | ||
156 | /** | 144 | /** |
157 | * Counter we use to make service home paths unique on this system; | 145 | * Counter we use to make service home paths unique on this system; |
@@ -568,12 +556,10 @@ GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, | |||
568 | * Reserve a TCP or UDP port for a peer. | 556 | * Reserve a TCP or UDP port for a peer. |
569 | * | 557 | * |
570 | * @param system system to use for reservation tracking | 558 | * @param system system to use for reservation tracking |
571 | * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP | ||
572 | * @return 0 if no free port was available | 559 | * @return 0 if no free port was available |
573 | */ | 560 | */ |
574 | uint16_t | 561 | uint16_t |
575 | GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system, | 562 | GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) |
576 | int is_tcp) | ||
577 | { | 563 | { |
578 | struct GNUNET_NETWORK_Handle *socket; | 564 | struct GNUNET_NETWORK_Handle *socket; |
579 | struct addrinfo hint; | 565 | struct addrinfo hint; |
@@ -597,15 +583,14 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system, | |||
597 | open in the respective address family | 583 | open in the respective address family |
598 | */ | 584 | */ |
599 | hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */ | 585 | hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */ |
600 | hint.ai_socktype = (GNUNET_YES == is_tcp)? SOCK_STREAM : SOCK_DGRAM; | 586 | hint.ai_socktype = 0; |
601 | hint.ai_protocol = 0; | 587 | hint.ai_protocol = 0; |
602 | hint.ai_addrlen = 0; | 588 | hint.ai_addrlen = 0; |
603 | hint.ai_addr = NULL; | 589 | hint.ai_addr = NULL; |
604 | hint.ai_canonname = NULL; | 590 | hint.ai_canonname = NULL; |
605 | hint.ai_next = NULL; | 591 | hint.ai_next = NULL; |
606 | hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */ | 592 | hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */ |
607 | port_buckets = (GNUNET_YES == is_tcp) ? | 593 | port_buckets = system->reserved_ports; |
608 | system->reserved_tcp_ports : system->reserved_udp_ports; | ||
609 | for (index = (system->lowport / 32) + 1; index < (system->highport / 32); index++) | 594 | for (index = (system->lowport / 32) + 1; index < (system->highport / 32); index++) |
610 | { | 595 | { |
611 | xor_image = (UINT32_MAX ^ port_buckets[index]); | 596 | xor_image = (UINT32_MAX ^ port_buckets[index]); |
@@ -629,10 +614,17 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system, | |||
629 | bind_status = GNUNET_NO; | 614 | bind_status = GNUNET_NO; |
630 | for (ai = ret; NULL != ai; ai = ai->ai_next) | 615 | for (ai = ret; NULL != ai; ai = ai->ai_next) |
631 | { | 616 | { |
632 | socket = GNUNET_NETWORK_socket_create (ai->ai_family, | 617 | socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0); |
633 | (GNUNET_YES == is_tcp) ? | 618 | if (NULL == socket) |
634 | SOCK_STREAM : SOCK_DGRAM, | 619 | continue; |
635 | 0); | 620 | bind_status = GNUNET_NETWORK_socket_bind (socket, |
621 | ai->ai_addr, | ||
622 | ai->ai_addrlen, | ||
623 | 0); | ||
624 | GNUNET_NETWORK_socket_close (socket); | ||
625 | if (GNUNET_OK != bind_status) | ||
626 | break; | ||
627 | socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0); | ||
636 | if (NULL == socket) | 628 | if (NULL == socket) |
637 | continue; | 629 | continue; |
638 | bind_status = GNUNET_NETWORK_socket_bind (socket, | 630 | bind_status = GNUNET_NETWORK_socket_bind (socket, |
@@ -663,20 +655,17 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system, | |||
663 | * (used during GNUNET_TESTING_peer_destroy). | 655 | * (used during GNUNET_TESTING_peer_destroy). |
664 | * | 656 | * |
665 | * @param system system to use for reservation tracking | 657 | * @param system system to use for reservation tracking |
666 | * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP | ||
667 | * @param port reserved port to release | 658 | * @param port reserved port to release |
668 | */ | 659 | */ |
669 | void | 660 | void |
670 | GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, | 661 | GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, |
671 | int is_tcp, | ||
672 | uint16_t port) | 662 | uint16_t port) |
673 | { | 663 | { |
674 | uint32_t *port_buckets; | 664 | uint32_t *port_buckets; |
675 | uint16_t bucket; | 665 | uint16_t bucket; |
676 | uint16_t pos; | 666 | uint16_t pos; |
677 | 667 | ||
678 | port_buckets = (GNUNET_YES == is_tcp) ? | 668 | port_buckets = system->reserved_ports; |
679 | system->reserved_tcp_ports : system->reserved_udp_ports; | ||
680 | bucket = port / 32; | 669 | bucket = port / 32; |
681 | pos = port % 32; | 670 | pos = port % 32; |
682 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port); | 671 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port); |
@@ -819,8 +808,7 @@ update_config (void *cls, const char *section, const char *option, | |||
819 | GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing", | 808 | GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing", |
820 | single_variable))) | 809 | single_variable))) |
821 | { | 810 | { |
822 | /* FIXME: What about UDP? */ | 811 | new_port = GNUNET_TESTING_reserve_port (uc->system); |
823 | new_port = GNUNET_TESTING_reserve_port (uc->system, GNUNET_YES); | ||
824 | if (0 == new_port) | 812 | if (0 == new_port) |
825 | { | 813 | { |
826 | uc->status = GNUNET_SYSERR; | 814 | uc->status = GNUNET_SYSERR; |
@@ -998,7 +986,7 @@ associate_shared_service (struct GNUNET_TESTING_System *system, | |||
998 | (void) GNUNET_asprintf (&service_home, "%s/shared/%s/%u", | 986 | (void) GNUNET_asprintf (&service_home, "%s/shared/%s/%u", |
999 | system->tmppath, ss->sname, ss->n_instances); | 987 | system->tmppath, ss->sname, ss->n_instances); |
1000 | (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", service_home); | 988 | (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", service_home); |
1001 | port = GNUNET_TESTING_reserve_port (system, GNUNET_YES); | 989 | port = GNUNET_TESTING_reserve_port (system); |
1002 | if (0 == port) | 990 | if (0 == port) |
1003 | { | 991 | { |
1004 | GNUNET_free (service_home); | 992 | GNUNET_free (service_home); |
@@ -1589,9 +1577,7 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer) | |||
1589 | if (NULL != peer->ports) | 1577 | if (NULL != peer->ports) |
1590 | { | 1578 | { |
1591 | for (cnt = 0; cnt < peer->nports; cnt++) | 1579 | for (cnt = 0; cnt < peer->nports; cnt++) |
1592 | GNUNET_TESTING_release_port (peer->system, | 1580 | GNUNET_TESTING_release_port (peer->system, peer->ports[cnt]); |
1593 | GNUNET_YES, | ||
1594 | peer->ports[cnt]); | ||
1595 | GNUNET_free (peer->ports); | 1581 | GNUNET_free (peer->ports); |
1596 | } | 1582 | } |
1597 | GNUNET_free (peer); | 1583 | GNUNET_free (peer); |