aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_new.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_new.c')
-rw-r--r--src/testing/testing_new.c32
1 files changed, 19 insertions, 13 deletions
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