diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-05-26 15:14:54 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-05-26 15:14:54 +0000 |
commit | a710e7a806760db7ebec24ca2ae2d81ce3867ceb (patch) | |
tree | 9e012f4941dd67bf12200e624dc646588b1792da /src | |
parent | 3dfcafa46627f230f83bb323cac321346a0f75eb (diff) | |
download | gnunet-a710e7a806760db7ebec24ca2ae2d81ce3867ceb.tar.gz gnunet-a710e7a806760db7ebec24ca2ae2d81ce3867ceb.zip |
port reservation - release
Diffstat (limited to 'src')
-rw-r--r-- | src/testing/test_testing_new_portreservation.c | 15 | ||||
-rw-r--r-- | src/testing/testing_new.c | 32 |
2 files changed, 33 insertions, 14 deletions
diff --git a/src/testing/test_testing_new_portreservation.c b/src/testing/test_testing_new_portreservation.c index a5821edb0..c1382df38 100644 --- a/src/testing/test_testing_new_portreservation.c +++ b/src/testing/test_testing_new_portreservation.c | |||
@@ -39,8 +39,10 @@ static void | |||
39 | run (void *cls, char *const *args, const char *cfgfile, | 39 | run (void *cls, char *const *args, const char *cfgfile, |
40 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 40 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
41 | { | 41 | { |
42 | uint16_t new_port1, new_port2; | ||
43 | struct GNUNET_TESTING_System *system; | 42 | struct GNUNET_TESTING_System *system; |
43 | uint16_t new_port1; | ||
44 | uint16_t new_port2; | ||
45 | uint16_t old_port1; | ||
44 | 46 | ||
45 | system = GNUNET_TESTING_system_create ("/tmp/gnunet-testing-new", | 47 | system = GNUNET_TESTING_system_create ("/tmp/gnunet-testing-new", |
46 | "localhost"); | 48 | "localhost"); |
@@ -54,6 +56,17 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
54 | "Reserved TCP port %u\n", new_port2); | 56 | "Reserved TCP port %u\n", new_port2); |
55 | GNUNET_assert (0 != new_port2); | 57 | GNUNET_assert (0 != new_port2); |
56 | GNUNET_assert (new_port1 != new_port2); | 58 | GNUNET_assert (new_port1 != new_port2); |
59 | release_port (system, GNUNET_YES, new_port1); | ||
60 | old_port1 = new_port1; | ||
61 | new_port1 = 0; | ||
62 | new_port1 = reserve_port (system, GNUNET_YES); | ||
63 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
64 | "Reserved TCP port %u\n", new_port1); | ||
65 | GNUNET_assert (0 != new_port1); | ||
66 | GNUNET_assert (old_port1 == new_port1); | ||
67 | release_port (system, GNUNET_YES, new_port1); | ||
68 | release_port (system, GNUNET_YES, new_port2); | ||
69 | release_port (system, GNUNET_YES, new_port2 + 1); /* OK to get error :) */ | ||
57 | GNUNET_TESTING_system_destroy (system, GNUNET_NO); | 70 | GNUNET_TESTING_system_destroy (system, GNUNET_NO); |
58 | } | 71 | } |
59 | 72 | ||
diff --git a/src/testing/testing_new.c b/src/testing/testing_new.c index 7a97b3b9c..73b50575b 100644 --- a/src/testing/testing_new.c +++ b/src/testing/testing_new.c | |||
@@ -34,6 +34,8 @@ | |||
34 | #include "gnunet_network_lib.h" | 34 | #include "gnunet_network_lib.h" |
35 | #include "gnunet_testing_lib-new.h" | 35 | #include "gnunet_testing_lib-new.h" |
36 | 36 | ||
37 | #define LOG(kind,...) \ | ||
38 | GNUNET_log_from (kind, "testing-new-api", __VA_ARGS__) | ||
37 | 39 | ||
38 | /** | 40 | /** |
39 | * Handle for a system on which GNUnet peers are executed; | 41 | * Handle for a system on which GNUnet peers are executed; |
@@ -137,17 +139,6 @@ struct GNUNET_TESTING_Peer | |||
137 | 139 | ||
138 | 140 | ||
139 | /** | 141 | /** |
140 | * The lowest port bucket for ports available for GNUnet testing | ||
141 | */ | ||
142 | #define LOW_PORT_BUCKET (LOW_PORT / 32) | ||
143 | |||
144 | /** | ||
145 | * The highest port bucket for ports available for GNUNET_testing | ||
146 | */ | ||
147 | #define HIGH_PORT_BUCKET (HIGH_PORT / 32) | ||
148 | |||
149 | |||
150 | /** | ||
151 | * Create a system handle. There must only be one system | 142 | * Create a system handle. There must only be one system |
152 | * handle per operating system. | 143 | * handle per operating system. |
153 | * | 144 | * |
@@ -226,7 +217,7 @@ reserve_port (struct GNUNET_TESTING_System *system, | |||
226 | hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */ | 217 | hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */ |
227 | port_buckets = (GNUNET_YES == is_tcp) ? | 218 | port_buckets = (GNUNET_YES == is_tcp) ? |
228 | system->reserved_tcp_ports : system->reserved_udp_ports; | 219 | system->reserved_tcp_ports : system->reserved_udp_ports; |
229 | for (index = LOW_PORT_BUCKET + 1; index < HIGH_PORT_BUCKET; index++) | 220 | for (index = (LOW_PORT / 32) + 1; index < (HIGH_PORT / 32); index++) |
230 | { | 221 | { |
231 | xor_image = (UINT32_MAX ^ port_buckets[index]); | 222 | xor_image = (UINT32_MAX ^ port_buckets[index]); |
232 | if (0 == xor_image) /* Ports in the bucket are full */ | 223 | if (0 == xor_image) /* Ports in the bucket are full */ |
@@ -279,7 +270,22 @@ release_port (struct GNUNET_TESTING_System *system, | |||
279 | int is_tcp, | 270 | int is_tcp, |
280 | uint16_t port) | 271 | uint16_t port) |
281 | { | 272 | { |
282 | GNUNET_break (0); | 273 | uint32_t *port_buckets; |
274 | uint16_t bucket; | ||
275 | uint16_t pos; | ||
276 | |||
277 | GNUNET_assert (NULL != system); | ||
278 | port_buckets = (GNUNET_YES == is_tcp) ? | ||
279 | system->reserved_tcp_ports : system->reserved_udp_ports; | ||
280 | bucket = port / 32; | ||
281 | pos = port % 32; | ||
282 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port); | ||
283 | if (0 == (port_buckets[bucket] & (1U << pos))) | ||
284 | { | ||
285 | GNUNET_break(0); /* Port was not reserved by us using reserve_port() */ | ||
286 | return; | ||
287 | } | ||
288 | port_buckets[bucket] &= ~(1U << pos); | ||
283 | } | 289 | } |
284 | 290 | ||
285 | 291 | ||