diff options
-rw-r--r-- | src/testing/test_testing.c | 12 | ||||
-rw-r--r-- | src/testing/test_testing_connect.c | 22 | ||||
-rw-r--r-- | src/testing/test_testing_group.c | 27 | ||||
-rw-r--r-- | src/testing/test_testing_group_remote.c | 133 | ||||
-rw-r--r-- | src/testing/test_testing_topology.c | 633 | ||||
-rw-r--r-- | src/testing/test_testing_topology_blacklist.c | 246 | ||||
-rw-r--r-- | src/testing/test_testing_topology_churn.c | 93 | ||||
-rw-r--r-- | src/testing/testing.c | 658 | ||||
-rw-r--r-- | src/testing/testing_group.c | 2114 |
9 files changed, 2243 insertions, 1695 deletions
diff --git a/src/testing/test_testing.c b/src/testing/test_testing.c index 079ccb6db..64bf7572a 100644 --- a/src/testing/test_testing.c +++ b/src/testing/test_testing.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_testing_lib.h" | 25 | #include "gnunet_testing_lib.h" |
26 | 26 | ||
27 | #define VERBOSE GNUNET_NO | 27 | #define VERBOSE GNUNET_YES |
28 | 28 | ||
29 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) | 29 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) |
30 | 30 | ||
@@ -41,7 +41,8 @@ end_cb (void *cls, const char *emsg) | |||
41 | else | 41 | else |
42 | { | 42 | { |
43 | #if VERBOSE | 43 | #if VERBOSE |
44 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon terminated, will now exit.\n"); | 44 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
45 | "Daemon terminated, will now exit.\n"); | ||
45 | #endif | 46 | #endif |
46 | ok = 0; | 47 | ok = 0; |
47 | } | 48 | } |
@@ -58,7 +59,8 @@ my_cb (void *cls, | |||
58 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
59 | "Daemon `%s' started, will now stop it.\n", GNUNET_i2s (id)); | 60 | "Daemon `%s' started, will now stop it.\n", GNUNET_i2s (id)); |
60 | #endif | 61 | #endif |
61 | GNUNET_TESTING_daemon_stop (d, TIMEOUT, &end_cb, NULL, GNUNET_YES, GNUNET_NO); | 62 | GNUNET_TESTING_daemon_stop (d, TIMEOUT, &end_cb, NULL, GNUNET_YES, |
63 | GNUNET_NO); | ||
62 | } | 64 | } |
63 | 65 | ||
64 | 66 | ||
@@ -73,7 +75,9 @@ run (void *cls, | |||
73 | #if VERBOSE | 75 | #if VERBOSE |
74 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n"); | 76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n"); |
75 | #endif | 77 | #endif |
76 | d = GNUNET_TESTING_daemon_start (cfg, TIMEOUT, NULL, NULL, 0, NULL, NULL, &my_cb, NULL); | 78 | d = |
79 | GNUNET_TESTING_daemon_start (cfg, TIMEOUT, NULL, NULL, 0, NULL, NULL, | ||
80 | &my_cb, NULL); | ||
77 | GNUNET_assert (d != NULL); | 81 | GNUNET_assert (d != NULL); |
78 | } | 82 | } |
79 | 83 | ||
diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c index 8da9b05d8..2c3014635 100644 --- a/src/testing/test_testing_connect.c +++ b/src/testing/test_testing_connect.c | |||
@@ -67,7 +67,8 @@ end1_cb (void *cls, const char *emsg) | |||
67 | { | 67 | { |
68 | if (emsg != NULL) | 68 | if (emsg != NULL) |
69 | { | 69 | { |
70 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping daemon 1 gave: %s\n", emsg); | 70 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping daemon 1 gave: %s\n", |
71 | emsg); | ||
71 | ok = 1; | 72 | ok = 1; |
72 | } | 73 | } |
73 | else | 74 | else |
@@ -75,14 +76,16 @@ end1_cb (void *cls, const char *emsg) | |||
75 | ok = 0; | 76 | ok = 0; |
76 | } | 77 | } |
77 | 78 | ||
78 | GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL, GNUNET_YES, GNUNET_NO); | 79 | GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL, GNUNET_YES, |
80 | GNUNET_NO); | ||
79 | d2 = NULL; | 81 | d2 = NULL; |
80 | } | 82 | } |
81 | 83 | ||
82 | static void | 84 | static void |
83 | finish_testing(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 85 | finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
84 | { | 86 | { |
85 | GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &end1_cb, NULL, GNUNET_YES, GNUNET_NO); | 87 | GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &end1_cb, NULL, GNUNET_YES, |
88 | GNUNET_NO); | ||
86 | d1 = NULL; | 89 | d1 = NULL; |
87 | } | 90 | } |
88 | 91 | ||
@@ -113,7 +116,8 @@ my_cb2 (void *cls, | |||
113 | "Daemon `%s' started.\n", GNUNET_i2s (id)); | 116 | "Daemon `%s' started.\n", GNUNET_i2s (id)); |
114 | #endif | 117 | #endif |
115 | GNUNET_TESTING_daemons_connect (d1, d2, | 118 | GNUNET_TESTING_daemons_connect (d1, d2, |
116 | TIMEOUT, CONNECT_ATTEMPTS, &my_connect_complete, NULL); | 119 | TIMEOUT, CONNECT_ATTEMPTS, |
120 | &my_connect_complete, NULL); | ||
117 | } | 121 | } |
118 | 122 | ||
119 | 123 | ||
@@ -128,7 +132,9 @@ my_cb1 (void *cls, | |||
128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
129 | "Daemon `%s' started.\n", GNUNET_i2s (id)); | 133 | "Daemon `%s' started.\n", GNUNET_i2s (id)); |
130 | #endif | 134 | #endif |
131 | d2 = GNUNET_TESTING_daemon_start (c2, TIMEOUT, NULL, NULL, 0, NULL, NULL, &my_cb2, NULL); | 135 | d2 = |
136 | GNUNET_TESTING_daemon_start (c2, TIMEOUT, NULL, NULL, 0, NULL, NULL, | ||
137 | &my_cb2, NULL); | ||
132 | GNUNET_assert (d2 != NULL); | 138 | GNUNET_assert (d2 != NULL); |
133 | 139 | ||
134 | } | 140 | } |
@@ -147,7 +153,9 @@ run (void *cls, | |||
147 | GNUNET_CONFIGURATION_parse (c1, "test_testing_connect_peer1.conf"); | 153 | GNUNET_CONFIGURATION_parse (c1, "test_testing_connect_peer1.conf"); |
148 | c2 = GNUNET_CONFIGURATION_create (); | 154 | c2 = GNUNET_CONFIGURATION_create (); |
149 | GNUNET_CONFIGURATION_parse (c2, "test_testing_connect_peer2.conf"); | 155 | GNUNET_CONFIGURATION_parse (c2, "test_testing_connect_peer2.conf"); |
150 | d1 = GNUNET_TESTING_daemon_start (c1, TIMEOUT, NULL, NULL, 0, NULL, NULL, &my_cb1, NULL); | 156 | d1 = |
157 | GNUNET_TESTING_daemon_start (c1, TIMEOUT, NULL, NULL, 0, NULL, NULL, | ||
158 | &my_cb1, NULL); | ||
151 | GNUNET_assert (d1 != NULL); | 159 | GNUNET_assert (d1 != NULL); |
152 | } | 160 | } |
153 | 161 | ||
diff --git a/src/testing/test_testing_group.c b/src/testing/test_testing_group.c index b1e6be395..e3a3b2e63 100644 --- a/src/testing/test_testing_group.c +++ b/src/testing/test_testing_group.c | |||
@@ -44,14 +44,13 @@ static struct GNUNET_TESTING_PeerGroup *pg; | |||
44 | /** | 44 | /** |
45 | * Check whether peers successfully shut down. | 45 | * Check whether peers successfully shut down. |
46 | */ | 46 | */ |
47 | void shutdown_callback (void *cls, | 47 | void |
48 | const char *emsg) | 48 | shutdown_callback (void *cls, const char *emsg) |
49 | { | 49 | { |
50 | if (emsg != NULL) | 50 | if (emsg != NULL) |
51 | { | 51 | { |
52 | #if VERBOSE | 52 | #if VERBOSE |
53 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 53 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); |
54 | "Shutdown of peers failed!\n"); | ||
55 | #endif | 54 | #endif |
56 | if (ok == 0) | 55 | if (ok == 0) |
57 | ok = 666; | 56 | ok = 666; |
@@ -74,28 +73,32 @@ my_cb (void *cls, | |||
74 | { | 73 | { |
75 | if (id == NULL) | 74 | if (id == NULL) |
76 | { | 75 | { |
77 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start callback called with error (too long starting peers), aborting test!\n"); | 76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
77 | "Start callback called with error (too long starting peers), aborting test!\n"); | ||
78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); | 78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); |
79 | failed_peers++; | 79 | failed_peers++; |
80 | if (failed_peers == peers_left) | 80 | if (failed_peers == peers_left) |
81 | { | 81 | { |
82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n"); | 82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
83 | ok = 1; | 83 | "Too many peers failed, ending test!\n"); |
84 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 84 | ok = 1; |
85 | } | 85 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
86 | } | ||
86 | return; | 87 | return; |
87 | } | 88 | } |
88 | 89 | ||
89 | peers_left--; | 90 | peers_left--; |
90 | if (peers_left == 0) | 91 | if (peers_left == 0) |
91 | { | 92 | { |
92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started successfully, ending test!\n"); | 93 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
94 | "All peers started successfully, ending test!\n"); | ||
93 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 95 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
94 | ok = 0; | 96 | ok = 0; |
95 | } | 97 | } |
96 | else if (failed_peers == peers_left) | 98 | else if (failed_peers == peers_left) |
97 | { | 99 | { |
98 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n"); | 100 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
101 | "Too many peers failed, ending test!\n"); | ||
99 | ok = 1; | 102 | ok = 1; |
100 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 103 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
101 | } | 104 | } |
diff --git a/src/testing/test_testing_group_remote.c b/src/testing/test_testing_group_remote.c index e0338f534..8547e4de5 100644 --- a/src/testing/test_testing_group_remote.c +++ b/src/testing/test_testing_group_remote.c | |||
@@ -50,14 +50,13 @@ static unsigned long long num_peers; | |||
50 | /** | 50 | /** |
51 | * Check whether peers successfully shut down. | 51 | * Check whether peers successfully shut down. |
52 | */ | 52 | */ |
53 | void shutdown_callback (void *cls, | 53 | void |
54 | const char *emsg) | 54 | shutdown_callback (void *cls, const char *emsg) |
55 | { | 55 | { |
56 | if (emsg != NULL) | 56 | if (emsg != NULL) |
57 | { | 57 | { |
58 | #if VERBOSE | 58 | #if VERBOSE |
59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); |
60 | "Shutdown of peers failed!\n"); | ||
61 | #endif | 60 | #endif |
62 | if (ok == 0) | 61 | if (ok == 0) |
63 | ok = 666; | 62 | ok = 666; |
@@ -91,7 +90,8 @@ my_cb (void *cls, | |||
91 | } | 90 | } |
92 | else if (peers_failed == peers_left) | 91 | else if (peers_failed == peers_left) |
93 | { | 92 | { |
94 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n"); | 93 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
94 | "Too many peers failed, ending test!\n"); | ||
95 | //GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 95 | //GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
96 | } | 96 | } |
97 | } | 97 | } |
@@ -121,7 +121,7 @@ run (void *cls, | |||
121 | &num_peers)) | 121 | &num_peers)) |
122 | num_peers = DEFAULT_NUM_PEERS; | 122 | num_peers = DEFAULT_NUM_PEERS; |
123 | 123 | ||
124 | GNUNET_assert(num_peers > 0 && num_peers < (unsigned long long)-1); | 124 | GNUNET_assert (num_peers > 0 && num_peers < (unsigned long long) -1); |
125 | if (GNUNET_OK != | 125 | if (GNUNET_OK != |
126 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile", | 126 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile", |
127 | &hostfile)) | 127 | &hostfile)) |
@@ -132,64 +132,72 @@ run (void *cls, | |||
132 | if (hostfile != NULL) | 132 | if (hostfile != NULL) |
133 | { | 133 | { |
134 | if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) | 134 | if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) |
135 | GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ | 135 | GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ |
136 | | GNUNET_DISK_PERM_USER_WRITE); | 136 | | GNUNET_DISK_PERM_USER_WRITE); |
137 | if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0)) | 137 | if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0)) |
138 | { | 138 | { |
139 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 139 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
140 | "Could not open file specified for host list, ending test!"); | 140 | "Could not open file specified for host list, ending test!"); |
141 | ok = 1119; | 141 | ok = 1119; |
142 | GNUNET_free(hostfile); | 142 | GNUNET_free (hostfile); |
143 | return; | ||
144 | } | ||
145 | |||
146 | data = GNUNET_malloc_large (frstat.st_size); | ||
147 | GNUNET_assert (data != NULL); | ||
148 | if (frstat.st_size != | ||
149 | GNUNET_DISK_fn_read (hostfile, data, frstat.st_size)) | ||
150 | { | ||
151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
152 | "Could not read file %s specified for host list, ending test!", | ||
153 | hostfile); | ||
154 | GNUNET_free (hostfile); | ||
155 | GNUNET_free (data); | ||
143 | return; | 156 | return; |
144 | } | 157 | } |
145 | 158 | ||
146 | data = GNUNET_malloc_large (frstat.st_size); | 159 | GNUNET_free_non_null (hostfile); |
147 | GNUNET_assert(data != NULL); | 160 | |
148 | if (frstat.st_size != | 161 | buf = data; |
149 | GNUNET_DISK_fn_read (hostfile, data, frstat.st_size)) | 162 | count = 0; |
150 | { | 163 | while (count < frstat.st_size) |
151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 164 | { |
152 | "Could not read file %s specified for host list, ending test!", hostfile); | 165 | count++; |
153 | GNUNET_free (hostfile); | 166 | if (count >= frstat.st_size) |
154 | GNUNET_free (data); | 167 | break; |
155 | return; | 168 | |
156 | } | 169 | /* if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count])) */ |
157 | 170 | if (((data[count] == '\n')) && (buf != &data[count])) | |
158 | GNUNET_free_non_null(hostfile); | 171 | { |
159 | 172 | data[count] = '\0'; | |
160 | buf = data; | 173 | temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host)); |
161 | count = 0; | 174 | ret = |
162 | while (count < frstat.st_size) | 175 | sscanf (buf, "%a[a-zA-Z0-9]@%a[a-zA-Z0-9.]:%hd", |
163 | { | 176 | &temphost->username, &temphost->hostname, |
164 | count++; | 177 | &temphost->port); |
165 | if (count >= frstat.st_size) | 178 | if (3 == ret) |
166 | break; | 179 | { |
167 | 180 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | |
168 | /* if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count]))*/ | 181 | "Successfully read host %s, port %d and user %s from file\n", |
169 | if (((data[count] == '\n')) && (buf != &data[count])) | 182 | temphost->hostname, temphost->port, |
170 | { | 183 | temphost->username); |
171 | data[count] = '\0'; | 184 | } |
172 | temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host)); | 185 | else |
173 | ret = sscanf(buf, "%a[a-zA-Z0-9]@%a[a-zA-Z0-9.]:%hd", &temphost->username, &temphost->hostname, &temphost->port); | 186 | { |
174 | if (3 == ret) | 187 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
175 | { | 188 | "Error reading line `%s' in hostfile\n", buf); |
176 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Successfully read host %s, port %d and user %s from file\n", temphost->hostname, temphost->port, temphost->username); | 189 | GNUNET_free (temphost); |
177 | } | 190 | buf = &data[count + 1]; |
178 | else | 191 | continue; |
179 | { | 192 | } |
180 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Error reading line `%s' in hostfile\n", buf); | 193 | /* temphost->hostname = buf; */ |
181 | GNUNET_free(temphost); | 194 | temphost->next = hosts; |
182 | buf = &data[count + 1]; | 195 | hosts = temphost; |
183 | continue; | 196 | buf = &data[count + 1]; |
184 | } | 197 | } |
185 | /* temphost->hostname = buf; */ | 198 | else if ((data[count] == '\n') || (data[count] == '\0')) |
186 | temphost->next = hosts; | ||
187 | hosts = temphost; | ||
188 | buf = &data[count + 1]; | 199 | buf = &data[count + 1]; |
189 | } | 200 | } |
190 | else if ((data[count] == '\n') || (data[count] == '\0')) | ||
191 | buf = &data[count + 1]; | ||
192 | } | ||
193 | } | 201 | } |
194 | 202 | ||
195 | peers_left = num_peers; | 203 | peers_left = num_peers; |
@@ -197,22 +205,17 @@ run (void *cls, | |||
197 | peers_left, | 205 | peers_left, |
198 | TIMEOUT, | 206 | TIMEOUT, |
199 | NULL, | 207 | NULL, |
200 | NULL, | 208 | NULL, &my_cb, NULL, NULL, NULL, hosts); |
201 | &my_cb, | ||
202 | NULL, | ||
203 | NULL, | ||
204 | NULL, | ||
205 | hosts); | ||
206 | hostpos = hosts; | 209 | hostpos = hosts; |
207 | while (hostpos != NULL) | 210 | while (hostpos != NULL) |
208 | { | 211 | { |
209 | temphost = hostpos->next; | 212 | temphost = hostpos->next; |
210 | GNUNET_free(hostpos->hostname); | 213 | GNUNET_free (hostpos->hostname); |
211 | GNUNET_free(hostpos->username); | 214 | GNUNET_free (hostpos->username); |
212 | GNUNET_free(hostpos); | 215 | GNUNET_free (hostpos); |
213 | hostpos = temphost; | 216 | hostpos = temphost; |
214 | } | 217 | } |
215 | GNUNET_free_non_null(data); | 218 | GNUNET_free_non_null (data); |
216 | GNUNET_assert (pg != NULL); | 219 | GNUNET_assert (pg != NULL); |
217 | 220 | ||
218 | } | 221 | } |
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c index 62fbc07e0..36ccad6c9 100644 --- a/src/testing/test_testing_topology.c +++ b/src/testing/test_testing_topology.c | |||
@@ -96,11 +96,12 @@ static unsigned int dotnum; | |||
96 | 96 | ||
97 | static enum GNUNET_TESTING_Topology topology; | 97 | static enum GNUNET_TESTING_Topology topology; |
98 | 98 | ||
99 | static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */ | 99 | static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */ |
100 | 100 | ||
101 | static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */ | 101 | static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */ |
102 | 102 | ||
103 | static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; | 103 | static enum GNUNET_TESTING_TopologyOption connect_topology_option = |
104 | GNUNET_TESTING_TOPOLOGY_OPTION_ALL; | ||
104 | 105 | ||
105 | static double connect_topology_option_modifier = 0.0; | 106 | static double connect_topology_option_modifier = 0.0; |
106 | 107 | ||
@@ -151,14 +152,13 @@ static struct TestMessageContext *test_messages; | |||
151 | /** | 152 | /** |
152 | * Check whether peers successfully shut down. | 153 | * Check whether peers successfully shut down. |
153 | */ | 154 | */ |
154 | void shutdown_callback (void *cls, | 155 | void |
155 | const char *emsg) | 156 | shutdown_callback (void *cls, const char *emsg) |
156 | { | 157 | { |
157 | if (emsg != NULL) | 158 | if (emsg != NULL) |
158 | { | 159 | { |
159 | #if VERBOSE | 160 | #if VERBOSE |
160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); |
161 | "Shutdown of peers failed!\n"); | ||
162 | #endif | 162 | #endif |
163 | if (ok == 0) | 163 | if (ok == 0) |
164 | ok = 666; | 164 | ok = 666; |
@@ -173,15 +173,17 @@ void shutdown_callback (void *cls, | |||
173 | } | 173 | } |
174 | 174 | ||
175 | #if DELAY_FOR_LOGGING | 175 | #if DELAY_FOR_LOGGING |
176 | static void gather_log_data () | 176 | static void |
177 | gather_log_data () | ||
177 | { | 178 | { |
178 | char *peer_number; | 179 | char *peer_number; |
179 | char *connect_number; | 180 | char *connect_number; |
180 | struct GNUNET_OS_Process *mem_process; | 181 | struct GNUNET_OS_Process *mem_process; |
181 | GNUNET_asprintf(&peer_number, "%llu", num_peers); | 182 | GNUNET_asprintf (&peer_number, "%llu", num_peers); |
182 | GNUNET_asprintf(&connect_number, "%llu", expected_connections); | 183 | GNUNET_asprintf (&connect_number, "%llu", expected_connections); |
183 | mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", | 184 | mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", |
184 | "memsize.pl", "totals.txt", peer_number, connect_number, NULL); | 185 | "memsize.pl", "totals.txt", |
186 | peer_number, connect_number, NULL); | ||
185 | GNUNET_OS_process_wait (mem_process); | 187 | GNUNET_OS_process_wait (mem_process); |
186 | GNUNET_OS_process_close (mem_process); | 188 | GNUNET_OS_process_close (mem_process); |
187 | mem_process = NULL; | 189 | mem_process = NULL; |
@@ -205,37 +207,38 @@ finish_testing () | |||
205 | { | 207 | { |
206 | if (pos->peer1handle != NULL) | 208 | if (pos->peer1handle != NULL) |
207 | { | 209 | { |
208 | GNUNET_CORE_disconnect(pos->peer1handle); | 210 | GNUNET_CORE_disconnect (pos->peer1handle); |
209 | pos->peer1handle = NULL; | 211 | pos->peer1handle = NULL; |
210 | } | 212 | } |
211 | if (pos->peer2handle != NULL) | 213 | if (pos->peer2handle != NULL) |
212 | { | 214 | { |
213 | GNUNET_CORE_disconnect(pos->peer2handle); | 215 | GNUNET_CORE_disconnect (pos->peer2handle); |
214 | pos->peer2handle = NULL; | 216 | pos->peer2handle = NULL; |
215 | } | 217 | } |
216 | free_pos = pos; | 218 | free_pos = pos; |
217 | pos = pos->next; | 219 | pos = pos->next; |
218 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | 220 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) |
219 | { | 221 | { |
220 | GNUNET_SCHEDULER_cancel(free_pos->disconnect_task); | 222 | GNUNET_SCHEDULER_cancel (free_pos->disconnect_task); |
221 | } | 223 | } |
222 | GNUNET_free(free_pos); | 224 | GNUNET_free (free_pos); |
223 | } | 225 | } |
224 | #if VERBOSE | 226 | #if VERBOSE |
225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 227 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
226 | "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called); | 228 | "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", |
229 | transmit_ready_scheduled, transmit_ready_failed, | ||
230 | transmit_ready_called); | ||
227 | #endif | 231 | #endif |
228 | 232 | ||
229 | #if VERBOSE | 233 | #if VERBOSE |
230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n"); |
231 | "Calling daemons_stop\n"); | ||
232 | #endif | 235 | #endif |
233 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 236 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
234 | 237 | ||
235 | if (dotOutFile != NULL) | 238 | if (dotOutFile != NULL) |
236 | { | 239 | { |
237 | fprintf(dotOutFile, "}"); | 240 | fprintf (dotOutFile, "}"); |
238 | fclose(dotOutFile); | 241 | fclose (dotOutFile); |
239 | } | 242 | } |
240 | 243 | ||
241 | ok = 0; | 244 | ok = 0; |
@@ -243,23 +246,25 @@ finish_testing () | |||
243 | 246 | ||
244 | 247 | ||
245 | static void | 248 | static void |
246 | disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 249 | disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
247 | { | 250 | { |
248 | struct TestMessageContext *pos = cls; | 251 | struct TestMessageContext *pos = cls; |
249 | 252 | ||
250 | /* Disconnect from the respective cores */ | 253 | /* Disconnect from the respective cores */ |
251 | #if VERBOSE > 1 | 254 | #if VERBOSE > 1 |
252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
253 | "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id)); | 256 | "Disconnecting from peer 1 `%4s'\n", |
257 | GNUNET_i2s (&pos->peer1->id)); | ||
254 | #endif | 258 | #endif |
255 | if (pos->peer1handle != NULL) | 259 | if (pos->peer1handle != NULL) |
256 | GNUNET_CORE_disconnect(pos->peer1handle); | 260 | GNUNET_CORE_disconnect (pos->peer1handle); |
257 | #if VERBOSE > 1 | 261 | #if VERBOSE > 1 |
258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 262 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
259 | "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id)); | 263 | "Disconnecting from peer 2 `%4s'\n", |
264 | GNUNET_i2s (&pos->peer2->id)); | ||
260 | #endif | 265 | #endif |
261 | if (pos->peer2handle != NULL) | 266 | if (pos->peer2handle != NULL) |
262 | GNUNET_CORE_disconnect(pos->peer2handle); | 267 | GNUNET_CORE_disconnect (pos->peer2handle); |
263 | /* Set handles to NULL so test case can be ended properly */ | 268 | /* Set handles to NULL so test case can be ended properly */ |
264 | pos->peer1handle = NULL; | 269 | pos->peer1handle = NULL; |
265 | pos->peer2handle = NULL; | 270 | pos->peer2handle = NULL; |
@@ -268,7 +273,8 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
268 | total_server_connections -= 2; | 273 | total_server_connections -= 2; |
269 | } | 274 | } |
270 | 275 | ||
271 | static void stats_finished (void *cls, int result) | 276 | static void |
277 | stats_finished (void *cls, int result) | ||
272 | { | 278 | { |
273 | GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | 279 | GNUNET_SCHEDULER_add_now (&finish_testing, NULL); |
274 | } | 280 | } |
@@ -284,42 +290,45 @@ static void stats_finished (void *cls, int result) | |||
284 | * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not | 290 | * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not |
285 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | 291 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration |
286 | */ | 292 | */ |
287 | static int stats_print (void *cls, | 293 | static int |
288 | const struct GNUNET_PeerIdentity *peer, | 294 | stats_print (void *cls, |
289 | const char *subsystem, | 295 | const struct GNUNET_PeerIdentity *peer, |
290 | const char *name, | 296 | const char *subsystem, |
291 | uint64_t value, | 297 | const char *name, uint64_t value, int is_persistent) |
292 | int is_persistent) | ||
293 | { | 298 | { |
294 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n", GNUNET_i2s(peer), subsystem, name, value); | 299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n", |
300 | GNUNET_i2s (peer), subsystem, name, value); | ||
295 | return GNUNET_OK; | 301 | return GNUNET_OK; |
296 | } | 302 | } |
297 | 303 | ||
298 | static void topology_cb (void *cls, | 304 | static void |
299 | const struct GNUNET_PeerIdentity *first, | 305 | topology_cb (void *cls, |
300 | const struct GNUNET_PeerIdentity *second, | 306 | const struct GNUNET_PeerIdentity *first, |
301 | const char *emsg) | 307 | const struct GNUNET_PeerIdentity *second, const char *emsg) |
302 | { | 308 | { |
303 | FILE *outfile = cls; | 309 | FILE *outfile = cls; |
304 | if (first != NULL) | 310 | if (first != NULL) |
305 | { | ||
306 | if (outfile != NULL) | ||
307 | { | 311 | { |
308 | fprintf(outfile, "\t\"%s\" -- ", GNUNET_i2s(first)); | 312 | if (outfile != NULL) |
309 | fprintf(outfile, "\"%s\";\n", GNUNET_i2s(second)); | 313 | { |
314 | fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first)); | ||
315 | fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second)); | ||
316 | } | ||
317 | topology_connections++; | ||
310 | } | 318 | } |
311 | topology_connections++; | ||
312 | } | ||
313 | else | 319 | else |
314 | { | 320 | { |
315 | fprintf(stderr, "Finished iterating over topology, %d total connections!\n", topology_connections); | 321 | fprintf (stderr, |
322 | "Finished iterating over topology, %d total connections!\n", | ||
323 | topology_connections); | ||
316 | if (outfile != NULL) | 324 | if (outfile != NULL) |
317 | { | 325 | { |
318 | fprintf(outfile, "}\n"); | 326 | fprintf (outfile, "}\n"); |
319 | fclose(outfile); | 327 | fclose (outfile); |
320 | GNUNET_TESTING_get_statistics(pg, &stats_finished, &stats_print, NULL); | 328 | GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print, |
321 | //GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | 329 | NULL); |
322 | } | 330 | //GNUNET_SCHEDULER_add_now (&finish_testing, NULL); |
331 | } | ||
323 | } | 332 | } |
324 | } | 333 | } |
325 | 334 | ||
@@ -327,68 +336,71 @@ static int | |||
327 | process_mtype (void *cls, | 336 | process_mtype (void *cls, |
328 | const struct GNUNET_PeerIdentity *peer, | 337 | const struct GNUNET_PeerIdentity *peer, |
329 | const struct GNUNET_MessageHeader *message, | 338 | const struct GNUNET_MessageHeader *message, |
330 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 339 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
331 | { | 340 | { |
332 | char *dotOutFileNameFinished; | 341 | char *dotOutFileNameFinished; |
333 | FILE *dotOutFileFinished; | 342 | FILE *dotOutFileFinished; |
334 | struct TestMessageContext *pos = cls; | 343 | struct TestMessageContext *pos = cls; |
335 | struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message; | 344 | struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message; |
336 | if (pos->uid != ntohl(msg->uid)) | 345 | if (pos->uid != ntohl (msg->uid)) |
337 | return GNUNET_OK; | 346 | return GNUNET_OK; |
338 | 347 | ||
339 | #if VERBOSE | 348 | #if VERBOSE |
340 | if ((total_messages_received) % modnum == 0) | 349 | if ((total_messages_received) % modnum == 0) |
341 | { | 350 | { |
342 | if (total_messages_received == 0) | 351 | if (total_messages_received == 0) |
343 | fprintf (stdout, "0%%"); | 352 | fprintf (stdout, "0%%"); |
344 | else | 353 | else |
345 | fprintf (stdout, "%d%%", | 354 | fprintf (stdout, "%d%%", |
346 | (int) (((float) total_messages_received / | 355 | (int) (((float) total_messages_received / |
347 | expected_messages) * 100)); | 356 | expected_messages) * 100)); |
348 | 357 | ||
349 | } | 358 | } |
350 | else if (total_messages_received % dotnum == 0) | 359 | else if (total_messages_received % dotnum == 0) |
351 | { | 360 | { |
352 | fprintf (stdout, "."); | 361 | fprintf (stdout, "."); |
353 | } | 362 | } |
354 | fflush (stdout); | 363 | fflush (stdout); |
355 | #endif | 364 | #endif |
356 | 365 | ||
357 | total_messages_received++; | 366 | total_messages_received++; |
358 | #if VERBOSE > 1 | 367 | #if VERBOSE > 1 |
359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
360 | "Received message from `%4s', type %d.\n", GNUNET_i2s (peer), ntohs(message->type)); | 369 | "Received message from `%4s', type %d.\n", GNUNET_i2s (peer), |
370 | ntohs (message->type)); | ||
361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
362 | "Total messages received %d, expected %d.\n", total_messages_received, expected_messages); | 372 | "Total messages received %d, expected %d.\n", |
373 | total_messages_received, expected_messages); | ||
363 | #endif | 374 | #endif |
364 | 375 | ||
365 | if (total_messages_received == expected_messages) | 376 | if (total_messages_received == expected_messages) |
366 | { | 377 | { |
367 | #if VERBOSE | 378 | #if VERBOSE |
368 | fprintf(stdout, "100%%]\n"); | 379 | fprintf (stdout, "100%%]\n"); |
369 | #endif | 380 | #endif |
370 | GNUNET_SCHEDULER_cancel (die_task); | 381 | GNUNET_SCHEDULER_cancel (die_task); |
371 | GNUNET_asprintf(&dotOutFileNameFinished, "%s.dot", "final_topology"); | 382 | GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology"); |
372 | dotOutFileFinished = fopen (dotOutFileNameFinished, "w"); | 383 | dotOutFileFinished = fopen (dotOutFileNameFinished, "w"); |
373 | GNUNET_free(dotOutFileNameFinished); | 384 | GNUNET_free (dotOutFileNameFinished); |
374 | if (dotOutFileFinished != NULL) | 385 | if (dotOutFileFinished != NULL) |
375 | { | 386 | { |
376 | fprintf(dotOutFileFinished, "strict graph G {\n"); | 387 | fprintf (dotOutFileFinished, "strict graph G {\n"); |
377 | } | 388 | } |
378 | topology_connections = 0; | 389 | topology_connections = 0; |
379 | GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished); | 390 | GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished); |
380 | //GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | 391 | //GNUNET_SCHEDULER_add_now (&finish_testing, NULL); |
381 | } | 392 | } |
382 | else | 393 | else |
383 | { | 394 | { |
384 | pos->disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cores, pos); | 395 | pos->disconnect_task = |
396 | GNUNET_SCHEDULER_add_now (&disconnect_cores, pos); | ||
385 | } | 397 | } |
386 | 398 | ||
387 | return GNUNET_OK; | 399 | return GNUNET_OK; |
388 | } | 400 | } |
389 | 401 | ||
390 | static void | 402 | static void |
391 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 403 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
392 | { | 404 | { |
393 | char *msg = cls; | 405 | char *msg = cls; |
394 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 406 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -401,24 +413,27 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
401 | { | 413 | { |
402 | if (pos->peer1handle != NULL) | 414 | if (pos->peer1handle != NULL) |
403 | { | 415 | { |
404 | GNUNET_CORE_disconnect(pos->peer1handle); | 416 | GNUNET_CORE_disconnect (pos->peer1handle); |
405 | pos->peer1handle = NULL; | 417 | pos->peer1handle = NULL; |
406 | } | 418 | } |
407 | if (pos->peer2handle != NULL) | 419 | if (pos->peer2handle != NULL) |
408 | { | 420 | { |
409 | GNUNET_CORE_disconnect(pos->peer2handle); | 421 | GNUNET_CORE_disconnect (pos->peer2handle); |
410 | pos->peer2handle = NULL; | 422 | pos->peer2handle = NULL; |
411 | } | 423 | } |
412 | free_pos = pos; | 424 | free_pos = pos; |
413 | pos = pos->next; | 425 | pos = pos->next; |
414 | GNUNET_free(free_pos); | 426 | GNUNET_free (free_pos); |
415 | } | 427 | } |
416 | 428 | ||
417 | #if VERBOSE | 429 | #if VERBOSE |
418 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
419 | "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called); | 431 | "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", |
420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 432 | transmit_ready_scheduled, transmit_ready_failed, |
421 | "Total messages received %d, expected %d.\n", total_messages_received, expected_messages); | 433 | transmit_ready_called); |
434 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
435 | "Total messages received %d, expected %d.\n", | ||
436 | total_messages_received, expected_messages); | ||
422 | #endif | 437 | #endif |
423 | 438 | ||
424 | if (pg != NULL) | 439 | if (pg != NULL) |
@@ -431,8 +446,8 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
431 | 446 | ||
432 | if (dotOutFile != NULL) | 447 | if (dotOutFile != NULL) |
433 | { | 448 | { |
434 | fprintf(dotOutFile, "}"); | 449 | fprintf (dotOutFile, "}"); |
435 | fclose(dotOutFile); | 450 | fclose (dotOutFile); |
436 | } | 451 | } |
437 | } | 452 | } |
438 | 453 | ||
@@ -446,11 +461,13 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
446 | m = (struct GNUNET_TestMessage *) buf; | 461 | m = (struct GNUNET_TestMessage *) buf; |
447 | m->header.type = htons (MTYPE); | 462 | m->header.type = htons (MTYPE); |
448 | m->header.size = htons (sizeof (struct GNUNET_TestMessage)); | 463 | m->header.size = htons (sizeof (struct GNUNET_TestMessage)); |
449 | m->uid = htonl(pos->uid); | 464 | m->uid = htonl (pos->uid); |
450 | transmit_ready_called++; | 465 | transmit_ready_called++; |
451 | #if VERBOSE > 1 | 466 | #if VERBOSE > 1 |
452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 467 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
453 | "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n", GNUNET_i2s(&pos->peer1->id), transmit_ready_scheduled, transmit_ready_called); | 468 | "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n", |
469 | GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled, | ||
470 | transmit_ready_called); | ||
454 | #endif | 471 | #endif |
455 | return sizeof (struct GNUNET_TestMessage); | 472 | return sizeof (struct GNUNET_TestMessage); |
456 | } | 473 | } |
@@ -467,9 +484,10 @@ static struct GNUNET_CORE_MessageHandler handlers[] = { | |||
467 | 484 | ||
468 | static void | 485 | static void |
469 | init_notify_peer2 (void *cls, | 486 | init_notify_peer2 (void *cls, |
470 | struct GNUNET_CORE_Handle *server, | 487 | struct GNUNET_CORE_Handle *server, |
471 | const struct GNUNET_PeerIdentity *my_identity, | 488 | const struct GNUNET_PeerIdentity *my_identity, |
472 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) | 489 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
490 | *publicKey) | ||
473 | { | 491 | { |
474 | struct TestMessageContext *pos = cls; | 492 | struct TestMessageContext *pos = cls; |
475 | 493 | ||
@@ -484,7 +502,8 @@ init_notify_peer2 (void *cls, | |||
484 | 0, | 502 | 0, |
485 | TIMEOUT, | 503 | TIMEOUT, |
486 | &pos->peer2->id, | 504 | &pos->peer2->id, |
487 | sizeof (struct GNUNET_TestMessage), | 505 | sizeof (struct |
506 | GNUNET_TestMessage), | ||
488 | &transmit_ready, pos)) | 507 | &transmit_ready, pos)) |
489 | { | 508 | { |
490 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -501,9 +520,10 @@ init_notify_peer2 (void *cls, | |||
501 | 520 | ||
502 | static void | 521 | static void |
503 | init_notify_peer1 (void *cls, | 522 | init_notify_peer1 (void *cls, |
504 | struct GNUNET_CORE_Handle *server, | 523 | struct GNUNET_CORE_Handle *server, |
505 | const struct GNUNET_PeerIdentity *my_identity, | 524 | const struct GNUNET_PeerIdentity *my_identity, |
506 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) | 525 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
526 | *publicKey) | ||
507 | { | 527 | { |
508 | struct TestMessageContext *pos = cls; | 528 | struct TestMessageContext *pos = cls; |
509 | total_server_connections++; | 529 | total_server_connections++; |
@@ -518,19 +538,20 @@ init_notify_peer1 (void *cls, | |||
518 | * Connect to the receiving peer | 538 | * Connect to the receiving peer |
519 | */ | 539 | */ |
520 | pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg, | 540 | pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg, |
521 | 1, | 541 | 1, |
522 | pos, | 542 | pos, |
523 | &init_notify_peer2, | 543 | &init_notify_peer2, |
524 | NULL, | 544 | NULL, |
525 | NULL, | 545 | NULL, |
526 | NULL, NULL, | 546 | NULL, NULL, |
527 | GNUNET_YES, NULL, GNUNET_YES, handlers); | 547 | GNUNET_YES, NULL, GNUNET_YES, |
548 | handlers); | ||
528 | 549 | ||
529 | } | 550 | } |
530 | 551 | ||
531 | 552 | ||
532 | static void | 553 | static void |
533 | send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 554 | send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
534 | { | 555 | { |
535 | struct TestMessageContext *pos = cls; | 556 | struct TestMessageContext *pos = cls; |
536 | 557 | ||
@@ -545,29 +566,32 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
545 | if (die_task == GNUNET_SCHEDULER_NO_TASK) | 566 | if (die_task == GNUNET_SCHEDULER_NO_TASK) |
546 | { | 567 | { |
547 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, | 568 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, |
548 | &end_badly, "from send test messages (timeout)"); | 569 | &end_badly, |
570 | "from send test messages (timeout)"); | ||
549 | } | 571 | } |
550 | 572 | ||
551 | if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) | 573 | if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) |
552 | { | 574 | { |
553 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), | 575 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
576 | (GNUNET_TIME_UNIT_SECONDS, 1), | ||
554 | &send_test_messages, pos); | 577 | &send_test_messages, pos); |
555 | return; /* Otherwise we'll double schedule messages here! */ | 578 | return; /* Otherwise we'll double schedule messages here! */ |
556 | } | 579 | } |
557 | 580 | ||
558 | /* | 581 | /* |
559 | * Connect to the sending peer | 582 | * Connect to the sending peer |
560 | */ | 583 | */ |
561 | pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg, | 584 | pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg, |
562 | 1, | 585 | 1, |
563 | pos, | 586 | pos, |
564 | &init_notify_peer1, | 587 | &init_notify_peer1, |
565 | NULL, NULL, | 588 | NULL, NULL, |
566 | NULL, | 589 | NULL, |
567 | NULL, | 590 | NULL, |
568 | GNUNET_NO, NULL, GNUNET_NO, no_handlers); | 591 | GNUNET_NO, NULL, GNUNET_NO, |
592 | no_handlers); | ||
569 | 593 | ||
570 | GNUNET_assert(pos->peer1handle != NULL); | 594 | GNUNET_assert (pos->peer1handle != NULL); |
571 | 595 | ||
572 | if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS) | 596 | if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS) |
573 | { | 597 | { |
@@ -575,7 +599,8 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
575 | } | 599 | } |
576 | else | 600 | else |
577 | { | 601 | { |
578 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), | 602 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
603 | (GNUNET_TIME_UNIT_SECONDS, 1), | ||
579 | &send_test_messages, pos->next); | 604 | &send_test_messages, pos->next); |
580 | } | 605 | } |
581 | } | 606 | } |
@@ -596,29 +621,28 @@ topology_callback (void *cls, | |||
596 | if (emsg == NULL) | 621 | if (emsg == NULL) |
597 | { | 622 | { |
598 | #if VERBOSE | 623 | #if VERBOSE |
599 | if ((total_connections) % modnum == 0) | 624 | if ((total_connections) % modnum == 0) |
600 | { | 625 | { |
601 | if (total_connections == 0) | 626 | if (total_connections == 0) |
602 | fprintf (stdout, "0%%"); | 627 | fprintf (stdout, "0%%"); |
603 | else | 628 | else |
604 | fprintf (stdout, "%d%%", | 629 | fprintf (stdout, "%d%%", |
605 | (int) (((float) total_connections / | 630 | (int) (((float) total_connections / |
606 | expected_connections) * 100)); | 631 | expected_connections) * 100)); |
607 | 632 | ||
608 | } | 633 | } |
609 | else if (total_connections % dotnum == 0) | 634 | else if (total_connections % dotnum == 0) |
610 | { | 635 | { |
611 | fprintf (stdout, "."); | 636 | fprintf (stdout, "."); |
612 | } | 637 | } |
613 | fflush (stdout); | 638 | fflush (stdout); |
614 | #endif | 639 | #endif |
615 | total_connections++; | 640 | total_connections++; |
616 | #if VERBOSE > 1 | 641 | #if VERBOSE > 1 |
617 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n", | 642 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n", |
618 | first_daemon->shortname, | 643 | first_daemon->shortname, second_daemon->shortname); |
619 | second_daemon->shortname); | ||
620 | #endif | 644 | #endif |
621 | temp_context = GNUNET_malloc(sizeof(struct TestMessageContext)); | 645 | temp_context = GNUNET_malloc (sizeof (struct TestMessageContext)); |
622 | temp_context->peer1 = first_daemon; | 646 | temp_context->peer1 = first_daemon; |
623 | temp_context->peer2 = second_daemon; | 647 | temp_context->peer2 = second_daemon; |
624 | temp_context->next = test_messages; | 648 | temp_context->next = test_messages; |
@@ -628,22 +652,23 @@ topology_callback (void *cls, | |||
628 | 652 | ||
629 | expected_messages++; | 653 | expected_messages++; |
630 | if (dotOutFile != NULL) | 654 | if (dotOutFile != NULL) |
631 | fprintf(dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, second_daemon->shortname); | 655 | fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, |
656 | second_daemon->shortname); | ||
632 | } | 657 | } |
633 | #if VERBOSE | 658 | #if VERBOSE |
634 | else | 659 | else |
635 | { | 660 | { |
636 | failed_connections++; | 661 | failed_connections++; |
637 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n", | 662 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
638 | first_daemon->shortname, | 663 | "Failed to connect peer %s to peer %s with error :\n%s\n", |
639 | second_daemon->shortname, emsg); | 664 | first_daemon->shortname, second_daemon->shortname, emsg); |
640 | } | 665 | } |
641 | #endif | 666 | #endif |
642 | 667 | ||
643 | if (total_connections == expected_connections) | 668 | if (total_connections == expected_connections) |
644 | { | 669 | { |
645 | #if VERBOSE | 670 | #if VERBOSE |
646 | fprintf(stdout, "100%%]\n"); | 671 | fprintf (stdout, "100%%]\n"); |
647 | #endif | 672 | #endif |
648 | #if VERBOSE | 673 | #if VERBOSE |
649 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -655,26 +680,28 @@ topology_callback (void *cls, | |||
655 | GNUNET_SCHEDULER_cancel (die_task); | 680 | GNUNET_SCHEDULER_cancel (die_task); |
656 | die_task = GNUNET_SCHEDULER_NO_TASK; | 681 | die_task = GNUNET_SCHEDULER_NO_TASK; |
657 | #if DELAY_FOR_LOGGING | 682 | #if DELAY_FOR_LOGGING |
658 | fprintf(stdout, "Sending test messages in 10 seconds.\n"); | 683 | fprintf (stdout, "Sending test messages in 10 seconds.\n"); |
659 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 684 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
660 | (GNUNET_TIME_UNIT_SECONDS, 10), | 685 | (GNUNET_TIME_UNIT_SECONDS, 10), |
661 | &send_test_messages, test_messages); | 686 | &send_test_messages, test_messages); |
662 | gather_log_data(); | 687 | gather_log_data (); |
663 | #else | 688 | #else |
664 | if (settle_time.rel_value > 0) | 689 | if (settle_time.rel_value > 0) |
665 | { | 690 | { |
666 | GNUNET_TESTING_get_topology (pg, &topology_cb, NULL); | 691 | GNUNET_TESTING_get_topology (pg, &topology_cb, NULL); |
667 | } | 692 | } |
668 | GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages, test_messages); | 693 | GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages, |
694 | test_messages); | ||
669 | #endif | 695 | #endif |
670 | #if VERBOSE | 696 | #if VERBOSE |
671 | fprintf(stdout, "Test message progress: ["); | 697 | fprintf (stdout, "Test message progress: ["); |
672 | #endif | 698 | #endif |
673 | 699 | ||
674 | } | 700 | } |
675 | else if (total_connections + failed_connections == expected_connections) | 701 | else if (total_connections + failed_connections == expected_connections) |
676 | { | 702 | { |
677 | if (failed_connections < (unsigned int)(fail_percentage * total_connections)) | 703 | if (failed_connections < |
704 | (unsigned int) (fail_percentage * total_connections)) | ||
678 | { | 705 | { |
679 | GNUNET_SCHEDULER_cancel (die_task); | 706 | GNUNET_SCHEDULER_cancel (die_task); |
680 | die_task = GNUNET_SCHEDULER_NO_TASK; | 707 | die_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -683,7 +710,9 @@ topology_callback (void *cls, | |||
683 | else | 710 | else |
684 | { | 711 | { |
685 | GNUNET_SCHEDULER_cancel (die_task); | 712 | GNUNET_SCHEDULER_cancel (die_task); |
686 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)"); | 713 | die_task = |
714 | GNUNET_SCHEDULER_add_now (&end_badly, | ||
715 | "from topology_callback (too many failed connections)"); | ||
687 | } | 716 | } |
688 | } | 717 | } |
689 | else | 718 | else |
@@ -691,17 +720,20 @@ topology_callback (void *cls, | |||
691 | #if VERBOSE > 1 | 720 | #if VERBOSE > 1 |
692 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 721 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
693 | "Have %d total connections, %d failed connections, Want %d (at least %d)\n", | 722 | "Have %d total connections, %d failed connections, Want %d (at least %d)\n", |
694 | total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections)); | 723 | total_connections, failed_connections, expected_connections, |
724 | expected_connections - | ||
725 | (unsigned int) (fail_percentage * expected_connections)); | ||
695 | #endif | 726 | #endif |
696 | } | 727 | } |
697 | } | 728 | } |
698 | 729 | ||
699 | static void topology_creation_finished (void *cls, | 730 | static void |
700 | const char *emsg) | 731 | topology_creation_finished (void *cls, const char *emsg) |
701 | { | 732 | { |
702 | #if VERBOSE | 733 | #if VERBOSE |
703 | if (emsg == NULL) | 734 | if (emsg == NULL) |
704 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All topology connections created successfully!\n"); | 735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
736 | "All topology connections created successfully!\n"); | ||
705 | #endif | 737 | #endif |
706 | } | 738 | } |
707 | 739 | ||
@@ -711,7 +743,11 @@ connect_topology () | |||
711 | expected_connections = -1; | 743 | expected_connections = -1; |
712 | if ((pg != NULL) && (peers_left == 0)) | 744 | if ((pg != NULL) && (peers_left == 0)) |
713 | { | 745 | { |
714 | expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier, &topology_creation_finished, NULL); | 746 | expected_connections = |
747 | GNUNET_TESTING_connect_topology (pg, connection_topology, | ||
748 | connect_topology_option, | ||
749 | connect_topology_option_modifier, | ||
750 | &topology_creation_finished, NULL); | ||
715 | #if VERBOSE > 1 | 751 | #if VERBOSE > 1 |
716 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 752 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
717 | "Have %d expected connections\n", expected_connections); | 753 | "Have %d expected connections\n", expected_connections); |
@@ -721,52 +757,60 @@ connect_topology () | |||
721 | GNUNET_SCHEDULER_cancel (die_task); | 757 | GNUNET_SCHEDULER_cancel (die_task); |
722 | if (expected_connections == GNUNET_SYSERR) | 758 | if (expected_connections == GNUNET_SYSERR) |
723 | { | 759 | { |
724 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)"); | 760 | die_task = |
761 | GNUNET_SCHEDULER_add_now (&end_badly, | ||
762 | "from connect topology (bad return)"); | ||
725 | } | 763 | } |
726 | 764 | ||
727 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, | 765 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, |
728 | &end_badly, "from connect topology (timeout)"); | 766 | &end_badly, |
767 | "from connect topology (timeout)"); | ||
729 | modnum = expected_connections / 4; | 768 | modnum = expected_connections / 4; |
730 | dotnum = (expected_connections / 50) + 1; | 769 | dotnum = (expected_connections / 50) + 1; |
731 | #if VERBOSE | 770 | #if VERBOSE |
732 | fprintf(stdout, "Peer connection progress: ["); | 771 | fprintf (stdout, "Peer connection progress: ["); |
733 | #endif | 772 | #endif |
734 | } | 773 | } |
735 | 774 | ||
736 | static void | 775 | static void |
737 | create_topology () | 776 | create_topology () |
738 | { | 777 | { |
739 | peers_left = num_peers; /* Reset counter */ | 778 | peers_left = num_peers; /* Reset counter */ |
740 | if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR) | 779 | if (GNUNET_TESTING_create_topology |
780 | (pg, topology, blacklist_topology, | ||
781 | blacklist_transports) != GNUNET_SYSERR) | ||
741 | { | 782 | { |
742 | #if VERBOSE | 783 | #if VERBOSE |
743 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 784 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
744 | "Topology set up, now starting peers!\n"); | 785 | "Topology set up, now starting peers!\n"); |
745 | fprintf(stdout, "Daemon start progress ["); | 786 | fprintf (stdout, "Daemon start progress ["); |
746 | #endif | 787 | #endif |
747 | GNUNET_TESTING_daemons_continue_startup(pg); | 788 | GNUNET_TESTING_daemons_continue_startup (pg); |
748 | } | 789 | } |
749 | else | 790 | else |
750 | { | 791 | { |
751 | GNUNET_SCHEDULER_cancel (die_task); | 792 | GNUNET_SCHEDULER_cancel (die_task); |
752 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from create topology (bad return)"); | 793 | die_task = |
794 | GNUNET_SCHEDULER_add_now (&end_badly, | ||
795 | "from create topology (bad return)"); | ||
753 | } | 796 | } |
754 | GNUNET_SCHEDULER_cancel (die_task); | 797 | GNUNET_SCHEDULER_cancel (die_task); |
755 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, | 798 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, |
756 | &end_badly, "from continue startup (timeout)"); | 799 | &end_badly, |
800 | "from continue startup (timeout)"); | ||
757 | } | 801 | } |
758 | 802 | ||
759 | 803 | ||
760 | static void | 804 | static void |
761 | peers_started_callback (void *cls, | 805 | peers_started_callback (void *cls, |
762 | const struct GNUNET_PeerIdentity *id, | 806 | const struct GNUNET_PeerIdentity *id, |
763 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 807 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
764 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 808 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
765 | { | 809 | { |
766 | if (emsg != NULL) | 810 | if (emsg != NULL) |
767 | { | 811 | { |
768 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n", | 812 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
769 | emsg); | 813 | "Failed to start daemon with error: `%s'\n", emsg); |
770 | return; | 814 | return; |
771 | } | 815 | } |
772 | GNUNET_assert (id != NULL); | 816 | GNUNET_assert (id != NULL); |
@@ -775,27 +819,27 @@ peers_started_callback (void *cls, | |||
775 | (num_peers - peers_left) + 1, num_peers); | 819 | (num_peers - peers_left) + 1, num_peers); |
776 | #endif | 820 | #endif |
777 | #if VERBOSE | 821 | #if VERBOSE |
778 | if ((num_peers - peers_left) % modnum == 0) | 822 | if ((num_peers - peers_left) % modnum == 0) |
779 | { | 823 | { |
780 | if (num_peers - peers_left == 0) | 824 | if (num_peers - peers_left == 0) |
781 | fprintf (stdout, "0%%"); | 825 | fprintf (stdout, "0%%"); |
782 | else | 826 | else |
783 | fprintf (stdout, "%d%%", | 827 | fprintf (stdout, "%d%%", |
784 | (int) (((float) (num_peers - peers_left) / | 828 | (int) (((float) (num_peers - peers_left) / |
785 | num_peers) * 100)); | 829 | num_peers) * 100)); |
786 | 830 | ||
787 | } | 831 | } |
788 | else if ((num_peers - peers_left) % dotnum == 0) | 832 | else if ((num_peers - peers_left) % dotnum == 0) |
789 | { | 833 | { |
790 | fprintf (stdout, "."); | 834 | fprintf (stdout, "."); |
791 | } | 835 | } |
792 | fflush (stdout); | 836 | fflush (stdout); |
793 | #endif | 837 | #endif |
794 | peers_left--; | 838 | peers_left--; |
795 | if (peers_left == 0) | 839 | if (peers_left == 0) |
796 | { | 840 | { |
797 | #if VERBOSE | 841 | #if VERBOSE |
798 | fprintf(stdout, "100%%]\n"); | 842 | fprintf (stdout, "100%%]\n"); |
799 | #endif | 843 | #endif |
800 | #if VERBOSE | 844 | #if VERBOSE |
801 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 845 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -807,10 +851,11 @@ peers_started_callback (void *cls, | |||
807 | * within a reasonable amount of time */ | 851 | * within a reasonable amount of time */ |
808 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 852 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
809 | (GNUNET_TIME_UNIT_MINUTES, 8), | 853 | (GNUNET_TIME_UNIT_MINUTES, 8), |
810 | &end_badly, "from peers_started_callback"); | 854 | &end_badly, |
855 | "from peers_started_callback"); | ||
811 | #if DELAY_FOR_LOGGING | 856 | #if DELAY_FOR_LOGGING |
812 | fprintf(stdout, "Connecting topology in 10 seconds\n"); | 857 | fprintf (stdout, "Connecting topology in 10 seconds\n"); |
813 | gather_log_data(); | 858 | gather_log_data (); |
814 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 859 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
815 | (GNUNET_TIME_UNIT_SECONDS, 10), | 860 | (GNUNET_TIME_UNIT_SECONDS, 10), |
816 | &connect_topology, NULL); | 861 | &connect_topology, NULL); |
@@ -829,56 +874,58 @@ peers_started_callback (void *cls, | |||
829 | * @param d the daemon handle (pretty useless at this point, remove?) | 874 | * @param d the daemon handle (pretty useless at this point, remove?) |
830 | * @param emsg non-null on failure | 875 | * @param emsg non-null on failure |
831 | */ | 876 | */ |
832 | void hostkey_callback (void *cls, | 877 | void |
833 | const struct GNUNET_PeerIdentity *id, | 878 | hostkey_callback (void *cls, |
834 | struct GNUNET_TESTING_Daemon *d, | 879 | const struct GNUNET_PeerIdentity *id, |
835 | const char *emsg) | 880 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
836 | { | 881 | { |
837 | if (emsg != NULL) | 882 | if (emsg != NULL) |
838 | { | 883 | { |
839 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg); | 884 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
885 | "Hostkey callback received error: %s\n", emsg); | ||
840 | } | 886 | } |
841 | 887 | ||
842 | #if VERBOSE > 1 | 888 | #if VERBOSE > 1 |
843 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 889 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
844 | "Hostkey (%d/%d) created for peer `%s'\n", | 890 | "Hostkey (%d/%d) created for peer `%s'\n", |
845 | num_peers - peers_left, num_peers, GNUNET_i2s(id)); | 891 | num_peers - peers_left, num_peers, GNUNET_i2s (id)); |
846 | #endif | 892 | #endif |
847 | 893 | ||
848 | #if VERBOSE | 894 | #if VERBOSE |
849 | if ((num_peers - peers_left) % modnum == 0) | 895 | if ((num_peers - peers_left) % modnum == 0) |
850 | { | 896 | { |
851 | if (num_peers - peers_left == 0) | 897 | if (num_peers - peers_left == 0) |
852 | fprintf (stdout, "0%%"); | 898 | fprintf (stdout, "0%%"); |
853 | else | 899 | else |
854 | fprintf (stdout, "%d%%", | 900 | fprintf (stdout, "%d%%", |
855 | (int) (((float) (num_peers - peers_left) / | 901 | (int) (((float) (num_peers - peers_left) / |
856 | num_peers) * 100)); | 902 | num_peers) * 100)); |
857 | 903 | ||
858 | } | 904 | } |
859 | else if ((num_peers - peers_left) % dotnum == 0) | 905 | else if ((num_peers - peers_left) % dotnum == 0) |
860 | { | 906 | { |
861 | fprintf (stdout, "."); | 907 | fprintf (stdout, "."); |
862 | } | 908 | } |
863 | fflush (stdout); | 909 | fflush (stdout); |
864 | #endif | 910 | #endif |
865 | peers_left--; | 911 | peers_left--; |
866 | if (peers_left == 0) | 912 | if (peers_left == 0) |
867 | { | 913 | { |
868 | #if VERBOSE | 914 | #if VERBOSE |
869 | fprintf(stdout, "100%%]\n"); | 915 | fprintf (stdout, "100%%]\n"); |
870 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 916 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
871 | "All %d hostkeys created, now creating topology!\n", | 917 | "All %d hostkeys created, now creating topology!\n", |
872 | num_peers); | 918 | num_peers); |
873 | #endif | 919 | #endif |
874 | GNUNET_SCHEDULER_cancel (die_task); | 920 | GNUNET_SCHEDULER_cancel (die_task); |
875 | /* Set up task in case topology creation doesn't finish | 921 | /* Set up task in case topology creation doesn't finish |
876 | * within a reasonable amount of time */ | 922 | * within a reasonable amount of time */ |
877 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 923 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
878 | &end_badly, "from create_topology"); | 924 | &end_badly, |
879 | GNUNET_SCHEDULER_add_now(&create_topology, NULL); | 925 | "from create_topology"); |
880 | ok = 0; | 926 | GNUNET_SCHEDULER_add_now (&create_topology, NULL); |
881 | } | 927 | ok = 0; |
928 | } | ||
882 | } | 929 | } |
883 | 930 | ||
884 | static void | 931 | static void |
@@ -886,11 +933,11 @@ run (void *cls, | |||
886 | char *const *args, | 933 | char *const *args, |
887 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | 934 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
888 | { | 935 | { |
889 | char * topology_str; | 936 | char *topology_str; |
890 | char * connect_topology_str; | 937 | char *connect_topology_str; |
891 | char * blacklist_topology_str; | 938 | char *blacklist_topology_str; |
892 | char * connect_topology_option_str; | 939 | char *connect_topology_option_str; |
893 | char * connect_topology_option_modifier_string; | 940 | char *connect_topology_option_modifier_string; |
894 | unsigned long long temp_settle; | 941 | unsigned long long temp_settle; |
895 | ok = 1; | 942 | ok = 1; |
896 | 943 | ||
@@ -905,71 +952,97 @@ run (void *cls, | |||
905 | "Starting daemons based on config file %s\n", cfgfile); | 952 | "Starting daemons based on config file %s\n", cfgfile); |
906 | #endif | 953 | #endif |
907 | 954 | ||
908 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) | 955 | if (GNUNET_YES != |
956 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", | ||
957 | &test_directory)) | ||
909 | { | 958 | { |
910 | ok = 404; | 959 | ok = 404; |
911 | return; | 960 | return; |
912 | } | 961 | } |
913 | 962 | ||
914 | if ((GNUNET_YES == | 963 | if ((GNUNET_YES == |
915 | GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology", | 964 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology", |
916 | &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str))) | 965 | &topology_str)) |
966 | && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str))) | ||
917 | { | 967 | { |
918 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 968 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
919 | "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY"); | 969 | "Invalid topology `%s' given for section %s option %s\n", |
920 | topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ | 970 | topology_str, "TESTING", "TOPOLOGY"); |
971 | topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ | ||
921 | } | 972 | } |
922 | 973 | ||
923 | if ((GNUNET_YES == | 974 | if ((GNUNET_YES == |
924 | GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology", | 975 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
925 | &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str))) | 976 | "connect_topology", |
977 | &connect_topology_str)) | ||
978 | && (GNUNET_NO == | ||
979 | GNUNET_TESTING_topology_get (&connection_topology, | ||
980 | connect_topology_str))) | ||
926 | { | 981 | { |
927 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 982 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
928 | "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY"); | 983 | "Invalid connect topology `%s' given for section %s option %s\n", |
984 | connect_topology_str, "TESTING", "CONNECT_TOPOLOGY"); | ||
929 | } | 985 | } |
930 | GNUNET_free_non_null(connect_topology_str); | 986 | GNUNET_free_non_null (connect_topology_str); |
931 | if ((GNUNET_YES == | 987 | if ((GNUNET_YES == |
932 | GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option", | 988 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
933 | &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str))) | 989 | "connect_topology_option", |
990 | &connect_topology_option_str)) | ||
991 | && (GNUNET_NO == | ||
992 | GNUNET_TESTING_topology_option_get (&connect_topology_option, | ||
993 | connect_topology_option_str))) | ||
934 | { | 994 | { |
935 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 995 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
936 | "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION"); | 996 | "Invalid connect topology option `%s' given for section %s option %s\n", |
937 | connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ | 997 | connect_topology_option_str, "TESTING", |
998 | "CONNECT_TOPOLOGY_OPTION"); | ||
999 | connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ | ||
938 | } | 1000 | } |
939 | GNUNET_free_non_null(connect_topology_option_str); | 1001 | GNUNET_free_non_null (connect_topology_option_str); |
940 | if (GNUNET_YES == | 1002 | if (GNUNET_YES == |
941 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier", | 1003 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
942 | &connect_topology_option_modifier_string)) | 1004 | "connect_topology_option_modifier", |
1005 | &connect_topology_option_modifier_string)) | ||
943 | { | 1006 | { |
944 | if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1) | 1007 | if (sscanf |
945 | { | 1008 | (connect_topology_option_modifier_string, "%lf", |
946 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1009 | &connect_topology_option_modifier) != 1) |
947 | _("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1010 | { |
948 | connect_topology_option_modifier_string, | 1011 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
949 | "connect_topology_option_modifier", | 1012 | _ |
950 | "TESTING"); | 1013 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
951 | } | 1014 | connect_topology_option_modifier_string, |
1015 | "connect_topology_option_modifier", "TESTING"); | ||
1016 | } | ||
952 | GNUNET_free (connect_topology_option_modifier_string); | 1017 | GNUNET_free (connect_topology_option_modifier_string); |
953 | } | 1018 | } |
954 | 1019 | ||
955 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports", | 1020 | if (GNUNET_YES != |
956 | &blacklist_transports)) | 1021 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
1022 | "blacklist_transports", | ||
1023 | &blacklist_transports)) | ||
957 | blacklist_transports = NULL; | 1024 | blacklist_transports = NULL; |
958 | 1025 | ||
959 | if ((GNUNET_YES == | 1026 | if ((GNUNET_YES == |
960 | GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology", | 1027 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
961 | &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str))) | 1028 | "blacklist_topology", |
1029 | &blacklist_topology_str)) | ||
1030 | && (GNUNET_NO == | ||
1031 | GNUNET_TESTING_topology_get (&blacklist_topology, | ||
1032 | blacklist_topology_str))) | ||
962 | { | 1033 | { |
963 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1034 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
964 | "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY"); | 1035 | "Invalid topology `%s' given for section %s option %s\n", |
1036 | topology_str, "TESTING", "BLACKLIST_TOPOLOGY"); | ||
965 | } | 1037 | } |
966 | GNUNET_free_non_null(topology_str); | 1038 | GNUNET_free_non_null (topology_str); |
967 | GNUNET_free_non_null(blacklist_topology_str); | 1039 | GNUNET_free_non_null (blacklist_topology_str); |
968 | 1040 | ||
969 | if (GNUNET_OK == | 1041 | if (GNUNET_OK == |
970 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time", | 1042 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time", |
971 | &temp_settle)) | 1043 | &temp_settle)) |
972 | settle_time = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_settle); | 1044 | settle_time = |
1045 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle); | ||
973 | 1046 | ||
974 | if (GNUNET_SYSERR == | 1047 | if (GNUNET_SYSERR == |
975 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", | 1048 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", |
@@ -985,12 +1058,21 @@ run (void *cls, | |||
985 | fprintf (stdout, "Hostkey generation progress: ["); | 1058 | fprintf (stdout, "Hostkey generation progress: ["); |
986 | #endif | 1059 | #endif |
987 | /* Set up a task to end testing if peer start fails */ | 1060 | /* Set up a task to end testing if peer start fails */ |
988 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), | 1061 | die_task = |
989 | &end_badly, "didn't generate all hostkeys within a reasonable amount of time!!!"); | 1062 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
990 | 1063 | (GNUNET_TIME_UNIT_SECONDS, | |
991 | GNUNET_assert(num_peers > 0 && num_peers < (unsigned int)-1); | 1064 | SECONDS_PER_PEER_START * num_peers), |
1065 | &end_badly, | ||
1066 | "didn't generate all hostkeys within a reasonable amount of time!!!"); | ||
1067 | |||
1068 | GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1); | ||
992 | pg = GNUNET_TESTING_daemons_start (cfg, | 1069 | pg = GNUNET_TESTING_daemons_start (cfg, |
993 | peers_left, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), &hostkey_callback, NULL, &peers_started_callback, NULL, | 1070 | peers_left, |
1071 | GNUNET_TIME_relative_multiply | ||
1072 | (GNUNET_TIME_UNIT_SECONDS, | ||
1073 | SECONDS_PER_PEER_START * num_peers), | ||
1074 | &hostkey_callback, NULL, | ||
1075 | &peers_started_callback, NULL, | ||
994 | &topology_callback, NULL, NULL); | 1076 | &topology_callback, NULL, NULL); |
995 | 1077 | ||
996 | } | 1078 | } |
@@ -1000,10 +1082,11 @@ check () | |||
1000 | { | 1082 | { |
1001 | char *binary_name; | 1083 | char *binary_name; |
1002 | char *config_file_name; | 1084 | char *config_file_name; |
1003 | GNUNET_asprintf(&binary_name, "test-testing-topology-%s", topology_string); | 1085 | GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string); |
1004 | GNUNET_asprintf(&config_file_name, "test_testing_data_topology_%s.conf", topology_string); | 1086 | GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf", |
1087 | topology_string); | ||
1005 | int ret; | 1088 | int ret; |
1006 | char *const argv[] = {binary_name, | 1089 | char *const argv[] = { binary_name, |
1007 | "-c", | 1090 | "-c", |
1008 | config_file_name, | 1091 | config_file_name, |
1009 | #if VERBOSE | 1092 | #if VERBOSE |
@@ -1015,14 +1098,15 @@ check () | |||
1015 | GNUNET_GETOPT_OPTION_END | 1098 | GNUNET_GETOPT_OPTION_END |
1016 | }; | 1099 | }; |
1017 | ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 1100 | ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
1018 | argv, binary_name, "nohelp", | 1101 | argv, binary_name, "nohelp", options, &run, &ok); |
1019 | options, &run, &ok); | ||
1020 | if (ret != GNUNET_OK) | 1102 | if (ret != GNUNET_OK) |
1021 | { | 1103 | { |
1022 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-testing-topology-%s': Failed with error code %d\n", topology_string, ret); | 1104 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1105 | "`test-testing-topology-%s': Failed with error code %d\n", | ||
1106 | topology_string, ret); | ||
1023 | } | 1107 | } |
1024 | GNUNET_free(binary_name); | 1108 | GNUNET_free (binary_name); |
1025 | GNUNET_free(config_file_name); | 1109 | GNUNET_free (config_file_name); |
1026 | return ok; | 1110 | return ok; |
1027 | } | 1111 | } |
1028 | 1112 | ||
@@ -1033,18 +1117,18 @@ main (int argc, char *argv[]) | |||
1033 | char *binary_start_pos; | 1117 | char *binary_start_pos; |
1034 | char *our_binary_name; | 1118 | char *our_binary_name; |
1035 | 1119 | ||
1036 | binary_start_pos = rindex(argv[0], '/'); | 1120 | binary_start_pos = rindex (argv[0], '/'); |
1037 | GNUNET_assert(binary_start_pos != NULL); | 1121 | GNUNET_assert (binary_start_pos != NULL); |
1038 | topology_string = strstr (binary_start_pos, | 1122 | topology_string = strstr (binary_start_pos, "_topology"); |
1039 | "_topology"); | ||
1040 | GNUNET_assert (topology_string != NULL); | 1123 | GNUNET_assert (topology_string != NULL); |
1041 | topology_string++; | 1124 | topology_string++; |
1042 | topology_string = strstr (topology_string, "_"); | 1125 | topology_string = strstr (topology_string, "_"); |
1043 | GNUNET_assert (topology_string != NULL); | 1126 | GNUNET_assert (topology_string != NULL); |
1044 | topology_string++; | 1127 | topology_string++; |
1045 | 1128 | ||
1046 | GNUNET_asprintf(&our_binary_name, "test-testing-topology_%s", topology_string); | 1129 | GNUNET_asprintf (&our_binary_name, "test-testing-topology_%s", |
1047 | GNUNET_asprintf(&dotOutFileName, "topology_%s.dot", topology_string); | 1130 | topology_string); |
1131 | GNUNET_asprintf (&dotOutFileName, "topology_%s.dot", topology_string); | ||
1048 | 1132 | ||
1049 | GNUNET_log_setup (our_binary_name, | 1133 | GNUNET_log_setup (our_binary_name, |
1050 | #if VERBOSE | 1134 | #if VERBOSE |
@@ -1061,9 +1145,10 @@ main (int argc, char *argv[]) | |||
1061 | */ | 1145 | */ |
1062 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) | 1146 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) |
1063 | { | 1147 | { |
1064 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory); | 1148 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1149 | "Failed to remove testing directory %s\n", test_directory); | ||
1065 | } | 1150 | } |
1066 | GNUNET_free(our_binary_name); | 1151 | GNUNET_free (our_binary_name); |
1067 | return ret; | 1152 | return ret; |
1068 | } | 1153 | } |
1069 | 1154 | ||
diff --git a/src/testing/test_testing_topology_blacklist.c b/src/testing/test_testing_topology_blacklist.c index 13df683e9..1123c2f39 100644 --- a/src/testing/test_testing_topology_blacklist.c +++ b/src/testing/test_testing_topology_blacklist.c | |||
@@ -67,9 +67,9 @@ static FILE *dotOutFile; | |||
67 | 67 | ||
68 | static char *blacklist_transports; | 68 | static char *blacklist_transports; |
69 | 69 | ||
70 | static enum GNUNET_TESTING_Topology topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Overlay should allow all connections */ | 70 | static enum GNUNET_TESTING_Topology topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Overlay should allow all connections */ |
71 | 71 | ||
72 | static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_RING; /* Blacklist underlay into a ring */ | 72 | static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_RING; /* Blacklist underlay into a ring */ |
73 | 73 | ||
74 | static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */ | 74 | static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */ |
75 | 75 | ||
@@ -98,14 +98,13 @@ struct GNUNET_TestMessage | |||
98 | /** | 98 | /** |
99 | * Check whether peers successfully shut down. | 99 | * Check whether peers successfully shut down. |
100 | */ | 100 | */ |
101 | void shutdown_callback (void *cls, | 101 | void |
102 | const char *emsg) | 102 | shutdown_callback (void *cls, const char *emsg) |
103 | { | 103 | { |
104 | if (emsg != NULL) | 104 | if (emsg != NULL) |
105 | { | 105 | { |
106 | #if VERBOSE | 106 | #if VERBOSE |
107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); |
108 | "Shutdown of peers failed!\n"); | ||
109 | #endif | 108 | #endif |
110 | if (ok == 0) | 109 | if (ok == 0) |
111 | ok = 666; | 110 | ok = 666; |
@@ -128,27 +127,25 @@ finish_testing () | |||
128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
129 | "Called finish testing, stopping daemons.\n"); | 128 | "Called finish testing, stopping daemons.\n"); |
130 | #endif | 129 | #endif |
131 | sleep(1); | 130 | sleep (1); |
132 | #if VERBOSE | 131 | #if VERBOSE |
133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n"); |
134 | "Calling daemons_stop\n"); | ||
135 | #endif | 133 | #endif |
136 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 134 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
137 | #if VERBOSE | 135 | #if VERBOSE |
138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "daemons_stop finished\n"); |
139 | "daemons_stop finished\n"); | ||
140 | #endif | 137 | #endif |
141 | if (dotOutFile != NULL) | 138 | if (dotOutFile != NULL) |
142 | { | 139 | { |
143 | fprintf(dotOutFile, "}"); | 140 | fprintf (dotOutFile, "}"); |
144 | fclose(dotOutFile); | 141 | fclose (dotOutFile); |
145 | } | 142 | } |
146 | 143 | ||
147 | ok = 0; | 144 | ok = 0; |
148 | } | 145 | } |
149 | 146 | ||
150 | static void | 147 | static void |
151 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 148 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
152 | { | 149 | { |
153 | char *msg = cls; | 150 | char *msg = cls; |
154 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 151 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -164,8 +161,8 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
164 | 161 | ||
165 | if (dotOutFile != NULL) | 162 | if (dotOutFile != NULL) |
166 | { | 163 | { |
167 | fprintf(dotOutFile, "}"); | 164 | fprintf (dotOutFile, "}"); |
168 | fclose(dotOutFile); | 165 | fclose (dotOutFile); |
169 | } | 166 | } |
170 | } | 167 | } |
171 | 168 | ||
@@ -187,19 +184,19 @@ topology_callback (void *cls, | |||
187 | total_connections++; | 184 | total_connections++; |
188 | #if VERBOSE | 185 | #if VERBOSE |
189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n", | 186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n", |
190 | first_daemon->shortname, | 187 | first_daemon->shortname, second_daemon->shortname); |
191 | second_daemon->shortname); | ||
192 | #endif | 188 | #endif |
193 | if (dotOutFile != NULL) | 189 | if (dotOutFile != NULL) |
194 | fprintf(dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, second_daemon->shortname); | 190 | fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, |
191 | second_daemon->shortname); | ||
195 | } | 192 | } |
196 | #if VERBOSE | 193 | #if VERBOSE |
197 | else | 194 | else |
198 | { | 195 | { |
199 | failed_connections++; | 196 | failed_connections++; |
200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n", | 197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
201 | first_daemon->shortname, | 198 | "Failed to connect peer %s to peer %s with error :\n%s\n", |
202 | second_daemon->shortname, emsg); | 199 | first_daemon->shortname, second_daemon->shortname, emsg); |
203 | } | 200 | } |
204 | #endif | 201 | #endif |
205 | 202 | ||
@@ -213,11 +210,15 @@ topology_callback (void *cls, | |||
213 | 210 | ||
214 | GNUNET_SCHEDULER_cancel (die_task); | 211 | GNUNET_SCHEDULER_cancel (die_task); |
215 | die_task = GNUNET_SCHEDULER_NO_TASK; | 212 | die_task = GNUNET_SCHEDULER_NO_TASK; |
216 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many successful connections)"); | 213 | die_task = |
214 | GNUNET_SCHEDULER_add_now (&end_badly, | ||
215 | "from topology_callback (too many successful connections)"); | ||
217 | } | 216 | } |
218 | else if (total_connections + failed_connections == expected_connections) | 217 | else if (total_connections + failed_connections == expected_connections) |
219 | { | 218 | { |
220 | if ((failed_connections == expected_failed_connections) && (total_connections == expected_connections - expected_failed_connections)) | 219 | if ((failed_connections == expected_failed_connections) |
220 | && (total_connections == | ||
221 | expected_connections - expected_failed_connections)) | ||
221 | { | 222 | { |
222 | GNUNET_SCHEDULER_cancel (die_task); | 223 | GNUNET_SCHEDULER_cancel (die_task); |
223 | die_task = GNUNET_SCHEDULER_NO_TASK; | 224 | die_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -226,7 +227,9 @@ topology_callback (void *cls, | |||
226 | else | 227 | else |
227 | { | 228 | { |
228 | GNUNET_SCHEDULER_cancel (die_task); | 229 | GNUNET_SCHEDULER_cancel (die_task); |
229 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (wrong number of failed connections)"); | 230 | die_task = |
231 | GNUNET_SCHEDULER_add_now (&end_badly, | ||
232 | "from topology_callback (wrong number of failed connections)"); | ||
230 | } | 233 | } |
231 | } | 234 | } |
232 | else | 235 | else |
@@ -234,7 +237,9 @@ topology_callback (void *cls, | |||
234 | #if VERBOSE | 237 | #if VERBOSE |
235 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
236 | "Have %d total connections, %d failed connections, Want %d (failed) and %d (successful)\n", | 239 | "Have %d total connections, %d failed connections, Want %d (failed) and %d (successful)\n", |
237 | total_connections, failed_connections, expected_failed_connections, expected_connections - expected_failed_connections); | 240 | total_connections, failed_connections, |
241 | expected_failed_connections, | ||
242 | expected_connections - expected_failed_connections); | ||
238 | #endif | 243 | #endif |
239 | } | 244 | } |
240 | } | 245 | } |
@@ -245,7 +250,11 @@ connect_topology () | |||
245 | expected_connections = -1; | 250 | expected_connections = -1; |
246 | if ((pg != NULL) && (peers_left == 0)) | 251 | if ((pg != NULL) && (peers_left == 0)) |
247 | { | 252 | { |
248 | expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier, NULL, NULL); | 253 | expected_connections = |
254 | GNUNET_TESTING_connect_topology (pg, connection_topology, | ||
255 | connect_topology_option, | ||
256 | connect_topology_option_modifier, | ||
257 | NULL, NULL); | ||
249 | #if VERBOSE | 258 | #if VERBOSE |
250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
251 | "Have %d expected connections\n", expected_connections); | 260 | "Have %d expected connections\n", expected_connections); |
@@ -255,46 +264,54 @@ connect_topology () | |||
255 | GNUNET_SCHEDULER_cancel (die_task); | 264 | GNUNET_SCHEDULER_cancel (die_task); |
256 | if (expected_connections == GNUNET_SYSERR) | 265 | if (expected_connections == GNUNET_SYSERR) |
257 | { | 266 | { |
258 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)"); | 267 | die_task = |
268 | GNUNET_SCHEDULER_add_now (&end_badly, | ||
269 | "from connect topology (bad return)"); | ||
259 | } | 270 | } |
260 | 271 | ||
261 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, | 272 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, |
262 | &end_badly, "from connect topology (timeout)"); | 273 | &end_badly, |
274 | "from connect topology (timeout)"); | ||
263 | } | 275 | } |
264 | 276 | ||
265 | static void | 277 | static void |
266 | create_topology () | 278 | create_topology () |
267 | { | 279 | { |
268 | peers_left = num_peers; /* Reset counter */ | 280 | peers_left = num_peers; /* Reset counter */ |
269 | if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR) | 281 | if (GNUNET_TESTING_create_topology |
282 | (pg, topology, blacklist_topology, | ||
283 | blacklist_transports) != GNUNET_SYSERR) | ||
270 | { | 284 | { |
271 | #if VERBOSE | 285 | #if VERBOSE |
272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
273 | "Topology set up, now starting peers!\n"); | 287 | "Topology set up, now starting peers!\n"); |
274 | #endif | 288 | #endif |
275 | GNUNET_TESTING_daemons_continue_startup(pg); | 289 | GNUNET_TESTING_daemons_continue_startup (pg); |
276 | } | 290 | } |
277 | else | 291 | else |
278 | { | 292 | { |
279 | GNUNET_SCHEDULER_cancel (die_task); | 293 | GNUNET_SCHEDULER_cancel (die_task); |
280 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from create topology (bad return)"); | 294 | die_task = |
295 | GNUNET_SCHEDULER_add_now (&end_badly, | ||
296 | "from create topology (bad return)"); | ||
281 | } | 297 | } |
282 | GNUNET_SCHEDULER_cancel (die_task); | 298 | GNUNET_SCHEDULER_cancel (die_task); |
283 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, | 299 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, |
284 | &end_badly, "from continue startup (timeout)"); | 300 | &end_badly, |
301 | "from continue startup (timeout)"); | ||
285 | } | 302 | } |
286 | 303 | ||
287 | 304 | ||
288 | static void | 305 | static void |
289 | peers_started_callback (void *cls, | 306 | peers_started_callback (void *cls, |
290 | const struct GNUNET_PeerIdentity *id, | 307 | const struct GNUNET_PeerIdentity *id, |
291 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 308 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
292 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 309 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
293 | { | 310 | { |
294 | if (emsg != NULL) | 311 | if (emsg != NULL) |
295 | { | 312 | { |
296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n", | 313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
297 | emsg); | 314 | "Failed to start daemon with error: `%s'\n", emsg); |
298 | return; | 315 | return; |
299 | } | 316 | } |
300 | GNUNET_assert (id != NULL); | 317 | GNUNET_assert (id != NULL); |
@@ -315,7 +332,8 @@ peers_started_callback (void *cls, | |||
315 | * within a reasonable amount of time */ | 332 | * within a reasonable amount of time */ |
316 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 333 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
317 | (GNUNET_TIME_UNIT_MINUTES, 5), | 334 | (GNUNET_TIME_UNIT_MINUTES, 5), |
318 | &end_badly, "from peers_started_callback"); | 335 | &end_badly, |
336 | "from peers_started_callback"); | ||
319 | connect_topology (); | 337 | connect_topology (); |
320 | ok = 0; | 338 | ok = 0; |
321 | } | 339 | } |
@@ -329,38 +347,39 @@ peers_started_callback (void *cls, | |||
329 | * @param d the daemon handle (pretty useless at this point, remove?) | 347 | * @param d the daemon handle (pretty useless at this point, remove?) |
330 | * @param emsg non-null on failure | 348 | * @param emsg non-null on failure |
331 | */ | 349 | */ |
332 | void hostkey_callback (void *cls, | 350 | void |
333 | const struct GNUNET_PeerIdentity *id, | 351 | hostkey_callback (void *cls, |
334 | struct GNUNET_TESTING_Daemon *d, | 352 | const struct GNUNET_PeerIdentity *id, |
335 | const char *emsg) | 353 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
336 | { | 354 | { |
337 | if (emsg != NULL) | 355 | if (emsg != NULL) |
338 | { | 356 | { |
339 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg); | 357 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
358 | "Hostkey callback received error: %s\n", emsg); | ||
340 | } | 359 | } |
341 | 360 | ||
342 | #if VERBOSE | 361 | #if VERBOSE |
343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
344 | "Hostkey created for peer `%s'\n", | 363 | "Hostkey created for peer `%s'\n", GNUNET_i2s (id)); |
345 | GNUNET_i2s(id)); | ||
346 | #endif | 364 | #endif |
347 | peers_left--; | 365 | peers_left--; |
348 | if (peers_left == 0) | 366 | if (peers_left == 0) |
349 | { | 367 | { |
350 | #if VERBOSE | 368 | #if VERBOSE |
351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
352 | "All %d hostkeys created, now creating topology!\n", | 370 | "All %d hostkeys created, now creating topology!\n", |
353 | num_peers); | 371 | num_peers); |
354 | #endif | 372 | #endif |
355 | GNUNET_SCHEDULER_cancel (die_task); | 373 | GNUNET_SCHEDULER_cancel (die_task); |
356 | /* Set up task in case topology creation doesn't finish | 374 | /* Set up task in case topology creation doesn't finish |
357 | * within a reasonable amount of time */ | 375 | * within a reasonable amount of time */ |
358 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 376 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
359 | (GNUNET_TIME_UNIT_MINUTES, 5), | 377 | (GNUNET_TIME_UNIT_MINUTES, 5), |
360 | &end_badly, "from hostkey_callback"); | 378 | &end_badly, |
361 | GNUNET_SCHEDULER_add_now(&create_topology, NULL); | 379 | "from hostkey_callback"); |
362 | ok = 0; | 380 | GNUNET_SCHEDULER_add_now (&create_topology, NULL); |
363 | } | 381 | ok = 0; |
382 | } | ||
364 | } | 383 | } |
365 | 384 | ||
366 | static void | 385 | static void |
@@ -386,12 +405,14 @@ run (void *cls, | |||
386 | "Starting daemons based on config file %s\n", cfgfile); | 405 | "Starting daemons based on config file %s\n", cfgfile); |
387 | #endif | 406 | #endif |
388 | 407 | ||
389 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) | 408 | if (GNUNET_YES != |
409 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", | ||
410 | &test_directory)) | ||
390 | { | 411 | { |
391 | ok = 404; | 412 | ok = 404; |
392 | if (dotOutFile != NULL) | 413 | if (dotOutFile != NULL) |
393 | { | 414 | { |
394 | fclose(dotOutFile); | 415 | fclose (dotOutFile); |
395 | } | 416 | } |
396 | return; | 417 | return; |
397 | } | 418 | } |
@@ -402,51 +423,60 @@ run (void *cls, | |||
402 | topology = topology_num; | 423 | topology = topology_num; |
403 | 424 | ||
404 | if (GNUNET_YES == | 425 | if (GNUNET_YES == |
405 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_topology", | 426 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", |
427 | "connect_topology", | ||
406 | &connect_topology_num)) | 428 | &connect_topology_num)) |
407 | connection_topology = connect_topology_num; | 429 | connection_topology = connect_topology_num; |
408 | 430 | ||
409 | if (GNUNET_YES == | 431 | if (GNUNET_YES == |
410 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_topology_option", | 432 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", |
411 | &connect_topology_option_num)) | 433 | "connect_topology_option", |
434 | &connect_topology_option_num)) | ||
412 | connect_topology_option = connect_topology_option_num; | 435 | connect_topology_option = connect_topology_option_num; |
413 | 436 | ||
414 | if (GNUNET_YES == | 437 | if (GNUNET_YES == |
415 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier", | 438 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
416 | &connect_topology_option_modifier_string)) | 439 | "connect_topology_option_modifier", |
440 | &connect_topology_option_modifier_string)) | ||
417 | { | 441 | { |
418 | if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1) | 442 | if (sscanf |
419 | { | 443 | (connect_topology_option_modifier_string, "%lf", |
420 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 444 | &connect_topology_option_modifier) != 1) |
421 | _("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 445 | { |
422 | connect_topology_option_modifier_string, | 446 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
423 | "connect_topology_option_modifier", | 447 | _ |
424 | "TESTING"); | 448 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
425 | GNUNET_free (connect_topology_option_modifier_string); | 449 | connect_topology_option_modifier_string, |
426 | ok = 707; | 450 | "connect_topology_option_modifier", "TESTING"); |
427 | if (dotOutFile != NULL) | 451 | GNUNET_free (connect_topology_option_modifier_string); |
428 | { | 452 | ok = 707; |
429 | fclose(dotOutFile); | 453 | if (dotOutFile != NULL) |
430 | } | 454 | { |
431 | return; | 455 | fclose (dotOutFile); |
432 | } | 456 | } |
457 | return; | ||
458 | } | ||
433 | GNUNET_free (connect_topology_option_modifier_string); | 459 | GNUNET_free (connect_topology_option_modifier_string); |
434 | } | 460 | } |
435 | 461 | ||
436 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports", | 462 | if (GNUNET_OK != |
437 | &blacklist_transports)) | 463 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
438 | { | 464 | "blacklist_transports", |
439 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "No transports specified for blacklisting in blacklist testcase (this shouldn't happen!)\n"); | 465 | &blacklist_transports)) |
440 | ok = 808; | 466 | { |
441 | if (dotOutFile != NULL) | 467 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
442 | { | 468 | "No transports specified for blacklisting in blacklist testcase (this shouldn't happen!)\n"); |
443 | fclose(dotOutFile); | 469 | ok = 808; |
444 | } | 470 | if (dotOutFile != NULL) |
445 | return; | 471 | { |
446 | } | 472 | fclose (dotOutFile); |
473 | } | ||
474 | return; | ||
475 | } | ||
447 | 476 | ||
448 | if (GNUNET_YES == | 477 | if (GNUNET_YES == |
449 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "blacklist_topology", | 478 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", |
479 | "blacklist_topology", | ||
450 | &blacklist_topology_num)) | 480 | &blacklist_topology_num)) |
451 | blacklist_topology = blacklist_topology_num; | 481 | blacklist_topology = blacklist_topology_num; |
452 | 482 | ||
@@ -457,7 +487,7 @@ run (void *cls, | |||
457 | 487 | ||
458 | main_cfg = cfg; | 488 | main_cfg = cfg; |
459 | 489 | ||
460 | GNUNET_assert(num_peers > 0 && num_peers < (unsigned int)-1); | 490 | GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1); |
461 | peers_left = num_peers; | 491 | peers_left = num_peers; |
462 | 492 | ||
463 | /* For this specific test we only really want a CLIQUE topology as the | 493 | /* For this specific test we only really want a CLIQUE topology as the |
@@ -472,10 +502,12 @@ run (void *cls, | |||
472 | /* Set up a task to end testing if peer start fails */ | 502 | /* Set up a task to end testing if peer start fails */ |
473 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 503 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
474 | (GNUNET_TIME_UNIT_MINUTES, 5), | 504 | (GNUNET_TIME_UNIT_MINUTES, 5), |
475 | &end_badly, "didn't start all daemons in reasonable amount of time!!!"); | 505 | &end_badly, |
506 | "didn't start all daemons in reasonable amount of time!!!"); | ||
476 | 507 | ||
477 | pg = GNUNET_TESTING_daemons_start (cfg, | 508 | pg = GNUNET_TESTING_daemons_start (cfg, |
478 | peers_left, TIMEOUT, &hostkey_callback, NULL, &peers_started_callback, NULL, | 509 | peers_left, TIMEOUT, &hostkey_callback, |
510 | NULL, &peers_started_callback, NULL, | ||
479 | &topology_callback, NULL, NULL); | 511 | &topology_callback, NULL, NULL); |
480 | 512 | ||
481 | } | 513 | } |
@@ -484,7 +516,7 @@ static int | |||
484 | check () | 516 | check () |
485 | { | 517 | { |
486 | int ret; | 518 | int ret; |
487 | char *const argv[] = {"test-testing-topology-blacklist", | 519 | char *const argv[] = { "test-testing-topology-blacklist", |
488 | "-c", | 520 | "-c", |
489 | "test_testing_data_topology_blacklist.conf", | 521 | "test_testing_data_topology_blacklist.conf", |
490 | #if VERBOSE | 522 | #if VERBOSE |
@@ -496,11 +528,13 @@ check () | |||
496 | GNUNET_GETOPT_OPTION_END | 528 | GNUNET_GETOPT_OPTION_END |
497 | }; | 529 | }; |
498 | ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 530 | ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
499 | argv, "test-testing-topology-blacklist", "nohelp", | 531 | argv, "test-testing-topology-blacklist", "nohelp", |
500 | options, &run, &ok); | 532 | options, &run, &ok); |
501 | if (ret != GNUNET_OK) | 533 | if (ret != GNUNET_OK) |
502 | { | 534 | { |
503 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-testing-topology-blacklist': Failed with error code %d\n", ret); | 535 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
536 | "`test-testing-topology-blacklist': Failed with error code %d\n", | ||
537 | ret); | ||
504 | } | 538 | } |
505 | 539 | ||
506 | return ok; | 540 | return ok; |
@@ -528,7 +562,9 @@ main (int argc, char *argv[]) | |||
528 | { | 562 | { |
529 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) | 563 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) |
530 | { | 564 | { |
531 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory); | 565 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
566 | "Failed to remove testing directory %s\n", | ||
567 | test_directory); | ||
532 | } | 568 | } |
533 | } | 569 | } |
534 | 570 | ||
diff --git a/src/testing/test_testing_topology_churn.c b/src/testing/test_testing_topology_churn.c index 0e3647015..8b2a12069 100644 --- a/src/testing/test_testing_topology_churn.c +++ b/src/testing/test_testing_topology_churn.c | |||
@@ -75,14 +75,13 @@ struct GNUNET_TestMessage | |||
75 | /** | 75 | /** |
76 | * Check whether peers successfully shut down. | 76 | * Check whether peers successfully shut down. |
77 | */ | 77 | */ |
78 | void shutdown_callback (void *cls, | 78 | void |
79 | const char *emsg) | 79 | shutdown_callback (void *cls, const char *emsg) |
80 | { | 80 | { |
81 | if (emsg != NULL) | 81 | if (emsg != NULL) |
82 | { | 82 | { |
83 | #if VERBOSE | 83 | #if VERBOSE |
84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); |
85 | "Shutdown of peers failed!\n"); | ||
86 | #endif | 85 | #endif |
87 | if (ok == 0) | 86 | if (ok == 0) |
88 | ok = 666; | 87 | ok = 666; |
@@ -102,7 +101,7 @@ finish_testing () | |||
102 | GNUNET_assert (pg != NULL); | 101 | GNUNET_assert (pg != NULL); |
103 | 102 | ||
104 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 103 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
105 | GNUNET_SCHEDULER_cancel(die_task); | 104 | GNUNET_SCHEDULER_cancel (die_task); |
106 | 105 | ||
107 | #if VERBOSE | 106 | #if VERBOSE |
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -110,20 +109,18 @@ finish_testing () | |||
110 | #endif | 109 | #endif |
111 | 110 | ||
112 | #if VERBOSE | 111 | #if VERBOSE |
113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n"); |
114 | "Calling daemons_stop\n"); | ||
115 | #endif | 113 | #endif |
116 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 114 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
117 | #if VERBOSE | 115 | #if VERBOSE |
118 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "daemons_stop finished\n"); |
119 | "daemons_stop finished\n"); | ||
120 | #endif | 117 | #endif |
121 | 118 | ||
122 | ok = 0; | 119 | ok = 0; |
123 | } | 120 | } |
124 | 121 | ||
125 | static void | 122 | static void |
126 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 123 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
127 | { | 124 | { |
128 | char *msg = cls; | 125 | char *msg = cls; |
129 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -153,61 +150,63 @@ static struct ChurnTestContext churn_ctx; | |||
153 | * @param cls closure | 150 | * @param cls closure |
154 | * @param emsg NULL on success | 151 | * @param emsg NULL on success |
155 | */ | 152 | */ |
156 | void churn_callback(void *cls, | 153 | void |
157 | const char *emsg) | 154 | churn_callback (void *cls, const char *emsg) |
158 | { | 155 | { |
159 | if (emsg == NULL) | 156 | if (emsg == NULL) |
160 | { | 157 | { |
161 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Successfully churned peers!\n", emsg); | 158 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Successfully churned peers!\n", |
162 | GNUNET_SCHEDULER_add_now(churn_ctx.next_task, NULL); | 159 | emsg); |
160 | GNUNET_SCHEDULER_add_now (churn_ctx.next_task, NULL); | ||
163 | } | 161 | } |
164 | else | 162 | else |
165 | { | 163 | { |
166 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to churn peers with error `%s'\n", emsg); | 164 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
167 | GNUNET_SCHEDULER_cancel(die_task); | 165 | "Failed to churn peers with error `%s'\n", emsg); |
168 | die_task = GNUNET_SCHEDULER_add_now(&end_badly, NULL); | 166 | GNUNET_SCHEDULER_cancel (die_task); |
167 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
169 | } | 168 | } |
170 | } | 169 | } |
171 | 170 | ||
172 | 171 | ||
173 | static void | 172 | static void |
174 | churn_peers_both() | 173 | churn_peers_both () |
175 | { | 174 | { |
176 | churn_ctx.next_task = &finish_testing; | 175 | churn_ctx.next_task = &finish_testing; |
177 | GNUNET_TESTING_daemons_churn(pg, 1, 1, TIMEOUT, &churn_callback, NULL); | 176 | GNUNET_TESTING_daemons_churn (pg, 1, 1, TIMEOUT, &churn_callback, NULL); |
178 | } | 177 | } |
179 | 178 | ||
180 | static void | 179 | static void |
181 | churn_peers_off_again() | 180 | churn_peers_off_again () |
182 | { | 181 | { |
183 | churn_ctx.next_task = &churn_peers_both; | 182 | churn_ctx.next_task = &churn_peers_both; |
184 | GNUNET_TESTING_daemons_churn(pg, 2, 0, TIMEOUT, &churn_callback, NULL); | 183 | GNUNET_TESTING_daemons_churn (pg, 2, 0, TIMEOUT, &churn_callback, NULL); |
185 | } | 184 | } |
186 | 185 | ||
187 | static void | 186 | static void |
188 | churn_peers_on() | 187 | churn_peers_on () |
189 | { | 188 | { |
190 | churn_ctx.next_task = &churn_peers_off_again; | 189 | churn_ctx.next_task = &churn_peers_off_again; |
191 | GNUNET_TESTING_daemons_churn(pg, 0, 2, TIMEOUT, &churn_callback, NULL); | 190 | GNUNET_TESTING_daemons_churn (pg, 0, 2, TIMEOUT, &churn_callback, NULL); |
192 | } | 191 | } |
193 | 192 | ||
194 | static void | 193 | static void |
195 | churn_peers_off() | 194 | churn_peers_off () |
196 | { | 195 | { |
197 | churn_ctx.next_task = &churn_peers_on; | 196 | churn_ctx.next_task = &churn_peers_on; |
198 | GNUNET_TESTING_daemons_churn(pg, 2, 0, TIMEOUT, &churn_callback, NULL); | 197 | GNUNET_TESTING_daemons_churn (pg, 2, 0, TIMEOUT, &churn_callback, NULL); |
199 | } | 198 | } |
200 | 199 | ||
201 | static void | 200 | static void |
202 | peers_started_callback (void *cls, | 201 | peers_started_callback (void *cls, |
203 | const struct GNUNET_PeerIdentity *id, | 202 | const struct GNUNET_PeerIdentity *id, |
204 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 203 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
205 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 204 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
206 | { | 205 | { |
207 | if (emsg != NULL) | 206 | if (emsg != NULL) |
208 | { | 207 | { |
209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n", | 208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
210 | emsg); | 209 | "Failed to start daemon with error: `%s'\n", emsg); |
211 | return; | 210 | return; |
212 | } | 211 | } |
213 | GNUNET_assert (id != NULL); | 212 | GNUNET_assert (id != NULL); |
@@ -220,15 +219,15 @@ peers_started_callback (void *cls, | |||
220 | { | 219 | { |
221 | #if VERBOSE | 220 | #if VERBOSE |
222 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
223 | "All %d daemons started, now testing churn!\n", | 222 | "All %d daemons started, now testing churn!\n", num_peers); |
224 | num_peers); | ||
225 | #endif | 223 | #endif |
226 | GNUNET_SCHEDULER_cancel (die_task); | 224 | GNUNET_SCHEDULER_cancel (die_task); |
227 | /* Set up task in case topology creation doesn't finish | 225 | /* Set up task in case topology creation doesn't finish |
228 | * within a reasonable amount of time */ | 226 | * within a reasonable amount of time */ |
229 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 227 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
230 | (GNUNET_TIME_UNIT_MINUTES, 5), | 228 | (GNUNET_TIME_UNIT_MINUTES, 5), |
231 | &end_badly, "from peers_started_callback"); | 229 | &end_badly, |
230 | "from peers_started_callback"); | ||
232 | churn_peers_off (); | 231 | churn_peers_off (); |
233 | ok = 0; | 232 | ok = 0; |
234 | } | 233 | } |
@@ -247,7 +246,9 @@ run (void *cls, | |||
247 | "Starting daemons based on config file %s\n", cfgfile); | 246 | "Starting daemons based on config file %s\n", cfgfile); |
248 | #endif | 247 | #endif |
249 | 248 | ||
250 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) | 249 | if (GNUNET_YES != |
250 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", | ||
251 | &test_directory)) | ||
251 | { | 252 | { |
252 | ok = 404; | 253 | ok = 404; |
253 | return; | 254 | return; |
@@ -261,7 +262,7 @@ run (void *cls, | |||
261 | main_cfg = cfg; | 262 | main_cfg = cfg; |
262 | 263 | ||
263 | peers_left = num_peers; | 264 | peers_left = num_peers; |
264 | GNUNET_assert(num_peers > 0 && num_peers < (unsigned int)-1); | 265 | GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1); |
265 | 266 | ||
266 | /* For this specific test we only really want a CLIQUE topology as the | 267 | /* For this specific test we only really want a CLIQUE topology as the |
267 | * overlay allowed topology, and a RING topology as the underlying connection | 268 | * overlay allowed topology, and a RING topology as the underlying connection |
@@ -275,11 +276,13 @@ run (void *cls, | |||
275 | /* Set up a task to end testing if peer start fails */ | 276 | /* Set up a task to end testing if peer start fails */ |
276 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 277 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
277 | (GNUNET_TIME_UNIT_MINUTES, 5), | 278 | (GNUNET_TIME_UNIT_MINUTES, 5), |
278 | &end_badly, "didn't start all daemons in reasonable amount of time!!!"); | 279 | &end_badly, |
280 | "didn't start all daemons in reasonable amount of time!!!"); | ||
279 | 281 | ||
280 | pg = GNUNET_TESTING_daemons_start (cfg, | 282 | pg = GNUNET_TESTING_daemons_start (cfg, |
281 | peers_left, TIMEOUT, NULL, NULL, &peers_started_callback, NULL, | 283 | peers_left, TIMEOUT, NULL, NULL, |
282 | NULL, NULL, NULL); | 284 | &peers_started_callback, NULL, NULL, |
285 | NULL, NULL); | ||
283 | 286 | ||
284 | } | 287 | } |
285 | 288 | ||
@@ -287,7 +290,7 @@ static int | |||
287 | check () | 290 | check () |
288 | { | 291 | { |
289 | int ret; | 292 | int ret; |
290 | char *const argv[] = {"test-testing-topology-churn", | 293 | char *const argv[] = { "test-testing-topology-churn", |
291 | "-c", | 294 | "-c", |
292 | "test_testing_data_topology_churn.conf", | 295 | "test_testing_data_topology_churn.conf", |
293 | #if VERBOSE | 296 | #if VERBOSE |
@@ -299,11 +302,13 @@ check () | |||
299 | GNUNET_GETOPT_OPTION_END | 302 | GNUNET_GETOPT_OPTION_END |
300 | }; | 303 | }; |
301 | ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 304 | ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
302 | argv, "test-testing-topology-churn", "nohelp", | 305 | argv, "test-testing-topology-churn", "nohelp", |
303 | options, &run, &ok); | 306 | options, &run, &ok); |
304 | if (ret != GNUNET_OK) | 307 | if (ret != GNUNET_OK) |
305 | { | 308 | { |
306 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-testing-topology-churn': Failed with error code %d\n", ret); | 309 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
310 | "`test-testing-topology-churn': Failed with error code %d\n", | ||
311 | ret); | ||
307 | } | 312 | } |
308 | 313 | ||
309 | return ok; | 314 | return ok; |
@@ -331,7 +336,9 @@ main (int argc, char *argv[]) | |||
331 | { | 336 | { |
332 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) | 337 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) |
333 | { | 338 | { |
334 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory); | 339 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
340 | "Failed to remove testing directory %s\n", | ||
341 | test_directory); | ||
335 | } | 342 | } |
336 | } | 343 | } |
337 | 344 | ||
diff --git a/src/testing/testing.c b/src/testing/testing.c index ecf2a2591..84493410a 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -37,8 +37,8 @@ | |||
37 | #include "gnunet_transport_service.h" | 37 | #include "gnunet_transport_service.h" |
38 | #include "gnunet_hello_lib.h" | 38 | #include "gnunet_hello_lib.h" |
39 | 39 | ||
40 | #define DEBUG_TESTING GNUNET_NO | 40 | #define DEBUG_TESTING GNUNET_YES |
41 | #define DEBUG_TESTING_RECONNECT GNUNET_NO | 41 | #define DEBUG_TESTING_RECONNECT GNUNET_YES |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * How long do we wait after starting gnunet-service-arm | 44 | * How long do we wait after starting gnunet-service-arm |
@@ -71,19 +71,24 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
71 | 71 | ||
72 | if (daemon->server != NULL) | 72 | if (daemon->server != NULL) |
73 | { | 73 | { |
74 | GNUNET_CORE_disconnect(daemon->server); | 74 | #if DEBUG_TESTING |
75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
76 | "Received `%s' from transport service of `%4s', disconnecting core!\n", | ||
77 | "HELLO", GNUNET_i2s (&daemon->id)); | ||
78 | #endif | ||
79 | GNUNET_CORE_disconnect (daemon->server); | ||
75 | daemon->server = NULL; | 80 | daemon->server = NULL; |
76 | } | 81 | } |
77 | 82 | ||
78 | GNUNET_assert (message != NULL); | 83 | GNUNET_assert (message != NULL); |
79 | msize = ntohs(message->size); | 84 | msize = ntohs (message->size); |
80 | if (msize < 1) | 85 | if (msize < 1) |
81 | { | 86 | { |
82 | return; | 87 | return; |
83 | } | 88 | } |
84 | if (daemon->th != NULL) | 89 | if (daemon->th != NULL) |
85 | { | 90 | { |
86 | GNUNET_TRANSPORT_get_hello_cancel(daemon->th, &process_hello, daemon); | 91 | GNUNET_TRANSPORT_get_hello_cancel (daemon->th, &process_hello, daemon); |
87 | } | 92 | } |
88 | #if DEBUG_TESTING | 93 | #if DEBUG_TESTING |
89 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 94 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -91,18 +96,14 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
91 | "HELLO", GNUNET_i2s (&daemon->id)); | 96 | "HELLO", GNUNET_i2s (&daemon->id)); |
92 | #endif | 97 | #endif |
93 | 98 | ||
99 | GNUNET_free_non_null (daemon->hello); | ||
100 | daemon->hello = GNUNET_malloc (msize); | ||
101 | memcpy (daemon->hello, message, msize); | ||
94 | 102 | ||
95 | 103 | if (daemon->th != NULL) | |
96 | { | 104 | { |
97 | GNUNET_free_non_null(daemon->hello); | 105 | GNUNET_TRANSPORT_disconnect (daemon->th); |
98 | daemon->hello = GNUNET_malloc(msize); | 106 | daemon->th = NULL; |
99 | memcpy(daemon->hello, message, msize); | ||
100 | |||
101 | if (daemon->th != NULL) | ||
102 | { | ||
103 | GNUNET_TRANSPORT_disconnect(daemon->th); | ||
104 | daemon->th = NULL; | ||
105 | } | ||
106 | } | 107 | } |
107 | 108 | ||
108 | } | 109 | } |
@@ -136,7 +137,10 @@ testing_init (void *cls, | |||
136 | { | 137 | { |
137 | d->server = NULL; | 138 | d->server = NULL; |
138 | if (GNUNET_YES == d->dead) | 139 | if (GNUNET_YES == d->dead) |
139 | GNUNET_TESTING_daemon_stop (d, GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, GNUNET_YES, GNUNET_NO); | 140 | GNUNET_TESTING_daemon_stop (d, |
141 | GNUNET_TIME_absolute_get_remaining | ||
142 | (d->max_timeout), d->dead_cb, | ||
143 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); | ||
140 | else if (NULL != cb) | 144 | else if (NULL != cb) |
141 | cb (d->cb_cls, NULL, d->cfg, d, | 145 | cb (d->cb_cls, NULL, d->cfg, d, |
142 | _("Failed to connect to core service\n")); | 146 | _("Failed to connect to core service\n")); |
@@ -150,28 +154,42 @@ testing_init (void *cls, | |||
150 | d->shortname = strdup (GNUNET_i2s (my_identity)); | 154 | d->shortname = strdup (GNUNET_i2s (my_identity)); |
151 | d->server = server; | 155 | d->server = server; |
152 | d->running = GNUNET_YES; | 156 | d->running = GNUNET_YES; |
153 | if (GNUNET_YES == d->dead) | 157 | |
154 | GNUNET_TESTING_daemon_stop (d, GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, GNUNET_YES, GNUNET_NO); | 158 | if (NULL != cb) /* FIXME: what happens when this callback calls GNUNET_TESTING_daemon_stop? */ |
155 | else if (NULL != cb) | ||
156 | cb (d->cb_cls, my_identity, d->cfg, d, NULL); | 159 | cb (d->cb_cls, my_identity, d->cfg, d, NULL); |
160 | |||
161 | if (GNUNET_NO == d->running) | ||
162 | { | ||
163 | #if DEBUG_TESTING | ||
164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
165 | "Peer is dead (d->running == GNUNET_NO)\n"); | ||
166 | #endif | ||
167 | return; | ||
168 | } | ||
157 | #if DEBUG_TESTING | 169 | #if DEBUG_TESTING |
158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
159 | "Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity)); | 171 | "Successfully started peer `%4s', connecting to transport service.\n", |
172 | GNUNET_i2s (my_identity)); | ||
160 | #endif | 173 | #endif |
161 | 174 | ||
162 | 175 | d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL); | |
163 | d->th = GNUNET_TRANSPORT_connect (d->cfg, | ||
164 | &d->id, | ||
165 | d, NULL, NULL, NULL); | ||
166 | if (d->th == NULL) | 176 | if (d->th == NULL) |
167 | { | 177 | { |
168 | if (GNUNET_YES == d->dead) | 178 | if (GNUNET_YES == d->dead) |
169 | GNUNET_TESTING_daemon_stop (d, GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, GNUNET_YES, GNUNET_NO); | 179 | GNUNET_TESTING_daemon_stop (d, |
180 | GNUNET_TIME_absolute_get_remaining | ||
181 | (d->max_timeout), d->dead_cb, | ||
182 | d->dead_cb_cls, GNUNET_YES, GNUNET_NO); | ||
170 | else if (NULL != d->cb) | 183 | else if (NULL != d->cb) |
171 | d->cb (d->cb_cls, &d->id, d->cfg, d, | 184 | d->cb (d->cb_cls, &d->id, d->cfg, d, |
172 | _("Failed to connect to transport service!\n")); | 185 | _("Failed to connect to transport service!\n")); |
173 | return; | 186 | return; |
174 | } | 187 | } |
188 | #if DEBUG_TESTING | ||
189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
190 | "Connected to transport service `%s', getting HELLO\n", | ||
191 | GNUNET_i2s (my_identity)); | ||
192 | #endif | ||
175 | 193 | ||
176 | GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); | 194 | GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); |
177 | } | 195 | } |
@@ -184,8 +202,7 @@ testing_init (void *cls, | |||
184 | * @param tc unused | 202 | * @param tc unused |
185 | */ | 203 | */ |
186 | static void | 204 | static void |
187 | start_fsm (void *cls, | 205 | start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
188 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
189 | { | 206 | { |
190 | struct GNUNET_TESTING_Daemon *d = cls; | 207 | struct GNUNET_TESTING_Daemon *d = cls; |
191 | GNUNET_TESTING_NotifyDaemonRunning cb; | 208 | GNUNET_TESTING_NotifyDaemonRunning cb; |
@@ -206,14 +223,17 @@ start_fsm (void *cls, | |||
206 | /* confirm copying complete */ | 223 | /* confirm copying complete */ |
207 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | 224 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) |
208 | { | 225 | { |
209 | if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).rel_value == 0) | 226 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == |
227 | 0) | ||
210 | { | 228 | { |
211 | cb = d->cb; | 229 | cb = d->cb; |
212 | d->cb = NULL; | 230 | d->cb = NULL; |
213 | if (NULL != cb) | 231 | if (NULL != cb) |
214 | cb (d->cb_cls, | 232 | cb (d->cb_cls, |
215 | NULL, | 233 | NULL, |
216 | d->cfg, d, _("`scp' does not seem to terminate (timeout copying config).\n")); | 234 | d->cfg, d, |
235 | _ | ||
236 | ("`scp' does not seem to terminate (timeout copying config).\n")); | ||
217 | return; | 237 | return; |
218 | } | 238 | } |
219 | /* wait some more */ | 239 | /* wait some more */ |
@@ -262,11 +282,12 @@ start_fsm (void *cls, | |||
262 | "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile, | 282 | "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile, |
263 | "-sq"); | 283 | "-sq"); |
264 | #endif | 284 | #endif |
265 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo", | 285 | d->proc = |
266 | "gnunet-peerinfo", | 286 | GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo", |
267 | "-c", d->cfgfile, | 287 | "gnunet-peerinfo", "-c", d->cfgfile, |
268 | "-sq", NULL); | 288 | "-sq", NULL); |
269 | GNUNET_DISK_pipe_close_end(d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); | 289 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, |
290 | GNUNET_DISK_PIPE_END_WRITE); | ||
270 | } | 291 | } |
271 | else | 292 | else |
272 | { | 293 | { |
@@ -278,32 +299,35 @@ start_fsm (void *cls, | |||
278 | #if DEBUG_TESTING | 299 | #if DEBUG_TESTING |
279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
280 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", | 301 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", |
281 | "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", d->cfgfile, | 302 | "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", |
282 | "-sq"); | 303 | d->cfgfile, "-sq"); |
283 | #endif | 304 | #endif |
284 | if (d->ssh_port_str == NULL) | 305 | if (d->ssh_port_str == NULL) |
285 | { | 306 | { |
286 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", | 307 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", |
287 | "ssh", | 308 | "ssh", |
288 | #if !DEBUG_TESTING | 309 | #if !DEBUG_TESTING |
289 | "-q", | 310 | "-q", |
290 | #endif | 311 | #endif |
291 | dst, | 312 | dst, |
292 | "gnunet-peerinfo", | 313 | "gnunet-peerinfo", |
293 | "-c", d->cfgfile, "-sq", NULL); | 314 | "-c", d->cfgfile, "-sq", |
315 | NULL); | ||
294 | } | 316 | } |
295 | else | 317 | else |
296 | { | 318 | { |
297 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", | 319 | d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", |
298 | "ssh", "-p", d->ssh_port_str, | 320 | "ssh", "-p", d->ssh_port_str, |
299 | #if !DEBUG_TESTING | 321 | #if !DEBUG_TESTING |
300 | "-q", | 322 | "-q", |
301 | #endif | 323 | #endif |
302 | dst, | 324 | dst, |
303 | "gnunet-peerinfo", | 325 | "gnunet-peerinfo", |
304 | "-c", d->cfgfile, "-sq", NULL); | 326 | "-c", d->cfgfile, "-sq", |
327 | NULL); | ||
305 | } | 328 | } |
306 | GNUNET_DISK_pipe_close_end(d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); | 329 | GNUNET_DISK_pipe_close_end (d->pipe_stdout, |
330 | GNUNET_DISK_PIPE_END_WRITE); | ||
307 | GNUNET_free (dst); | 331 | GNUNET_free (dst); |
308 | } | 332 | } |
309 | if (NULL == d->proc) | 333 | if (NULL == d->proc) |
@@ -321,84 +345,82 @@ start_fsm (void *cls, | |||
321 | (NULL == d->hostname) | 345 | (NULL == d->hostname) |
322 | ? _("Failed to start `gnunet-peerinfo' process.\n") | 346 | ? _("Failed to start `gnunet-peerinfo' process.\n") |
323 | : _("Failed to start `ssh' process.\n")); | 347 | : _("Failed to start `ssh' process.\n")); |
324 | GNUNET_DISK_pipe_close(d->pipe_stdout); | 348 | GNUNET_DISK_pipe_close (d->pipe_stdout); |
325 | return; | 349 | return; |
326 | } | 350 | } |
327 | #if DEBUG_TESTING | 351 | #if DEBUG_TESTING |
328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
329 | "Started `%s', waiting for hostkey.\n", | 353 | "Started `%s', waiting for hostkey.\n", "gnunet-peerinfo"); |
330 | "gnunet-peerinfo"); | ||
331 | #endif | 354 | #endif |
332 | d->phase = SP_HOSTKEY_CREATE; | 355 | d->phase = SP_HOSTKEY_CREATE; |
333 | d->task | 356 | d->task |
334 | = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining(d->max_timeout), | 357 | = |
335 | GNUNET_DISK_pipe_handle(d->pipe_stdout, | 358 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining |
336 | GNUNET_DISK_PIPE_END_READ), | 359 | (d->max_timeout), |
337 | &start_fsm, | 360 | GNUNET_DISK_pipe_handle |
338 | d); | 361 | (d->pipe_stdout, |
362 | GNUNET_DISK_PIPE_END_READ), | ||
363 | &start_fsm, d); | ||
339 | break; | 364 | break; |
340 | case SP_HOSTKEY_CREATE: | 365 | case SP_HOSTKEY_CREATE: |
341 | bytes_read = GNUNET_DISK_file_read(GNUNET_DISK_pipe_handle(d->pipe_stdout, | 366 | bytes_read = |
342 | GNUNET_DISK_PIPE_END_READ), | 367 | GNUNET_DISK_file_read (GNUNET_DISK_pipe_handle |
343 | &d->hostkeybuf[d->hostkeybufpos], | 368 | (d->pipe_stdout, GNUNET_DISK_PIPE_END_READ), |
344 | sizeof(d->hostkeybuf) - d->hostkeybufpos); | 369 | &d->hostkeybuf[d->hostkeybufpos], |
370 | sizeof (d->hostkeybuf) - d->hostkeybufpos); | ||
345 | if (bytes_read > 0) | 371 | if (bytes_read > 0) |
346 | d->hostkeybufpos += bytes_read; | 372 | d->hostkeybufpos += bytes_read; |
347 | 373 | ||
348 | if ( (d->hostkeybufpos < 104) && | 374 | if ((d->hostkeybufpos < 104) && (bytes_read > 0)) |
349 | (bytes_read > 0) ) | 375 | { |
350 | { | 376 | /* keep reading */ |
351 | /* keep reading */ | ||
352 | d->task | 377 | d->task |
353 | = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining(d->max_timeout), | 378 | = |
354 | GNUNET_DISK_pipe_handle(d->pipe_stdout, | 379 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining |
355 | GNUNET_DISK_PIPE_END_READ), | 380 | (d->max_timeout), |
356 | &start_fsm, | 381 | GNUNET_DISK_pipe_handle |
357 | d); | 382 | (d->pipe_stdout, |
383 | GNUNET_DISK_PIPE_END_READ), | ||
384 | &start_fsm, d); | ||
358 | return; | 385 | return; |
359 | } | 386 | } |
360 | d->hostkeybuf[103] = '\0'; | 387 | d->hostkeybuf[103] = '\0'; |
361 | if ( (bytes_read < 0) || | 388 | if ((bytes_read < 0) || |
362 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf, | 389 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf, |
363 | &d->id.hashPubKey)) ) | 390 | &d->id.hashPubKey))) |
364 | { | 391 | { |
365 | /* error */ | 392 | /* error */ |
366 | if (bytes_read < 0) | 393 | if (bytes_read < 0) |
367 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 394 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
368 | _("Error reading from gnunet-peerinfo: %s\n"), | 395 | _("Error reading from gnunet-peerinfo: %s\n"), |
369 | STRERROR (errno)); | 396 | STRERROR (errno)); |
370 | else | 397 | else |
371 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 398 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
372 | _("Malformed output from gnunet-peerinfo!\n")); | 399 | _("Malformed output from gnunet-peerinfo!\n")); |
373 | cb = d->cb; | 400 | cb = d->cb; |
374 | d->cb = NULL; | 401 | d->cb = NULL; |
375 | GNUNET_DISK_pipe_close(d->pipe_stdout); | 402 | GNUNET_DISK_pipe_close (d->pipe_stdout); |
376 | d->pipe_stdout = NULL; | 403 | d->pipe_stdout = NULL; |
377 | (void) GNUNET_OS_process_kill (d->proc, SIGKILL); | 404 | (void) GNUNET_OS_process_kill (d->proc, SIGKILL); |
378 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); | 405 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); |
379 | GNUNET_OS_process_close (d->proc); | 406 | GNUNET_OS_process_close (d->proc); |
380 | d->proc = NULL; | 407 | d->proc = NULL; |
381 | if (NULL != cb) | 408 | if (NULL != cb) |
382 | cb (d->cb_cls, | 409 | cb (d->cb_cls, NULL, d->cfg, d, _("`Failed to get hostkey!\n")); |
383 | NULL, | 410 | return; |
384 | d->cfg, | 411 | } |
385 | d, | 412 | GNUNET_DISK_pipe_close (d->pipe_stdout); |
386 | _("`Failed to get hostkey!\n")); | ||
387 | return; | ||
388 | } | ||
389 | GNUNET_DISK_pipe_close(d->pipe_stdout); | ||
390 | d->pipe_stdout = NULL; | 413 | d->pipe_stdout = NULL; |
391 | (void) GNUNET_OS_process_kill (d->proc, SIGKILL); | 414 | (void) GNUNET_OS_process_kill (d->proc, SIGKILL); |
392 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); | 415 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); |
393 | GNUNET_OS_process_close (d->proc); | 416 | GNUNET_OS_process_close (d->proc); |
394 | d->proc = NULL; | 417 | d->proc = NULL; |
395 | #if DEBUG_TESTING | 418 | #if DEBUG_TESTING |
396 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 419 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n"); |
397 | "Successfully got hostkey!\n"); | ||
398 | #endif | 420 | #endif |
399 | if (d->hostkey_callback != NULL) | 421 | if (d->hostkey_callback != NULL) |
400 | { | 422 | { |
401 | d->hostkey_callback(d->hostkey_cls, &d->id, d, NULL); | 423 | d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL); |
402 | d->phase = SP_HOSTKEY_CREATED; | 424 | d->phase = SP_HOSTKEY_CREATED; |
403 | } | 425 | } |
404 | else | 426 | else |
@@ -408,16 +430,16 @@ start_fsm (void *cls, | |||
408 | /* Fall through */ | 430 | /* Fall through */ |
409 | case SP_HOSTKEY_CREATED: | 431 | case SP_HOSTKEY_CREATED: |
410 | /* wait for topology finished */ | 432 | /* wait for topology finished */ |
411 | if ((GNUNET_YES == d->dead) || (GNUNET_TIME_absolute_get_remaining(d->max_timeout).rel_value == 0)) | 433 | if ((GNUNET_YES == d->dead) |
434 | || (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | ||
435 | 0)) | ||
412 | { | 436 | { |
413 | cb = d->cb; | 437 | cb = d->cb; |
414 | d->cb = NULL; | 438 | d->cb = NULL; |
415 | if (NULL != cb) | 439 | if (NULL != cb) |
416 | cb (d->cb_cls, | 440 | cb (d->cb_cls, |
417 | NULL, | 441 | NULL, |
418 | d->cfg, | 442 | d->cfg, d, _("`Failed while waiting for topology setup!\n")); |
419 | d, | ||
420 | _("`Failed while waiting for topology setup!\n")); | ||
421 | return; | 443 | return; |
422 | } | 444 | } |
423 | 445 | ||
@@ -433,16 +455,14 @@ start_fsm (void *cls, | |||
433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 455 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
434 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", | 456 | "Starting `%s', with command `%s %s %s %s %s %s'.\n", |
435 | "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, | 457 | "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, |
436 | "-L", "DEBUG", | 458 | "-L", "DEBUG", "-s"); |
437 | "-s"); | ||
438 | #endif | 459 | #endif |
439 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 460 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", |
440 | "gnunet-arm", | 461 | "gnunet-arm", "-c", d->cfgfile, |
441 | "-c", d->cfgfile, | ||
442 | #if DEBUG_TESTING | 462 | #if DEBUG_TESTING |
443 | "-L", "DEBUG", | 463 | "-L", "DEBUG", |
444 | #endif | 464 | #endif |
445 | "-s", "-q", NULL); | 465 | "-s", "-q", NULL); |
446 | } | 466 | } |
447 | else | 467 | else |
448 | { | 468 | { |
@@ -454,37 +474,36 @@ start_fsm (void *cls, | |||
454 | #if DEBUG_TESTING | 474 | #if DEBUG_TESTING |
455 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
456 | "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n", | 476 | "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n", |
457 | "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", d->cfgfile, | 477 | "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", |
458 | "-L", "DEBUG", "-s", "-q"); | 478 | d->cfgfile, "-L", "DEBUG", "-s", "-q"); |
459 | #endif | 479 | #endif |
460 | if (d->ssh_port_str == NULL) | 480 | if (d->ssh_port_str == NULL) |
461 | { | 481 | { |
462 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", | 482 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
463 | "ssh", | ||
464 | #if !DEBUG_TESTING | 483 | #if !DEBUG_TESTING |
465 | "-q", | 484 | "-q", |
466 | #endif | 485 | #endif |
467 | dst, | 486 | dst, "gnunet-arm", |
468 | "gnunet-arm", | ||
469 | #if DEBUG_TESTING | 487 | #if DEBUG_TESTING |
470 | "-L", "DEBUG", | 488 | "-L", "DEBUG", |
471 | #endif | 489 | #endif |
472 | "-c", d->cfgfile, "-s", "-q", NULL); | 490 | "-c", d->cfgfile, "-s", "-q", |
491 | NULL); | ||
473 | } | 492 | } |
474 | else | 493 | else |
475 | { | 494 | { |
476 | 495 | ||
477 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", | 496 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", |
478 | "ssh", "-p", d->ssh_port_str, | 497 | "ssh", "-p", d->ssh_port_str, |
479 | #if !DEBUG_TESTING | 498 | #if !DEBUG_TESTING |
480 | "-q", | 499 | "-q", |
481 | #endif | 500 | #endif |
482 | dst, | 501 | dst, "gnunet-arm", |
483 | "gnunet-arm", | ||
484 | #if DEBUG_TESTING | 502 | #if DEBUG_TESTING |
485 | "-L", "DEBUG", | 503 | "-L", "DEBUG", |
486 | #endif | 504 | #endif |
487 | "-c", d->cfgfile, "-s", "-q", NULL); | 505 | "-c", d->cfgfile, "-s", "-q", |
506 | NULL); | ||
488 | } | 507 | } |
489 | GNUNET_free (dst); | 508 | GNUNET_free (dst); |
490 | } | 509 | } |
@@ -518,7 +537,8 @@ start_fsm (void *cls, | |||
518 | case SP_START_ARMING: | 537 | case SP_START_ARMING: |
519 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | 538 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) |
520 | { | 539 | { |
521 | if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).rel_value == 0) | 540 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == |
541 | 0) | ||
522 | { | 542 | { |
523 | cb = d->cb; | 543 | cb = d->cb; |
524 | d->cb = NULL; | 544 | d->cb = NULL; |
@@ -543,8 +563,7 @@ start_fsm (void *cls, | |||
543 | "Successfully started `%s'.\n", "gnunet-arm"); | 563 | "Successfully started `%s'.\n", "gnunet-arm"); |
544 | #endif | 564 | #endif |
545 | d->phase = SP_START_CORE; | 565 | d->phase = SP_START_CORE; |
546 | d->server = GNUNET_CORE_connect (d->cfg, | 566 | d->server = GNUNET_CORE_connect (d->cfg, 1, |
547 | 1, | ||
548 | #if NO_MORE_TIMEOUT_FIXME | 567 | #if NO_MORE_TIMEOUT_FIXME |
549 | ARM_START_WAIT, | 568 | ARM_START_WAIT, |
550 | #endif | 569 | #endif |
@@ -564,20 +583,23 @@ start_fsm (void *cls, | |||
564 | /* confirm copying complete */ | 583 | /* confirm copying complete */ |
565 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | 584 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) |
566 | { | 585 | { |
567 | if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).rel_value == 0) | 586 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == |
587 | 0) | ||
568 | { | 588 | { |
569 | if (NULL != d->dead_cb) | 589 | if (NULL != d->dead_cb) |
570 | d->dead_cb (d->dead_cb_cls, | 590 | d->dead_cb (d->dead_cb_cls, |
571 | _("either `gnunet-arm' or `ssh' does not seem to terminate.\n")); | 591 | _ |
592 | ("either `gnunet-arm' or `ssh' does not seem to terminate.\n")); | ||
572 | if (d->th != NULL) | 593 | if (d->th != NULL) |
573 | { | 594 | { |
574 | GNUNET_TRANSPORT_get_hello_cancel(d->th, &process_hello, d); | 595 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, |
575 | GNUNET_TRANSPORT_disconnect(d->th); | 596 | d); |
597 | GNUNET_TRANSPORT_disconnect (d->th); | ||
576 | d->th = NULL; | 598 | d->th = NULL; |
577 | } | 599 | } |
578 | GNUNET_CONFIGURATION_destroy (d->cfg); | 600 | GNUNET_CONFIGURATION_destroy (d->cfg); |
579 | GNUNET_free (d->cfgfile); | 601 | GNUNET_free (d->cfgfile); |
580 | GNUNET_free_non_null(d->hello); | 602 | GNUNET_free_non_null (d->hello); |
581 | GNUNET_free_non_null (d->hostname); | 603 | GNUNET_free_non_null (d->hostname); |
582 | GNUNET_free_non_null (d->username); | 604 | GNUNET_free_non_null (d->username); |
583 | GNUNET_free_non_null (d->shortname); | 605 | GNUNET_free_non_null (d->shortname); |
@@ -594,16 +616,22 @@ start_fsm (void *cls, | |||
594 | { | 616 | { |
595 | if (NULL != d->dead_cb) | 617 | if (NULL != d->dead_cb) |
596 | d->dead_cb (d->dead_cb_cls, | 618 | d->dead_cb (d->dead_cb_cls, |
597 | _("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n")); | 619 | _ |
620 | ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n")); | ||
598 | if (d->th != NULL) | 621 | if (d->th != NULL) |
599 | { | 622 | { |
600 | GNUNET_TRANSPORT_get_hello_cancel(d->th, &process_hello, d); | 623 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); |
601 | GNUNET_TRANSPORT_disconnect(d->th); | 624 | GNUNET_TRANSPORT_disconnect (d->th); |
602 | d->th = NULL; | 625 | d->th = NULL; |
603 | } | 626 | } |
627 | if (d->server != NULL) | ||
628 | { | ||
629 | GNUNET_CORE_disconnect (d->server); | ||
630 | d->server = NULL; | ||
631 | } | ||
604 | GNUNET_CONFIGURATION_destroy (d->cfg); | 632 | GNUNET_CONFIGURATION_destroy (d->cfg); |
605 | GNUNET_free (d->cfgfile); | 633 | GNUNET_free (d->cfgfile); |
606 | GNUNET_free_non_null(d->hello); | 634 | GNUNET_free_non_null (d->hello); |
607 | GNUNET_free_non_null (d->hostname); | 635 | GNUNET_free_non_null (d->hostname); |
608 | GNUNET_free_non_null (d->username); | 636 | GNUNET_free_non_null (d->username); |
609 | GNUNET_free_non_null (d->shortname); | 637 | GNUNET_free_non_null (d->shortname); |
@@ -613,10 +641,16 @@ start_fsm (void *cls, | |||
613 | #if DEBUG_TESTING | 641 | #if DEBUG_TESTING |
614 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n"); | 642 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n"); |
615 | #endif | 643 | #endif |
644 | if (d->server != NULL) | ||
645 | { | ||
646 | GNUNET_CORE_disconnect (d->server); | ||
647 | d->server = NULL; | ||
648 | } | ||
649 | |||
616 | if (d->th != NULL) | 650 | if (d->th != NULL) |
617 | { | 651 | { |
618 | GNUNET_TRANSPORT_get_hello_cancel(d->th, &process_hello, d); | 652 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); |
619 | GNUNET_TRANSPORT_disconnect(d->th); | 653 | GNUNET_TRANSPORT_disconnect (d->th); |
620 | d->th = NULL; | 654 | d->th = NULL; |
621 | } | 655 | } |
622 | /* state clean up and notifications */ | 656 | /* state clean up and notifications */ |
@@ -628,7 +662,7 @@ start_fsm (void *cls, | |||
628 | GNUNET_free_non_null (d->username); | 662 | GNUNET_free_non_null (d->username); |
629 | } | 663 | } |
630 | 664 | ||
631 | GNUNET_free_non_null(d->hello); | 665 | GNUNET_free_non_null (d->hello); |
632 | d->hello = NULL; | 666 | d->hello = NULL; |
633 | GNUNET_free_non_null (d->shortname); | 667 | GNUNET_free_non_null (d->shortname); |
634 | d->shortname = NULL; | 668 | d->shortname = NULL; |
@@ -643,7 +677,7 @@ start_fsm (void *cls, | |||
643 | /* confirm copying complete */ | 677 | /* confirm copying complete */ |
644 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | 678 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) |
645 | { | 679 | { |
646 | if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).rel_value == 0) /* FIXME: config update should take timeout parameter! */ | 680 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) /* FIXME: config update should take timeout parameter! */ |
647 | { | 681 | { |
648 | cb = d->cb; | 682 | cb = d->cb; |
649 | d->cb = NULL; | 683 | d->cb = NULL; |
@@ -685,9 +719,9 @@ start_fsm (void *cls, | |||
685 | * @param daemon the daemon to finish starting | 719 | * @param daemon the daemon to finish starting |
686 | */ | 720 | */ |
687 | void | 721 | void |
688 | GNUNET_TESTING_daemon_continue_startup(struct GNUNET_TESTING_Daemon *daemon) | 722 | GNUNET_TESTING_daemon_continue_startup (struct GNUNET_TESTING_Daemon *daemon) |
689 | { | 723 | { |
690 | GNUNET_assert(daemon->phase == SP_HOSTKEY_CREATED); | 724 | GNUNET_assert (daemon->phase == SP_HOSTKEY_CREATED); |
691 | daemon->phase = SP_TOPOLOGY_SETUP; | 725 | daemon->phase = SP_TOPOLOGY_SETUP; |
692 | } | 726 | } |
693 | 727 | ||
@@ -727,15 +761,16 @@ GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon, | |||
727 | void *cb_cls) | 761 | void *cb_cls) |
728 | { | 762 | { |
729 | if (daemon->running == GNUNET_YES) | 763 | if (daemon->running == GNUNET_YES) |
730 | { | 764 | { |
731 | cb(cb_cls, &daemon->id, daemon->cfg, daemon, "Daemon already running, can't restart!"); | 765 | cb (cb_cls, &daemon->id, daemon->cfg, daemon, |
732 | return; | 766 | "Daemon already running, can't restart!"); |
733 | } | 767 | return; |
768 | } | ||
734 | 769 | ||
735 | daemon->cb = cb; | 770 | daemon->cb = cb; |
736 | daemon->cb_cls = cb_cls; | 771 | daemon->cb_cls = cb_cls; |
737 | daemon->phase = SP_TOPOLOGY_SETUP; | 772 | daemon->phase = SP_TOPOLOGY_SETUP; |
738 | daemon->max_timeout = GNUNET_TIME_relative_to_absolute(timeout); | 773 | daemon->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
739 | 774 | ||
740 | GNUNET_SCHEDULER_add_continuation (&start_fsm, | 775 | GNUNET_SCHEDULER_add_continuation (&start_fsm, |
741 | daemon, | 776 | daemon, |
@@ -768,8 +803,8 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
768 | const char *hostname, | 803 | const char *hostname, |
769 | const char *ssh_username, | 804 | const char *ssh_username, |
770 | uint16_t sshport, | 805 | uint16_t sshport, |
771 | GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback, | 806 | GNUNET_TESTING_NotifyHostkeyCreated |
772 | void *hostkey_cls, | 807 | hostkey_callback, void *hostkey_cls, |
773 | GNUNET_TESTING_NotifyDaemonRunning cb, | 808 | GNUNET_TESTING_NotifyDaemonRunning cb, |
774 | void *cb_cls) | 809 | void *cb_cls) |
775 | { | 810 | { |
@@ -781,7 +816,7 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
781 | ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname); | 816 | ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname); |
782 | if (sshport != 0) | 817 | if (sshport != 0) |
783 | { | 818 | { |
784 | GNUNET_asprintf(&ret->ssh_port_str, "%d", sshport); | 819 | GNUNET_asprintf (&ret->ssh_port_str, "%d", sshport); |
785 | } | 820 | } |
786 | else | 821 | else |
787 | ret->ssh_port_str = NULL; | 822 | ret->ssh_port_str = NULL; |
@@ -802,7 +837,7 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
802 | ret->hostkey_cls = hostkey_cls; | 837 | ret->hostkey_cls = hostkey_cls; |
803 | ret->cb = cb; | 838 | ret->cb = cb; |
804 | ret->cb_cls = cb_cls; | 839 | ret->cb_cls = cb_cls; |
805 | ret->max_timeout = GNUNET_TIME_relative_to_absolute(timeout); | 840 | ret->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
806 | ret->cfg = GNUNET_CONFIGURATION_dup (cfg); | 841 | ret->cfg = GNUNET_CONFIGURATION_dup (cfg); |
807 | GNUNET_CONFIGURATION_set_value_string (ret->cfg, | 842 | GNUNET_CONFIGURATION_set_value_string (ret->cfg, |
808 | "PATHS", | 843 | "PATHS", |
@@ -820,11 +855,12 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
820 | return NULL; | 855 | return NULL; |
821 | } | 856 | } |
822 | if (ssh_username != NULL) | 857 | if (ssh_username != NULL) |
823 | username = GNUNET_strdup(ssh_username); | 858 | username = GNUNET_strdup (ssh_username); |
824 | if ((ssh_username == NULL) && (GNUNET_OK != | 859 | if ((ssh_username == NULL) && (GNUNET_OK != |
825 | GNUNET_CONFIGURATION_get_value_string (cfg, | 860 | GNUNET_CONFIGURATION_get_value_string (cfg, |
826 | "TESTING", | 861 | "TESTING", |
827 | "USERNAME", &username))) | 862 | "USERNAME", |
863 | &username))) | ||
828 | { | 864 | { |
829 | if (NULL != getenv ("USER")) | 865 | if (NULL != getenv ("USER")) |
830 | username = GNUNET_strdup (getenv ("USER")); | 866 | username = GNUNET_strdup (getenv ("USER")); |
@@ -848,21 +884,20 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
848 | 884 | ||
849 | if (ret->ssh_port_str == NULL) | 885 | if (ret->ssh_port_str == NULL) |
850 | { | 886 | { |
851 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", | 887 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", |
852 | "scp", | ||
853 | #if !DEBUG_TESTING | 888 | #if !DEBUG_TESTING |
854 | "-q", | 889 | "-q", |
855 | #endif | 890 | #endif |
856 | ret->cfgfile, arg, NULL); | 891 | ret->cfgfile, arg, NULL); |
857 | } | 892 | } |
858 | else | 893 | else |
859 | { | 894 | { |
860 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", | 895 | ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", |
861 | "scp", "-P", ret->ssh_port_str, | 896 | "scp", "-P", ret->ssh_port_str, |
862 | #if !DEBUG_TESTING | 897 | #if !DEBUG_TESTING |
863 | "-q", | 898 | "-q", |
864 | #endif | 899 | #endif |
865 | ret->cfgfile, arg, NULL); | 900 | ret->cfgfile, arg, NULL); |
866 | } | 901 | } |
867 | GNUNET_free (arg); | 902 | GNUNET_free (arg); |
868 | if (NULL == ret->proc) | 903 | if (NULL == ret->proc) |
@@ -907,7 +942,8 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
907 | */ | 942 | */ |
908 | void | 943 | void |
909 | GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, | 944 | GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, |
910 | GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls) | 945 | GNUNET_TESTING_NotifyDaemonRunning cb, |
946 | void *cb_cls) | ||
911 | { | 947 | { |
912 | char *arg; | 948 | char *arg; |
913 | char *del_arg; | 949 | char *del_arg; |
@@ -935,26 +971,27 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, | |||
935 | 971 | ||
936 | if (d->th != NULL) | 972 | if (d->th != NULL) |
937 | { | 973 | { |
938 | GNUNET_TRANSPORT_get_hello_cancel(d->th, &process_hello, d); | 974 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); |
939 | GNUNET_TRANSPORT_disconnect(d->th); | 975 | GNUNET_TRANSPORT_disconnect (d->th); |
940 | d->th = NULL; | 976 | d->th = NULL; |
941 | } | 977 | } |
942 | /* state clean up and notifications */ | 978 | /* state clean up and notifications */ |
943 | GNUNET_free_non_null(d->hello); | 979 | GNUNET_free_non_null (d->hello); |
944 | 980 | ||
945 | #if DEBUG_TESTING | 981 | #if DEBUG_TESTING |
946 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 982 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
947 | _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); | 983 | _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); |
948 | #endif | 984 | #endif |
949 | 985 | ||
950 | d->phase = SP_START_ARMING; | 986 | d->phase = SP_START_ARMING; |
951 | 987 | ||
952 | /* Check if this is a local or remote process */ | 988 | /* Check if this is a local or remote process */ |
953 | if (NULL != d->hostname) | 989 | if (NULL != d->hostname) |
954 | { | 990 | { |
955 | #if DEBUG_TESTING | 991 | #if DEBUG_TESTING |
956 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 992 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
957 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", d->cfgfile, d->hostname); | 993 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", |
994 | d->cfgfile, d->hostname); | ||
958 | #endif | 995 | #endif |
959 | 996 | ||
960 | if (d->username != NULL) | 997 | if (d->username != NULL) |
@@ -964,13 +1001,13 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, | |||
964 | 1001 | ||
965 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 1002 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
966 | #if !DEBUG_TESTING | 1003 | #if !DEBUG_TESTING |
967 | "-q", | 1004 | "-q", |
968 | #endif | 1005 | #endif |
969 | arg, "gnunet-arm", | 1006 | arg, "gnunet-arm", |
970 | #if DEBUG_TESTING | 1007 | #if DEBUG_TESTING |
971 | "-L", "DEBUG", | 1008 | "-L", "DEBUG", |
972 | #endif | 1009 | #endif |
973 | "-c", d->cfgfile, "-e", "-r", NULL); | 1010 | "-c", d->cfgfile, "-e", "-r", NULL); |
974 | /* Use -r to restart arm and all services */ | 1011 | /* Use -r to restart arm and all services */ |
975 | 1012 | ||
976 | GNUNET_free (arg); | 1013 | GNUNET_free (arg); |
@@ -979,20 +1016,21 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, | |||
979 | { | 1016 | { |
980 | #if DEBUG_TESTING | 1017 | #if DEBUG_TESTING |
981 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1018 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
982 | "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); | 1019 | "Stopping gnunet-arm with config `%s' locally.\n", |
1020 | d->cfgfile); | ||
983 | #endif | 1021 | #endif |
984 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 1022 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", |
985 | "gnunet-arm", | 1023 | "gnunet-arm", |
986 | #if DEBUG_TESTING | 1024 | #if DEBUG_TESTING |
987 | "-L", "DEBUG", | 1025 | "-L", "DEBUG", |
988 | #endif | 1026 | #endif |
989 | "-c", d->cfgfile, "-e", "-r", NULL); | 1027 | "-c", d->cfgfile, "-e", "-r", NULL); |
990 | } | 1028 | } |
991 | 1029 | ||
992 | GNUNET_free_non_null(del_arg); | 1030 | GNUNET_free_non_null (del_arg); |
993 | d->task | 1031 | d->task |
994 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | 1032 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
995 | &start_fsm, d); | 1033 | &start_fsm, d); |
996 | 1034 | ||
997 | } | 1035 | } |
998 | 1036 | ||
@@ -1013,8 +1051,7 @@ void | |||
1013 | GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | 1051 | GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, |
1014 | struct GNUNET_TIME_Relative timeout, | 1052 | struct GNUNET_TIME_Relative timeout, |
1015 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls, | 1053 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls, |
1016 | int delete_files, | 1054 | int delete_files, int allow_restart) |
1017 | int allow_restart) | ||
1018 | { | 1055 | { |
1019 | char *arg; | 1056 | char *arg; |
1020 | char *del_arg; | 1057 | char *del_arg; |
@@ -1025,22 +1062,22 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
1025 | { | 1062 | { |
1026 | #if DEBUG_TESTING | 1063 | #if DEBUG_TESTING |
1027 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1064 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1028 | _("Setting d->dead on peer `%4s'\n"), GNUNET_i2s (&d->id)); | 1065 | _("Setting d->dead on peer `%4s'\n"), GNUNET_i2s (&d->id)); |
1029 | #endif | 1066 | #endif |
1030 | d->dead = GNUNET_YES; | 1067 | d->dead = GNUNET_YES; |
1031 | return; | 1068 | return; |
1032 | } | 1069 | } |
1033 | 1070 | ||
1034 | if ((d->running == GNUNET_NO) && (d->churn == GNUNET_YES)) /* Peer has already been stopped in churn context! */ | 1071 | if ((d->running == GNUNET_NO) && (d->churn == GNUNET_YES)) /* Peer has already been stopped in churn context! */ |
1035 | { | 1072 | { |
1036 | /* Free what was left from churning! */ | 1073 | /* Free what was left from churning! */ |
1037 | GNUNET_assert(d->cfg != NULL); | 1074 | GNUNET_assert (d->cfg != NULL); |
1038 | GNUNET_CONFIGURATION_destroy (d->cfg); | 1075 | GNUNET_CONFIGURATION_destroy (d->cfg); |
1039 | if (delete_files == GNUNET_YES) | 1076 | if (delete_files == GNUNET_YES) |
1040 | { | 1077 | { |
1041 | if (0 != UNLINK(d->cfgfile)) | 1078 | if (0 != UNLINK (d->cfgfile)) |
1042 | { | 1079 | { |
1043 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "unlink"); | 1080 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "unlink"); |
1044 | } | 1081 | } |
1045 | } | 1082 | } |
1046 | GNUNET_free (d->cfgfile); | 1083 | GNUNET_free (d->cfgfile); |
@@ -1048,14 +1085,14 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
1048 | GNUNET_free_non_null (d->username); | 1085 | GNUNET_free_non_null (d->username); |
1049 | if (NULL != d->dead_cb) | 1086 | if (NULL != d->dead_cb) |
1050 | d->dead_cb (d->dead_cb_cls, NULL); | 1087 | d->dead_cb (d->dead_cb_cls, NULL); |
1051 | GNUNET_free(d); | 1088 | GNUNET_free (d); |
1052 | return; | 1089 | return; |
1053 | } | 1090 | } |
1054 | 1091 | ||
1055 | del_arg = NULL; | 1092 | del_arg = NULL; |
1056 | if (delete_files == GNUNET_YES) | 1093 | if (delete_files == GNUNET_YES) |
1057 | { | 1094 | { |
1058 | GNUNET_asprintf(&del_arg, "-d"); | 1095 | GNUNET_asprintf (&del_arg, "-d"); |
1059 | } | 1096 | } |
1060 | 1097 | ||
1061 | if (d->phase == SP_CONFIG_UPDATE) | 1098 | if (d->phase == SP_CONFIG_UPDATE) |
@@ -1063,11 +1100,13 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
1063 | GNUNET_SCHEDULER_cancel (d->task); | 1100 | GNUNET_SCHEDULER_cancel (d->task); |
1064 | d->phase = SP_START_DONE; | 1101 | d->phase = SP_START_DONE; |
1065 | } | 1102 | } |
1103 | /** Move this call to scheduled shutdown as fix for CORE_connect calling daemon_stop? | ||
1066 | if (d->server != NULL) | 1104 | if (d->server != NULL) |
1067 | { | 1105 | { |
1068 | GNUNET_CORE_disconnect (d->server); | 1106 | GNUNET_CORE_disconnect (d->server); |
1069 | d->server = NULL; | 1107 | d->server = NULL; |
1070 | } | 1108 | } |
1109 | */ | ||
1071 | /* shutdown ARM process (will terminate others) */ | 1110 | /* shutdown ARM process (will terminate others) */ |
1072 | #if DEBUG_TESTING | 1111 | #if DEBUG_TESTING |
1073 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1079,8 +1118,8 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
1079 | d->churn = GNUNET_YES; | 1118 | d->churn = GNUNET_YES; |
1080 | if (d->th != NULL) | 1119 | if (d->th != NULL) |
1081 | { | 1120 | { |
1082 | GNUNET_TRANSPORT_get_hello_cancel(d->th, &process_hello, d); | 1121 | GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d); |
1083 | GNUNET_TRANSPORT_disconnect(d->th); | 1122 | GNUNET_TRANSPORT_disconnect (d->th); |
1084 | d->th = NULL; | 1123 | d->th = NULL; |
1085 | } | 1124 | } |
1086 | /* Check if this is a local or remote process */ | 1125 | /* Check if this is a local or remote process */ |
@@ -1088,7 +1127,8 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
1088 | { | 1127 | { |
1089 | #if DEBUG_TESTING | 1128 | #if DEBUG_TESTING |
1090 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1091 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", d->cfgfile, d->hostname); | 1130 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", |
1131 | d->cfgfile, d->hostname); | ||
1092 | #endif | 1132 | #endif |
1093 | 1133 | ||
1094 | if (d->username != NULL) | 1134 | if (d->username != NULL) |
@@ -1098,15 +1138,17 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
1098 | 1138 | ||
1099 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | 1139 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", |
1100 | #if !DEBUG_TESTING | 1140 | #if !DEBUG_TESTING |
1101 | "-q", | 1141 | "-q", |
1102 | #endif | 1142 | #endif |
1103 | arg, "gnunet-arm", | 1143 | arg, "gnunet-arm", |
1104 | #if DEBUG_TESTING | 1144 | #if DEBUG_TESTING |
1105 | "-L", "DEBUG", | 1145 | "-L", "DEBUG", |
1106 | #endif | 1146 | #endif |
1107 | "-c", d->cfgfile, "-e", "-q", del_arg, NULL); | 1147 | "-c", d->cfgfile, "-e", "-q", |
1148 | del_arg, NULL); | ||
1108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1109 | "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -e -q %s\n", arg, "gnunet-arm", d->cfgfile, del_arg); | 1150 | "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -e -q %s\n", |
1151 | arg, "gnunet-arm", d->cfgfile, del_arg); | ||
1110 | /* Use -e to end arm, and -d to remove temp files */ | 1152 | /* Use -e to end arm, and -d to remove temp files */ |
1111 | GNUNET_free (arg); | 1153 | GNUNET_free (arg); |
1112 | } | 1154 | } |
@@ -1114,20 +1156,21 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
1114 | { | 1156 | { |
1115 | #if DEBUG_TESTING | 1157 | #if DEBUG_TESTING |
1116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1117 | "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); | 1159 | "Stopping gnunet-arm with config `%s' locally.\n", |
1160 | d->cfgfile); | ||
1118 | #endif | 1161 | #endif |
1119 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | 1162 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", |
1120 | "gnunet-arm", | 1163 | "gnunet-arm", |
1121 | #if DEBUG_TESTING | 1164 | #if DEBUG_TESTING |
1122 | "-L", "DEBUG", | 1165 | "-L", "DEBUG", |
1123 | #endif | 1166 | #endif |
1124 | "-c", d->cfgfile, "-e", "-q", del_arg, NULL); | 1167 | "-c", d->cfgfile, "-e", "-q", |
1168 | del_arg, NULL); | ||
1125 | } | 1169 | } |
1126 | 1170 | ||
1127 | GNUNET_free_non_null(del_arg); | 1171 | GNUNET_free_non_null (del_arg); |
1128 | d->max_timeout = GNUNET_TIME_relative_to_absolute(timeout); | 1172 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1129 | d->task | 1173 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); |
1130 | = GNUNET_SCHEDULER_add_now (&start_fsm, d); | ||
1131 | } | 1174 | } |
1132 | 1175 | ||
1133 | 1176 | ||
@@ -1184,9 +1227,9 @@ GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d, | |||
1184 | GNUNET_asprintf (&arg, "%s:%s", d->hostname, d->cfgfile); | 1227 | GNUNET_asprintf (&arg, "%s:%s", d->hostname, d->cfgfile); |
1185 | d->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", | 1228 | d->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", |
1186 | #if !DEBUG_TESTING | 1229 | #if !DEBUG_TESTING |
1187 | "-q", | 1230 | "-q", |
1188 | #endif | 1231 | #endif |
1189 | d->cfgfile, arg, NULL); | 1232 | d->cfgfile, arg, NULL); |
1190 | GNUNET_free (arg); | 1233 | GNUNET_free (arg); |
1191 | if (NULL == d->proc) | 1234 | if (NULL == d->proc) |
1192 | { | 1235 | { |
@@ -1221,7 +1264,7 @@ struct ConnectContext | |||
1221 | /** | 1264 | /** |
1222 | * Handle to core of first daemon (to check connect) | 1265 | * Handle to core of first daemon (to check connect) |
1223 | */ | 1266 | */ |
1224 | struct GNUNET_CORE_Handle * d1core; | 1267 | struct GNUNET_CORE_Handle *d1core; |
1225 | 1268 | ||
1226 | /** | 1269 | /** |
1227 | * Testing handle to the second daemon. | 1270 | * Testing handle to the second daemon. |
@@ -1234,9 +1277,9 @@ struct ConnectContext | |||
1234 | struct GNUNET_CORE_PeerRequestHandle *connect_request_handle; | 1277 | struct GNUNET_CORE_PeerRequestHandle *connect_request_handle; |
1235 | 1278 | ||
1236 | /** | 1279 | /** |
1237 | * Transport handle to the second daemon. | 1280 | * Transport handle to the first daemon (to offer the HELLO of the second daemon to). |
1238 | */ | 1281 | */ |
1239 | struct GNUNET_TRANSPORT_Handle *d2th; | 1282 | struct GNUNET_TRANSPORT_Handle *d1th; |
1240 | 1283 | ||
1241 | /** | 1284 | /** |
1242 | * Function to call once we are done (or have timed out). | 1285 | * Function to call once we are done (or have timed out). |
@@ -1296,7 +1339,8 @@ struct ConnectContext | |||
1296 | 1339 | ||
1297 | /** Forward declaration **/ | 1340 | /** Forward declaration **/ |
1298 | static void | 1341 | static void |
1299 | reattempt_daemons_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 1342 | reattempt_daemons_connect (void *cls, |
1343 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
1300 | 1344 | ||
1301 | 1345 | ||
1302 | /** | 1346 | /** |
@@ -1316,7 +1360,7 @@ notify_connect_result (void *cls, | |||
1316 | ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1360 | ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1317 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) | 1361 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) |
1318 | { | 1362 | { |
1319 | GNUNET_SCHEDULER_cancel(ctx->hello_send_task); | 1363 | GNUNET_SCHEDULER_cancel (ctx->hello_send_task); |
1320 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; | 1364 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; |
1321 | } | 1365 | } |
1322 | 1366 | ||
@@ -1327,9 +1371,9 @@ notify_connect_result (void *cls, | |||
1327 | } | 1371 | } |
1328 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 1372 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
1329 | { | 1373 | { |
1330 | if (ctx->d2th != NULL) | 1374 | if (ctx->d1th != NULL) |
1331 | GNUNET_TRANSPORT_disconnect (ctx->d2th); | 1375 | GNUNET_TRANSPORT_disconnect (ctx->d1th); |
1332 | ctx->d2th = NULL; | 1376 | ctx->d1th = NULL; |
1333 | if (ctx->d1core != NULL) | 1377 | if (ctx->d1core != NULL) |
1334 | GNUNET_CORE_disconnect (ctx->d1core); | 1378 | GNUNET_CORE_disconnect (ctx->d1core); |
1335 | #if CONNECT_CORE2 | 1379 | #if CONNECT_CORE2 |
@@ -1343,44 +1387,40 @@ notify_connect_result (void *cls, | |||
1343 | return; | 1387 | return; |
1344 | } | 1388 | } |
1345 | 1389 | ||
1346 | remaining = GNUNET_TIME_absolute_get_remaining(ctx->timeout); | 1390 | remaining = GNUNET_TIME_absolute_get_remaining (ctx->timeout); |
1347 | 1391 | ||
1348 | if (ctx->connected == GNUNET_YES) | 1392 | if (ctx->connected == GNUNET_YES) |
1349 | { | 1393 | { |
1350 | if (ctx->cb != NULL) | 1394 | if (ctx->cb != NULL) |
1351 | { | 1395 | { |
1352 | ctx->cb (ctx->cb_cls, | 1396 | ctx->cb (ctx->cb_cls, |
1353 | &ctx->d1->id, | 1397 | &ctx->d1->id, |
1354 | &ctx->d2->id, | 1398 | &ctx->d2->id, |
1355 | ctx->distance, | 1399 | ctx->distance, |
1356 | ctx->d1->cfg, | 1400 | ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL); |
1357 | ctx->d2->cfg, | ||
1358 | ctx->d1, | ||
1359 | ctx->d2, | ||
1360 | NULL); | ||
1361 | } | 1401 | } |
1362 | } | 1402 | } |
1363 | else if (remaining.rel_value > 0) | 1403 | else if (remaining.rel_value > 0) |
1364 | { | 1404 | { |
1365 | if (ctx->d1core != NULL) | 1405 | if (ctx->d1core != NULL) |
1366 | { | 1406 | { |
1367 | GNUNET_CORE_disconnect(ctx->d1core); | 1407 | GNUNET_CORE_disconnect (ctx->d1core); |
1368 | ctx->d1core = NULL; | 1408 | ctx->d1core = NULL; |
1369 | } | 1409 | } |
1370 | #if CONNECT_CORE2 | 1410 | #if CONNECT_CORE2 |
1371 | if (ctx->d2core != NULL) | 1411 | if (ctx->d2core != NULL) |
1372 | { | 1412 | { |
1373 | GNUNET_CORE_disconnect(ctx->d2core); | 1413 | GNUNET_CORE_disconnect (ctx->d2core); |
1374 | ctx->d2core = NULL; | 1414 | ctx->d2core = NULL; |
1375 | } | 1415 | } |
1376 | #endif | 1416 | #endif |
1377 | 1417 | ||
1378 | if (ctx->d2th != NULL) | 1418 | if (ctx->d1th != NULL) |
1379 | { | 1419 | { |
1380 | GNUNET_TRANSPORT_disconnect(ctx->d2th); | 1420 | GNUNET_TRANSPORT_disconnect (ctx->d1th); |
1381 | ctx->d2th = NULL; | 1421 | ctx->d1th = NULL; |
1382 | } | 1422 | } |
1383 | GNUNET_SCHEDULER_add_now(&reattempt_daemons_connect, ctx); | 1423 | GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx); |
1384 | return; | 1424 | return; |
1385 | } | 1425 | } |
1386 | else | 1426 | else |
@@ -1393,8 +1433,8 @@ notify_connect_result (void *cls, | |||
1393 | } | 1433 | } |
1394 | } | 1434 | } |
1395 | 1435 | ||
1396 | GNUNET_TRANSPORT_disconnect (ctx->d2th); | 1436 | GNUNET_TRANSPORT_disconnect (ctx->d1th); |
1397 | ctx->d2th = NULL; | 1437 | ctx->d1th = NULL; |
1398 | GNUNET_CORE_disconnect (ctx->d1core); | 1438 | GNUNET_CORE_disconnect (ctx->d1core); |
1399 | ctx->d1core = NULL; | 1439 | ctx->d1core = NULL; |
1400 | GNUNET_free (ctx); | 1440 | GNUNET_free (ctx); |
@@ -1410,19 +1450,19 @@ notify_connect_result (void *cls, | |||
1410 | * | 1450 | * |
1411 | */ | 1451 | */ |
1412 | static void | 1452 | static void |
1413 | connect_notify (void *cls, | 1453 | connect_notify (void *cls, |
1414 | const struct GNUNET_PeerIdentity * peer, | 1454 | const struct GNUNET_PeerIdentity *peer, |
1415 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1455 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1416 | { | 1456 | { |
1417 | struct ConnectContext *ctx = cls; | 1457 | struct ConnectContext *ctx = cls; |
1418 | 1458 | ||
1419 | if (memcmp(&ctx->d2->id, peer, sizeof(struct GNUNET_PeerIdentity)) == 0) | 1459 | if (memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)) == 0) |
1420 | { | 1460 | { |
1421 | ctx->connected = GNUNET_YES; | 1461 | ctx->connected = GNUNET_YES; |
1422 | ctx->distance = 0; /* FIXME: distance */ | 1462 | ctx->distance = 0; /* FIXME: distance */ |
1423 | GNUNET_SCHEDULER_cancel(ctx->timeout_task); | 1463 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); |
1424 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, | 1464 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, |
1425 | ctx); | 1465 | ctx); |
1426 | } | 1466 | } |
1427 | } | 1467 | } |
1428 | 1468 | ||
@@ -1436,17 +1476,17 @@ connect_notify (void *cls, | |||
1436 | * | 1476 | * |
1437 | */ | 1477 | */ |
1438 | static void | 1478 | static void |
1439 | connect_notify_core2 (void *cls, | 1479 | connect_notify_core2 (void *cls, |
1440 | const struct GNUNET_PeerIdentity * peer, | 1480 | const struct GNUNET_PeerIdentity *peer, |
1441 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1481 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1442 | { | 1482 | { |
1443 | struct ConnectContext *ctx = cls; | 1483 | struct ConnectContext *ctx = cls; |
1444 | 1484 | ||
1445 | if (memcmp(&ctx->d2->id, peer, sizeof(struct GNUNET_PeerIdentity)) == 0) | 1485 | if (memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)) == 0) |
1446 | { | 1486 | { |
1447 | ctx->connected = GNUNET_YES; | 1487 | ctx->connected = GNUNET_YES; |
1448 | ctx->distance = 0; /* FIXME: distance */ | 1488 | ctx->distance = 0; /* FIXME: distance */ |
1449 | GNUNET_SCHEDULER_cancel(ctx->timeout_task); | 1489 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); |
1450 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, | 1490 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, |
1451 | ctx); | 1491 | ctx); |
1452 | } | 1492 | } |
@@ -1460,9 +1500,9 @@ connect_notify_core2 (void *cls, | |||
1460 | * @param cls struct ConnectContext | 1500 | * @param cls struct ConnectContext |
1461 | * @param tc context information (why was this task triggered now) | 1501 | * @param tc context information (why was this task triggered now) |
1462 | */ | 1502 | */ |
1463 | void core_connect_request_cont (void *cls, | 1503 | void |
1464 | const struct | 1504 | core_connect_request_cont (void *cls, |
1465 | GNUNET_SCHEDULER_TaskContext * tc) | 1505 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1466 | { | 1506 | { |
1467 | struct ConnectContext *ctx = cls; | 1507 | struct ConnectContext *ctx = cls; |
1468 | 1508 | ||
@@ -1472,33 +1512,38 @@ void core_connect_request_cont (void *cls, | |||
1472 | } | 1512 | } |
1473 | 1513 | ||
1474 | static void | 1514 | static void |
1475 | send_hello(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1515 | send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1476 | { | 1516 | { |
1477 | struct ConnectContext *ctx = cls; | 1517 | struct ConnectContext *ctx = cls; |
1478 | struct GNUNET_MessageHeader *hello; | 1518 | struct GNUNET_MessageHeader *hello; |
1479 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; | 1519 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; |
1480 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 1520 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
1481 | return; | 1521 | return; |
1482 | if ((ctx->d2->hello != NULL) && (NULL != GNUNET_HELLO_get_header(ctx->d2->hello))) | 1522 | if ((ctx->d2->hello != NULL) |
1523 | && (NULL != GNUNET_HELLO_get_header (ctx->d2->hello))) | ||
1483 | { | 1524 | { |
1484 | hello = GNUNET_HELLO_get_header(ctx->d2->hello); | 1525 | hello = GNUNET_HELLO_get_header (ctx->d2->hello); |
1485 | GNUNET_assert(hello != NULL); | 1526 | GNUNET_assert (hello != NULL); |
1486 | /* FIXME: if this works, change d2th to d1th */ | 1527 | GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello); |
1487 | GNUNET_TRANSPORT_offer_hello (ctx->d2th, hello); | 1528 | GNUNET_assert (ctx->d1core != NULL); |
1488 | GNUNET_assert(ctx->d1core != NULL); | 1529 | ctx->connect_request_handle = |
1489 | ctx->connect_request_handle = GNUNET_CORE_peer_request_connect (ctx->d1core, | 1530 | GNUNET_CORE_peer_request_connect (ctx->d1core, |
1490 | GNUNET_TIME_relative_divide(ctx->relative_timeout, | 1531 | GNUNET_TIME_relative_divide |
1491 | ctx->max_connect_attempts + 1), | 1532 | (ctx->relative_timeout, |
1492 | &ctx->d1->id, | 1533 | ctx->max_connect_attempts + 1), |
1493 | &core_connect_request_cont, | 1534 | &ctx->d2->id, |
1494 | ctx); | 1535 | &core_connect_request_cont, ctx); |
1495 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending connect request to core for peer %s\n", GNUNET_i2s(&ctx->d1->id)); | 1536 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1496 | ctx->timeout_hello = GNUNET_TIME_relative_add(ctx->timeout_hello, | 1537 | "Sending connect request to CORE of %s for peer %s\n", |
1497 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, | 1538 | GNUNET_i2s (&ctx->d1->id), |
1498 | 500)); | 1539 | GNUNET_h2s (&ctx->d2->id.hashPubKey)); |
1540 | ctx->timeout_hello = | ||
1541 | GNUNET_TIME_relative_add (ctx->timeout_hello, | ||
1542 | GNUNET_TIME_relative_multiply | ||
1543 | (GNUNET_TIME_UNIT_MILLISECONDS, 500)); | ||
1499 | } | 1544 | } |
1500 | ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed(ctx->timeout_hello, | 1545 | ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed (ctx->timeout_hello, |
1501 | &send_hello, ctx); | 1546 | &send_hello, ctx); |
1502 | } | 1547 | } |
1503 | 1548 | ||
1504 | /** | 1549 | /** |
@@ -1534,7 +1579,8 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
1534 | ctx->d1 = d1; | 1579 | ctx->d1 = d1; |
1535 | ctx->d2 = d2; | 1580 | ctx->d2 = d2; |
1536 | ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1581 | ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1537 | ctx->timeout_hello = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500); | 1582 | ctx->timeout_hello = |
1583 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500); | ||
1538 | ctx->relative_timeout = timeout; | 1584 | ctx->relative_timeout = timeout; |
1539 | ctx->cb = cb; | 1585 | ctx->cb = cb; |
1540 | ctx->cb_cls = cb_cls; | 1586 | ctx->cb_cls = cb_cls; |
@@ -1546,8 +1592,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
1546 | d1->shortname, d2->shortname); | 1592 | d1->shortname, d2->shortname); |
1547 | #endif | 1593 | #endif |
1548 | 1594 | ||
1549 | ctx->d1core = GNUNET_CORE_connect (d1->cfg, | 1595 | ctx->d1core = GNUNET_CORE_connect (d1->cfg, 1, |
1550 | 1, | ||
1551 | #if NO_MORE_TIMEOUT_FIXME | 1596 | #if NO_MORE_TIMEOUT_FIXME |
1552 | timeout, | 1597 | timeout, |
1553 | #endif | 1598 | #endif |
@@ -1566,8 +1611,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
1566 | } | 1611 | } |
1567 | 1612 | ||
1568 | #if CONNECT_CORE2 | 1613 | #if CONNECT_CORE2 |
1569 | ctx->d2core = GNUNET_CORE_connect (d2->cfg, | 1614 | ctx->d2core = GNUNET_CORE_connect (d2->cfg, 1, |
1570 | 1, | ||
1571 | #if NO_MORE_TIMEOUT_FIXME | 1615 | #if NO_MORE_TIMEOUT_FIXME |
1572 | timeout, | 1616 | timeout, |
1573 | #endif | 1617 | #endif |
@@ -1595,12 +1639,11 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
1595 | 1639 | ||
1596 | #endif | 1640 | #endif |
1597 | 1641 | ||
1598 | ctx->d2th = GNUNET_TRANSPORT_connect (d1->cfg, | 1642 | ctx->d1th = GNUNET_TRANSPORT_connect (d1->cfg, |
1599 | &d1->id, | 1643 | &d1->id, d1, NULL, NULL, NULL); |
1600 | d1, NULL, NULL, NULL); | 1644 | if (ctx->d1th == NULL) |
1601 | if (ctx->d2th == NULL) | ||
1602 | { | 1645 | { |
1603 | GNUNET_CORE_disconnect(ctx->d1core); | 1646 | GNUNET_CORE_disconnect (ctx->d1core); |
1604 | GNUNET_free (ctx); | 1647 | GNUNET_free (ctx); |
1605 | if (NULL != cb) | 1648 | if (NULL != cb) |
1606 | cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, | 1649 | cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, |
@@ -1608,15 +1651,18 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
1608 | return; | 1651 | return; |
1609 | } | 1652 | } |
1610 | 1653 | ||
1611 | ctx->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide(ctx->relative_timeout, | 1654 | ctx->timeout_task = |
1612 | ctx->max_connect_attempts), | 1655 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide |
1613 | ¬ify_connect_result, ctx); | 1656 | (ctx->relative_timeout, |
1657 | ctx->max_connect_attempts), | ||
1658 | ¬ify_connect_result, ctx); | ||
1614 | 1659 | ||
1615 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now(&send_hello, ctx); | 1660 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); |
1616 | } | 1661 | } |
1617 | 1662 | ||
1618 | static void | 1663 | static void |
1619 | reattempt_daemons_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1664 | reattempt_daemons_connect (void *cls, |
1665 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1620 | { | 1666 | { |
1621 | 1667 | ||
1622 | struct ConnectContext *ctx = cls; | 1668 | struct ConnectContext *ctx = cls; |
@@ -1625,16 +1671,17 @@ reattempt_daemons_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext | |||
1625 | return; | 1671 | return; |
1626 | } | 1672 | } |
1627 | #if DEBUG_TESTING_RECONNECT | 1673 | #if DEBUG_TESTING_RECONNECT |
1628 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "re-attempting connect of peer %s to peer %s\n", | 1674 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1675 | "re-attempting connect of peer %s to peer %s\n", | ||
1629 | ctx->d1->shortname, ctx->d2->shortname); | 1676 | ctx->d1->shortname, ctx->d2->shortname); |
1630 | #endif | 1677 | #endif |
1631 | 1678 | ||
1632 | GNUNET_assert(ctx->d1core == NULL); | 1679 | GNUNET_assert (ctx->d1core == NULL); |
1633 | 1680 | ||
1634 | ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, | 1681 | ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1, |
1635 | 1, | ||
1636 | #if NO_MORE_TIMEOUT_FIXME | 1682 | #if NO_MORE_TIMEOUT_FIXME |
1637 | GNUNET_TIME_absolute_get_remaining(ctx->timeout), | 1683 | GNUNET_TIME_absolute_get_remaining |
1684 | (ctx->timeout), | ||
1638 | #endif | 1685 | #endif |
1639 | ctx, | 1686 | ctx, |
1640 | NULL, | 1687 | NULL, |
@@ -1644,29 +1691,34 @@ reattempt_daemons_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext | |||
1644 | if (ctx->d1core == NULL) | 1691 | if (ctx->d1core == NULL) |
1645 | { | 1692 | { |
1646 | if (NULL != ctx->cb) | 1693 | if (NULL != ctx->cb) |
1647 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, | 1694 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
1695 | ctx->d2->cfg, ctx->d1, ctx->d2, | ||
1648 | _("Failed to connect to core service of first peer!\n")); | 1696 | _("Failed to connect to core service of first peer!\n")); |
1649 | GNUNET_free (ctx); | 1697 | GNUNET_free (ctx); |
1650 | return; | 1698 | return; |
1651 | } | 1699 | } |
1652 | 1700 | ||
1653 | ctx->d2th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, | 1701 | ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, |
1654 | &ctx->d1->id, | 1702 | &ctx->d1->id, |
1655 | ctx->d1, NULL, NULL, NULL); | 1703 | ctx->d1, NULL, NULL, NULL); |
1656 | if (ctx->d2th == NULL) | 1704 | if (ctx->d1th == NULL) |
1657 | { | 1705 | { |
1658 | GNUNET_CORE_disconnect(ctx->d1core); | 1706 | GNUNET_CORE_disconnect (ctx->d1core); |
1659 | GNUNET_free (ctx); | 1707 | GNUNET_free (ctx); |
1660 | if (NULL != ctx->cb) | 1708 | if (NULL != ctx->cb) |
1661 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, | 1709 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, |
1662 | _("Failed to connect to transport service!\n")); | 1710 | ctx->d2->cfg, ctx->d1, ctx->d2, |
1711 | _("Failed to connect to transport service!\n")); | ||
1663 | return; | 1712 | return; |
1664 | } | 1713 | } |
1665 | 1714 | ||
1666 | ctx->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide(ctx->relative_timeout, ctx->max_connect_attempts), | 1715 | ctx->timeout_task = |
1667 | ¬ify_connect_result, ctx); | 1716 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide |
1717 | (ctx->relative_timeout, | ||
1718 | ctx->max_connect_attempts), | ||
1719 | ¬ify_connect_result, ctx); | ||
1668 | 1720 | ||
1669 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now(&send_hello, ctx); | 1721 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); |
1670 | } | 1722 | } |
1671 | 1723 | ||
1672 | /* end of testing.c */ | 1724 | /* end of testing.c */ |
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index a243a7d7c..9c0dbd8fa 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -67,9 +67,13 @@ | |||
67 | * Prototype of a function called whenever two peers would be connected | 67 | * Prototype of a function called whenever two peers would be connected |
68 | * in a certain topology. | 68 | * in a certain topology. |
69 | */ | 69 | */ |
70 | typedef unsigned int (*GNUNET_TESTING_ConnectionProcessor)(struct GNUNET_TESTING_PeerGroup *pg, | 70 | typedef unsigned int (*GNUNET_TESTING_ConnectionProcessor) (struct |
71 | unsigned int first, | 71 | GNUNET_TESTING_PeerGroup |
72 | unsigned int second); | 72 | * pg, |
73 | unsigned int | ||
74 | first, | ||
75 | unsigned int | ||
76 | second); | ||
73 | 77 | ||
74 | 78 | ||
75 | /** | 79 | /** |
@@ -96,7 +100,7 @@ struct ChurnContext | |||
96 | * Number of peers that still need to be stopped | 100 | * Number of peers that still need to be stopped |
97 | */ | 101 | */ |
98 | unsigned int num_to_stop; | 102 | unsigned int num_to_stop; |
99 | 103 | ||
100 | /** | 104 | /** |
101 | * Number of peers that failed to start | 105 | * Number of peers that failed to start |
102 | */ | 106 | */ |
@@ -604,11 +608,10 @@ struct ConnectContext | |||
604 | * @param hash set to uid (extended with zeros) | 608 | * @param hash set to uid (extended with zeros) |
605 | */ | 609 | */ |
606 | static void | 610 | static void |
607 | hash_from_uid (uint32_t uid, | 611 | hash_from_uid (uint32_t uid, GNUNET_HashCode * hash) |
608 | GNUNET_HashCode *hash) | ||
609 | { | 612 | { |
610 | memset (hash, 0, sizeof(GNUNET_HashCode)); | 613 | memset (hash, 0, sizeof (GNUNET_HashCode)); |
611 | *((uint32_t*)hash) = uid; | 614 | *((uint32_t *) hash) = uid; |
612 | } | 615 | } |
613 | 616 | ||
614 | /** | 617 | /** |
@@ -618,9 +621,9 @@ hash_from_uid (uint32_t uid, | |||
618 | * @param hash set to uid (extended with zeros) | 621 | * @param hash set to uid (extended with zeros) |
619 | */ | 622 | */ |
620 | static void | 623 | static void |
621 | uid_from_hash (const GNUNET_HashCode *hash, uint32_t *uid) | 624 | uid_from_hash (const GNUNET_HashCode * hash, uint32_t * uid) |
622 | { | 625 | { |
623 | memcpy (uid, hash, sizeof(uint32_t)); | 626 | memcpy (uid, hash, sizeof (uint32_t)); |
624 | } | 627 | } |
625 | 628 | ||
626 | /** | 629 | /** |
@@ -639,77 +642,77 @@ static int outstanding_connects; | |||
639 | * known topology, GNUNET_NO if not | 642 | * known topology, GNUNET_NO if not |
640 | */ | 643 | */ |
641 | int | 644 | int |
642 | GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, const char * topology_string) | 645 | GNUNET_TESTING_topology_get (enum GNUNET_TESTING_Topology *topology, |
646 | const char *topology_string) | ||
643 | { | 647 | { |
644 | /** | 648 | /** |
645 | * Strings representing topologies in enum | 649 | * Strings representing topologies in enum |
646 | */ | 650 | */ |
647 | static const char * topology_strings[] = | 651 | static const char *topology_strings[] = { |
648 | { | ||
649 | /** | 652 | /** |
650 | * A clique (everyone connected to everyone else). | 653 | * A clique (everyone connected to everyone else). |
651 | */ | 654 | */ |
652 | "CLIQUE", | 655 | "CLIQUE", |
653 | 656 | ||
654 | /** | 657 | /** |
655 | * Small-world network (2d torus plus random links). | 658 | * Small-world network (2d torus plus random links). |
656 | */ | 659 | */ |
657 | "SMALL_WORLD", | 660 | "SMALL_WORLD", |
658 | 661 | ||
659 | /** | 662 | /** |
660 | * Small-world network (ring plus random links). | 663 | * Small-world network (ring plus random links). |
661 | */ | 664 | */ |
662 | "SMALL_WORLD_RING", | 665 | "SMALL_WORLD_RING", |
663 | 666 | ||
664 | /** | 667 | /** |
665 | * Ring topology. | 668 | * Ring topology. |
666 | */ | 669 | */ |
667 | "RING", | 670 | "RING", |
668 | 671 | ||
669 | /** | 672 | /** |
670 | * 2-d torus. | 673 | * 2-d torus. |
671 | */ | 674 | */ |
672 | "2D_TORUS", | 675 | "2D_TORUS", |
673 | 676 | ||
674 | /** | 677 | /** |
675 | * Random graph. | 678 | * Random graph. |
676 | */ | 679 | */ |
677 | "ERDOS_RENYI", | 680 | "ERDOS_RENYI", |
678 | 681 | ||
679 | /** | 682 | /** |
680 | * Certain percentage of peers are unable to communicate directly | 683 | * Certain percentage of peers are unable to communicate directly |
681 | * replicating NAT conditions | 684 | * replicating NAT conditions |
682 | */ | 685 | */ |
683 | "INTERNAT", | 686 | "INTERNAT", |
684 | 687 | ||
685 | /** | 688 | /** |
686 | * Scale free topology. | 689 | * Scale free topology. |
687 | */ | 690 | */ |
688 | "SCALE_FREE", | 691 | "SCALE_FREE", |
689 | 692 | ||
690 | /** | 693 | /** |
691 | * Straight line topology. | 694 | * Straight line topology. |
692 | */ | 695 | */ |
693 | "LINE", | 696 | "LINE", |
694 | 697 | ||
695 | /** | 698 | /** |
696 | * All peers are disconnected. | 699 | * All peers are disconnected. |
697 | */ | 700 | */ |
698 | "NONE", | 701 | "NONE", |
699 | 702 | ||
700 | NULL | 703 | NULL |
701 | }; | 704 | }; |
702 | 705 | ||
703 | int curr = 0; | 706 | int curr = 0; |
704 | if (topology_string == NULL) | 707 | if (topology_string == NULL) |
705 | return GNUNET_NO; | 708 | return GNUNET_NO; |
706 | while (topology_strings[curr] != NULL) | 709 | while (topology_strings[curr] != NULL) |
707 | { | 710 | { |
708 | if (strcasecmp(topology_strings[curr], topology_string) == 0) | 711 | if (strcasecmp (topology_strings[curr], topology_string) == 0) |
709 | { | 712 | { |
710 | *topology = curr; | 713 | *topology = curr; |
711 | return GNUNET_YES; | 714 | return GNUNET_YES; |
712 | } | 715 | } |
713 | curr++; | 716 | curr++; |
714 | } | 717 | } |
715 | *topology = GNUNET_TESTING_TOPOLOGY_NONE; | 718 | *topology = GNUNET_TESTING_TOPOLOGY_NONE; |
@@ -727,64 +730,64 @@ GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, const char * | |||
727 | * topology option, GNUNET_NO if not | 730 | * topology option, GNUNET_NO if not |
728 | */ | 731 | */ |
729 | int | 732 | int |
730 | GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption *topology_option, | 733 | GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption |
731 | const char * topology_string) | 734 | *topology_option, |
735 | const char *topology_string) | ||
732 | { | 736 | { |
733 | /** | 737 | /** |
734 | * Options for connecting a topology as strings. | 738 | * Options for connecting a topology as strings. |
735 | */ | 739 | */ |
736 | static const char * topology_option_strings[] = | 740 | static const char *topology_option_strings[] = { |
737 | { | ||
738 | /** | 741 | /** |
739 | * Try to connect all peers specified in the topology. | 742 | * Try to connect all peers specified in the topology. |
740 | */ | 743 | */ |
741 | "CONNECT_ALL", | 744 | "CONNECT_ALL", |
742 | 745 | ||
743 | /** | 746 | /** |
744 | * Choose a random subset of connections to create. | 747 | * Choose a random subset of connections to create. |
745 | */ | 748 | */ |
746 | "CONNECT_RANDOM_SUBSET", | 749 | "CONNECT_RANDOM_SUBSET", |
747 | 750 | ||
748 | /** | 751 | /** |
749 | * Create at least X connections for each peer. | 752 | * Create at least X connections for each peer. |
750 | */ | 753 | */ |
751 | "CONNECT_MINIMUM", | 754 | "CONNECT_MINIMUM", |
752 | 755 | ||
753 | /** | 756 | /** |
754 | * Using a depth first search, create one connection | 757 | * Using a depth first search, create one connection |
755 | * per peer. If any are missed (graph disconnected) | 758 | * per peer. If any are missed (graph disconnected) |
756 | * start over at those peers until all have at least one | 759 | * start over at those peers until all have at least one |
757 | * connection. | 760 | * connection. |
758 | */ | 761 | */ |
759 | "CONNECT_DFS", | 762 | "CONNECT_DFS", |
760 | 763 | ||
761 | /** | 764 | /** |
762 | * Find the N closest peers to each allowed peer in the | 765 | * Find the N closest peers to each allowed peer in the |
763 | * topology and make sure a connection to those peers | 766 | * topology and make sure a connection to those peers |
764 | * exists in the connect topology. | 767 | * exists in the connect topology. |
765 | */ | 768 | */ |
766 | "CONNECT_CLOSEST", | 769 | "CONNECT_CLOSEST", |
767 | 770 | ||
768 | /** | 771 | /** |
769 | * No options specified. | 772 | * No options specified. |
770 | */ | 773 | */ |
771 | "CONNECT_NONE", | 774 | "CONNECT_NONE", |
772 | 775 | ||
773 | NULL | 776 | NULL |
774 | }; | 777 | }; |
775 | int curr = 0; | 778 | int curr = 0; |
776 | 779 | ||
777 | if (topology_string == NULL) | 780 | if (topology_string == NULL) |
778 | return GNUNET_NO; | 781 | return GNUNET_NO; |
779 | while (NULL != topology_option_strings[curr]) | 782 | while (NULL != topology_option_strings[curr]) |
780 | { | 783 | { |
781 | if (strcasecmp(topology_option_strings[curr], topology_string) == 0) | 784 | if (strcasecmp (topology_option_strings[curr], topology_string) == 0) |
782 | { | 785 | { |
783 | *topology_option = curr; | 786 | *topology_option = curr; |
784 | return GNUNET_YES; | 787 | return GNUNET_YES; |
785 | } | 788 | } |
786 | curr++; | 789 | curr++; |
787 | } | 790 | } |
788 | *topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_NONE; | 791 | *topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_NONE; |
789 | return GNUNET_NO; | 792 | return GNUNET_NO; |
790 | } | 793 | } |
@@ -813,40 +816,45 @@ update_config (void *cls, | |||
813 | 816 | ||
814 | if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) | 817 | if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) |
815 | { | 818 | { |
816 | GNUNET_asprintf(&single_variable, "single_%s_per_host", section); | 819 | GNUNET_asprintf (&single_variable, "single_%s_per_host", section); |
817 | if ((ival != 0) && (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno(ctx->orig, "testing", single_variable))) | 820 | if ((ival != 0) |
818 | { | 821 | && (GNUNET_YES != |
819 | GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++); | 822 | GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing", |
820 | value = cval; | 823 | single_variable))) |
821 | } | 824 | { |
825 | GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++); | ||
826 | value = cval; | ||
827 | } | ||
822 | 828 | ||
823 | GNUNET_free(single_variable); | 829 | GNUNET_free (single_variable); |
824 | } | 830 | } |
825 | 831 | ||
826 | if (0 == strcmp (option, "UNIXPATH")) | 832 | if (0 == strcmp (option, "UNIXPATH")) |
827 | { | 833 | { |
828 | GNUNET_asprintf(&single_variable, "single_%s_per_host", section); | 834 | GNUNET_asprintf (&single_variable, "single_%s_per_host", section); |
829 | GNUNET_asprintf(&per_host_variable, "num_%s_per_host", section); | 835 | GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section); |
830 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno(ctx->orig, "testing", single_variable)) | 836 | if (GNUNET_YES != |
837 | GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing", | ||
838 | single_variable)) | ||
831 | { | 839 | { |
832 | GNUNET_snprintf (uval, | 840 | GNUNET_snprintf (uval, |
833 | sizeof (uval), | 841 | sizeof (uval), |
834 | "/tmp/test-service-%s-%u", | 842 | "/tmp/test-service-%s-%u", section, ctx->upnum++); |
835 | section, | ||
836 | ctx->upnum++); | ||
837 | value = uval; | 843 | value = uval; |
838 | } | 844 | } |
839 | else if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_number(ctx->orig, "testing", per_host_variable, &num_per_host)) | 845 | else if (GNUNET_YES == |
846 | GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", | ||
847 | per_host_variable, | ||
848 | &num_per_host)) | ||
840 | { | 849 | { |
841 | GNUNET_snprintf (uval, | 850 | GNUNET_snprintf (uval, |
842 | sizeof (uval), | 851 | sizeof (uval), |
843 | "/tmp/test-service-%s-%u", | 852 | "/tmp/test-service-%s-%u", |
844 | section, | 853 | section, ctx->fdnum % num_per_host); |
845 | ctx->fdnum % num_per_host); | ||
846 | value = uval; | 854 | value = uval; |
847 | } | 855 | } |
848 | GNUNET_free(single_variable); | 856 | GNUNET_free (single_variable); |
849 | GNUNET_free(per_host_variable); | 857 | GNUNET_free (per_host_variable); |
850 | 858 | ||
851 | } | 859 | } |
852 | 860 | ||
@@ -876,10 +884,9 @@ update_config (void *cls, | |||
876 | * @return new configuration, NULL on error | 884 | * @return new configuration, NULL on error |
877 | */ | 885 | */ |
878 | static struct GNUNET_CONFIGURATION_Handle * | 886 | static struct GNUNET_CONFIGURATION_Handle * |
879 | make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, | 887 | make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, |
880 | uint16_t * port, | 888 | uint16_t * port, |
881 | uint32_t * upnum, | 889 | uint32_t * upnum, const char *hostname, uint32_t * fdnum) |
882 | const char *hostname, uint32_t * fdnum) | ||
883 | { | 890 | { |
884 | struct UpdateContext uc; | 891 | struct UpdateContext uc; |
885 | uint16_t orig; | 892 | uint16_t orig; |
@@ -902,19 +909,25 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
902 | return NULL; | 909 | return NULL; |
903 | } | 910 | } |
904 | 911 | ||
905 | if (GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "control_host", &control_host) == GNUNET_OK) | 912 | if (GNUNET_CONFIGURATION_get_value_string |
913 | (cfg, "testing", "control_host", &control_host) == GNUNET_OK) | ||
906 | { | 914 | { |
907 | if (hostname != NULL) | 915 | if (hostname != NULL) |
908 | GNUNET_asprintf(&allowed_hosts, "%s; 127.0.0.1; %s;", control_host, hostname); | 916 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1; %s;", control_host, |
917 | hostname); | ||
909 | else | 918 | else |
910 | GNUNET_asprintf(&allowed_hosts, "%s; 127.0.0.1;", control_host); | 919 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", control_host); |
911 | 920 | ||
912 | GNUNET_CONFIGURATION_set_value_string(uc.ret, "core", "ACCEPT_FROM", allowed_hosts); | 921 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "ACCEPT_FROM", |
913 | GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport", "ACCEPT_FROM", allowed_hosts); | 922 | allowed_hosts); |
914 | GNUNET_CONFIGURATION_set_value_string(uc.ret, "dht", "ACCEPT_FROM", allowed_hosts); | 923 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", |
915 | GNUNET_CONFIGURATION_set_value_string(uc.ret, "statistics", "ACCEPT_FROM", allowed_hosts); | 924 | "ACCEPT_FROM", allowed_hosts); |
916 | GNUNET_free_non_null(control_host); | 925 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "ACCEPT_FROM", |
917 | GNUNET_free(allowed_hosts); | 926 | allowed_hosts); |
927 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", | ||
928 | "ACCEPT_FROM", allowed_hosts); | ||
929 | GNUNET_free_non_null (control_host); | ||
930 | GNUNET_free (allowed_hosts); | ||
918 | } | 931 | } |
919 | 932 | ||
920 | 933 | ||
@@ -922,16 +935,21 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
922 | * otherwise gnunet-arm is unable to connect to it in some instances */ | 935 | * otherwise gnunet-arm is unable to connect to it in some instances */ |
923 | if (hostname != NULL) | 936 | if (hostname != NULL) |
924 | { | 937 | { |
925 | GNUNET_asprintf(&allowed_hosts, "%s; 127.0.0.1;", hostname); | 938 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", hostname); |
926 | GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-udp", "BINDTO", hostname); | 939 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", |
927 | GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-tcp", "BINDTO", hostname); | 940 | "BINDTO", hostname); |
928 | GNUNET_CONFIGURATION_set_value_string(uc.ret, "arm", "ACCEPT_FROM", allowed_hosts); | 941 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", |
929 | GNUNET_free(allowed_hosts); | 942 | "BINDTO", hostname); |
943 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "arm", "ACCEPT_FROM", | ||
944 | allowed_hosts); | ||
945 | GNUNET_free (allowed_hosts); | ||
930 | } | 946 | } |
931 | else | 947 | else |
932 | { | 948 | { |
933 | GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-tcp", "BINDTO", "127.0.0.1"); | 949 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", |
934 | GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-udp", "BINDTO", "127.0.0.1"); | 950 | "BINDTO", "127.0.0.1"); |
951 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", | ||
952 | "BINDTO", "127.0.0.1"); | ||
935 | } | 953 | } |
936 | 954 | ||
937 | *port = (uint16_t) uc.nport; | 955 | *port = (uint16_t) uc.nport; |
@@ -954,7 +972,8 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
954 | * | 972 | * |
955 | */ | 973 | */ |
956 | static unsigned int | 974 | static unsigned int |
957 | add_actual_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second) | 975 | add_actual_connections (struct GNUNET_TESTING_PeerGroup *pg, |
976 | unsigned int first, unsigned int second) | ||
958 | { | 977 | { |
959 | int added; | 978 | int added; |
960 | int add_first; | 979 | int add_first; |
@@ -963,17 +982,21 @@ add_actual_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
963 | GNUNET_HashCode hash_first; | 982 | GNUNET_HashCode hash_first; |
964 | GNUNET_HashCode hash_second; | 983 | GNUNET_HashCode hash_second; |
965 | 984 | ||
966 | hash_from_uid(first, &hash_first); | 985 | hash_from_uid (first, &hash_first); |
967 | hash_from_uid(second, &hash_second); | 986 | hash_from_uid (second, &hash_second); |
968 | 987 | ||
969 | add_first = GNUNET_NO; | 988 | add_first = GNUNET_NO; |
970 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(pg->peers[first].connect_peers, &hash_second)) | 989 | if (GNUNET_NO == |
990 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].connect_peers, | ||
991 | &hash_second)) | ||
971 | { | 992 | { |
972 | add_first = GNUNET_YES; | 993 | add_first = GNUNET_YES; |
973 | } | 994 | } |
974 | 995 | ||
975 | add_second = GNUNET_NO; | 996 | add_second = GNUNET_NO; |
976 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(pg->peers[second].connect_peers, &hash_first)) | 997 | if (GNUNET_NO == |
998 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].connect_peers, | ||
999 | &hash_first)) | ||
977 | { | 1000 | { |
978 | add_second = GNUNET_YES; | 1001 | add_second = GNUNET_YES; |
979 | } | 1002 | } |
@@ -981,14 +1004,28 @@ add_actual_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
981 | added = 0; | 1004 | added = 0; |
982 | if (add_first) | 1005 | if (add_first) |
983 | { | 1006 | { |
984 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(pg->peers[first].connect_peers, &hash_second, pg->peers[second].daemon, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1007 | GNUNET_assert (GNUNET_OK == |
1008 | GNUNET_CONTAINER_multihashmap_put (pg-> | ||
1009 | peers | ||
1010 | [first].connect_peers, | ||
1011 | &hash_second, | ||
1012 | pg-> | ||
1013 | peers[second].daemon, | ||
1014 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
985 | pg->peers[first].num_connections++; | 1015 | pg->peers[first].num_connections++; |
986 | added++; | 1016 | added++; |
987 | } | 1017 | } |
988 | 1018 | ||
989 | if (add_second) | 1019 | if (add_second) |
990 | { | 1020 | { |
991 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(pg->peers[second].connect_peers, &hash_first, pg->peers[first].daemon, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1021 | GNUNET_assert (GNUNET_OK == |
1022 | GNUNET_CONTAINER_multihashmap_put (pg-> | ||
1023 | peers | ||
1024 | [second].connect_peers, | ||
1025 | &hash_first, | ||
1026 | pg-> | ||
1027 | peers[first].daemon, | ||
1028 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
992 | pg->peers[second].num_connections++; | 1029 | pg->peers[second].num_connections++; |
993 | added++; | 1030 | added++; |
994 | } | 1031 | } |
@@ -1011,7 +1048,8 @@ add_actual_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1011 | * | 1048 | * |
1012 | */ | 1049 | */ |
1013 | static unsigned int | 1050 | static unsigned int |
1014 | add_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second) | 1051 | add_allowed_connections (struct GNUNET_TESTING_PeerGroup *pg, |
1052 | unsigned int first, unsigned int second) | ||
1015 | { | 1053 | { |
1016 | int added; | 1054 | int added; |
1017 | #if OLD | 1055 | #if OLD |
@@ -1026,17 +1064,21 @@ add_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1026 | GNUNET_HashCode hash_first; | 1064 | GNUNET_HashCode hash_first; |
1027 | GNUNET_HashCode hash_second; | 1065 | GNUNET_HashCode hash_second; |
1028 | 1066 | ||
1029 | hash_from_uid(first, &hash_first); | 1067 | hash_from_uid (first, &hash_first); |
1030 | hash_from_uid(second, &hash_second); | 1068 | hash_from_uid (second, &hash_second); |
1031 | 1069 | ||
1032 | add_first = GNUNET_NO; | 1070 | add_first = GNUNET_NO; |
1033 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(pg->peers[first].allowed_peers, &hash_second)) | 1071 | if (GNUNET_NO == |
1072 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].allowed_peers, | ||
1073 | &hash_second)) | ||
1034 | { | 1074 | { |
1035 | add_first = GNUNET_YES; | 1075 | add_first = GNUNET_YES; |
1036 | } | 1076 | } |
1037 | 1077 | ||
1038 | add_second = GNUNET_NO; | 1078 | add_second = GNUNET_NO; |
1039 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(pg->peers[second].allowed_peers, &hash_first)) | 1079 | if (GNUNET_NO == |
1080 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].allowed_peers, | ||
1081 | &hash_first)) | ||
1040 | { | 1082 | { |
1041 | add_second = GNUNET_YES; | 1083 | add_second = GNUNET_YES; |
1042 | } | 1084 | } |
@@ -1062,9 +1104,16 @@ add_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1062 | added = 0; | 1104 | added = 0; |
1063 | if (add_first) | 1105 | if (add_first) |
1064 | { | 1106 | { |
1065 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(pg->peers[first].allowed_peers, &hash_second, pg->peers[second].daemon, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1107 | GNUNET_assert (GNUNET_OK == |
1108 | GNUNET_CONTAINER_multihashmap_put (pg-> | ||
1109 | peers | ||
1110 | [first].allowed_peers, | ||
1111 | &hash_second, | ||
1112 | pg-> | ||
1113 | peers[second].daemon, | ||
1114 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1066 | #if OLD | 1115 | #if OLD |
1067 | new_first = GNUNET_malloc(sizeof(struct PeerConnection)); | 1116 | new_first = GNUNET_malloc (sizeof (struct PeerConnection)); |
1068 | new_first->daemon = pg->peers[second].daemon; | 1117 | new_first->daemon = pg->peers[second].daemon; |
1069 | new_first->next = pg->peers[first].connected_peers; | 1118 | new_first->next = pg->peers[first].connected_peers; |
1070 | pg->peers[first].connected_peers = new_first; | 1119 | pg->peers[first].connected_peers = new_first; |
@@ -1075,9 +1124,16 @@ add_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1075 | 1124 | ||
1076 | if (add_second) | 1125 | if (add_second) |
1077 | { | 1126 | { |
1078 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(pg->peers[second].allowed_peers, &hash_first, pg->peers[first].daemon, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1127 | GNUNET_assert (GNUNET_OK == |
1128 | GNUNET_CONTAINER_multihashmap_put (pg-> | ||
1129 | peers | ||
1130 | [second].allowed_peers, | ||
1131 | &hash_first, | ||
1132 | pg-> | ||
1133 | peers[first].daemon, | ||
1134 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1079 | #if OLD | 1135 | #if OLD |
1080 | new_second = GNUNET_malloc(sizeof(struct PeerConnection)); | 1136 | new_second = GNUNET_malloc (sizeof (struct PeerConnection)); |
1081 | new_second->daemon = pg->peers[first].daemon; | 1137 | new_second->daemon = pg->peers[first].daemon; |
1082 | new_second->next = pg->peers[second].connected_peers; | 1138 | new_second->next = pg->peers[second].connected_peers; |
1083 | pg->peers[second].connected_peers = new_second; | 1139 | pg->peers[second].connected_peers = new_second; |
@@ -1101,7 +1157,8 @@ add_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1101 | * | 1157 | * |
1102 | */ | 1158 | */ |
1103 | static unsigned int | 1159 | static unsigned int |
1104 | blacklist_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second) | 1160 | blacklist_connections (struct GNUNET_TESTING_PeerGroup *pg, |
1161 | unsigned int first, unsigned int second) | ||
1105 | { | 1162 | { |
1106 | int added; | 1163 | int added; |
1107 | int add_first; | 1164 | int add_first; |
@@ -1109,17 +1166,23 @@ blacklist_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, u | |||
1109 | GNUNET_HashCode hash_first; | 1166 | GNUNET_HashCode hash_first; |
1110 | GNUNET_HashCode hash_second; | 1167 | GNUNET_HashCode hash_second; |
1111 | 1168 | ||
1112 | hash_from_uid(first, &hash_first); | 1169 | hash_from_uid (first, &hash_first); |
1113 | hash_from_uid(second, &hash_second); | 1170 | hash_from_uid (second, &hash_second); |
1114 | 1171 | ||
1115 | add_first = GNUNET_NO; | 1172 | add_first = GNUNET_NO; |
1116 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(pg->peers[first].blacklisted_peers, &hash_second)) | 1173 | if (GNUNET_NO == |
1174 | GNUNET_CONTAINER_multihashmap_contains (pg-> | ||
1175 | peers[first].blacklisted_peers, | ||
1176 | &hash_second)) | ||
1117 | { | 1177 | { |
1118 | add_first = GNUNET_YES; | 1178 | add_first = GNUNET_YES; |
1119 | } | 1179 | } |
1120 | 1180 | ||
1121 | add_second = GNUNET_NO; | 1181 | add_second = GNUNET_NO; |
1122 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(pg->peers[second].blacklisted_peers, &hash_first)) | 1182 | if (GNUNET_NO == |
1183 | GNUNET_CONTAINER_multihashmap_contains (pg-> | ||
1184 | peers[second].blacklisted_peers, | ||
1185 | &hash_first)) | ||
1123 | { | 1186 | { |
1124 | add_second = GNUNET_YES; | 1187 | add_second = GNUNET_YES; |
1125 | } | 1188 | } |
@@ -1127,14 +1190,28 @@ blacklist_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, u | |||
1127 | added = 0; | 1190 | added = 0; |
1128 | if (add_first) | 1191 | if (add_first) |
1129 | { | 1192 | { |
1130 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(pg->peers[first].blacklisted_peers, &hash_second, pg->peers[second].daemon, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1193 | GNUNET_assert (GNUNET_OK == |
1194 | GNUNET_CONTAINER_multihashmap_put (pg-> | ||
1195 | peers | ||
1196 | [first].blacklisted_peers, | ||
1197 | &hash_second, | ||
1198 | pg-> | ||
1199 | peers[second].daemon, | ||
1200 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1131 | pg->peers[first].num_connections++; | 1201 | pg->peers[first].num_connections++; |
1132 | added++; | 1202 | added++; |
1133 | } | 1203 | } |
1134 | 1204 | ||
1135 | if (add_second) | 1205 | if (add_second) |
1136 | { | 1206 | { |
1137 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(pg->peers[second].blacklisted_peers, &hash_first, pg->peers[first].daemon, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1207 | GNUNET_assert (GNUNET_OK == |
1208 | GNUNET_CONTAINER_multihashmap_put (pg-> | ||
1209 | peers | ||
1210 | [second].blacklisted_peers, | ||
1211 | &hash_first, | ||
1212 | pg-> | ||
1213 | peers[first].daemon, | ||
1214 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1138 | pg->peers[second].num_connections++; | 1215 | pg->peers[second].num_connections++; |
1139 | added++; | 1216 | added++; |
1140 | } | 1217 | } |
@@ -1153,7 +1230,8 @@ blacklist_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, u | |||
1153 | * | 1230 | * |
1154 | */ | 1231 | */ |
1155 | static unsigned int | 1232 | static unsigned int |
1156 | unblacklist_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigned int second) | 1233 | unblacklist_connections (struct GNUNET_TESTING_PeerGroup *pg, |
1234 | unsigned int first, unsigned int second) | ||
1157 | { | 1235 | { |
1158 | int removed; | 1236 | int removed; |
1159 | int remove_first; | 1237 | int remove_first; |
@@ -1161,22 +1239,42 @@ unblacklist_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1161 | GNUNET_HashCode hash_first; | 1239 | GNUNET_HashCode hash_first; |
1162 | GNUNET_HashCode hash_second; | 1240 | GNUNET_HashCode hash_second; |
1163 | 1241 | ||
1164 | hash_from_uid(first, &hash_first); | 1242 | hash_from_uid (first, &hash_first); |
1165 | hash_from_uid(second, &hash_second); | 1243 | hash_from_uid (second, &hash_second); |
1166 | 1244 | ||
1167 | remove_first = GNUNET_CONTAINER_multihashmap_contains(pg->peers[first].blacklisted_peers, &hash_second); | 1245 | remove_first = |
1168 | remove_second = GNUNET_CONTAINER_multihashmap_contains(pg->peers[second].blacklisted_peers, &hash_first); | 1246 | GNUNET_CONTAINER_multihashmap_contains (pg-> |
1247 | peers[first].blacklisted_peers, | ||
1248 | &hash_second); | ||
1249 | remove_second = | ||
1250 | GNUNET_CONTAINER_multihashmap_contains (pg-> | ||
1251 | peers[second].blacklisted_peers, | ||
1252 | &hash_first); | ||
1169 | 1253 | ||
1170 | removed = 0; | 1254 | removed = 0; |
1171 | if (remove_first) | 1255 | if (remove_first) |
1172 | { | 1256 | { |
1173 | GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(pg->peers[first].blacklisted_peers, &hash_second, pg->peers[second].daemon)); | 1257 | GNUNET_assert (GNUNET_YES == |
1258 | GNUNET_CONTAINER_multihashmap_remove (pg-> | ||
1259 | peers | ||
1260 | [first].blacklisted_peers, | ||
1261 | &hash_second, | ||
1262 | pg-> | ||
1263 | peers | ||
1264 | [second].daemon)); | ||
1174 | removed++; | 1265 | removed++; |
1175 | } | 1266 | } |
1176 | 1267 | ||
1177 | if (remove_second) | 1268 | if (remove_second) |
1178 | { | 1269 | { |
1179 | GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(pg->peers[second].blacklisted_peers, &hash_first, pg->peers[first].daemon)); | 1270 | GNUNET_assert (GNUNET_YES == |
1271 | GNUNET_CONTAINER_multihashmap_remove (pg-> | ||
1272 | peers | ||
1273 | [second].blacklisted_peers, | ||
1274 | &hash_first, | ||
1275 | pg-> | ||
1276 | peers | ||
1277 | [first].daemon)); | ||
1180 | removed++; | 1278 | removed++; |
1181 | } | 1279 | } |
1182 | 1280 | ||
@@ -1199,7 +1297,8 @@ unblacklist_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1199 | * @return the number of connections created | 1297 | * @return the number of connections created |
1200 | */ | 1298 | */ |
1201 | static unsigned int | 1299 | static unsigned int |
1202 | create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) | 1300 | create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, |
1301 | GNUNET_TESTING_ConnectionProcessor proc) | ||
1203 | { | 1302 | { |
1204 | 1303 | ||
1205 | unsigned int total_connections; | 1304 | unsigned int total_connections; |
@@ -1209,19 +1308,23 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connectio | |||
1209 | double random; | 1308 | double random; |
1210 | double probability; | 1309 | double probability; |
1211 | 1310 | ||
1212 | GNUNET_assert(pg->total > 1); | 1311 | GNUNET_assert (pg->total > 1); |
1213 | 1312 | ||
1214 | /* Add a connection between the first two nodes */ | 1313 | /* Add a connection between the first two nodes */ |
1215 | total_connections = proc(pg, 0, 1); | 1314 | total_connections = proc (pg, 0, 1); |
1216 | 1315 | ||
1217 | for (outer_count = 1; outer_count < pg->total; outer_count++) | 1316 | for (outer_count = 1; outer_count < pg->total; outer_count++) |
1218 | { | 1317 | { |
1219 | previous_total_connections = total_connections; | 1318 | previous_total_connections = total_connections; |
1220 | for (i = 0; i < outer_count; i++) | 1319 | for (i = 0; i < outer_count; i++) |
1221 | { | 1320 | { |
1222 | probability = pg->peers[i].num_connections / (double)previous_total_connections; | 1321 | probability = |
1223 | random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 1322 | pg->peers[i].num_connections / |
1224 | UINT64_MAX)) / ( (double) UINT64_MAX); | 1323 | (double) previous_total_connections; |
1324 | random = | ||
1325 | ((double) | ||
1326 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1327 | UINT64_MAX)) / ((double) UINT64_MAX); | ||
1225 | #if VERBOSE_TESTING | 1328 | #if VERBOSE_TESTING |
1226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1227 | "Considering connecting peer %d to peer %d\n", | 1330 | "Considering connecting peer %d to peer %d\n", |
@@ -1231,10 +1334,9 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connectio | |||
1231 | { | 1334 | { |
1232 | #if VERBOSE_TESTING | 1335 | #if VERBOSE_TESTING |
1233 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1234 | "Connecting peer %d to peer %d\n", | 1337 | "Connecting peer %d to peer %d\n", outer_count, i); |
1235 | outer_count, i); | ||
1236 | #endif | 1338 | #endif |
1237 | total_connections += proc(pg, outer_count, i); | 1339 | total_connections += proc (pg, outer_count, i); |
1238 | } | 1340 | } |
1239 | } | 1341 | } |
1240 | } | 1342 | } |
@@ -1254,7 +1356,8 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connectio | |||
1254 | * | 1356 | * |
1255 | */ | 1357 | */ |
1256 | static unsigned int | 1358 | static unsigned int |
1257 | create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) | 1359 | create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg, |
1360 | GNUNET_TESTING_ConnectionProcessor proc) | ||
1258 | { | 1361 | { |
1259 | unsigned int i, j; | 1362 | unsigned int i, j; |
1260 | int nodeToConnect; | 1363 | int nodeToConnect; |
@@ -1269,32 +1372,30 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Conn | |||
1269 | unsigned int useAnd; | 1372 | unsigned int useAnd; |
1270 | int connect_attempts; | 1373 | int connect_attempts; |
1271 | 1374 | ||
1272 | logNModifier = 0.5; /* FIXME: default value? */ | 1375 | logNModifier = 0.5; /* FIXME: default value? */ |
1273 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(pg->cfg, | 1376 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, |
1274 | "TESTING", | 1377 | "TESTING", |
1275 | "LOGNMODIFIER", | 1378 | "LOGNMODIFIER", |
1276 | &p_string)) | 1379 | &p_string)) |
1277 | { | 1380 | { |
1278 | if (sscanf(p_string, "%lf", &logNModifier) != 1) | 1381 | if (sscanf (p_string, "%lf", &logNModifier) != 1) |
1279 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1382 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1280 | _("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1383 | _ |
1281 | p_string, | 1384 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1282 | "LOGNMODIFIER", | 1385 | p_string, "LOGNMODIFIER", "TESTING"); |
1283 | "TESTING"); | ||
1284 | GNUNET_free (p_string); | 1386 | GNUNET_free (p_string); |
1285 | } | 1387 | } |
1286 | percentage = 0.5; /* FIXME: default percentage? */ | 1388 | percentage = 0.5; /* FIXME: default percentage? */ |
1287 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(pg->cfg, | 1389 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, |
1288 | "TESTING", | 1390 | "TESTING", |
1289 | "PERCENTAGE", | 1391 | "PERCENTAGE", |
1290 | &p_string)) | 1392 | &p_string)) |
1291 | { | 1393 | { |
1292 | if (sscanf(p_string, "%lf", &percentage) != 1) | 1394 | if (sscanf (p_string, "%lf", &percentage) != 1) |
1293 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1395 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1294 | _("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1396 | _ |
1295 | p_string, | 1397 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1296 | "PERCENTAGE", | 1398 | p_string, "PERCENTAGE", "TESTING"); |
1297 | "TESTING"); | ||
1298 | GNUNET_free (p_string); | 1399 | GNUNET_free (p_string); |
1299 | } | 1400 | } |
1300 | natLog = log (pg->total); | 1401 | natLog = log (pg->total); |
@@ -1325,25 +1426,26 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Conn | |||
1325 | 1426 | ||
1326 | for (j = 0; j < connsPerPeer / 2; j++) | 1427 | for (j = 0; j < connsPerPeer / 2; j++) |
1327 | { | 1428 | { |
1328 | random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 1429 | random = |
1329 | UINT64_MAX) / ( (double) UINT64_MAX)); | 1430 | ((double) |
1431 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1432 | UINT64_MAX) / ((double) UINT64_MAX)); | ||
1330 | if (random < percentage) | 1433 | if (random < percentage) |
1331 | { | 1434 | { |
1332 | /* Connect to uniformly selected random peer */ | 1435 | /* Connect to uniformly selected random peer */ |
1333 | randomPeer = | 1436 | randomPeer = |
1334 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1437 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1335 | pg->total); | 1438 | pg->total); |
1336 | while ((((randomPeer < max) && (randomPeer > min)) | 1439 | while ((((randomPeer < max) && (randomPeer > min)) |
1337 | && (useAnd == 0)) || (((randomPeer > min) | 1440 | && (useAnd == 0)) || (((randomPeer > min) |
1338 | || (randomPeer < max)) | 1441 | || (randomPeer < max)) |
1339 | && (useAnd == 1))) | 1442 | && (useAnd == 1))) |
1340 | { | 1443 | { |
1341 | randomPeer = | 1444 | randomPeer = |
1342 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1445 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1343 | pg->total); | 1446 | pg->total); |
1344 | } | 1447 | } |
1345 | smallWorldConnections += | 1448 | smallWorldConnections += proc (pg, i, randomPeer); |
1346 | proc (pg, i, randomPeer); | ||
1347 | } | 1449 | } |
1348 | else | 1450 | else |
1349 | { | 1451 | { |
@@ -1352,8 +1454,7 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Conn | |||
1352 | { | 1454 | { |
1353 | nodeToConnect = nodeToConnect - pg->total; | 1455 | nodeToConnect = nodeToConnect - pg->total; |
1354 | } | 1456 | } |
1355 | connect_attempts += | 1457 | connect_attempts += proc (pg, i, nodeToConnect); |
1356 | proc (pg, i, nodeToConnect); | ||
1357 | } | 1458 | } |
1358 | } | 1459 | } |
1359 | 1460 | ||
@@ -1376,7 +1477,8 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Conn | |||
1376 | * | 1477 | * |
1377 | */ | 1478 | */ |
1378 | static unsigned int | 1479 | static unsigned int |
1379 | create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) | 1480 | create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, |
1481 | GNUNET_TESTING_ConnectionProcessor proc) | ||
1380 | { | 1482 | { |
1381 | unsigned int outer_count, inner_count; | 1483 | unsigned int outer_count, inner_count; |
1382 | unsigned int cutoff; | 1484 | unsigned int cutoff; |
@@ -1384,18 +1486,17 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Conne | |||
1384 | double nat_percentage; | 1486 | double nat_percentage; |
1385 | char *p_string; | 1487 | char *p_string; |
1386 | 1488 | ||
1387 | nat_percentage = 0.6; /* FIXME: default percentage? */ | 1489 | nat_percentage = 0.6; /* FIXME: default percentage? */ |
1388 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(pg->cfg, | 1490 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, |
1389 | "TESTING", | 1491 | "TESTING", |
1390 | "NATPERCENTAGE", | 1492 | "NATPERCENTAGE", |
1391 | &p_string)) | 1493 | &p_string)) |
1392 | { | 1494 | { |
1393 | if (sscanf(p_string, "%lf", &nat_percentage) != 1) | 1495 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) |
1394 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1496 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1395 | _("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1497 | _ |
1396 | p_string, | 1498 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1397 | "NATPERCENTAGE", | 1499 | p_string, "NATPERCENTAGE", "TESTING"); |
1398 | "TESTING"); | ||
1399 | GNUNET_free (p_string); | 1500 | GNUNET_free (p_string); |
1400 | } | 1501 | } |
1401 | 1502 | ||
@@ -1417,7 +1518,7 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Conne | |||
1417 | "Connecting peer %d to peer %d\n", | 1518 | "Connecting peer %d to peer %d\n", |
1418 | outer_count, inner_count); | 1519 | outer_count, inner_count); |
1419 | #endif | 1520 | #endif |
1420 | connect_attempts += proc(pg, outer_count, inner_count); | 1521 | connect_attempts += proc (pg, outer_count, inner_count); |
1421 | } | 1522 | } |
1422 | } | 1523 | } |
1423 | } | 1524 | } |
@@ -1438,7 +1539,8 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Conne | |||
1438 | * | 1539 | * |
1439 | */ | 1540 | */ |
1440 | static unsigned int | 1541 | static unsigned int |
1441 | create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) | 1542 | create_small_world (struct GNUNET_TESTING_PeerGroup *pg, |
1543 | GNUNET_TESTING_ConnectionProcessor proc) | ||
1442 | { | 1544 | { |
1443 | unsigned int i, j, k; | 1545 | unsigned int i, j, k; |
1444 | unsigned int square; | 1546 | unsigned int square; |
@@ -1461,39 +1563,38 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti | |||
1461 | rows = square; | 1563 | rows = square; |
1462 | cols = square; | 1564 | cols = square; |
1463 | 1565 | ||
1464 | percentage = 0.5; /* FIXME: default percentage? */ | 1566 | percentage = 0.5; /* FIXME: default percentage? */ |
1465 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(pg->cfg, | 1567 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, |
1466 | "TESTING", | 1568 | "TESTING", |
1467 | "PERCENTAGE", | 1569 | "PERCENTAGE", |
1468 | &p_string)) | 1570 | &p_string)) |
1469 | { | 1571 | { |
1470 | if (sscanf(p_string, "%lf", &percentage) != 1) | 1572 | if (sscanf (p_string, "%lf", &percentage) != 1) |
1471 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1573 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1472 | _("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1574 | _ |
1473 | p_string, | 1575 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1474 | "PERCENTAGE", | 1576 | p_string, "PERCENTAGE", "TESTING"); |
1475 | "TESTING"); | ||
1476 | GNUNET_free (p_string); | 1577 | GNUNET_free (p_string); |
1477 | } | 1578 | } |
1478 | if (percentage < 0.0) | 1579 | if (percentage < 0.0) |
1479 | { | 1580 | { |
1480 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1581 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1481 | _("Invalid value `%s' for option `%s' in section `%s': got %f, needed value greater than 0\n"), | 1582 | _ |
1583 | ("Invalid value `%s' for option `%s' in section `%s': got %f, needed value greater than 0\n"), | ||
1482 | "PERCENTAGE", "TESTING", percentage); | 1584 | "PERCENTAGE", "TESTING", percentage); |
1483 | percentage = 0.5; | 1585 | percentage = 0.5; |
1484 | } | 1586 | } |
1485 | probability = 0.5; /* FIXME: default percentage? */ | 1587 | probability = 0.5; /* FIXME: default percentage? */ |
1486 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(pg->cfg, | 1588 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, |
1487 | "TESTING", | 1589 | "TESTING", |
1488 | "PROBABILITY", | 1590 | "PROBABILITY", |
1489 | &p_string)) | 1591 | &p_string)) |
1490 | { | 1592 | { |
1491 | if (sscanf(p_string, "%lf", &probability) != 1) | 1593 | if (sscanf (p_string, "%lf", &probability) != 1) |
1492 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1594 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1493 | _("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1595 | _ |
1494 | p_string, | 1596 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1495 | "PROBABILITY", | 1597 | p_string, "PROBABILITY", "TESTING"); |
1496 | "TESTING"); | ||
1497 | GNUNET_free (p_string); | 1598 | GNUNET_free (p_string); |
1498 | } | 1599 | } |
1499 | if (square * square != pg->total) | 1600 | if (square * square != pg->total) |
@@ -1509,9 +1610,10 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti | |||
1509 | } | 1610 | } |
1510 | } | 1611 | } |
1511 | #if VERBOSE_TESTING | 1612 | #if VERBOSE_TESTING |
1512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1513 | _("Connecting nodes in 2d torus topology: %u rows %u columns\n"), | 1614 | _ |
1514 | rows, cols); | 1615 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), |
1616 | rows, cols); | ||
1515 | #endif | 1617 | #endif |
1516 | 1618 | ||
1517 | connect_attempts = 0; | 1619 | connect_attempts = 0; |
@@ -1544,14 +1646,15 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti | |||
1544 | #if VERBOSE_TESTING > 2 | 1646 | #if VERBOSE_TESTING > 2 |
1545 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1647 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1546 | _("natural log of %d is %d, will run %d iterations\n"), | 1648 | _("natural log of %d is %d, will run %d iterations\n"), |
1547 | pg->total, natLog, (int) (natLog * percentage)); | 1649 | pg->total, natLog, (int) (natLog * percentage)); |
1548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Total connections added thus far: %u!\n"), connect_attempts); | 1650 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1651 | _("Total connections added thus far: %u!\n"), connect_attempts); | ||
1549 | #endif | 1652 | #endif |
1550 | smallWorldConnections = 0; | 1653 | smallWorldConnections = 0; |
1551 | small_world_it = (unsigned int)(natLog * percentage); | 1654 | small_world_it = (unsigned int) (natLog * percentage); |
1552 | if (small_world_it < 1) | 1655 | if (small_world_it < 1) |
1553 | small_world_it = 1; | 1656 | small_world_it = 1; |
1554 | GNUNET_assert(small_world_it > 0 && small_world_it < (unsigned int)-1); | 1657 | GNUNET_assert (small_world_it > 0 && small_world_it < (unsigned int) -1); |
1555 | for (i = 0; i < small_world_it; i++) | 1658 | for (i = 0; i < small_world_it; i++) |
1556 | { | 1659 | { |
1557 | for (j = 0; j < pg->total; j++) | 1660 | for (j = 0; j < pg->total; j++) |
@@ -1565,14 +1668,18 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti | |||
1565 | node2Row = k / cols; | 1668 | node2Row = k / cols; |
1566 | node2Col = k - (node2Row * cols); | 1669 | node2Col = k - (node2Row * cols); |
1567 | /* Simple Cartesian distance */ | 1670 | /* Simple Cartesian distance */ |
1568 | distance = abs (node1Row - node2Row) + abs (node1Col - node2Col); | 1671 | distance = |
1672 | abs (node1Row - node2Row) + abs (node1Col - node2Col); | ||
1569 | if (distance > 1) | 1673 | if (distance > 1) |
1570 | { | 1674 | { |
1571 | /* Calculate probability as 1 over the square of the distance */ | 1675 | /* Calculate probability as 1 over the square of the distance */ |
1572 | probability = 1.0 / (distance * distance); | 1676 | probability = 1.0 / (distance * distance); |
1573 | /* Choose a random value between 0 and 1 */ | 1677 | /* Choose a random value between 0 and 1 */ |
1574 | random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 1678 | random = |
1575 | UINT64_MAX)) / ( (double) UINT64_MAX); | 1679 | ((double) |
1680 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1681 | UINT64_MAX)) / | ||
1682 | ((double) UINT64_MAX); | ||
1576 | /* If random < probability, then connect the two nodes */ | 1683 | /* If random < probability, then connect the two nodes */ |
1577 | if (random < probability) | 1684 | if (random < probability) |
1578 | smallWorldConnections += proc (pg, j, k); | 1685 | smallWorldConnections += proc (pg, j, k); |
@@ -1583,9 +1690,9 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti | |||
1583 | } | 1690 | } |
1584 | connect_attempts += smallWorldConnections; | 1691 | connect_attempts += smallWorldConnections; |
1585 | #if VERBOSE_TESTING > 2 | 1692 | #if VERBOSE_TESTING > 2 |
1586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1693 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1587 | _("Total connections added for small world: %d!\n"), | 1694 | _("Total connections added for small world: %d!\n"), |
1588 | smallWorldConnections); | 1695 | smallWorldConnections); |
1589 | #endif | 1696 | #endif |
1590 | return connect_attempts; | 1697 | return connect_attempts; |
1591 | } | 1698 | } |
@@ -1602,7 +1709,8 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti | |||
1602 | * | 1709 | * |
1603 | */ | 1710 | */ |
1604 | static unsigned int | 1711 | static unsigned int |
1605 | create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) | 1712 | create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, |
1713 | GNUNET_TESTING_ConnectionProcessor proc) | ||
1606 | { | 1714 | { |
1607 | double temp_rand; | 1715 | double temp_rand; |
1608 | unsigned int outer_count; | 1716 | unsigned int outer_count; |
@@ -1611,18 +1719,17 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti | |||
1611 | double probability; | 1719 | double probability; |
1612 | char *p_string; | 1720 | char *p_string; |
1613 | 1721 | ||
1614 | probability = 0.5; /* FIXME: default percentage? */ | 1722 | probability = 0.5; /* FIXME: default percentage? */ |
1615 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(pg->cfg, | 1723 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, |
1616 | "TESTING", | 1724 | "TESTING", |
1617 | "PROBABILITY", | 1725 | "PROBABILITY", |
1618 | &p_string)) | 1726 | &p_string)) |
1619 | { | 1727 | { |
1620 | if (sscanf(p_string, "%lf", &probability) != 1) | 1728 | if (sscanf (p_string, "%lf", &probability) != 1) |
1621 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1729 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1622 | _("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1730 | _ |
1623 | p_string, | 1731 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1624 | "PROBABILITY", | 1732 | p_string, "PROBABILITY", "TESTING"); |
1625 | "TESTING"); | ||
1626 | GNUNET_free (p_string); | 1733 | GNUNET_free (p_string); |
1627 | } | 1734 | } |
1628 | connect_attempts = 0; | 1735 | connect_attempts = 0; |
@@ -1631,8 +1738,10 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti | |||
1631 | for (inner_count = outer_count + 1; inner_count < pg->total; | 1738 | for (inner_count = outer_count + 1; inner_count < pg->total; |
1632 | inner_count++) | 1739 | inner_count++) |
1633 | { | 1740 | { |
1634 | temp_rand = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 1741 | temp_rand = |
1635 | UINT64_MAX)) / ( (double) UINT64_MAX); | 1742 | ((double) |
1743 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1744 | UINT64_MAX)) / ((double) UINT64_MAX); | ||
1636 | #if VERBOSE_TESTING | 1745 | #if VERBOSE_TESTING |
1637 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1746 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1638 | _("rand is %f probability is %f\n"), temp_rand, | 1747 | _("rand is %f probability is %f\n"), temp_rand, |
@@ -1662,7 +1771,8 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti | |||
1662 | * | 1771 | * |
1663 | */ | 1772 | */ |
1664 | static unsigned int | 1773 | static unsigned int |
1665 | create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) | 1774 | create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, |
1775 | GNUNET_TESTING_ConnectionProcessor proc) | ||
1666 | { | 1776 | { |
1667 | unsigned int i; | 1777 | unsigned int i; |
1668 | unsigned int square; | 1778 | unsigned int square; |
@@ -1691,9 +1801,10 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionP | |||
1691 | } | 1801 | } |
1692 | } | 1802 | } |
1693 | #if VERBOSE_TESTING | 1803 | #if VERBOSE_TESTING |
1694 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1804 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1695 | _("Connecting nodes in 2d torus topology: %u rows %u columns\n"), | 1805 | _ |
1696 | rows, cols); | 1806 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), |
1807 | rows, cols); | ||
1697 | #endif | 1808 | #endif |
1698 | /* Rows and columns are all sorted out, now iterate over all nodes and connect each | 1809 | /* Rows and columns are all sorted out, now iterate over all nodes and connect each |
1699 | * to the node to its right and above. Once this is over, we'll have our torus! | 1810 | * to the node to its right and above. Once this is over, we'll have our torus! |
@@ -1710,11 +1821,10 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionP | |||
1710 | else | 1821 | else |
1711 | nodeToConnect = i - cols + 1; | 1822 | nodeToConnect = i - cols + 1; |
1712 | #if VERBOSE_TESTING | 1823 | #if VERBOSE_TESTING |
1713 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1824 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1714 | "Connecting peer %d to peer %d\n", | 1825 | "Connecting peer %d to peer %d\n", i, nodeToConnect); |
1715 | i, nodeToConnect); | ||
1716 | #endif | 1826 | #endif |
1717 | connect_attempts += proc(pg, i, nodeToConnect); | 1827 | connect_attempts += proc (pg, i, nodeToConnect); |
1718 | 1828 | ||
1719 | /* Second connect to the node immediately above */ | 1829 | /* Second connect to the node immediately above */ |
1720 | if (i < cols) | 1830 | if (i < cols) |
@@ -1726,10 +1836,9 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionP | |||
1726 | { | 1836 | { |
1727 | #if VERBOSE_TESTING | 1837 | #if VERBOSE_TESTING |
1728 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1838 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1729 | "Connecting peer %d to peer %d\n", | 1839 | "Connecting peer %d to peer %d\n", i, nodeToConnect); |
1730 | i, nodeToConnect); | ||
1731 | #endif | 1840 | #endif |
1732 | connect_attempts += proc(pg, i, nodeToConnect); | 1841 | connect_attempts += proc (pg, i, nodeToConnect); |
1733 | } | 1842 | } |
1734 | 1843 | ||
1735 | } | 1844 | } |
@@ -1750,7 +1859,8 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionP | |||
1750 | * | 1859 | * |
1751 | */ | 1860 | */ |
1752 | static unsigned int | 1861 | static unsigned int |
1753 | create_clique (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) | 1862 | create_clique (struct GNUNET_TESTING_PeerGroup *pg, |
1863 | GNUNET_TESTING_ConnectionProcessor proc) | ||
1754 | { | 1864 | { |
1755 | unsigned int outer_count; | 1865 | unsigned int outer_count; |
1756 | unsigned int inner_count; | 1866 | unsigned int inner_count; |
@@ -1768,7 +1878,7 @@ create_clique (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionPro | |||
1768 | "Connecting peer %d to peer %d\n", | 1878 | "Connecting peer %d to peer %d\n", |
1769 | outer_count, inner_count); | 1879 | outer_count, inner_count); |
1770 | #endif | 1880 | #endif |
1771 | connect_attempts += proc(pg, outer_count, inner_count); | 1881 | connect_attempts += proc (pg, outer_count, inner_count); |
1772 | } | 1882 | } |
1773 | } | 1883 | } |
1774 | 1884 | ||
@@ -1787,7 +1897,8 @@ create_clique (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionPro | |||
1787 | * | 1897 | * |
1788 | */ | 1898 | */ |
1789 | static unsigned int | 1899 | static unsigned int |
1790 | create_line (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) | 1900 | create_line (struct GNUNET_TESTING_PeerGroup *pg, |
1901 | GNUNET_TESTING_ConnectionProcessor proc) | ||
1791 | { | 1902 | { |
1792 | unsigned int count; | 1903 | unsigned int count; |
1793 | int connect_attempts; | 1904 | int connect_attempts; |
@@ -1798,11 +1909,10 @@ create_line (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProce | |||
1798 | for (count = 0; count < pg->total - 1; count++) | 1909 | for (count = 0; count < pg->total - 1; count++) |
1799 | { | 1910 | { |
1800 | #if VERBOSE_TESTING | 1911 | #if VERBOSE_TESTING |
1801 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1912 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1802 | "Connecting peer %d to peer %d\n", | 1913 | "Connecting peer %d to peer %d\n", count, count + 1); |
1803 | count, count + 1); | ||
1804 | #endif | 1914 | #endif |
1805 | connect_attempts += proc(pg, count, count + 1); | 1915 | connect_attempts += proc (pg, count, count + 1); |
1806 | } | 1916 | } |
1807 | 1917 | ||
1808 | return connect_attempts; | 1918 | return connect_attempts; |
@@ -1820,7 +1930,8 @@ create_line (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProce | |||
1820 | * | 1930 | * |
1821 | */ | 1931 | */ |
1822 | static unsigned int | 1932 | static unsigned int |
1823 | create_ring (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProcessor proc) | 1933 | create_ring (struct GNUNET_TESTING_PeerGroup *pg, |
1934 | GNUNET_TESTING_ConnectionProcessor proc) | ||
1824 | { | 1935 | { |
1825 | unsigned int count; | 1936 | unsigned int count; |
1826 | int connect_attempts; | 1937 | int connect_attempts; |
@@ -1831,15 +1942,14 @@ create_ring (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProce | |||
1831 | for (count = 0; count < pg->total - 1; count++) | 1942 | for (count = 0; count < pg->total - 1; count++) |
1832 | { | 1943 | { |
1833 | #if VERBOSE_TESTING | 1944 | #if VERBOSE_TESTING |
1834 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1945 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1835 | "Connecting peer %d to peer %d\n", | 1946 | "Connecting peer %d to peer %d\n", count, count + 1); |
1836 | count, count + 1); | ||
1837 | #endif | 1947 | #endif |
1838 | connect_attempts += proc(pg, count, count + 1); | 1948 | connect_attempts += proc (pg, count, count + 1); |
1839 | } | 1949 | } |
1840 | 1950 | ||
1841 | /* Connect the last peer to the first peer */ | 1951 | /* Connect the last peer to the first peer */ |
1842 | connect_attempts += proc(pg, pg->total - 1, 0); | 1952 | connect_attempts += proc (pg, pg->total - 1, 0); |
1843 | 1953 | ||
1844 | return connect_attempts; | 1954 | return connect_attempts; |
1845 | } | 1955 | } |
@@ -1863,9 +1973,7 @@ create_ring (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_ConnectionProce | |||
1863 | * "fixing" now. | 1973 | * "fixing" now. |
1864 | */ | 1974 | */ |
1865 | static int | 1975 | static int |
1866 | friend_file_iterator (void *cls, | 1976 | friend_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
1867 | const GNUNET_HashCode * key, | ||
1868 | void *value) | ||
1869 | { | 1977 | { |
1870 | FILE *temp_friend_handle = cls; | 1978 | FILE *temp_friend_handle = cls; |
1871 | struct GNUNET_TESTING_Daemon *peer = value; | 1979 | struct GNUNET_TESTING_Daemon *peer = value; |
@@ -1873,8 +1981,8 @@ friend_file_iterator (void *cls, | |||
1873 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; | 1981 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; |
1874 | 1982 | ||
1875 | temppeer = &peer->id; | 1983 | temppeer = &peer->id; |
1876 | GNUNET_CRYPTO_hash_to_enc(&temppeer->hashPubKey, &peer_enc); | 1984 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); |
1877 | fprintf(temp_friend_handle, "%s\n", (char *)&peer_enc); | 1985 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); |
1878 | 1986 | ||
1879 | return GNUNET_YES; | 1987 | return GNUNET_YES; |
1880 | } | 1988 | } |
@@ -1902,9 +2010,7 @@ struct BlacklistContext | |||
1902 | * @return GNUNET_YES to continue iteration | 2010 | * @return GNUNET_YES to continue iteration |
1903 | */ | 2011 | */ |
1904 | static int | 2012 | static int |
1905 | blacklist_file_iterator (void *cls, | 2013 | blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
1906 | const GNUNET_HashCode * key, | ||
1907 | void *value) | ||
1908 | { | 2014 | { |
1909 | struct BlacklistContext *blacklist_ctx = cls; | 2015 | struct BlacklistContext *blacklist_ctx = cls; |
1910 | //FILE *temp_blacklist_handle = cls; | 2016 | //FILE *temp_blacklist_handle = cls; |
@@ -1913,8 +2019,9 @@ blacklist_file_iterator (void *cls, | |||
1913 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; | 2019 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; |
1914 | 2020 | ||
1915 | temppeer = &peer->id; | 2021 | temppeer = &peer->id; |
1916 | GNUNET_CRYPTO_hash_to_enc(&temppeer->hashPubKey, &peer_enc); | 2022 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); |
1917 | fprintf(blacklist_ctx->temp_file_handle, "%s:%s\n", blacklist_ctx->transport, (char *)&peer_enc); | 2023 | fprintf (blacklist_ctx->temp_file_handle, "%s:%s\n", |
2024 | blacklist_ctx->transport, (char *) &peer_enc); | ||
1918 | 2025 | ||
1919 | return GNUNET_YES; | 2026 | return GNUNET_YES; |
1920 | } | 2027 | } |
@@ -1934,62 +2041,76 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
1934 | char *temp_service_path; | 2041 | char *temp_service_path; |
1935 | struct GNUNET_OS_Process **procarr; | 2042 | struct GNUNET_OS_Process **procarr; |
1936 | char *arg; | 2043 | char *arg; |
1937 | char * mytemp; | 2044 | char *mytemp; |
1938 | enum GNUNET_OS_ProcessStatusType type; | 2045 | enum GNUNET_OS_ProcessStatusType type; |
1939 | unsigned long return_code; | 2046 | unsigned long return_code; |
1940 | int count; | 2047 | int count; |
1941 | int ret; | 2048 | int ret; |
1942 | int max_wait = 10; | 2049 | int max_wait = 10; |
1943 | 2050 | ||
1944 | procarr = GNUNET_malloc(sizeof(struct GNUNET_OS_Process *) * pg->total); | 2051 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); |
1945 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 2052 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
1946 | { | 2053 | { |
1947 | mytemp = GNUNET_DISK_mktemp("friends"); | 2054 | mytemp = GNUNET_DISK_mktemp ("friends"); |
1948 | GNUNET_assert(mytemp != NULL); | 2055 | GNUNET_assert (mytemp != NULL); |
1949 | temp_friend_handle = fopen (mytemp, "wt"); | 2056 | temp_friend_handle = fopen (mytemp, "wt"); |
1950 | GNUNET_assert(temp_friend_handle != NULL); | 2057 | GNUNET_assert (temp_friend_handle != NULL); |
1951 | GNUNET_CONTAINER_multihashmap_iterate(pg->peers[pg_iter].allowed_peers, &friend_file_iterator, temp_friend_handle); | 2058 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers, |
1952 | fclose(temp_friend_handle); | 2059 | &friend_file_iterator, |
2060 | temp_friend_handle); | ||
2061 | fclose (temp_friend_handle); | ||
1953 | 2062 | ||
1954 | if (GNUNET_OK != | 2063 | if (GNUNET_OK != |
1955 | GNUNET_CONFIGURATION_get_value_string(pg->peers[pg_iter].daemon->cfg, "PATHS", "SERVICEHOME", &temp_service_path)) | 2064 | GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter]. |
1956 | { | 2065 | daemon->cfg, "PATHS", |
2066 | "SERVICEHOME", | ||
2067 | &temp_service_path)) | ||
2068 | { | ||
1957 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2069 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1958 | _("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), | 2070 | _ |
1959 | "SERVICEHOME", | 2071 | ("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), |
1960 | "PATHS"); | 2072 | "SERVICEHOME", "PATHS"); |
1961 | if (UNLINK (mytemp) != 0) | 2073 | if (UNLINK (mytemp) != 0) |
1962 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", mytemp); | 2074 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", |
1963 | GNUNET_free (mytemp); | 2075 | mytemp); |
2076 | GNUNET_free (mytemp); | ||
1964 | break; | 2077 | break; |
1965 | } | 2078 | } |
1966 | 2079 | ||
1967 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ | 2080 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ |
1968 | { | 2081 | { |
1969 | GNUNET_asprintf (&arg, "%s/friends", temp_service_path); | 2082 | GNUNET_asprintf (&arg, "%s/friends", temp_service_path); |
1970 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", | 2083 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", |
1971 | "mv", mytemp, arg, NULL); | 2084 | "mv", mytemp, arg, |
2085 | NULL); | ||
1972 | #if VERBOSE_TESTING | 2086 | #if VERBOSE_TESTING |
1973 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2087 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1974 | _("Copying file with command cp %s %s\n"), mytemp, arg); | 2088 | _("Copying file with command cp %s %s\n"), mytemp, arg); |
1975 | #endif | 2089 | #endif |
1976 | 2090 | ||
1977 | GNUNET_free(arg); | 2091 | GNUNET_free (arg); |
1978 | } | 2092 | } |
1979 | else /* Remote, scp the file to the correct place */ | 2093 | else /* Remote, scp the file to the correct place */ |
1980 | { | 2094 | { |
1981 | if (NULL != pg->peers[pg_iter].daemon->username) | 2095 | if (NULL != pg->peers[pg_iter].daemon->username) |
1982 | GNUNET_asprintf (&arg, "%s@%s:%s/friends", pg->peers[pg_iter].daemon->username, pg->peers[pg_iter].daemon->hostname, temp_service_path); | 2096 | GNUNET_asprintf (&arg, "%s@%s:%s/friends", |
2097 | pg->peers[pg_iter].daemon->username, | ||
2098 | pg->peers[pg_iter].daemon->hostname, | ||
2099 | temp_service_path); | ||
1983 | else | 2100 | else |
1984 | GNUNET_asprintf (&arg, "%s:%s/friends", pg->peers[pg_iter].daemon->hostname, temp_service_path); | 2101 | GNUNET_asprintf (&arg, "%s:%s/friends", |
1985 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", | 2102 | pg->peers[pg_iter].daemon->hostname, |
1986 | "scp", mytemp, arg, NULL); | 2103 | temp_service_path); |
2104 | procarr[pg_iter] = | ||
2105 | GNUNET_OS_start_process (NULL, NULL, "scp", "scp", mytemp, arg, | ||
2106 | NULL); | ||
1987 | 2107 | ||
1988 | #if VERBOSE_TESTING | 2108 | #if VERBOSE_TESTING |
1989 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1990 | _("Copying file with command scp %s %s\n"), mytemp, arg); | 2110 | _("Copying file with command scp %s %s\n"), mytemp, |
2111 | arg); | ||
1991 | #endif | 2112 | #endif |
1992 | GNUNET_free(arg); | 2113 | GNUNET_free (arg); |
1993 | } | 2114 | } |
1994 | GNUNET_free (temp_service_path); | 2115 | GNUNET_free (temp_service_path); |
1995 | GNUNET_free (mytemp); | 2116 | GNUNET_free (mytemp); |
@@ -2008,11 +2129,13 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
2008 | #endif | 2129 | #endif |
2009 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ | 2130 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ |
2010 | { | 2131 | { |
2011 | if (GNUNET_OS_process_status(procarr[pg_iter], &type, &return_code) != GNUNET_OK) | 2132 | if (GNUNET_OS_process_status |
2133 | (procarr[pg_iter], &type, &return_code) != GNUNET_OK) | ||
2012 | { | 2134 | { |
2013 | ret = GNUNET_SYSERR; | 2135 | ret = GNUNET_SYSERR; |
2014 | } | 2136 | } |
2015 | else if ((type != GNUNET_OS_PROCESS_EXITED) || (return_code != 0)) | 2137 | else if ((type != GNUNET_OS_PROCESS_EXITED) |
2138 | || (return_code != 0)) | ||
2016 | { | 2139 | { |
2017 | ret = GNUNET_SYSERR; | 2140 | ret = GNUNET_SYSERR; |
2018 | } | 2141 | } |
@@ -2021,8 +2144,8 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
2021 | GNUNET_OS_process_close (procarr[pg_iter]); | 2144 | GNUNET_OS_process_close (procarr[pg_iter]); |
2022 | procarr[pg_iter] = NULL; | 2145 | procarr[pg_iter] = NULL; |
2023 | #if VERBOSE_TESTING | 2146 | #if VERBOSE_TESTING |
2024 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2025 | _("File %d copied\n"), pg_iter); | 2148 | _("File %d copied\n"), pg_iter); |
2026 | #endif | 2149 | #endif |
2027 | } | 2150 | } |
2028 | } | 2151 | } |
@@ -2030,16 +2153,16 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
2030 | count++; | 2153 | count++; |
2031 | if (ret == GNUNET_SYSERR) | 2154 | if (ret == GNUNET_SYSERR) |
2032 | { | 2155 | { |
2033 | /* FIXME: why sleep here? -CG */ | 2156 | /* FIXME: why sleep here? -CG */ |
2034 | sleep(1); | 2157 | sleep (1); |
2035 | } | 2158 | } |
2036 | } | 2159 | } |
2037 | 2160 | ||
2038 | #if VERBOSE_TESTING | 2161 | #if VERBOSE_TESTING |
2039 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2040 | _("Finished copying all friend files!\n")); | 2163 | _("Finished copying all friend files!\n")); |
2041 | #endif | 2164 | #endif |
2042 | GNUNET_free(procarr); | 2165 | GNUNET_free (procarr); |
2043 | return ret; | 2166 | return ret; |
2044 | } | 2167 | } |
2045 | 2168 | ||
@@ -2053,7 +2176,8 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
2053 | * @param transports space delimited list of transports to blacklist | 2176 | * @param transports space delimited list of transports to blacklist |
2054 | */ | 2177 | */ |
2055 | static int | 2178 | static int |
2056 | create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char *transports) | 2179 | create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, |
2180 | const char *transports) | ||
2057 | { | 2181 | { |
2058 | FILE *temp_file_handle; | 2182 | FILE *temp_file_handle; |
2059 | static struct BlacklistContext blacklist_ctx; | 2183 | static struct BlacklistContext blacklist_ctx; |
@@ -2072,77 +2196,93 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char | |||
2072 | char *pos; | 2196 | char *pos; |
2073 | char *temp_transports; | 2197 | char *temp_transports; |
2074 | 2198 | ||
2075 | procarr = GNUNET_malloc(sizeof(struct GNUNET_OS_Process *) * pg->total); | 2199 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); |
2076 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 2200 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2077 | { | 2201 | { |
2078 | mytemp = GNUNET_DISK_mktemp("blacklist"); | 2202 | mytemp = GNUNET_DISK_mktemp ("blacklist"); |
2079 | GNUNET_assert(mytemp != NULL); | 2203 | GNUNET_assert (mytemp != NULL); |
2080 | temp_file_handle = fopen (mytemp, "wt"); | 2204 | temp_file_handle = fopen (mytemp, "wt"); |
2081 | GNUNET_assert(temp_file_handle != NULL); | 2205 | GNUNET_assert (temp_file_handle != NULL); |
2082 | temp_transports = GNUNET_strdup(transports); | 2206 | temp_transports = GNUNET_strdup (transports); |
2083 | blacklist_ctx.temp_file_handle = temp_file_handle; | 2207 | blacklist_ctx.temp_file_handle = temp_file_handle; |
2084 | transport_len = strlen(temp_transports) + 1; | 2208 | transport_len = strlen (temp_transports) + 1; |
2085 | pos = NULL; | 2209 | pos = NULL; |
2086 | 2210 | ||
2087 | for (i = 0; i < transport_len; i++) | 2211 | for (i = 0; i < transport_len; i++) |
2088 | { | ||
2089 | if ((temp_transports[i] == ' ') && (pos == NULL)) | ||
2090 | continue; /* At start of string (whitespace) */ | ||
2091 | else if ((temp_transports[i] == ' ') || (temp_transports[i] == '\0')) /* At end of string */ | ||
2092 | { | ||
2093 | temp_transports[i] = '\0'; | ||
2094 | blacklist_ctx.transport = pos; | ||
2095 | GNUNET_CONTAINER_multihashmap_iterate(pg->peers[pg_iter].blacklisted_peers, &blacklist_file_iterator, &blacklist_ctx); | ||
2096 | pos = NULL; | ||
2097 | } /* At beginning of actual string */ | ||
2098 | else if (pos == NULL) | ||
2099 | { | 2212 | { |
2100 | pos = &temp_transports[i]; | 2213 | if ((temp_transports[i] == ' ') && (pos == NULL)) |
2214 | continue; /* At start of string (whitespace) */ | ||
2215 | else if ((temp_transports[i] == ' ') || (temp_transports[i] == '\0')) /* At end of string */ | ||
2216 | { | ||
2217 | temp_transports[i] = '\0'; | ||
2218 | blacklist_ctx.transport = pos; | ||
2219 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | ||
2220 | peers | ||
2221 | [pg_iter].blacklisted_peers, | ||
2222 | &blacklist_file_iterator, | ||
2223 | &blacklist_ctx); | ||
2224 | pos = NULL; | ||
2225 | } /* At beginning of actual string */ | ||
2226 | else if (pos == NULL) | ||
2227 | { | ||
2228 | pos = &temp_transports[i]; | ||
2229 | } | ||
2101 | } | 2230 | } |
2102 | } | ||
2103 | 2231 | ||
2104 | GNUNET_free (temp_transports); | 2232 | GNUNET_free (temp_transports); |
2105 | fclose(temp_file_handle); | 2233 | fclose (temp_file_handle); |
2106 | 2234 | ||
2107 | if (GNUNET_OK != | 2235 | if (GNUNET_OK != |
2108 | GNUNET_CONFIGURATION_get_value_string(pg->peers[pg_iter].daemon->cfg, "PATHS", "SERVICEHOME", &temp_service_path)) | 2236 | GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter]. |
2237 | daemon->cfg, "PATHS", | ||
2238 | "SERVICEHOME", | ||
2239 | &temp_service_path)) | ||
2109 | { | 2240 | { |
2110 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2241 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2111 | _("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), | 2242 | _ |
2112 | "SERVICEHOME", | 2243 | ("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), |
2113 | "PATHS"); | 2244 | "SERVICEHOME", "PATHS"); |
2114 | if (UNLINK (mytemp) != 0) | 2245 | if (UNLINK (mytemp) != 0) |
2115 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", mytemp); | 2246 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", |
2247 | mytemp); | ||
2116 | GNUNET_free (mytemp); | 2248 | GNUNET_free (mytemp); |
2117 | break; | 2249 | break; |
2118 | } | 2250 | } |
2119 | 2251 | ||
2120 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ | 2252 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ |
2121 | { | 2253 | { |
2122 | GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path); | 2254 | GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path); |
2123 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", | 2255 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", |
2124 | "mv", mytemp, arg, NULL); | 2256 | "mv", mytemp, arg, |
2257 | NULL); | ||
2125 | #if VERBOSE_TESTING | 2258 | #if VERBOSE_TESTING |
2126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2127 | _("Copying file with command cp %s %s\n"), mytemp, arg); | 2260 | _("Copying file with command cp %s %s\n"), mytemp, arg); |
2128 | #endif | 2261 | #endif |
2129 | 2262 | ||
2130 | GNUNET_free(arg); | 2263 | GNUNET_free (arg); |
2131 | } | 2264 | } |
2132 | else /* Remote, scp the file to the correct place */ | 2265 | else /* Remote, scp the file to the correct place */ |
2133 | { | 2266 | { |
2134 | if (NULL != pg->peers[pg_iter].daemon->username) | 2267 | if (NULL != pg->peers[pg_iter].daemon->username) |
2135 | GNUNET_asprintf (&arg, "%s@%s:%s/blacklist", pg->peers[pg_iter].daemon->username, pg->peers[pg_iter].daemon->hostname, temp_service_path); | 2268 | GNUNET_asprintf (&arg, "%s@%s:%s/blacklist", |
2269 | pg->peers[pg_iter].daemon->username, | ||
2270 | pg->peers[pg_iter].daemon->hostname, | ||
2271 | temp_service_path); | ||
2136 | else | 2272 | else |
2137 | GNUNET_asprintf (&arg, "%s:%s/blacklist", pg->peers[pg_iter].daemon->hostname, temp_service_path); | 2273 | GNUNET_asprintf (&arg, "%s:%s/blacklist", |
2138 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", | 2274 | pg->peers[pg_iter].daemon->hostname, |
2139 | "scp", mytemp, arg, NULL); | 2275 | temp_service_path); |
2276 | procarr[pg_iter] = | ||
2277 | GNUNET_OS_start_process (NULL, NULL, "scp", "scp", mytemp, arg, | ||
2278 | NULL); | ||
2140 | 2279 | ||
2141 | #if VERBOSE_TESTING | 2280 | #if VERBOSE_TESTING |
2142 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2281 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2143 | _("Copying file with command scp %s %s\n"), mytemp, arg); | 2282 | _("Copying file with command scp %s %s\n"), mytemp, |
2283 | arg); | ||
2144 | #endif | 2284 | #endif |
2145 | GNUNET_free(arg); | 2285 | GNUNET_free (arg); |
2146 | } | 2286 | } |
2147 | GNUNET_free (temp_service_path); | 2287 | GNUNET_free (temp_service_path); |
2148 | GNUNET_free (mytemp); | 2288 | GNUNET_free (mytemp); |
@@ -2161,11 +2301,13 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char | |||
2161 | #endif | 2301 | #endif |
2162 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ | 2302 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ |
2163 | { | 2303 | { |
2164 | if (GNUNET_OS_process_status(procarr[pg_iter], &type, &return_code) != GNUNET_OK) | 2304 | if (GNUNET_OS_process_status |
2305 | (procarr[pg_iter], &type, &return_code) != GNUNET_OK) | ||
2165 | { | 2306 | { |
2166 | ret = GNUNET_SYSERR; | 2307 | ret = GNUNET_SYSERR; |
2167 | } | 2308 | } |
2168 | else if ((type != GNUNET_OS_PROCESS_EXITED) || (return_code != 0)) | 2309 | else if ((type != GNUNET_OS_PROCESS_EXITED) |
2310 | || (return_code != 0)) | ||
2169 | { | 2311 | { |
2170 | ret = GNUNET_SYSERR; | 2312 | ret = GNUNET_SYSERR; |
2171 | } | 2313 | } |
@@ -2174,8 +2316,8 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char | |||
2174 | GNUNET_OS_process_close (procarr[pg_iter]); | 2316 | GNUNET_OS_process_close (procarr[pg_iter]); |
2175 | procarr[pg_iter] = NULL; | 2317 | procarr[pg_iter] = NULL; |
2176 | #if VERBOSE_TESTING | 2318 | #if VERBOSE_TESTING |
2177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2178 | _("File %d copied\n"), pg_iter); | 2320 | _("File %d copied\n"), pg_iter); |
2179 | #endif | 2321 | #endif |
2180 | } | 2322 | } |
2181 | } | 2323 | } |
@@ -2183,16 +2325,16 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char | |||
2183 | count++; | 2325 | count++; |
2184 | if (ret == GNUNET_SYSERR) | 2326 | if (ret == GNUNET_SYSERR) |
2185 | { | 2327 | { |
2186 | /* FIXME: why sleep here? -CG */ | 2328 | /* FIXME: why sleep here? -CG */ |
2187 | sleep(1); | 2329 | sleep (1); |
2188 | } | 2330 | } |
2189 | } | 2331 | } |
2190 | 2332 | ||
2191 | #if VERBOSE_TESTING | 2333 | #if VERBOSE_TESTING |
2192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2334 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2193 | _("Finished copying all blacklist files!\n")); | 2335 | _("Finished copying all blacklist files!\n")); |
2194 | #endif | 2336 | #endif |
2195 | GNUNET_free(procarr); | 2337 | GNUNET_free (procarr); |
2196 | return ret; | 2338 | return ret; |
2197 | } | 2339 | } |
2198 | 2340 | ||
@@ -2201,15 +2343,16 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char | |||
2201 | * Internal notification of a connection, kept so that we can ensure some connections | 2343 | * Internal notification of a connection, kept so that we can ensure some connections |
2202 | * happen instead of flooding all testing daemons with requests to connect. | 2344 | * happen instead of flooding all testing daemons with requests to connect. |
2203 | */ | 2345 | */ |
2204 | static void internal_connect_notify (void *cls, | 2346 | static void |
2205 | const struct GNUNET_PeerIdentity *first, | 2347 | internal_connect_notify (void *cls, |
2206 | const struct GNUNET_PeerIdentity *second, | 2348 | const struct GNUNET_PeerIdentity *first, |
2207 | uint32_t distance, | 2349 | const struct GNUNET_PeerIdentity *second, |
2208 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, | 2350 | uint32_t distance, |
2209 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, | 2351 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, |
2210 | struct GNUNET_TESTING_Daemon *first_daemon, | 2352 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, |
2211 | struct GNUNET_TESTING_Daemon *second_daemon, | 2353 | struct GNUNET_TESTING_Daemon *first_daemon, |
2212 | const char *emsg) | 2354 | struct GNUNET_TESTING_Daemon *second_daemon, |
2355 | const char *emsg) | ||
2213 | { | 2356 | { |
2214 | struct ConnectTopologyContext *ct_ctx = cls; | 2357 | struct ConnectTopologyContext *ct_ctx = cls; |
2215 | struct GNUNET_TESTING_PeerGroup *pg = ct_ctx->pg; | 2358 | struct GNUNET_TESTING_PeerGroup *pg = ct_ctx->pg; |
@@ -2218,12 +2361,14 @@ static void internal_connect_notify (void *cls, | |||
2218 | if (ct_ctx->remaining_connections == 0) | 2361 | if (ct_ctx->remaining_connections == 0) |
2219 | { | 2362 | { |
2220 | if (ct_ctx->notify_connections_done != NULL) | 2363 | if (ct_ctx->notify_connections_done != NULL) |
2221 | ct_ctx->notify_connections_done(ct_ctx->notify_cls, NULL); | 2364 | ct_ctx->notify_connections_done (ct_ctx->notify_cls, NULL); |
2222 | GNUNET_free(ct_ctx); | 2365 | GNUNET_free (ct_ctx); |
2223 | } | 2366 | } |
2224 | 2367 | ||
2225 | if (pg->notify_connection != NULL) | 2368 | if (pg->notify_connection != NULL) |
2226 | pg->notify_connection (pg->notify_connection_cls, first, second, distance, first_cfg, second_cfg, first_daemon, second_daemon, emsg); | 2369 | pg->notify_connection (pg->notify_connection_cls, first, second, distance, |
2370 | first_cfg, second_cfg, first_daemon, second_daemon, | ||
2371 | emsg); | ||
2227 | } | 2372 | } |
2228 | 2373 | ||
2229 | 2374 | ||
@@ -2234,7 +2379,8 @@ static void internal_connect_notify (void *cls, | |||
2234 | * @param cls a connection context | 2379 | * @param cls a connection context |
2235 | * @param tc the task runtime context | 2380 | * @param tc the task runtime context |
2236 | */ | 2381 | */ |
2237 | static void schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 2382 | static void |
2383 | schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2238 | { | 2384 | { |
2239 | struct ConnectContext *connect_context = cls; | 2385 | struct ConnectContext *connect_context = cls; |
2240 | 2386 | ||
@@ -2244,16 +2390,20 @@ static void schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContex | |||
2244 | if (outstanding_connects > MAX_OUTSTANDING_CONNECTIONS) | 2390 | if (outstanding_connects > MAX_OUTSTANDING_CONNECTIONS) |
2245 | { | 2391 | { |
2246 | #if VERBOSE_TESTING > 2 | 2392 | #if VERBOSE_TESTING > 2 |
2247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2248 | _("Delaying connect, we have too many outstanding connections!\n")); | 2394 | _ |
2395 | ("Delaying connect, we have too many outstanding connections!\n")); | ||
2249 | #endif | 2396 | #endif |
2250 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &schedule_connect, connect_context); | 2397 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
2398 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | ||
2399 | &schedule_connect, connect_context); | ||
2251 | } | 2400 | } |
2252 | else | 2401 | else |
2253 | { | 2402 | { |
2254 | #if VERBOSE_TESTING > 2 | 2403 | #if VERBOSE_TESTING > 2 |
2255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2256 | _("Creating connection, outstanding_connections is %d\n"), outstanding_connects); | 2405 | _("Creating connection, outstanding_connections is %d\n"), |
2406 | outstanding_connects); | ||
2257 | #endif | 2407 | #endif |
2258 | outstanding_connects++; | 2408 | outstanding_connects++; |
2259 | GNUNET_TESTING_daemons_connect (connect_context->first, | 2409 | GNUNET_TESTING_daemons_connect (connect_context->first, |
@@ -2262,7 +2412,7 @@ static void schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContex | |||
2262 | CONNECT_ATTEMPTS, | 2412 | CONNECT_ATTEMPTS, |
2263 | &internal_connect_notify, | 2413 | &internal_connect_notify, |
2264 | connect_context->ct_ctx); | 2414 | connect_context->ct_ctx); |
2265 | GNUNET_free(connect_context); | 2415 | GNUNET_free (connect_context); |
2266 | } | 2416 | } |
2267 | } | 2417 | } |
2268 | 2418 | ||
@@ -2278,20 +2428,18 @@ static void schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContex | |||
2278 | * @return GNUNET_YES to continue iteration | 2428 | * @return GNUNET_YES to continue iteration |
2279 | */ | 2429 | */ |
2280 | static int | 2430 | static int |
2281 | connect_iterator (void *cls, | 2431 | connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
2282 | const GNUNET_HashCode * key, | ||
2283 | void *value) | ||
2284 | { | 2432 | { |
2285 | struct ConnectTopologyContext *ct_ctx = cls; | 2433 | struct ConnectTopologyContext *ct_ctx = cls; |
2286 | struct PeerData *first = ct_ctx->first; | 2434 | struct PeerData *first = ct_ctx->first; |
2287 | struct GNUNET_TESTING_Daemon *second = value; | 2435 | struct GNUNET_TESTING_Daemon *second = value; |
2288 | struct ConnectContext *connect_context; | 2436 | struct ConnectContext *connect_context; |
2289 | 2437 | ||
2290 | connect_context = GNUNET_malloc(sizeof(struct ConnectContext)); | 2438 | connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); |
2291 | connect_context->first = first->daemon; | 2439 | connect_context->first = first->daemon; |
2292 | connect_context->second = second; | 2440 | connect_context->second = second; |
2293 | connect_context->ct_ctx = ct_ctx; | 2441 | connect_context->ct_ctx = ct_ctx; |
2294 | GNUNET_SCHEDULER_add_now(&schedule_connect, connect_context); | 2442 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); |
2295 | 2443 | ||
2296 | return GNUNET_YES; | 2444 | return GNUNET_YES; |
2297 | } | 2445 | } |
@@ -2308,13 +2456,14 @@ connect_iterator (void *cls, | |||
2308 | * @return GNUNET_YES to continue iteration | 2456 | * @return GNUNET_YES to continue iteration |
2309 | */ | 2457 | */ |
2310 | static int | 2458 | static int |
2311 | copy_topology_iterator (void *cls, | 2459 | copy_topology_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
2312 | const GNUNET_HashCode * key, | ||
2313 | void *value) | ||
2314 | { | 2460 | { |
2315 | struct PeerData *first = cls; | 2461 | struct PeerData *first = cls; |
2316 | 2462 | ||
2317 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(first->connect_peers, key, value, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2463 | GNUNET_assert (GNUNET_OK == |
2464 | GNUNET_CONTAINER_multihashmap_put (first->connect_peers, key, | ||
2465 | value, | ||
2466 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
2318 | 2467 | ||
2319 | return GNUNET_YES; | 2468 | return GNUNET_YES; |
2320 | } | 2469 | } |
@@ -2335,7 +2484,11 @@ copy_allowed_topology (struct GNUNET_TESTING_PeerGroup *pg) | |||
2335 | total = 0; | 2484 | total = 0; |
2336 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 2485 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2337 | { | 2486 | { |
2338 | ret = GNUNET_CONTAINER_multihashmap_iterate(pg->peers[pg_iter].allowed_peers, ©_topology_iterator, &pg->peers[pg_iter]); | 2487 | ret = |
2488 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | ||
2489 | peers[pg_iter].allowed_peers, | ||
2490 | ©_topology_iterator, | ||
2491 | &pg->peers[pg_iter]); | ||
2339 | if (GNUNET_SYSERR == ret) | 2492 | if (GNUNET_SYSERR == ret) |
2340 | return GNUNET_SYSERR; | 2493 | return GNUNET_SYSERR; |
2341 | 2494 | ||
@@ -2354,7 +2507,9 @@ copy_allowed_topology (struct GNUNET_TESTING_PeerGroup *pg) | |||
2354 | * @return the number of connections that will be attempted | 2507 | * @return the number of connections that will be attempted |
2355 | */ | 2508 | */ |
2356 | static int | 2509 | static int |
2357 | connect_topology (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_NotifyCompletion notify_callback, void *notify_cls) | 2510 | connect_topology (struct GNUNET_TESTING_PeerGroup *pg, |
2511 | GNUNET_TESTING_NotifyCompletion notify_callback, | ||
2512 | void *notify_cls) | ||
2358 | { | 2513 | { |
2359 | unsigned int pg_iter; | 2514 | unsigned int pg_iter; |
2360 | int ret; | 2515 | int ret; |
@@ -2366,19 +2521,20 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_NotifyComp | |||
2366 | #endif | 2521 | #endif |
2367 | 2522 | ||
2368 | total = 0; | 2523 | total = 0; |
2369 | ct_ctx = GNUNET_malloc(sizeof(struct ConnectTopologyContext)); | 2524 | ct_ctx = GNUNET_malloc (sizeof (struct ConnectTopologyContext)); |
2370 | ct_ctx->notify_connections_done = notify_callback; | 2525 | ct_ctx->notify_connections_done = notify_callback; |
2371 | ct_ctx->notify_cls = notify_cls; | 2526 | ct_ctx->notify_cls = notify_cls; |
2372 | ct_ctx->pg = pg; | 2527 | ct_ctx->pg = pg; |
2373 | 2528 | ||
2374 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 2529 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2375 | { | 2530 | { |
2376 | total += GNUNET_CONTAINER_multihashmap_size(pg->peers[pg_iter].connect_peers); | 2531 | total += |
2532 | GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].connect_peers); | ||
2377 | } | 2533 | } |
2378 | 2534 | ||
2379 | if (total == 0) | 2535 | if (total == 0) |
2380 | { | 2536 | { |
2381 | GNUNET_free(ct_ctx); | 2537 | GNUNET_free (ct_ctx); |
2382 | return total; | 2538 | return total; |
2383 | } | 2539 | } |
2384 | ct_ctx->remaining_connections = total; | 2540 | ct_ctx->remaining_connections = total; |
@@ -2387,19 +2543,22 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_NotifyComp | |||
2387 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 2543 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2388 | { | 2544 | { |
2389 | ct_ctx->first = &pg->peers[pg_iter]; | 2545 | ct_ctx->first = &pg->peers[pg_iter]; |
2390 | ret = GNUNET_CONTAINER_multihashmap_iterate(pg->peers[pg_iter].connect_peers, &connect_iterator, ct_ctx); | 2546 | ret = |
2391 | GNUNET_assert(GNUNET_SYSERR != ret && ret >= 0); | 2547 | GNUNET_CONTAINER_multihashmap_iterate (pg-> |
2548 | peers[pg_iter].connect_peers, | ||
2549 | &connect_iterator, ct_ctx); | ||
2550 | GNUNET_assert (GNUNET_SYSERR != ret && ret >= 0); | ||
2392 | total = total + ret; | 2551 | total = total + ret; |
2393 | 2552 | ||
2394 | #if OLD | 2553 | #if OLD |
2395 | connection_iter = FIXME; | 2554 | connection_iter = FIXME; |
2396 | while (connection_iter != NULL) | 2555 | while (connection_iter != NULL) |
2397 | { | 2556 | { |
2398 | connect_context = GNUNET_malloc(sizeof(struct ConnectContext)); | 2557 | connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); |
2399 | connect_context->pg = pg; | 2558 | connect_context->pg = pg; |
2400 | connect_context->first = FIXME; | 2559 | connect_context->first = FIXME; |
2401 | connect_context->second = connection_iter->daemon; | 2560 | connect_context->second = connection_iter->daemon; |
2402 | GNUNET_SCHEDULER_add_now(&schedule_connect, connect_context); | 2561 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); |
2403 | connection_iter = connection_iter->next; | 2562 | connection_iter = connection_iter->next; |
2404 | } | 2563 | } |
2405 | #endif | 2564 | #endif |
@@ -2431,7 +2590,8 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_NotifyComp | |||
2431 | unsigned int | 2590 | unsigned int |
2432 | GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | 2591 | GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, |
2433 | enum GNUNET_TESTING_Topology topology, | 2592 | enum GNUNET_TESTING_Topology topology, |
2434 | enum GNUNET_TESTING_Topology restrict_topology, | 2593 | enum GNUNET_TESTING_Topology |
2594 | restrict_topology, | ||
2435 | const char *restrict_transports) | 2595 | const char *restrict_transports) |
2436 | { | 2596 | { |
2437 | int ret; | 2597 | int ret; |
@@ -2442,8 +2602,7 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2442 | { | 2602 | { |
2443 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | 2603 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: |
2444 | #if VERBOSE_TESTING | 2604 | #if VERBOSE_TESTING |
2445 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating clique topology\n")); |
2446 | _("Creating clique topology\n")); | ||
2447 | #endif | 2606 | #endif |
2448 | num_connections = create_clique (pg, &add_allowed_connections); | 2607 | num_connections = create_clique (pg, &add_allowed_connections); |
2449 | break; | 2608 | break; |
@@ -2452,7 +2611,8 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2611 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2453 | _("Creating small world (ring) topology\n")); | 2612 | _("Creating small world (ring) topology\n")); |
2454 | #endif | 2613 | #endif |
2455 | num_connections = create_small_world_ring (pg, &add_allowed_connections); | 2614 | num_connections = |
2615 | create_small_world_ring (pg, &add_allowed_connections); | ||
2456 | break; | 2616 | break; |
2457 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | 2617 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: |
2458 | #if VERBOSE_TESTING | 2618 | #if VERBOSE_TESTING |
@@ -2463,15 +2623,13 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2463 | break; | 2623 | break; |
2464 | case GNUNET_TESTING_TOPOLOGY_RING: | 2624 | case GNUNET_TESTING_TOPOLOGY_RING: |
2465 | #if VERBOSE_TESTING | 2625 | #if VERBOSE_TESTING |
2466 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2626 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating ring topology\n")); |
2467 | _("Creating ring topology\n")); | ||
2468 | #endif | 2627 | #endif |
2469 | num_connections = create_ring (pg, &add_allowed_connections); | 2628 | num_connections = create_ring (pg, &add_allowed_connections); |
2470 | break; | 2629 | break; |
2471 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: | 2630 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: |
2472 | #if VERBOSE_TESTING | 2631 | #if VERBOSE_TESTING |
2473 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2632 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating 2d torus topology\n")); |
2474 | _("Creating 2d torus topology\n")); | ||
2475 | #endif | 2633 | #endif |
2476 | num_connections = create_2d_torus (pg, &add_allowed_connections); | 2634 | num_connections = create_2d_torus (pg, &add_allowed_connections); |
2477 | break; | 2635 | break; |
@@ -2484,8 +2642,7 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2484 | break; | 2642 | break; |
2485 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: | 2643 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: |
2486 | #if VERBOSE_TESTING | 2644 | #if VERBOSE_TESTING |
2487 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2645 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating InterNAT topology\n")); |
2488 | _("Creating InterNAT topology\n")); | ||
2489 | #endif | 2646 | #endif |
2490 | num_connections = create_nated_internet (pg, &add_allowed_connections); | 2647 | num_connections = create_nated_internet (pg, &add_allowed_connections); |
2491 | break; | 2648 | break; |
@@ -2506,7 +2663,8 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2506 | case GNUNET_TESTING_TOPOLOGY_NONE: | 2663 | case GNUNET_TESTING_TOPOLOGY_NONE: |
2507 | #if VERBOSE_TESTING | 2664 | #if VERBOSE_TESTING |
2508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2665 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2509 | _("Creating no allowed topology (all peers can connect at core level)\n")); | 2666 | _ |
2667 | ("Creating no allowed topology (all peers can connect at core level)\n")); | ||
2510 | #endif | 2668 | #endif |
2511 | num_connections = 0; | 2669 | num_connections = 0; |
2512 | break; | 2670 | break; |
@@ -2515,9 +2673,10 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2515 | break; | 2673 | break; |
2516 | } | 2674 | } |
2517 | 2675 | ||
2518 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", "F2F")) | 2676 | if (GNUNET_YES == |
2677 | GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", "F2F")) | ||
2519 | { | 2678 | { |
2520 | ret = create_and_copy_friend_files(pg); | 2679 | ret = create_and_copy_friend_files (pg); |
2521 | if (ret != GNUNET_OK) | 2680 | if (ret != GNUNET_OK) |
2522 | { | 2681 | { |
2523 | #if VERBOSE_TESTING | 2682 | #if VERBOSE_TESTING |
@@ -2529,8 +2688,8 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2529 | else | 2688 | else |
2530 | { | 2689 | { |
2531 | #if VERBOSE_TESTING | 2690 | #if VERBOSE_TESTING |
2532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2691 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2533 | _("Friend files created/copied successfully!\n")); | 2692 | _("Friend files created/copied successfully!\n")); |
2534 | #endif | 2693 | #endif |
2535 | } | 2694 | } |
2536 | } | 2695 | } |
@@ -2548,21 +2707,25 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2707 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2549 | _("Blacklisting all but clique topology\n")); | 2708 | _("Blacklisting all but clique topology\n")); |
2550 | #endif | 2709 | #endif |
2551 | unblacklisted_connections = create_clique (pg, &unblacklist_connections); | 2710 | unblacklisted_connections = |
2711 | create_clique (pg, &unblacklist_connections); | ||
2552 | break; | 2712 | break; |
2553 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: | 2713 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: |
2554 | #if VERBOSE_TESTING | 2714 | #if VERBOSE_TESTING |
2555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2556 | _("Blacklisting all but small world (ring) topology\n")); | 2716 | _("Blacklisting all but small world (ring) topology\n")); |
2557 | #endif | 2717 | #endif |
2558 | unblacklisted_connections = create_small_world_ring (pg, &unblacklist_connections); | 2718 | unblacklisted_connections = |
2719 | create_small_world_ring (pg, &unblacklist_connections); | ||
2559 | break; | 2720 | break; |
2560 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | 2721 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: |
2561 | #if VERBOSE_TESTING | 2722 | #if VERBOSE_TESTING |
2562 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2723 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2563 | _("Blacklisting all but small world (2d-torus) topology\n")); | 2724 | _ |
2725 | ("Blacklisting all but small world (2d-torus) topology\n")); | ||
2564 | #endif | 2726 | #endif |
2565 | unblacklisted_connections = create_small_world (pg, &unblacklist_connections); | 2727 | unblacklisted_connections = |
2728 | create_small_world (pg, &unblacklist_connections); | ||
2566 | break; | 2729 | break; |
2567 | case GNUNET_TESTING_TOPOLOGY_RING: | 2730 | case GNUNET_TESTING_TOPOLOGY_RING: |
2568 | #if VERBOSE_TESTING | 2731 | #if VERBOSE_TESTING |
@@ -2576,28 +2739,32 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2576 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2739 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2577 | _("Blacklisting all but 2d torus topology\n")); | 2740 | _("Blacklisting all but 2d torus topology\n")); |
2578 | #endif | 2741 | #endif |
2579 | unblacklisted_connections = create_2d_torus (pg, &unblacklist_connections); | 2742 | unblacklisted_connections = |
2743 | create_2d_torus (pg, &unblacklist_connections); | ||
2580 | break; | 2744 | break; |
2581 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | 2745 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: |
2582 | #if VERBOSE_TESTING | 2746 | #if VERBOSE_TESTING |
2583 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2747 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2584 | _("Blacklisting all but Erdos-Renyi topology\n")); | 2748 | _("Blacklisting all but Erdos-Renyi topology\n")); |
2585 | #endif | 2749 | #endif |
2586 | unblacklisted_connections = create_erdos_renyi (pg, &unblacklist_connections); | 2750 | unblacklisted_connections = |
2751 | create_erdos_renyi (pg, &unblacklist_connections); | ||
2587 | break; | 2752 | break; |
2588 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: | 2753 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: |
2589 | #if VERBOSE_TESTING | 2754 | #if VERBOSE_TESTING |
2590 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2755 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2591 | _("Blacklisting all but InterNAT topology\n")); | 2756 | _("Blacklisting all but InterNAT topology\n")); |
2592 | #endif | 2757 | #endif |
2593 | unblacklisted_connections = create_nated_internet (pg, &unblacklist_connections); | 2758 | unblacklisted_connections = |
2759 | create_nated_internet (pg, &unblacklist_connections); | ||
2594 | break; | 2760 | break; |
2595 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | 2761 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: |
2596 | #if VERBOSE_TESTING | 2762 | #if VERBOSE_TESTING |
2597 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2598 | _("Blacklisting all but Scale Free topology\n")); | 2764 | _("Blacklisting all but Scale Free topology\n")); |
2599 | #endif | 2765 | #endif |
2600 | unblacklisted_connections = create_scale_free (pg, &unblacklist_connections); | 2766 | unblacklisted_connections = |
2767 | create_scale_free (pg, &unblacklist_connections); | ||
2601 | break; | 2768 | break; |
2602 | case GNUNET_TESTING_TOPOLOGY_LINE: | 2769 | case GNUNET_TESTING_TOPOLOGY_LINE: |
2603 | #if VERBOSE_TESTING | 2770 | #if VERBOSE_TESTING |
@@ -2609,31 +2776,32 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
2609 | case GNUNET_TESTING_TOPOLOGY_NONE: | 2776 | case GNUNET_TESTING_TOPOLOGY_NONE: |
2610 | #if VERBOSE_TESTING | 2777 | #if VERBOSE_TESTING |
2611 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2778 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2612 | _("Creating no blacklist topology (all peers can connect at transport level)\n")); | 2779 | _ |
2780 | ("Creating no blacklist topology (all peers can connect at transport level)\n")); | ||
2613 | #endif | 2781 | #endif |
2614 | default: | 2782 | default: |
2615 | break; | 2783 | break; |
2616 | } | 2784 | } |
2617 | 2785 | ||
2618 | if ((unblacklisted_connections > 0) && (restrict_transports != NULL)) | 2786 | if ((unblacklisted_connections > 0) && (restrict_transports != NULL)) |
2619 | { | 2787 | { |
2620 | ret = create_and_copy_blacklist_files(pg, restrict_transports); | 2788 | ret = create_and_copy_blacklist_files (pg, restrict_transports); |
2621 | if (ret != GNUNET_OK) | 2789 | if (ret != GNUNET_OK) |
2622 | { | 2790 | { |
2623 | #if VERBOSE_TESTING | 2791 | #if VERBOSE_TESTING |
2624 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2792 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2625 | _("Failed during blacklist file copying!\n")); | 2793 | _("Failed during blacklist file copying!\n")); |
2626 | #endif | 2794 | #endif |
2627 | return 0; | 2795 | return 0; |
2628 | } | 2796 | } |
2629 | else | 2797 | else |
2630 | { | 2798 | { |
2631 | #if VERBOSE_TESTING | 2799 | #if VERBOSE_TESTING |
2632 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2800 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2633 | _("Blacklist files created/copied successfully!\n")); | 2801 | _("Blacklist files created/copied successfully!\n")); |
2634 | #endif | 2802 | #endif |
2635 | } | 2803 | } |
2636 | } | 2804 | } |
2637 | return num_connections; | 2805 | return num_connections; |
2638 | } | 2806 | } |
2639 | 2807 | ||
@@ -2737,25 +2905,35 @@ struct DFSContext | |||
2737 | * @return GNUNET_YES to continue iteration | 2905 | * @return GNUNET_YES to continue iteration |
2738 | */ | 2906 | */ |
2739 | static int | 2907 | static int |
2740 | random_connect_iterator (void *cls, | 2908 | random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
2741 | const GNUNET_HashCode * key, | ||
2742 | void *value) | ||
2743 | { | 2909 | { |
2744 | struct RandomContext *random_ctx = cls; | 2910 | struct RandomContext *random_ctx = cls; |
2745 | double random_number; | 2911 | double random_number; |
2746 | uint32_t second_pos; | 2912 | uint32_t second_pos; |
2747 | GNUNET_HashCode first_hash; | 2913 | GNUNET_HashCode first_hash; |
2748 | random_number = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 2914 | random_number = |
2749 | UINT64_MAX)) / ( (double) UINT64_MAX); | 2915 | ((double) |
2916 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
2917 | UINT64_MAX)) / ((double) UINT64_MAX); | ||
2750 | if (random_number < random_ctx->percentage) | 2918 | if (random_number < random_ctx->percentage) |
2751 | { | 2919 | { |
2752 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(random_ctx->first->connect_peers_working_set, key, value, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2920 | GNUNET_assert (GNUNET_OK == |
2753 | } | 2921 | GNUNET_CONTAINER_multihashmap_put (random_ctx-> |
2922 | first->connect_peers_working_set, | ||
2923 | key, value, | ||
2924 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
2925 | } | ||
2754 | /* Now we have considered this particular connection, remove it from the second peer so it's not double counted */ | 2926 | /* Now we have considered this particular connection, remove it from the second peer so it's not double counted */ |
2755 | uid_from_hash(key, &second_pos); | 2927 | uid_from_hash (key, &second_pos); |
2756 | hash_from_uid(random_ctx->first_uid, &first_hash); | 2928 | hash_from_uid (random_ctx->first_uid, &first_hash); |
2757 | GNUNET_assert(random_ctx->pg->total > second_pos); | 2929 | GNUNET_assert (random_ctx->pg->total > second_pos); |
2758 | GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(random_ctx->pg->peers[second_pos].connect_peers, &first_hash, random_ctx->first->daemon)); | 2930 | GNUNET_assert (GNUNET_YES == |
2931 | GNUNET_CONTAINER_multihashmap_remove (random_ctx-> | ||
2932 | pg->peers | ||
2933 | [second_pos].connect_peers, | ||
2934 | &first_hash, | ||
2935 | random_ctx-> | ||
2936 | first->daemon)); | ||
2759 | 2937 | ||
2760 | return GNUNET_YES; | 2938 | return GNUNET_YES; |
2761 | } | 2939 | } |
@@ -2770,35 +2948,48 @@ random_connect_iterator (void *cls, | |||
2770 | * @return GNUNET_YES to continue iteration | 2948 | * @return GNUNET_YES to continue iteration |
2771 | */ | 2949 | */ |
2772 | static int | 2950 | static int |
2773 | minimum_connect_iterator (void *cls, | 2951 | minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
2774 | const GNUNET_HashCode * key, | ||
2775 | void *value) | ||
2776 | { | 2952 | { |
2777 | struct MinimumContext *min_ctx = cls; | 2953 | struct MinimumContext *min_ctx = cls; |
2778 | uint32_t second_pos; | 2954 | uint32_t second_pos; |
2779 | GNUNET_HashCode first_hash; | 2955 | GNUNET_HashCode first_hash; |
2780 | unsigned int i; | 2956 | unsigned int i; |
2781 | 2957 | ||
2782 | if (GNUNET_CONTAINER_multihashmap_size(min_ctx->first->connect_peers_working_set) < min_ctx->num_to_add) | 2958 | if (GNUNET_CONTAINER_multihashmap_size |
2783 | { | 2959 | (min_ctx->first->connect_peers_working_set) < min_ctx->num_to_add) |
2784 | for (i = 0; i < min_ctx->num_to_add; i++) | 2960 | { |
2785 | { | 2961 | for (i = 0; i < min_ctx->num_to_add; i++) |
2786 | if (min_ctx->pg_array[i] == min_ctx->current) | 2962 | { |
2787 | { | 2963 | if (min_ctx->pg_array[i] == min_ctx->current) |
2788 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(min_ctx->first->connect_peers_working_set, key, value, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2964 | { |
2789 | uid_from_hash(key, &second_pos); | 2965 | GNUNET_assert (GNUNET_OK == |
2790 | hash_from_uid(min_ctx->first_uid, &first_hash); | 2966 | GNUNET_CONTAINER_multihashmap_put |
2791 | GNUNET_assert(min_ctx->pg->total > second_pos); | 2967 | (min_ctx->first->connect_peers_working_set, key, |
2792 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(min_ctx->pg->peers[second_pos].connect_peers_working_set, &first_hash, min_ctx->first->daemon, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2968 | value, |
2793 | /* Now we have added this particular connection, remove it from the second peer's map so it's not double counted */ | 2969 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
2794 | GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(min_ctx->pg->peers[second_pos].connect_peers, &first_hash, min_ctx->first->daemon)); | 2970 | uid_from_hash (key, &second_pos); |
2795 | } | 2971 | hash_from_uid (min_ctx->first_uid, &first_hash); |
2796 | } | 2972 | GNUNET_assert (min_ctx->pg->total > second_pos); |
2797 | min_ctx->current++; | 2973 | GNUNET_assert (GNUNET_OK == |
2798 | return GNUNET_YES; | 2974 | GNUNET_CONTAINER_multihashmap_put (min_ctx-> |
2799 | } | 2975 | pg->peers |
2976 | [second_pos].connect_peers_working_set, | ||
2977 | &first_hash, | ||
2978 | min_ctx->first-> | ||
2979 | daemon, | ||
2980 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
2981 | /* Now we have added this particular connection, remove it from the second peer's map so it's not double counted */ | ||
2982 | GNUNET_assert (GNUNET_YES == | ||
2983 | GNUNET_CONTAINER_multihashmap_remove | ||
2984 | (min_ctx->pg->peers[second_pos].connect_peers, | ||
2985 | &first_hash, min_ctx->first->daemon)); | ||
2986 | } | ||
2987 | } | ||
2988 | min_ctx->current++; | ||
2989 | return GNUNET_YES; | ||
2990 | } | ||
2800 | else | 2991 | else |
2801 | return GNUNET_NO; /* We can stop iterating, we have enough peers! */ | 2992 | return GNUNET_NO; /* We can stop iterating, we have enough peers! */ |
2802 | 2993 | ||
2803 | } | 2994 | } |
2804 | 2995 | ||
@@ -2813,22 +3004,37 @@ minimum_connect_iterator (void *cls, | |||
2813 | * @return GNUNET_YES to continue iteration | 3004 | * @return GNUNET_YES to continue iteration |
2814 | */ | 3005 | */ |
2815 | static int | 3006 | static int |
2816 | dfs_connect_iterator (void *cls, | 3007 | dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
2817 | const GNUNET_HashCode * key, | ||
2818 | void *value) | ||
2819 | { | 3008 | { |
2820 | struct DFSContext *dfs_ctx = cls; | 3009 | struct DFSContext *dfs_ctx = cls; |
2821 | GNUNET_HashCode first_hash; | 3010 | GNUNET_HashCode first_hash; |
2822 | 3011 | ||
2823 | if (dfs_ctx->current == dfs_ctx->chosen) | 3012 | if (dfs_ctx->current == dfs_ctx->chosen) |
2824 | { | 3013 | { |
2825 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(dfs_ctx->first->connect_peers_working_set, key, value, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 3014 | GNUNET_assert (GNUNET_OK == |
2826 | uid_from_hash(key, &dfs_ctx->second_uid); | 3015 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx-> |
2827 | hash_from_uid(dfs_ctx->first_uid, &first_hash); | 3016 | first->connect_peers_working_set, |
2828 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(dfs_ctx->pg->peers[dfs_ctx->second_uid].connect_peers_working_set, &first_hash, dfs_ctx->first->daemon, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 3017 | key, value, |
2829 | GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(dfs_ctx->pg->peers[dfs_ctx->second_uid].connect_peers, &first_hash, dfs_ctx->first->daemon)); | 3018 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
3019 | uid_from_hash (key, &dfs_ctx->second_uid); | ||
3020 | hash_from_uid (dfs_ctx->first_uid, &first_hash); | ||
3021 | GNUNET_assert (GNUNET_OK == | ||
3022 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx-> | ||
3023 | pg->peers | ||
3024 | [dfs_ctx->second_uid].connect_peers_working_set, | ||
3025 | &first_hash, | ||
3026 | dfs_ctx-> | ||
3027 | first->daemon, | ||
3028 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
3029 | GNUNET_assert (GNUNET_YES == | ||
3030 | GNUNET_CONTAINER_multihashmap_remove (dfs_ctx-> | ||
3031 | pg->peers | ||
3032 | [dfs_ctx->second_uid].connect_peers, | ||
3033 | &first_hash, | ||
3034 | dfs_ctx-> | ||
3035 | first->daemon)); | ||
2830 | /* Can't remove second from first yet because we are currently iterating, hence the return value in the DFSContext! */ | 3036 | /* Can't remove second from first yet because we are currently iterating, hence the return value in the DFSContext! */ |
2831 | return GNUNET_NO; /* We have found our peer, don't iterate more */ | 3037 | return GNUNET_NO; /* We have found our peer, don't iterate more */ |
2832 | } | 3038 | } |
2833 | 3039 | ||
2834 | dfs_ctx->current++; | 3040 | dfs_ctx->current++; |
@@ -2844,7 +3050,8 @@ dfs_connect_iterator (void *cls, | |||
2844 | * @param percentage what percent of total connections to make | 3050 | * @param percentage what percent of total connections to make |
2845 | */ | 3051 | */ |
2846 | void | 3052 | void |
2847 | choose_random_connections(struct GNUNET_TESTING_PeerGroup *pg, double percentage) | 3053 | choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg, |
3054 | double percentage) | ||
2848 | { | 3055 | { |
2849 | struct RandomContext random_ctx; | 3056 | struct RandomContext random_ctx; |
2850 | uint32_t pg_iter; | 3057 | uint32_t pg_iter; |
@@ -2855,12 +3062,17 @@ choose_random_connections(struct GNUNET_TESTING_PeerGroup *pg, double percentage | |||
2855 | random_ctx.first = &pg->peers[pg_iter]; | 3062 | random_ctx.first = &pg->peers[pg_iter]; |
2856 | random_ctx.percentage = percentage; | 3063 | random_ctx.percentage = percentage; |
2857 | random_ctx.pg = pg; | 3064 | random_ctx.pg = pg; |
2858 | pg->peers[pg_iter].connect_peers_working_set = GNUNET_CONTAINER_multihashmap_create(pg->total); | 3065 | pg->peers[pg_iter].connect_peers_working_set = |
2859 | GNUNET_CONTAINER_multihashmap_iterate(pg->peers[pg_iter].connect_peers, &random_connect_iterator, &random_ctx); | 3066 | GNUNET_CONTAINER_multihashmap_create (pg->total); |
3067 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, | ||
3068 | &random_connect_iterator, | ||
3069 | &random_ctx); | ||
2860 | /* Now remove the old connections */ | 3070 | /* Now remove the old connections */ |
2861 | GNUNET_CONTAINER_multihashmap_destroy(pg->peers[pg_iter].connect_peers); | 3071 | GNUNET_CONTAINER_multihashmap_destroy (pg-> |
3072 | peers[pg_iter].connect_peers); | ||
2862 | /* And replace with the random set */ | 3073 | /* And replace with the random set */ |
2863 | pg->peers[pg_iter].connect_peers = pg->peers[pg_iter].connect_peers_working_set; | 3074 | pg->peers[pg_iter].connect_peers = |
3075 | pg->peers[pg_iter].connect_peers_working_set; | ||
2864 | } | 3076 | } |
2865 | } | 3077 | } |
2866 | 3078 | ||
@@ -2872,43 +3084,48 @@ choose_random_connections(struct GNUNET_TESTING_PeerGroup *pg, double percentage | |||
2872 | * @param num how many connections at least should each peer have (if possible)? | 3084 | * @param num how many connections at least should each peer have (if possible)? |
2873 | */ | 3085 | */ |
2874 | static void | 3086 | static void |
2875 | choose_minimum(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | 3087 | choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) |
2876 | { | 3088 | { |
2877 | struct MinimumContext minimum_ctx; | 3089 | struct MinimumContext minimum_ctx; |
2878 | uint32_t pg_iter; | 3090 | uint32_t pg_iter; |
2879 | 3091 | ||
2880 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3092 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2881 | { | 3093 | { |
2882 | pg->peers[pg_iter].connect_peers_working_set = GNUNET_CONTAINER_multihashmap_create(num); | 3094 | pg->peers[pg_iter].connect_peers_working_set = |
2883 | } | 3095 | GNUNET_CONTAINER_multihashmap_create (num); |
3096 | } | ||
2884 | 3097 | ||
2885 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3098 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2886 | { | 3099 | { |
2887 | minimum_ctx.first_uid = pg_iter; | 3100 | minimum_ctx.first_uid = pg_iter; |
2888 | minimum_ctx.pg_array = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, | 3101 | minimum_ctx.pg_array = |
2889 | GNUNET_CONTAINER_multihashmap_size(pg->peers[pg_iter].connect_peers)); | 3102 | GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, |
3103 | GNUNET_CONTAINER_multihashmap_size | ||
3104 | (pg->peers[pg_iter].connect_peers)); | ||
2890 | minimum_ctx.first = &pg->peers[pg_iter]; | 3105 | minimum_ctx.first = &pg->peers[pg_iter]; |
2891 | minimum_ctx.pg = pg; | 3106 | minimum_ctx.pg = pg; |
2892 | minimum_ctx.num_to_add = num; | 3107 | minimum_ctx.num_to_add = num; |
2893 | minimum_ctx.current = 0; | 3108 | minimum_ctx.current = 0; |
2894 | GNUNET_CONTAINER_multihashmap_iterate(pg->peers[pg_iter].connect_peers, | 3109 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, |
2895 | &minimum_connect_iterator, | 3110 | &minimum_connect_iterator, |
2896 | &minimum_ctx); | 3111 | &minimum_ctx); |
2897 | } | 3112 | } |
2898 | 3113 | ||
2899 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3114 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2900 | { | 3115 | { |
2901 | /* Remove the "old" connections */ | 3116 | /* Remove the "old" connections */ |
2902 | GNUNET_CONTAINER_multihashmap_destroy(pg->peers[pg_iter].connect_peers); | 3117 | GNUNET_CONTAINER_multihashmap_destroy (pg-> |
3118 | peers[pg_iter].connect_peers); | ||
2903 | /* And replace with the working set */ | 3119 | /* And replace with the working set */ |
2904 | pg->peers[pg_iter].connect_peers = pg->peers[pg_iter].connect_peers_working_set; | 3120 | pg->peers[pg_iter].connect_peers = |
3121 | pg->peers[pg_iter].connect_peers_working_set; | ||
2905 | } | 3122 | } |
2906 | 3123 | ||
2907 | } | 3124 | } |
2908 | 3125 | ||
2909 | 3126 | ||
2910 | static unsigned int | 3127 | static unsigned int |
2911 | count_workingset_connections(struct GNUNET_TESTING_PeerGroup *pg) | 3128 | count_workingset_connections (struct GNUNET_TESTING_PeerGroup *pg) |
2912 | { | 3129 | { |
2913 | unsigned int count; | 3130 | unsigned int count; |
2914 | unsigned int pg_iter; | 3131 | unsigned int pg_iter; |
@@ -2917,14 +3134,18 @@ count_workingset_connections(struct GNUNET_TESTING_PeerGroup *pg) | |||
2917 | 3134 | ||
2918 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3135 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2919 | { | 3136 | { |
2920 | count += GNUNET_CONTAINER_multihashmap_size(pg->peers[pg_iter].connect_peers_working_set); | 3137 | count += |
3138 | GNUNET_CONTAINER_multihashmap_size (pg-> | ||
3139 | peers | ||
3140 | [pg_iter].connect_peers_working_set); | ||
2921 | } | 3141 | } |
2922 | 3142 | ||
2923 | return count; | 3143 | return count; |
2924 | } | 3144 | } |
2925 | 3145 | ||
2926 | 3146 | ||
2927 | static unsigned int count_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg) | 3147 | static unsigned int |
3148 | count_allowed_connections (struct GNUNET_TESTING_PeerGroup *pg) | ||
2928 | { | 3149 | { |
2929 | unsigned int count; | 3150 | unsigned int count; |
2930 | unsigned int pg_iter; | 3151 | unsigned int pg_iter; |
@@ -2933,7 +3154,8 @@ static unsigned int count_allowed_connections(struct GNUNET_TESTING_PeerGroup *p | |||
2933 | 3154 | ||
2934 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3155 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2935 | { | 3156 | { |
2936 | count += GNUNET_CONTAINER_multihashmap_size(pg->peers[pg_iter].connect_peers); | 3157 | count += |
3158 | GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].connect_peers); | ||
2937 | } | 3159 | } |
2938 | 3160 | ||
2939 | return count; | 3161 | return count; |
@@ -2977,19 +3199,28 @@ struct FindClosestContext | |||
2977 | * iterate, | 3199 | * iterate, |
2978 | * GNUNET_NO if not. | 3200 | * GNUNET_NO if not. |
2979 | */ | 3201 | */ |
2980 | static | 3202 | static int |
2981 | int find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) | 3203 | find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) |
2982 | { | 3204 | { |
2983 | struct FindClosestContext *closest_ctx = cls; | 3205 | struct FindClosestContext *closest_ctx = cls; |
2984 | struct GNUNET_TESTING_Daemon *daemon = value; | 3206 | struct GNUNET_TESTING_Daemon *daemon = value; |
2985 | 3207 | ||
2986 | if (((closest_ctx->closest == NULL) || | 3208 | if (((closest_ctx->closest == NULL) || |
2987 | (GNUNET_CRYPTO_hash_matching_bits(&daemon->id.hashPubKey, &closest_ctx->curr_peer->daemon->id.hashPubKey) > closest_ctx->closest_dist)) | 3209 | (GNUNET_CRYPTO_hash_matching_bits |
2988 | && (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains(closest_ctx->curr_peer->connect_peers, key))) | 3210 | (&daemon->id.hashPubKey, |
3211 | &closest_ctx->curr_peer->daemon->id.hashPubKey) > | ||
3212 | closest_ctx->closest_dist)) | ||
3213 | && (GNUNET_YES != | ||
3214 | GNUNET_CONTAINER_multihashmap_contains (closest_ctx-> | ||
3215 | curr_peer->connect_peers, | ||
3216 | key))) | ||
2989 | { | 3217 | { |
2990 | closest_ctx->closest_dist = GNUNET_CRYPTO_hash_matching_bits(&daemon->id.hashPubKey, &closest_ctx->curr_peer->daemon->id.hashPubKey); | 3218 | closest_ctx->closest_dist = |
3219 | GNUNET_CRYPTO_hash_matching_bits (&daemon->id.hashPubKey, | ||
3220 | &closest_ctx->curr_peer->daemon-> | ||
3221 | id.hashPubKey); | ||
2991 | closest_ctx->closest = daemon; | 3222 | closest_ctx->closest = daemon; |
2992 | uid_from_hash(key, &closest_ctx->closest_num); | 3223 | uid_from_hash (key, &closest_ctx->closest_num); |
2993 | } | 3224 | } |
2994 | return GNUNET_YES; | 3225 | return GNUNET_YES; |
2995 | } | 3226 | } |
@@ -3005,13 +3236,14 @@ int find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) | |||
3005 | * @param proc processor to actually add the connections | 3236 | * @param proc processor to actually add the connections |
3006 | */ | 3237 | */ |
3007 | void | 3238 | void |
3008 | add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, GNUNET_TESTING_ConnectionProcessor proc) | 3239 | add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, |
3240 | GNUNET_TESTING_ConnectionProcessor proc) | ||
3009 | { | 3241 | { |
3010 | struct FindClosestContext closest_ctx; | 3242 | struct FindClosestContext closest_ctx; |
3011 | uint32_t pg_iter; | 3243 | uint32_t pg_iter; |
3012 | uint32_t i; | 3244 | uint32_t i; |
3013 | 3245 | ||
3014 | for (i = 0; i < num; i++) /* Each time find a closest peer (from those available) */ | 3246 | for (i = 0; i < num; i++) /* Each time find a closest peer (from those available) */ |
3015 | { | 3247 | { |
3016 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3248 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3017 | { | 3249 | { |
@@ -3019,11 +3251,14 @@ add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, GNUNET_TESTI | |||
3019 | closest_ctx.closest = NULL; | 3251 | closest_ctx.closest = NULL; |
3020 | closest_ctx.closest_dist = 0; | 3252 | closest_ctx.closest_dist = 0; |
3021 | closest_ctx.closest_num = 0; | 3253 | closest_ctx.closest_num = 0; |
3022 | GNUNET_CONTAINER_multihashmap_iterate(pg->peers[pg_iter].allowed_peers, &find_closest_peers, &closest_ctx); | 3254 | GNUNET_CONTAINER_multihashmap_iterate (pg-> |
3255 | peers[pg_iter].allowed_peers, | ||
3256 | &find_closest_peers, | ||
3257 | &closest_ctx); | ||
3023 | if (closest_ctx.closest != NULL) | 3258 | if (closest_ctx.closest != NULL) |
3024 | { | 3259 | { |
3025 | GNUNET_assert(closest_ctx.closest_num < pg->total); | 3260 | GNUNET_assert (closest_ctx.closest_num < pg->total); |
3026 | proc(pg, pg_iter, closest_ctx.closest_num); | 3261 | proc (pg, pg_iter, closest_ctx.closest_num); |
3027 | } | 3262 | } |
3028 | } | 3263 | } |
3029 | } | 3264 | } |
@@ -3049,52 +3284,73 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
3049 | 3284 | ||
3050 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3285 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3051 | { | 3286 | { |
3052 | pg->peers[pg_iter].connect_peers_working_set = GNUNET_CONTAINER_multihashmap_create(num); | 3287 | pg->peers[pg_iter].connect_peers_working_set = |
3288 | GNUNET_CONTAINER_multihashmap_create (num); | ||
3053 | } | 3289 | } |
3054 | 3290 | ||
3055 | starting_peer = 0; | 3291 | starting_peer = 0; |
3056 | dfs_count = 0; | 3292 | dfs_count = 0; |
3057 | while ((count_workingset_connections(pg) < num * pg->total) && (count_allowed_connections(pg) > 0)) | 3293 | while ((count_workingset_connections (pg) < num * pg->total) |
3294 | && (count_allowed_connections (pg) > 0)) | ||
3058 | { | 3295 | { |
3059 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ | 3296 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ |
3060 | { | 3297 | { |
3061 | least_connections = -1; /* Set to very high number */ | 3298 | least_connections = -1; /* Set to very high number */ |
3062 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3299 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3063 | { | 3300 | { |
3064 | if (GNUNET_CONTAINER_multihashmap_size(pg->peers[pg_iter].connect_peers_working_set) < least_connections) | 3301 | if (GNUNET_CONTAINER_multihashmap_size |
3302 | (pg->peers[pg_iter].connect_peers_working_set) < | ||
3303 | least_connections) | ||
3065 | { | 3304 | { |
3066 | starting_peer = pg_iter; | 3305 | starting_peer = pg_iter; |
3067 | least_connections = GNUNET_CONTAINER_multihashmap_size(pg->peers[pg_iter].connect_peers_working_set); | 3306 | least_connections = |
3307 | GNUNET_CONTAINER_multihashmap_size (pg-> | ||
3308 | peers | ||
3309 | [pg_iter].connect_peers_working_set); | ||
3068 | } | 3310 | } |
3069 | } | 3311 | } |
3070 | } | 3312 | } |
3071 | 3313 | ||
3072 | if (GNUNET_CONTAINER_multihashmap_size(pg->peers[starting_peer].connect_peers) == 0) /* Ensure there is at least one peer left to connect! */ | 3314 | if (GNUNET_CONTAINER_multihashmap_size (pg->peers[starting_peer].connect_peers) == 0) /* Ensure there is at least one peer left to connect! */ |
3073 | { | 3315 | { |
3074 | dfs_count = 0; | 3316 | dfs_count = 0; |
3075 | continue; | 3317 | continue; |
3076 | } | 3318 | } |
3077 | 3319 | ||
3078 | /* Choose a random peer from the chosen peers set of connections to add */ | 3320 | /* Choose a random peer from the chosen peers set of connections to add */ |
3079 | dfs_ctx.chosen = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CONTAINER_multihashmap_size(pg->peers[starting_peer].connect_peers)); | 3321 | dfs_ctx.chosen = |
3322 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
3323 | GNUNET_CONTAINER_multihashmap_size | ||
3324 | (pg->peers[starting_peer].connect_peers)); | ||
3080 | dfs_ctx.first_uid = starting_peer; | 3325 | dfs_ctx.first_uid = starting_peer; |
3081 | dfs_ctx.first = &pg->peers[starting_peer]; | 3326 | dfs_ctx.first = &pg->peers[starting_peer]; |
3082 | dfs_ctx.pg = pg; | 3327 | dfs_ctx.pg = pg; |
3083 | dfs_ctx.current = 0; | 3328 | dfs_ctx.current = 0; |
3084 | 3329 | ||
3085 | GNUNET_CONTAINER_multihashmap_iterate(pg->peers[starting_peer].connect_peers, &dfs_connect_iterator, &dfs_ctx); | 3330 | GNUNET_CONTAINER_multihashmap_iterate (pg-> |
3331 | peers | ||
3332 | [starting_peer].connect_peers, | ||
3333 | &dfs_connect_iterator, &dfs_ctx); | ||
3086 | /* Remove the second from the first, since we will be continuing the search and may encounter the first peer again! */ | 3334 | /* Remove the second from the first, since we will be continuing the search and may encounter the first peer again! */ |
3087 | hash_from_uid(dfs_ctx.second_uid, &second_hash); | 3335 | hash_from_uid (dfs_ctx.second_uid, &second_hash); |
3088 | GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(pg->peers[starting_peer].connect_peers, &second_hash, pg->peers[dfs_ctx.second_uid].daemon)); | 3336 | GNUNET_assert (GNUNET_YES == |
3337 | GNUNET_CONTAINER_multihashmap_remove (pg->peers | ||
3338 | [starting_peer].connect_peers, | ||
3339 | &second_hash, | ||
3340 | pg-> | ||
3341 | peers | ||
3342 | [dfs_ctx.second_uid].daemon)); | ||
3089 | starting_peer = dfs_ctx.second_uid; | 3343 | starting_peer = dfs_ctx.second_uid; |
3090 | } | 3344 | } |
3091 | 3345 | ||
3092 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3346 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3093 | { | 3347 | { |
3094 | /* Remove the "old" connections */ | 3348 | /* Remove the "old" connections */ |
3095 | GNUNET_CONTAINER_multihashmap_destroy(pg->peers[pg_iter].connect_peers); | 3349 | GNUNET_CONTAINER_multihashmap_destroy (pg-> |
3350 | peers[pg_iter].connect_peers); | ||
3096 | /* And replace with the working set */ | 3351 | /* And replace with the working set */ |
3097 | pg->peers[pg_iter].connect_peers = pg->peers[pg_iter].connect_peers_working_set; | 3352 | pg->peers[pg_iter].connect_peers = |
3353 | pg->peers[pg_iter].connect_peers_working_set; | ||
3098 | } | 3354 | } |
3099 | } | 3355 | } |
3100 | 3356 | ||
@@ -3102,32 +3358,32 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
3102 | * Internal callback for topology information for a particular peer. | 3358 | * Internal callback for topology information for a particular peer. |
3103 | */ | 3359 | */ |
3104 | static void | 3360 | static void |
3105 | internal_topology_callback(void *cls, | 3361 | internal_topology_callback (void *cls, |
3106 | const struct GNUNET_PeerIdentity *peer, | 3362 | const struct GNUNET_PeerIdentity *peer, |
3107 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 3363 | const struct GNUNET_TRANSPORT_ATS_Information |
3364 | *atsi) | ||
3108 | { | 3365 | { |
3109 | struct CoreContext *core_ctx = cls; | 3366 | struct CoreContext *core_ctx = cls; |
3110 | struct TopologyIterateContext *iter_ctx = core_ctx->iter_context; | 3367 | struct TopologyIterateContext *iter_ctx = core_ctx->iter_context; |
3111 | 3368 | ||
3112 | if (peer == NULL) /* Either finished, or something went wrong */ | 3369 | if (peer == NULL) /* Either finished, or something went wrong */ |
3113 | { | 3370 | { |
3114 | iter_ctx->completed++; | 3371 | iter_ctx->completed++; |
3115 | iter_ctx->connected--; | 3372 | iter_ctx->connected--; |
3116 | /* One core context allocated per iteration, must free! */ | 3373 | /* One core context allocated per iteration, must free! */ |
3117 | GNUNET_free(core_ctx); | 3374 | GNUNET_free (core_ctx); |
3118 | } | 3375 | } |
3119 | else | 3376 | else |
3120 | { | 3377 | { |
3121 | iter_ctx->topology_cb(iter_ctx->cls, &core_ctx->daemon->id, | 3378 | iter_ctx->topology_cb (iter_ctx->cls, &core_ctx->daemon->id, |
3122 | peer, NULL); | 3379 | peer, NULL); |
3123 | } | 3380 | } |
3124 | 3381 | ||
3125 | if (iter_ctx->completed == iter_ctx->total) | 3382 | if (iter_ctx->completed == iter_ctx->total) |
3126 | { | 3383 | { |
3127 | iter_ctx->topology_cb(iter_ctx->cls, NULL, NULL, | 3384 | iter_ctx->topology_cb (iter_ctx->cls, NULL, NULL, NULL); |
3128 | NULL); | ||
3129 | /* Once all are done, free the iteration context */ | 3385 | /* Once all are done, free the iteration context */ |
3130 | GNUNET_free(iter_ctx); | 3386 | GNUNET_free (iter_ctx); |
3131 | } | 3387 | } |
3132 | } | 3388 | } |
3133 | 3389 | ||
@@ -3137,30 +3393,39 @@ internal_topology_callback(void *cls, | |||
3137 | * schedule for some time in the future. | 3393 | * schedule for some time in the future. |
3138 | */ | 3394 | */ |
3139 | static void | 3395 | static void |
3140 | schedule_get_topology(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3396 | schedule_get_topology (void *cls, |
3397 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
3141 | { | 3398 | { |
3142 | struct CoreContext *core_context = cls; | 3399 | struct CoreContext *core_context = cls; |
3143 | struct TopologyIterateContext *topology_context = (struct TopologyIterateContext *)core_context->iter_context; | 3400 | struct TopologyIterateContext *topology_context = |
3401 | (struct TopologyIterateContext *) core_context->iter_context; | ||
3144 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 3402 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
3145 | return; | 3403 | return; |
3146 | 3404 | ||
3147 | if (topology_context->connected > MAX_OUTSTANDING_CONNECTIONS) | 3405 | if (topology_context->connected > MAX_OUTSTANDING_CONNECTIONS) |
3148 | { | 3406 | { |
3149 | #if VERBOSE_TESTING > 2 | 3407 | #if VERBOSE_TESTING > 2 |
3150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3408 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3151 | _("Delaying connect, we have too many outstanding connections!\n")); | 3409 | _ |
3410 | ("Delaying connect, we have too many outstanding connections!\n")); | ||
3152 | #endif | 3411 | #endif |
3153 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &schedule_get_topology, core_context); | 3412 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
3413 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | ||
3414 | &schedule_get_topology, core_context); | ||
3154 | } | 3415 | } |
3155 | else | 3416 | else |
3156 | { | 3417 | { |
3157 | #if VERBOSE_TESTING > 2 | 3418 | #if VERBOSE_TESTING > 2 |
3158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3419 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3159 | _("Creating connection, outstanding_connections is %d\n"), outstanding_connects); | 3420 | _("Creating connection, outstanding_connections is %d\n"), |
3421 | outstanding_connects); | ||
3160 | #endif | 3422 | #endif |
3161 | topology_context->connected++; | 3423 | topology_context->connected++; |
3162 | if (GNUNET_OK != GNUNET_CORE_iterate_peers (core_context->daemon->server, &internal_topology_callback, core_context)) | 3424 | if (GNUNET_OK != |
3163 | internal_topology_callback(core_context, NULL, NULL); | 3425 | GNUNET_CORE_iterate_peers (core_context->daemon->server, |
3426 | &internal_topology_callback, | ||
3427 | core_context)) | ||
3428 | internal_topology_callback (core_context, NULL, NULL); | ||
3164 | 3429 | ||
3165 | } | 3430 | } |
3166 | } | 3431 | } |
@@ -3170,7 +3435,8 @@ schedule_get_topology(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3170 | * all connections that each currently has. | 3435 | * all connections that each currently has. |
3171 | */ | 3436 | */ |
3172 | void | 3437 | void |
3173 | GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_NotifyTopology cb, void *cls) | 3438 | GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg, |
3439 | GNUNET_TESTING_NotifyTopology cb, void *cls) | ||
3174 | { | 3440 | { |
3175 | struct TopologyIterateContext *topology_context; | 3441 | struct TopologyIterateContext *topology_context; |
3176 | struct CoreContext *core_ctx; | 3442 | struct CoreContext *core_ctx; |
@@ -3178,7 +3444,7 @@ GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING | |||
3178 | unsigned int total_count; | 3444 | unsigned int total_count; |
3179 | 3445 | ||
3180 | /* Allocate a single topology iteration context */ | 3446 | /* Allocate a single topology iteration context */ |
3181 | topology_context = GNUNET_malloc(sizeof(struct TopologyIterateContext)); | 3447 | topology_context = GNUNET_malloc (sizeof (struct TopologyIterateContext)); |
3182 | topology_context->topology_cb = cb; | 3448 | topology_context->topology_cb = cb; |
3183 | topology_context->cls = cls; | 3449 | topology_context->cls = cls; |
3184 | total_count = 0; | 3450 | total_count = 0; |
@@ -3187,18 +3453,18 @@ GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING | |||
3187 | if (pg->peers[i].daemon->running == GNUNET_YES) | 3453 | if (pg->peers[i].daemon->running == GNUNET_YES) |
3188 | { | 3454 | { |
3189 | /* Allocate one core context per core we need to connect to */ | 3455 | /* Allocate one core context per core we need to connect to */ |
3190 | core_ctx = GNUNET_malloc(sizeof(struct CoreContext)); | 3456 | core_ctx = GNUNET_malloc (sizeof (struct CoreContext)); |
3191 | core_ctx->daemon = pg->peers[i].daemon; | 3457 | core_ctx->daemon = pg->peers[i].daemon; |
3192 | /* Set back pointer to topology iteration context */ | 3458 | /* Set back pointer to topology iteration context */ |
3193 | core_ctx->iter_context = topology_context; | 3459 | core_ctx->iter_context = topology_context; |
3194 | GNUNET_SCHEDULER_add_now(&schedule_get_topology, core_ctx); | 3460 | GNUNET_SCHEDULER_add_now (&schedule_get_topology, core_ctx); |
3195 | total_count++; | 3461 | total_count++; |
3196 | } | 3462 | } |
3197 | } | 3463 | } |
3198 | if (total_count == 0) | 3464 | if (total_count == 0) |
3199 | { | 3465 | { |
3200 | cb(cls, NULL, NULL, "Cannot iterate over topology, no running peers!"); | 3466 | cb (cls, NULL, NULL, "Cannot iterate over topology, no running peers!"); |
3201 | GNUNET_free(topology_context); | 3467 | GNUNET_free (topology_context); |
3202 | } | 3468 | } |
3203 | else | 3469 | else |
3204 | topology_context->total = total_count; | 3470 | topology_context->total = total_count; |
@@ -3218,16 +3484,17 @@ GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING | |||
3218 | * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not | 3484 | * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not |
3219 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | 3485 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration |
3220 | */ | 3486 | */ |
3221 | static int internal_stats_callback (void *cls, | 3487 | static int |
3222 | const char *subsystem, | 3488 | internal_stats_callback (void *cls, |
3223 | const char *name, | 3489 | const char *subsystem, |
3224 | uint64_t value, | 3490 | const char *name, uint64_t value, int is_persistent) |
3225 | int is_persistent) | ||
3226 | { | 3491 | { |
3227 | struct StatsCoreContext *core_context = cls; | 3492 | struct StatsCoreContext *core_context = cls; |
3228 | struct StatsIterateContext *stats_context = (struct StatsIterateContext *)core_context->iter_context; | 3493 | struct StatsIterateContext *stats_context = |
3494 | (struct StatsIterateContext *) core_context->iter_context; | ||
3229 | 3495 | ||
3230 | return stats_context->proc(stats_context->cls, &core_context->daemon->id, subsystem, name, value, is_persistent); | 3496 | return stats_context->proc (stats_context->cls, &core_context->daemon->id, |
3497 | subsystem, name, value, is_persistent); | ||
3231 | } | 3498 | } |
3232 | 3499 | ||
3233 | /** | 3500 | /** |
@@ -3237,24 +3504,26 @@ static int internal_stats_callback (void *cls, | |||
3237 | * @param success whether or not the statistics iterations | 3504 | * @param success whether or not the statistics iterations |
3238 | * was canceled or not (we don't care) | 3505 | * was canceled or not (we don't care) |
3239 | */ | 3506 | */ |
3240 | static void internal_stats_cont (void *cls, int success) | 3507 | static void |
3508 | internal_stats_cont (void *cls, int success) | ||
3241 | { | 3509 | { |
3242 | struct StatsCoreContext *core_context = cls; | 3510 | struct StatsCoreContext *core_context = cls; |
3243 | struct StatsIterateContext *stats_context = (struct StatsIterateContext *)core_context->iter_context; | 3511 | struct StatsIterateContext *stats_context = |
3512 | (struct StatsIterateContext *) core_context->iter_context; | ||
3244 | 3513 | ||
3245 | stats_context->connected--; | 3514 | stats_context->connected--; |
3246 | stats_context->completed++; | 3515 | stats_context->completed++; |
3247 | 3516 | ||
3248 | if (stats_context->completed == stats_context->total) | 3517 | if (stats_context->completed == stats_context->total) |
3249 | { | 3518 | { |
3250 | stats_context->cont(stats_context->cls, GNUNET_YES); | 3519 | stats_context->cont (stats_context->cls, GNUNET_YES); |
3251 | GNUNET_free(stats_context); | 3520 | GNUNET_free (stats_context); |
3252 | } | 3521 | } |
3253 | 3522 | ||
3254 | if (core_context->stats_handle != NULL) | 3523 | if (core_context->stats_handle != NULL) |
3255 | GNUNET_STATISTICS_destroy(core_context->stats_handle, GNUNET_NO); | 3524 | GNUNET_STATISTICS_destroy (core_context->stats_handle, GNUNET_NO); |
3256 | 3525 | ||
3257 | GNUNET_free(core_context); | 3526 | GNUNET_free (core_context); |
3258 | } | 3527 | } |
3259 | 3528 | ||
3260 | /** | 3529 | /** |
@@ -3262,10 +3531,12 @@ static void internal_stats_cont (void *cls, int success) | |||
3262 | * schedule for some time in the future. | 3531 | * schedule for some time in the future. |
3263 | */ | 3532 | */ |
3264 | static void | 3533 | static void |
3265 | schedule_get_statistics(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3534 | schedule_get_statistics (void *cls, |
3535 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
3266 | { | 3536 | { |
3267 | struct StatsCoreContext *core_context = cls; | 3537 | struct StatsCoreContext *core_context = cls; |
3268 | struct StatsIterateContext *stats_context = (struct StatsIterateContext *)core_context->iter_context; | 3538 | struct StatsIterateContext *stats_context = |
3539 | (struct StatsIterateContext *) core_context->iter_context; | ||
3269 | 3540 | ||
3270 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 3541 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
3271 | return; | 3542 | return; |
@@ -3273,27 +3544,36 @@ schedule_get_statistics(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
3273 | if (stats_context->connected > MAX_OUTSTANDING_CONNECTIONS) | 3544 | if (stats_context->connected > MAX_OUTSTANDING_CONNECTIONS) |
3274 | { | 3545 | { |
3275 | #if VERBOSE_TESTING > 2 | 3546 | #if VERBOSE_TESTING > 2 |
3276 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3547 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3277 | _("Delaying connect, we have too many outstanding connections!\n")); | 3548 | _ |
3549 | ("Delaying connect, we have too many outstanding connections!\n")); | ||
3278 | #endif | 3550 | #endif |
3279 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &schedule_get_statistics, core_context); | 3551 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
3552 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | ||
3553 | &schedule_get_statistics, core_context); | ||
3280 | } | 3554 | } |
3281 | else | 3555 | else |
3282 | { | 3556 | { |
3283 | #if VERBOSE_TESTING > 2 | 3557 | #if VERBOSE_TESTING > 2 |
3284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3558 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3285 | _("Creating connection, outstanding_connections is %d\n"), outstanding_connects); | 3559 | _("Creating connection, outstanding_connections is %d\n"), |
3560 | outstanding_connects); | ||
3286 | #endif | 3561 | #endif |
3287 | 3562 | ||
3288 | stats_context->connected++; | 3563 | stats_context->connected++; |
3289 | core_context->stats_handle = GNUNET_STATISTICS_create("testing", core_context->daemon->cfg); | 3564 | core_context->stats_handle = |
3565 | GNUNET_STATISTICS_create ("testing", core_context->daemon->cfg); | ||
3290 | if (core_context->stats_handle == NULL) | 3566 | if (core_context->stats_handle == NULL) |
3291 | { | 3567 | { |
3292 | internal_stats_cont (core_context, GNUNET_NO); | 3568 | internal_stats_cont (core_context, GNUNET_NO); |
3293 | return; | 3569 | return; |
3294 | } | 3570 | } |
3295 | 3571 | ||
3296 | core_context->stats_get_handle = GNUNET_STATISTICS_get(core_context->stats_handle, NULL, NULL, GNUNET_TIME_relative_get_forever(), &internal_stats_cont, &internal_stats_callback, core_context); | 3572 | core_context->stats_get_handle = |
3573 | GNUNET_STATISTICS_get (core_context->stats_handle, NULL, NULL, | ||
3574 | GNUNET_TIME_relative_get_forever (), | ||
3575 | &internal_stats_cont, &internal_stats_callback, | ||
3576 | core_context); | ||
3297 | if (core_context->stats_get_handle == NULL) | 3577 | if (core_context->stats_get_handle == NULL) |
3298 | internal_stats_cont (core_context, GNUNET_NO); | 3578 | internal_stats_cont (core_context, GNUNET_NO); |
3299 | 3579 | ||
@@ -3325,30 +3605,39 @@ struct DuplicateStats | |||
3325 | * GNUNET_NO if not (and we may have added it to the list) | 3605 | * GNUNET_NO if not (and we may have added it to the list) |
3326 | */ | 3606 | */ |
3327 | static int | 3607 | static int |
3328 | stats_check_existing(struct GNUNET_TESTING_PeerGroup *pg, struct PeerData *specific_peer, struct DuplicateStats **stats_list) | 3608 | stats_check_existing (struct GNUNET_TESTING_PeerGroup *pg, |
3609 | struct PeerData *specific_peer, | ||
3610 | struct DuplicateStats **stats_list) | ||
3329 | { | 3611 | { |
3330 | struct DuplicateStats *pos; | 3612 | struct DuplicateStats *pos; |
3331 | char *unix_domain_socket; | 3613 | char *unix_domain_socket; |
3332 | unsigned long long port; | 3614 | unsigned long long port; |
3333 | char *to_match; | 3615 | char *to_match; |
3334 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno(pg->cfg, "testing", "single_statistics_per_host")) | 3616 | if (GNUNET_YES != |
3335 | return GNUNET_NO; /* Each peer has its own statistics instance, do nothing! */ | 3617 | GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "testing", |
3618 | "single_statistics_per_host")) | ||
3619 | return GNUNET_NO; /* Each peer has its own statistics instance, do nothing! */ | ||
3336 | 3620 | ||
3337 | pos = *stats_list; | 3621 | pos = *stats_list; |
3338 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(specific_peer->cfg, "statistics", "unixpath", &unix_domain_socket)) | 3622 | if (GNUNET_OK != |
3623 | GNUNET_CONFIGURATION_get_value_string (specific_peer->cfg, "statistics", | ||
3624 | "unixpath", &unix_domain_socket)) | ||
3339 | return GNUNET_NO; | 3625 | return GNUNET_NO; |
3340 | 3626 | ||
3341 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(specific_peer->cfg, "statistics", "port", &port)) | 3627 | if (GNUNET_OK != |
3628 | GNUNET_CONFIGURATION_get_value_number (specific_peer->cfg, "statistics", | ||
3629 | "port", &port)) | ||
3342 | return GNUNET_NO; | 3630 | return GNUNET_NO; |
3343 | 3631 | ||
3344 | if (specific_peer->daemon->hostname != NULL) | 3632 | if (specific_peer->daemon->hostname != NULL) |
3345 | GNUNET_asprintf(&to_match, "%s%s%llu", specific_peer->daemon->hostname, unix_domain_socket, port); | 3633 | GNUNET_asprintf (&to_match, "%s%s%llu", specific_peer->daemon->hostname, |
3634 | unix_domain_socket, port); | ||
3346 | else | 3635 | else |
3347 | GNUNET_asprintf(&to_match, "%s%llu", unix_domain_socket, port); | 3636 | GNUNET_asprintf (&to_match, "%s%llu", unix_domain_socket, port); |
3348 | 3637 | ||
3349 | while (pos != NULL) | 3638 | while (pos != NULL) |
3350 | { | 3639 | { |
3351 | if (0 == strcmp(to_match, pos->unique_string)) | 3640 | if (0 == strcmp (to_match, pos->unique_string)) |
3352 | { | 3641 | { |
3353 | GNUNET_free (unix_domain_socket); | 3642 | GNUNET_free (unix_domain_socket); |
3354 | GNUNET_free (to_match); | 3643 | GNUNET_free (to_match); |
@@ -3356,7 +3645,7 @@ stats_check_existing(struct GNUNET_TESTING_PeerGroup *pg, struct PeerData *speci | |||
3356 | } | 3645 | } |
3357 | pos = pos->next; | 3646 | pos = pos->next; |
3358 | } | 3647 | } |
3359 | pos = GNUNET_malloc(sizeof(struct DuplicateStats)); | 3648 | pos = GNUNET_malloc (sizeof (struct DuplicateStats)); |
3360 | pos->unique_string = to_match; | 3649 | pos->unique_string = to_match; |
3361 | pos->next = *stats_list; | 3650 | pos->next = *stats_list; |
3362 | *stats_list = pos; | 3651 | *stats_list = pos; |
@@ -3371,7 +3660,8 @@ stats_check_existing(struct GNUNET_TESTING_PeerGroup *pg, struct PeerData *speci | |||
3371 | void | 3660 | void |
3372 | GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg, | 3661 | GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg, |
3373 | GNUNET_STATISTICS_Callback cont, | 3662 | GNUNET_STATISTICS_Callback cont, |
3374 | GNUNET_TESTING_STATISTICS_Iterator proc, void *cls) | 3663 | GNUNET_TESTING_STATISTICS_Iterator proc, |
3664 | void *cls) | ||
3375 | { | 3665 | { |
3376 | struct StatsIterateContext *stats_context; | 3666 | struct StatsIterateContext *stats_context; |
3377 | struct StatsCoreContext *core_ctx; | 3667 | struct StatsCoreContext *core_ctx; |
@@ -3382,7 +3672,7 @@ GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg, | |||
3382 | stats_list = NULL; | 3672 | stats_list = NULL; |
3383 | 3673 | ||
3384 | /* Allocate a single stats iteration context */ | 3674 | /* Allocate a single stats iteration context */ |
3385 | stats_context = GNUNET_malloc(sizeof(struct StatsIterateContext)); | 3675 | stats_context = GNUNET_malloc (sizeof (struct StatsIterateContext)); |
3386 | stats_context->cont = cont; | 3676 | stats_context->cont = cont; |
3387 | stats_context->proc = proc; | 3677 | stats_context->proc = proc; |
3388 | stats_context->cls = cls; | 3678 | stats_context->cls = cls; |
@@ -3390,28 +3680,31 @@ GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg, | |||
3390 | 3680 | ||
3391 | for (i = 0; i < pg->total; i++) | 3681 | for (i = 0; i < pg->total; i++) |
3392 | { | 3682 | { |
3393 | if ((pg->peers[i].daemon->running == GNUNET_YES) && (GNUNET_NO == stats_check_existing(pg, &pg->peers[i], &stats_list))) | 3683 | if ((pg->peers[i].daemon->running == GNUNET_YES) |
3684 | && (GNUNET_NO == | ||
3685 | stats_check_existing (pg, &pg->peers[i], &stats_list))) | ||
3394 | { | 3686 | { |
3395 | /* Allocate one core context per core we need to connect to */ | 3687 | /* Allocate one core context per core we need to connect to */ |
3396 | core_ctx = GNUNET_malloc(sizeof(struct StatsCoreContext)); | 3688 | core_ctx = GNUNET_malloc (sizeof (struct StatsCoreContext)); |
3397 | core_ctx->daemon = pg->peers[i].daemon; | 3689 | core_ctx->daemon = pg->peers[i].daemon; |
3398 | /* Set back pointer to topology iteration context */ | 3690 | /* Set back pointer to topology iteration context */ |
3399 | core_ctx->iter_context = stats_context; | 3691 | core_ctx->iter_context = stats_context; |
3400 | GNUNET_SCHEDULER_add_now(&schedule_get_statistics, core_ctx); | 3692 | GNUNET_SCHEDULER_add_now (&schedule_get_statistics, core_ctx); |
3401 | total_count++; | 3693 | total_count++; |
3402 | } | 3694 | } |
3403 | } | 3695 | } |
3404 | 3696 | ||
3405 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Retrieving stats from %u total instances.\n", total_count); | 3697 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3698 | "Retrieving stats from %u total instances.\n", total_count); | ||
3406 | stats_context->total = total_count; | 3699 | stats_context->total = total_count; |
3407 | if (stats_list != NULL) | 3700 | if (stats_list != NULL) |
3408 | { | 3701 | { |
3409 | pos = stats_list; | 3702 | pos = stats_list; |
3410 | while(pos != NULL) | 3703 | while (pos != NULL) |
3411 | { | 3704 | { |
3412 | GNUNET_free(pos->unique_string); | 3705 | GNUNET_free (pos->unique_string); |
3413 | stats_list = pos->next; | 3706 | stats_list = pos->next; |
3414 | GNUNET_free(pos); | 3707 | GNUNET_free (pos); |
3415 | pos = stats_list->next; | 3708 | pos = stats_list->next; |
3416 | } | 3709 | } |
3417 | } | 3710 | } |
@@ -3441,116 +3734,125 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3441 | enum GNUNET_TESTING_Topology topology, | 3734 | enum GNUNET_TESTING_Topology topology, |
3442 | enum GNUNET_TESTING_TopologyOption options, | 3735 | enum GNUNET_TESTING_TopologyOption options, |
3443 | double option_modifier, | 3736 | double option_modifier, |
3444 | GNUNET_TESTING_NotifyCompletion notify_callback, | 3737 | GNUNET_TESTING_NotifyCompletion |
3445 | void *notify_cls) | 3738 | notify_callback, void *notify_cls) |
3446 | { | 3739 | { |
3447 | switch (topology) | 3740 | switch (topology) |
3448 | { | 3741 | { |
3449 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | 3742 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: |
3450 | #if VERBOSE_TOPOLOGY | 3743 | #if VERBOSE_TOPOLOGY |
3451 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3744 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3452 | _("Creating clique CONNECT topology\n")); | 3745 | _("Creating clique CONNECT topology\n")); |
3453 | #endif | 3746 | #endif |
3454 | create_clique (pg, &add_actual_connections); | 3747 | create_clique (pg, &add_actual_connections); |
3455 | break; | 3748 | break; |
3456 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: | 3749 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: |
3457 | #if VERBOSE_TOPOLOGY | 3750 | #if VERBOSE_TOPOLOGY |
3458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3751 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3459 | _("Creating small world (ring) CONNECT topology\n")); | 3752 | _("Creating small world (ring) CONNECT topology\n")); |
3460 | #endif | 3753 | #endif |
3461 | create_small_world_ring (pg, &add_actual_connections); | 3754 | create_small_world_ring (pg, &add_actual_connections); |
3462 | break; | 3755 | break; |
3463 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | 3756 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: |
3464 | #if VERBOSE_TOPOLOGY | 3757 | #if VERBOSE_TOPOLOGY |
3465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3758 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3466 | _("Creating small world (2d-torus) CONNECT topology\n")); | 3759 | _("Creating small world (2d-torus) CONNECT topology\n")); |
3467 | #endif | 3760 | #endif |
3468 | create_small_world (pg, &add_actual_connections); | 3761 | create_small_world (pg, &add_actual_connections); |
3469 | break; | 3762 | break; |
3470 | case GNUNET_TESTING_TOPOLOGY_RING: | 3763 | case GNUNET_TESTING_TOPOLOGY_RING: |
3471 | #if VERBOSE_TOPOLOGY | 3764 | #if VERBOSE_TOPOLOGY |
3472 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3765 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3473 | _("Creating ring CONNECT topology\n")); | 3766 | _("Creating ring CONNECT topology\n")); |
3474 | #endif | 3767 | #endif |
3475 | create_ring (pg, &add_actual_connections); | 3768 | create_ring (pg, &add_actual_connections); |
3476 | break; | 3769 | break; |
3477 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: | 3770 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: |
3478 | #if VERBOSE_TOPOLOGY | 3771 | #if VERBOSE_TOPOLOGY |
3479 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3772 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3480 | _("Creating 2d torus CONNECT topology\n")); | 3773 | _("Creating 2d torus CONNECT topology\n")); |
3481 | #endif | 3774 | #endif |
3482 | create_2d_torus (pg, &add_actual_connections); | 3775 | create_2d_torus (pg, &add_actual_connections); |
3483 | break; | 3776 | break; |
3484 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | 3777 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: |
3485 | #if VERBOSE_TOPOLOGY | 3778 | #if VERBOSE_TOPOLOGY |
3486 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3779 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3487 | _("Creating Erdos-Renyi CONNECT topology\n")); | 3780 | _("Creating Erdos-Renyi CONNECT topology\n")); |
3488 | #endif | 3781 | #endif |
3489 | create_erdos_renyi (pg, &add_actual_connections); | 3782 | create_erdos_renyi (pg, &add_actual_connections); |
3490 | break; | 3783 | break; |
3491 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: | 3784 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: |
3492 | #if VERBOSE_TOPOLOGY | 3785 | #if VERBOSE_TOPOLOGY |
3493 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3786 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3494 | _("Creating InterNAT CONNECT topology\n")); | 3787 | _("Creating InterNAT CONNECT topology\n")); |
3495 | #endif | 3788 | #endif |
3496 | create_nated_internet (pg, &add_actual_connections); | 3789 | create_nated_internet (pg, &add_actual_connections); |
3497 | break; | 3790 | break; |
3498 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | 3791 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: |
3499 | #if VERBOSE_TOPOLOGY | 3792 | #if VERBOSE_TOPOLOGY |
3500 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3793 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3501 | _("Creating Scale Free CONNECT topology\n")); | 3794 | _("Creating Scale Free CONNECT topology\n")); |
3502 | #endif | 3795 | #endif |
3503 | create_scale_free (pg, &add_actual_connections); | 3796 | create_scale_free (pg, &add_actual_connections); |
3504 | break; | 3797 | break; |
3505 | case GNUNET_TESTING_TOPOLOGY_LINE: | 3798 | case GNUNET_TESTING_TOPOLOGY_LINE: |
3506 | #if VERBOSE_TOPOLOGY | 3799 | #if VERBOSE_TOPOLOGY |
3507 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3800 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3508 | _("Creating straight line CONNECT topology\n")); | 3801 | _("Creating straight line CONNECT topology\n")); |
3509 | #endif | 3802 | #endif |
3510 | create_line (pg, &add_actual_connections); | 3803 | create_line (pg, &add_actual_connections); |
3511 | break; | 3804 | break; |
3512 | case GNUNET_TESTING_TOPOLOGY_NONE: | 3805 | case GNUNET_TESTING_TOPOLOGY_NONE: |
3513 | #if VERBOSE_TOPOLOGY | 3806 | #if VERBOSE_TOPOLOGY |
3514 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3807 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3515 | _("Creating no CONNECT topology\n")); | 3808 | _("Creating no CONNECT topology\n")); |
3516 | #endif | 3809 | #endif |
3517 | copy_allowed_topology(pg); | 3810 | copy_allowed_topology (pg); |
3518 | break; | 3811 | break; |
3519 | default: | 3812 | default: |
3520 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 3813 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3521 | _("Unknown topology specification, can't connect peers!\n")); | 3814 | _ |
3522 | return GNUNET_SYSERR; | 3815 | ("Unknown topology specification, can't connect peers!\n")); |
3523 | } | 3816 | return GNUNET_SYSERR; |
3817 | } | ||
3524 | 3818 | ||
3525 | switch (options) | 3819 | switch (options) |
3526 | { | 3820 | { |
3527 | case GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM: | 3821 | case GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM: |
3528 | #if VERBOSE_TOPOLOGY | 3822 | #if VERBOSE_TOPOLOGY |
3529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3823 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3530 | _("Connecting random subset (%'.2f percent) of possible peers\n"), 100 * option_modifier); | 3824 | _ |
3825 | ("Connecting random subset (%'.2f percent) of possible peers\n"), | ||
3826 | 100 * option_modifier); | ||
3531 | #endif | 3827 | #endif |
3532 | choose_random_connections(pg, option_modifier); | 3828 | choose_random_connections (pg, option_modifier); |
3533 | break; | 3829 | break; |
3534 | case GNUNET_TESTING_TOPOLOGY_OPTION_MINIMUM: | 3830 | case GNUNET_TESTING_TOPOLOGY_OPTION_MINIMUM: |
3535 | #if VERBOSE_TOPOLOGY | 3831 | #if VERBOSE_TOPOLOGY |
3536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3832 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3537 | _("Connecting a minimum of %u peers each (if possible)\n"), (unsigned int)option_modifier); | 3833 | _("Connecting a minimum of %u peers each (if possible)\n"), |
3834 | (unsigned int) option_modifier); | ||
3538 | #endif | 3835 | #endif |
3539 | choose_minimum(pg, (unsigned int)option_modifier); | 3836 | choose_minimum (pg, (unsigned int) option_modifier); |
3540 | break; | 3837 | break; |
3541 | case GNUNET_TESTING_TOPOLOGY_OPTION_DFS: | 3838 | case GNUNET_TESTING_TOPOLOGY_OPTION_DFS: |
3542 | #if VERBOSE_TOPOLOGY | 3839 | #if VERBOSE_TOPOLOGY |
3543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3840 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3544 | _("Using DFS to connect a minimum of %u peers each (if possible)\n"), (unsigned int)option_modifier); | 3841 | _ |
3842 | ("Using DFS to connect a minimum of %u peers each (if possible)\n"), | ||
3843 | (unsigned int) option_modifier); | ||
3545 | #endif | 3844 | #endif |
3546 | perform_dfs(pg, (int)option_modifier); | 3845 | perform_dfs (pg, (int) option_modifier); |
3547 | break; | 3846 | break; |
3548 | case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST: | 3847 | case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST: |
3549 | #if VERBOSE_TOPOLOGY | 3848 | #if VERBOSE_TOPOLOGY |
3550 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3849 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3551 | _("Finding additional %u closest peers each (if possible)\n"), (unsigned int)option_modifier); | 3850 | _ |
3851 | ("Finding additional %u closest peers each (if possible)\n"), | ||
3852 | (unsigned int) option_modifier); | ||
3552 | #endif | 3853 | #endif |
3553 | add_closest(pg, (unsigned int)option_modifier, &add_actual_connections); | 3854 | add_closest (pg, (unsigned int) option_modifier, |
3855 | &add_actual_connections); | ||
3554 | break; | 3856 | break; |
3555 | case GNUNET_TESTING_TOPOLOGY_OPTION_NONE: | 3857 | case GNUNET_TESTING_TOPOLOGY_OPTION_NONE: |
3556 | break; | 3858 | break; |
@@ -3560,7 +3862,7 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3560 | break; | 3862 | break; |
3561 | } | 3863 | } |
3562 | 3864 | ||
3563 | return connect_topology(pg, notify_callback, notify_cls); | 3865 | return connect_topology (pg, notify_callback, notify_cls); |
3564 | } | 3866 | } |
3565 | 3867 | ||
3566 | /** | 3868 | /** |
@@ -3573,20 +3875,22 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3573 | * @param d handle for the daemon | 3875 | * @param d handle for the daemon |
3574 | * @param emsg error message (NULL on success) | 3876 | * @param emsg error message (NULL on success) |
3575 | */ | 3877 | */ |
3576 | static void internal_hostkey_callback (void *cls, | 3878 | static void |
3577 | const struct GNUNET_PeerIdentity *id, | 3879 | internal_hostkey_callback (void *cls, |
3578 | struct GNUNET_TESTING_Daemon *d, | 3880 | const struct GNUNET_PeerIdentity *id, |
3579 | const char *emsg) | 3881 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
3580 | { | 3882 | { |
3581 | struct InternalStartContext *internal_context = cls; | 3883 | struct InternalStartContext *internal_context = cls; |
3582 | internal_context->peer->pg->starting--; | 3884 | internal_context->peer->pg->starting--; |
3583 | internal_context->peer->pg->started++; | 3885 | internal_context->peer->pg->started++; |
3584 | if (internal_context->hostkey_callback != NULL) | 3886 | if (internal_context->hostkey_callback != NULL) |
3585 | internal_context->hostkey_callback(internal_context->hostkey_cls, id, d, emsg); | 3887 | internal_context->hostkey_callback (internal_context->hostkey_cls, id, d, |
3586 | else if (internal_context->peer->pg->started == internal_context->peer->pg->total) | 3888 | emsg); |
3889 | else if (internal_context->peer->pg->started == | ||
3890 | internal_context->peer->pg->total) | ||
3587 | { | 3891 | { |
3588 | internal_context->peer->pg->started = 0; /* Internal startup may use this counter! */ | 3892 | internal_context->peer->pg->started = 0; /* Internal startup may use this counter! */ |
3589 | GNUNET_TESTING_daemons_continue_startup(internal_context->peer->pg); | 3893 | GNUNET_TESTING_daemons_continue_startup (internal_context->peer->pg); |
3590 | } | 3894 | } |
3591 | } | 3895 | } |
3592 | 3896 | ||
@@ -3600,20 +3904,22 @@ static void internal_hostkey_callback (void *cls, | |||
3600 | * @param d handle for the daemon | 3904 | * @param d handle for the daemon |
3601 | * @param emsg error message (NULL on success) | 3905 | * @param emsg error message (NULL on success) |
3602 | */ | 3906 | */ |
3603 | static void internal_startup_callback (void *cls, | 3907 | static void |
3604 | const struct GNUNET_PeerIdentity *id, | 3908 | internal_startup_callback (void *cls, |
3605 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 3909 | const struct GNUNET_PeerIdentity *id, |
3606 | struct GNUNET_TESTING_Daemon *d, | 3910 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
3607 | const char *emsg) | 3911 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
3608 | { | 3912 | { |
3609 | struct InternalStartContext *internal_context = cls; | 3913 | struct InternalStartContext *internal_context = cls; |
3610 | internal_context->peer->pg->starting--; | 3914 | internal_context->peer->pg->starting--; |
3611 | if (internal_context->start_cb != NULL) | 3915 | if (internal_context->start_cb != NULL) |
3612 | internal_context->start_cb(internal_context->start_cb_cls, id, cfg, d, emsg); | 3916 | internal_context->start_cb (internal_context->start_cb_cls, id, cfg, d, |
3917 | emsg); | ||
3613 | } | 3918 | } |
3614 | 3919 | ||
3615 | static void | 3920 | static void |
3616 | internal_continue_startup (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 3921 | internal_continue_startup (void *cls, |
3922 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
3617 | { | 3923 | { |
3618 | struct InternalStartContext *internal_context = cls; | 3924 | struct InternalStartContext *internal_context = cls; |
3619 | 3925 | ||
@@ -3629,7 +3935,10 @@ internal_continue_startup (void *cls, const struct GNUNET_SCHEDULER_TaskContext | |||
3629 | } | 3935 | } |
3630 | else | 3936 | else |
3631 | { | 3937 | { |
3632 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &internal_continue_startup, internal_context); | 3938 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
3939 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | ||
3940 | &internal_continue_startup, | ||
3941 | internal_context); | ||
3633 | } | 3942 | } |
3634 | } | 3943 | } |
3635 | 3944 | ||
@@ -3649,8 +3958,7 @@ void | |||
3649 | churn_start_callback (void *cls, | 3958 | churn_start_callback (void *cls, |
3650 | const struct GNUNET_PeerIdentity *id, | 3959 | const struct GNUNET_PeerIdentity *id, |
3651 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 3960 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
3652 | struct GNUNET_TESTING_Daemon *d, | 3961 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
3653 | const char *emsg) | ||
3654 | { | 3962 | { |
3655 | struct ChurnRestartContext *startup_ctx = cls; | 3963 | struct ChurnRestartContext *startup_ctx = cls; |
3656 | struct ChurnContext *churn_ctx = startup_ctx->churn_ctx; | 3964 | struct ChurnContext *churn_ctx = startup_ctx->churn_ctx; |
@@ -3662,8 +3970,7 @@ churn_start_callback (void *cls, | |||
3662 | if (emsg != NULL) | 3970 | if (emsg != NULL) |
3663 | { | 3971 | { |
3664 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3972 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3665 | "Churn stop callback failed with error `%s'\n", | 3973 | "Churn stop callback failed with error `%s'\n", emsg); |
3666 | emsg); | ||
3667 | churn_ctx->num_failed_start++; | 3974 | churn_ctx->num_failed_start++; |
3668 | } | 3975 | } |
3669 | else | 3976 | else |
@@ -3672,47 +3979,54 @@ churn_start_callback (void *cls, | |||
3672 | } | 3979 | } |
3673 | 3980 | ||
3674 | #if DEBUG_CHURN | 3981 | #if DEBUG_CHURN |
3675 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 3982 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3676 | "Started peer, %d left.\n", | 3983 | "Started peer, %d left.\n", churn_ctx->num_to_start); |
3677 | churn_ctx->num_to_start); | ||
3678 | #endif | 3984 | #endif |
3679 | 3985 | ||
3680 | total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) + (churn_ctx->num_to_start - churn_ctx->num_failed_start); | 3986 | total_left = |
3987 | (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) + | ||
3988 | (churn_ctx->num_to_start - churn_ctx->num_failed_start); | ||
3681 | 3989 | ||
3682 | if (total_left == 0) | 3990 | if (total_left == 0) |
3683 | { | 3991 | { |
3684 | if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) | 3992 | if ((churn_ctx->num_failed_stop > 0) |
3685 | GNUNET_asprintf(&error_message, | 3993 | || (churn_ctx->num_failed_start > 0)) |
3686 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", | 3994 | GNUNET_asprintf (&error_message, |
3687 | churn_ctx->num_failed_start, | 3995 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", |
3688 | churn_ctx->num_failed_stop); | 3996 | churn_ctx->num_failed_start, |
3689 | churn_ctx->cb(churn_ctx->cb_cls, error_message); | 3997 | churn_ctx->num_failed_stop); |
3690 | GNUNET_free_non_null(error_message); | 3998 | churn_ctx->cb (churn_ctx->cb_cls, error_message); |
3691 | GNUNET_free(churn_ctx); | 3999 | GNUNET_free_non_null (error_message); |
3692 | GNUNET_free(startup_ctx); | 4000 | GNUNET_free (churn_ctx); |
3693 | } | 4001 | GNUNET_free (startup_ctx); |
4002 | } | ||
3694 | } | 4003 | } |
3695 | 4004 | ||
3696 | 4005 | ||
3697 | static void schedule_churn_restart(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 4006 | static void |
4007 | schedule_churn_restart (void *cls, | ||
4008 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
3698 | { | 4009 | { |
3699 | struct PeerRestartContext *peer_restart_ctx = cls; | 4010 | struct PeerRestartContext *peer_restart_ctx = cls; |
3700 | struct ChurnRestartContext *startup_ctx = peer_restart_ctx->churn_restart_ctx; | 4011 | struct ChurnRestartContext *startup_ctx = |
4012 | peer_restart_ctx->churn_restart_ctx; | ||
3701 | 4013 | ||
3702 | if (startup_ctx->outstanding > MAX_CONCURRENT_STARTING) | 4014 | if (startup_ctx->outstanding > MAX_CONCURRENT_STARTING) |
3703 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &schedule_churn_restart, peer_restart_ctx); | 4015 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
4016 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | ||
4017 | &schedule_churn_restart, peer_restart_ctx); | ||
3704 | else | 4018 | else |
3705 | { | 4019 | { |
3706 | GNUNET_TESTING_daemon_start_stopped(peer_restart_ctx->daemon, | 4020 | GNUNET_TESTING_daemon_start_stopped (peer_restart_ctx->daemon, |
3707 | startup_ctx->timeout, | 4021 | startup_ctx->timeout, |
3708 | &churn_start_callback, | 4022 | &churn_start_callback, |
3709 | startup_ctx); | 4023 | startup_ctx); |
3710 | GNUNET_free(peer_restart_ctx); | 4024 | GNUNET_free (peer_restart_ctx); |
3711 | } | 4025 | } |
3712 | } | 4026 | } |
3713 | 4027 | ||
3714 | static void | 4028 | static void |
3715 | internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 4029 | internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3716 | { | 4030 | { |
3717 | struct InternalStartContext *internal_context = cls; | 4031 | struct InternalStartContext *internal_context = cls; |
3718 | 4032 | ||
@@ -3724,19 +4038,22 @@ internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
3724 | if (internal_context->peer->pg->starting < MAX_CONCURRENT_HOSTKEYS) | 4038 | if (internal_context->peer->pg->starting < MAX_CONCURRENT_HOSTKEYS) |
3725 | { | 4039 | { |
3726 | internal_context->peer->pg->starting++; | 4040 | internal_context->peer->pg->starting++; |
3727 | internal_context->peer->daemon = GNUNET_TESTING_daemon_start (internal_context->peer->cfg, | 4041 | internal_context->peer->daemon = |
3728 | internal_context->timeout, | 4042 | GNUNET_TESTING_daemon_start (internal_context->peer->cfg, |
3729 | internal_context->hostname, | 4043 | internal_context->timeout, |
3730 | internal_context->username, | 4044 | internal_context->hostname, |
3731 | internal_context->sshport, | 4045 | internal_context->username, |
3732 | &internal_hostkey_callback, | 4046 | internal_context->sshport, |
3733 | internal_context, | 4047 | &internal_hostkey_callback, |
3734 | &internal_startup_callback, | 4048 | internal_context, |
3735 | internal_context); | 4049 | &internal_startup_callback, |
4050 | internal_context); | ||
3736 | } | 4051 | } |
3737 | else | 4052 | else |
3738 | { | 4053 | { |
3739 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &internal_start, internal_context); | 4054 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
4055 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | ||
4056 | &internal_start, internal_context); | ||
3740 | } | 4057 | } |
3741 | } | 4058 | } |
3742 | 4059 | ||
@@ -3748,14 +4065,15 @@ internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
3748 | * | 4065 | * |
3749 | */ | 4066 | */ |
3750 | void | 4067 | void |
3751 | GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg) | 4068 | GNUNET_TESTING_daemons_continue_startup (struct GNUNET_TESTING_PeerGroup *pg) |
3752 | { | 4069 | { |
3753 | unsigned int i; | 4070 | unsigned int i; |
3754 | 4071 | ||
3755 | pg->starting = 0; | 4072 | pg->starting = 0; |
3756 | for (i = 0; i < pg->total; i++) | 4073 | for (i = 0; i < pg->total; i++) |
3757 | { | 4074 | { |
3758 | GNUNET_SCHEDULER_add_now (&internal_continue_startup, &pg->peers[i].internal_context); | 4075 | GNUNET_SCHEDULER_add_now (&internal_continue_startup, |
4076 | &pg->peers[i].internal_context); | ||
3759 | //GNUNET_TESTING_daemon_continue_startup(pg->peers[i].daemon); | 4077 | //GNUNET_TESTING_daemon_continue_startup(pg->peers[i].daemon); |
3760 | } | 4078 | } |
3761 | } | 4079 | } |
@@ -3786,8 +4104,8 @@ struct GNUNET_TESTING_PeerGroup * | |||
3786 | GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 4104 | GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
3787 | unsigned int total, | 4105 | unsigned int total, |
3788 | struct GNUNET_TIME_Relative timeout, | 4106 | struct GNUNET_TIME_Relative timeout, |
3789 | GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback, | 4107 | GNUNET_TESTING_NotifyHostkeyCreated |
3790 | void *hostkey_cls, | 4108 | hostkey_callback, void *hostkey_cls, |
3791 | GNUNET_TESTING_NotifyDaemonRunning cb, | 4109 | GNUNET_TESTING_NotifyDaemonRunning cb, |
3792 | void *cb_cls, | 4110 | void *cb_cls, |
3793 | GNUNET_TESTING_NotifyConnection | 4111 | GNUNET_TESTING_NotifyConnection |
@@ -3826,7 +4144,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3826 | pg->notify_connection = connect_callback; | 4144 | pg->notify_connection = connect_callback; |
3827 | pg->notify_connection_cls = connect_callback_cls; | 4145 | pg->notify_connection_cls = connect_callback_cls; |
3828 | pg->total = total; | 4146 | pg->total = total; |
3829 | pg->max_timeout = GNUNET_TIME_relative_to_absolute(timeout); | 4147 | pg->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
3830 | pg->peers = GNUNET_malloc (total * sizeof (struct PeerData)); | 4148 | pg->peers = GNUNET_malloc (total * sizeof (struct PeerData)); |
3831 | if (NULL != hostnames) | 4149 | if (NULL != hostnames) |
3832 | { | 4150 | { |
@@ -3844,9 +4162,9 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3844 | while (hostpos != NULL) | 4162 | while (hostpos != NULL) |
3845 | { | 4163 | { |
3846 | pg->hosts[off].minport = LOW_PORT; | 4164 | pg->hosts[off].minport = LOW_PORT; |
3847 | pg->hosts[off].hostname = GNUNET_strdup(hostpos->hostname); | 4165 | pg->hosts[off].hostname = GNUNET_strdup (hostpos->hostname); |
3848 | if (hostpos->username != NULL) | 4166 | if (hostpos->username != NULL) |
3849 | pg->hosts[off].username = GNUNET_strdup(hostpos->username); | 4167 | pg->hosts[off].username = GNUNET_strdup (hostpos->username); |
3850 | pg->hosts[off].sshport = hostpos->port; | 4168 | pg->hosts[off].sshport = hostpos->port; |
3851 | hostpos = hostpos->next; | 4169 | hostpos = hostpos->next; |
3852 | off++; | 4170 | off++; |
@@ -3863,12 +4181,12 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3863 | #if NO_LL | 4181 | #if NO_LL |
3864 | off = 2; | 4182 | off = 2; |
3865 | /* skip leading spaces */ | 4183 | /* skip leading spaces */ |
3866 | while ((0 != *hostnames) && (isspace ( (unsigned char) *hostnames))) | 4184 | while ((0 != *hostnames) && (isspace ((unsigned char) *hostnames))) |
3867 | hostnames++; | 4185 | hostnames++; |
3868 | rpos = hostnames; | 4186 | rpos = hostnames; |
3869 | while ('\0' != *rpos) | 4187 | while ('\0' != *rpos) |
3870 | { | 4188 | { |
3871 | if (isspace ( (unsigned char) *rpos)) | 4189 | if (isspace ((unsigned char) *rpos)) |
3872 | off++; | 4190 | off++; |
3873 | rpos++; | 4191 | rpos++; |
3874 | } | 4192 | } |
@@ -3878,7 +4196,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3878 | pos = start; | 4196 | pos = start; |
3879 | while ('\0' != *pos) | 4197 | while ('\0' != *pos) |
3880 | { | 4198 | { |
3881 | if (isspace ( (unsigned char) *pos)) | 4199 | if (isspace ((unsigned char) *pos)) |
3882 | { | 4200 | { |
3883 | *pos = '\0'; | 4201 | *pos = '\0'; |
3884 | if (strlen (start) > 0) | 4202 | if (strlen (start) > 0) |
@@ -3917,20 +4235,16 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3917 | hostname = pg->hosts[off % hostcnt].hostname; | 4235 | hostname = pg->hosts[off % hostcnt].hostname; |
3918 | username = pg->hosts[off % hostcnt].username; | 4236 | username = pg->hosts[off % hostcnt].username; |
3919 | sshport = pg->hosts[off % hostcnt].sshport; | 4237 | sshport = pg->hosts[off % hostcnt].sshport; |
3920 | pcfg = make_config (cfg, | 4238 | pcfg = make_config (cfg, |
3921 | &pg->hosts[off % hostcnt].minport, | 4239 | &pg->hosts[off % hostcnt].minport, |
3922 | &upnum, | 4240 | &upnum, hostname, &fdnum); |
3923 | hostname, &fdnum); | ||
3924 | } | 4241 | } |
3925 | else | 4242 | else |
3926 | { | 4243 | { |
3927 | hostname = NULL; | 4244 | hostname = NULL; |
3928 | username = NULL; | 4245 | username = NULL; |
3929 | sshport = 0; | 4246 | sshport = 0; |
3930 | pcfg = make_config (cfg, | 4247 | pcfg = make_config (cfg, &minport, &upnum, hostname, &fdnum); |
3931 | &minport, | ||
3932 | &upnum, | ||
3933 | hostname, &fdnum); | ||
3934 | } | 4248 | } |
3935 | 4249 | ||
3936 | if (NULL == pcfg) | 4250 | if (NULL == pcfg) |
@@ -3946,27 +4260,28 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3946 | GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS", "SERVICEHOME", | 4260 | GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS", "SERVICEHOME", |
3947 | &baseservicehome)) | 4261 | &baseservicehome)) |
3948 | { | 4262 | { |
3949 | GNUNET_asprintf (&newservicehome, | 4263 | GNUNET_asprintf (&newservicehome, "%s/%d/", baseservicehome, off); |
3950 | "%s/%d/", baseservicehome, off); | 4264 | GNUNET_free (baseservicehome); |
3951 | GNUNET_free (baseservicehome); | ||
3952 | } | 4265 | } |
3953 | else | 4266 | else |
3954 | { | 4267 | { |
3955 | tmpdir = getenv ("TMPDIR"); | 4268 | tmpdir = getenv ("TMPDIR"); |
3956 | tmpdir = tmpdir ? tmpdir : "/tmp"; | 4269 | tmpdir = tmpdir ? tmpdir : "/tmp"; |
3957 | GNUNET_asprintf (&newservicehome, | 4270 | GNUNET_asprintf (&newservicehome, |
3958 | "%s/%s/%d/", | 4271 | "%s/%s/%d/", |
3959 | tmpdir, | 4272 | tmpdir, "gnunet-testing-test-test", off); |
3960 | "gnunet-testing-test-test", off); | ||
3961 | } | 4273 | } |
3962 | GNUNET_CONFIGURATION_set_value_string (pcfg, | 4274 | GNUNET_CONFIGURATION_set_value_string (pcfg, |
3963 | "PATHS", | 4275 | "PATHS", |
3964 | "SERVICEHOME", newservicehome); | 4276 | "SERVICEHOME", newservicehome); |
3965 | GNUNET_free (newservicehome); | 4277 | GNUNET_free (newservicehome); |
3966 | pg->peers[off].cfg = pcfg; | 4278 | pg->peers[off].cfg = pcfg; |
3967 | pg->peers[off].allowed_peers = GNUNET_CONTAINER_multihashmap_create(total); | 4279 | pg->peers[off].allowed_peers = |
3968 | pg->peers[off].connect_peers = GNUNET_CONTAINER_multihashmap_create(total); | 4280 | GNUNET_CONTAINER_multihashmap_create (total); |
3969 | pg->peers[off].blacklisted_peers = GNUNET_CONTAINER_multihashmap_create(total); | 4281 | pg->peers[off].connect_peers = |
4282 | GNUNET_CONTAINER_multihashmap_create (total); | ||
4283 | pg->peers[off].blacklisted_peers = | ||
4284 | GNUNET_CONTAINER_multihashmap_create (total); | ||
3970 | pg->peers[off].pg = pg; | 4285 | pg->peers[off].pg = pg; |
3971 | 4286 | ||
3972 | pg->peers[off].internal_context.peer = &pg->peers[off]; | 4287 | pg->peers[off].internal_context.peer = &pg->peers[off]; |
@@ -3979,7 +4294,8 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3979 | pg->peers[off].internal_context.start_cb = cb; | 4294 | pg->peers[off].internal_context.start_cb = cb; |
3980 | pg->peers[off].internal_context.start_cb_cls = cb_cls; | 4295 | pg->peers[off].internal_context.start_cb_cls = cb_cls; |
3981 | 4296 | ||
3982 | GNUNET_SCHEDULER_add_now (&internal_start, &pg->peers[off].internal_context); | 4297 | GNUNET_SCHEDULER_add_now (&internal_start, |
4298 | &pg->peers[off].internal_context); | ||
3983 | 4299 | ||
3984 | } | 4300 | } |
3985 | return pg; | 4301 | return pg; |
@@ -3990,7 +4306,8 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3990 | * offsetting operation. | 4306 | * offsetting operation. |
3991 | */ | 4307 | */ |
3992 | struct GNUNET_TESTING_Daemon * | 4308 | struct GNUNET_TESTING_Daemon * |
3993 | GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg, unsigned int position) | 4309 | GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg, |
4310 | unsigned int position) | ||
3994 | { | 4311 | { |
3995 | if (position < pg->total) | 4312 | if (position < pg->total) |
3996 | return pg->peers[position].daemon; | 4313 | return pg->peers[position].daemon; |
@@ -4008,13 +4325,16 @@ GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg, unsigned int pos | |||
4008 | * @return the daemon on success, or NULL if no such peer identity is found | 4325 | * @return the daemon on success, or NULL if no such peer identity is found |
4009 | */ | 4326 | */ |
4010 | struct GNUNET_TESTING_Daemon * | 4327 | struct GNUNET_TESTING_Daemon * |
4011 | GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg, struct GNUNET_PeerIdentity *peer_id) | 4328 | GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg, |
4329 | struct GNUNET_PeerIdentity *peer_id) | ||
4012 | { | 4330 | { |
4013 | unsigned int i; | 4331 | unsigned int i; |
4014 | 4332 | ||
4015 | for (i = 0; i < pg->total; i ++) | 4333 | for (i = 0; i < pg->total; i++) |
4016 | { | 4334 | { |
4017 | if (0 == memcmp(&pg->peers[i].daemon->id, peer_id, sizeof(struct GNUNET_PeerIdentity))) | 4335 | if (0 == |
4336 | memcmp (&pg->peers[i].daemon->id, peer_id, | ||
4337 | sizeof (struct GNUNET_PeerIdentity))) | ||
4018 | return pg->peers[i].daemon; | 4338 | return pg->peers[i].daemon; |
4019 | } | 4339 | } |
4020 | 4340 | ||
@@ -4031,11 +4351,11 @@ GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg, struct GNU | |||
4031 | * @param d handle to the daemon that was restarted | 4351 | * @param d handle to the daemon that was restarted |
4032 | * @param emsg NULL on success | 4352 | * @param emsg NULL on success |
4033 | */ | 4353 | */ |
4034 | void restart_callback (void *cls, | 4354 | void |
4035 | const struct GNUNET_PeerIdentity *id, | 4355 | restart_callback (void *cls, |
4036 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 4356 | const struct GNUNET_PeerIdentity *id, |
4037 | struct GNUNET_TESTING_Daemon *d, | 4357 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
4038 | const char *emsg) | 4358 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
4039 | { | 4359 | { |
4040 | struct RestartContext *restart_context = cls; | 4360 | struct RestartContext *restart_context = cls; |
4041 | 4361 | ||
@@ -4050,13 +4370,16 @@ void restart_callback (void *cls, | |||
4050 | 4370 | ||
4051 | if (restart_context->peers_restarted == restart_context->peer_group->total) | 4371 | if (restart_context->peers_restarted == restart_context->peer_group->total) |
4052 | { | 4372 | { |
4053 | restart_context->callback(restart_context->callback_cls, NULL); | 4373 | restart_context->callback (restart_context->callback_cls, NULL); |
4054 | GNUNET_free(restart_context); | 4374 | GNUNET_free (restart_context); |
4055 | } | 4375 | } |
4056 | else if (restart_context->peers_restart_failed + restart_context->peers_restarted == restart_context->peer_group->total) | 4376 | else if (restart_context->peers_restart_failed + |
4377 | restart_context->peers_restarted == | ||
4378 | restart_context->peer_group->total) | ||
4057 | { | 4379 | { |
4058 | restart_context->callback(restart_context->callback_cls, "Failed to restart peers!"); | 4380 | restart_context->callback (restart_context->callback_cls, |
4059 | GNUNET_free(restart_context); | 4381 | "Failed to restart peers!"); |
4382 | GNUNET_free (restart_context); | ||
4060 | } | 4383 | } |
4061 | 4384 | ||
4062 | } | 4385 | } |
@@ -4082,8 +4405,8 @@ churn_stop_callback (void *cls, const char *emsg) | |||
4082 | 4405 | ||
4083 | if (emsg != NULL) | 4406 | if (emsg != NULL) |
4084 | { | 4407 | { |
4085 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 4408 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
4086 | "Churn stop callback failed with error `%s'\n", emsg); | 4409 | "Churn stop callback failed with error `%s'\n", emsg); |
4087 | churn_ctx->num_failed_stop++; | 4410 | churn_ctx->num_failed_stop++; |
4088 | } | 4411 | } |
4089 | else | 4412 | else |
@@ -4092,26 +4415,28 @@ churn_stop_callback (void *cls, const char *emsg) | |||
4092 | } | 4415 | } |
4093 | 4416 | ||
4094 | #if DEBUG_CHURN | 4417 | #if DEBUG_CHURN |
4095 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 4418 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
4096 | "Stopped peer, %d left.\n", | 4419 | "Stopped peer, %d left.\n", churn_ctx->num_to_stop); |
4097 | churn_ctx->num_to_stop); | ||
4098 | #endif | 4420 | #endif |
4099 | total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) + (churn_ctx->num_to_start - churn_ctx->num_failed_start); | 4421 | total_left = |
4422 | (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) + | ||
4423 | (churn_ctx->num_to_start - churn_ctx->num_failed_start); | ||
4100 | 4424 | ||
4101 | if (total_left == 0) | 4425 | if (total_left == 0) |
4102 | { | 4426 | { |
4103 | if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) | 4427 | if ((churn_ctx->num_failed_stop > 0) |
4104 | { | 4428 | || (churn_ctx->num_failed_start > 0)) |
4105 | GNUNET_asprintf(&error_message, | 4429 | { |
4106 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", | 4430 | GNUNET_asprintf (&error_message, |
4107 | churn_ctx->num_failed_start, | 4431 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", |
4108 | churn_ctx->num_failed_stop); | 4432 | churn_ctx->num_failed_start, |
4109 | } | 4433 | churn_ctx->num_failed_stop); |
4110 | churn_ctx->cb(churn_ctx->cb_cls, error_message); | 4434 | } |
4111 | GNUNET_free_non_null(error_message); | 4435 | churn_ctx->cb (churn_ctx->cb_cls, error_message); |
4112 | GNUNET_free(churn_ctx); | 4436 | GNUNET_free_non_null (error_message); |
4113 | GNUNET_free(shutdown_ctx); | 4437 | GNUNET_free (churn_ctx); |
4114 | } | 4438 | GNUNET_free (shutdown_ctx); |
4439 | } | ||
4115 | } | 4440 | } |
4116 | 4441 | ||
4117 | /** | 4442 | /** |
@@ -4127,13 +4452,13 @@ GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg) | |||
4127 | unsigned int i; | 4452 | unsigned int i; |
4128 | unsigned int running = 0; | 4453 | unsigned int running = 0; |
4129 | for (i = 0; i < pg->total; i++) | 4454 | for (i = 0; i < pg->total; i++) |
4130 | { | ||
4131 | if (pg->peers[i].daemon->running == GNUNET_YES) | ||
4132 | { | 4455 | { |
4133 | GNUNET_assert(running != -1); | 4456 | if (pg->peers[i].daemon->running == GNUNET_YES) |
4134 | running++; | 4457 | { |
4458 | GNUNET_assert (running != -1); | ||
4459 | running++; | ||
4460 | } | ||
4135 | } | 4461 | } |
4136 | } | ||
4137 | return running; | 4462 | return running; |
4138 | } | 4463 | } |
4139 | 4464 | ||
@@ -4145,22 +4470,28 @@ GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg) | |||
4145 | * to calling gnunet-arm N times all at once). | 4470 | * to calling gnunet-arm N times all at once). |
4146 | */ | 4471 | */ |
4147 | static void | 4472 | static void |
4148 | schedule_churn_shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 4473 | schedule_churn_shutdown_task (void *cls, |
4474 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
4149 | { | 4475 | { |
4150 | struct PeerShutdownContext *peer_shutdown_ctx = cls; | 4476 | struct PeerShutdownContext *peer_shutdown_ctx = cls; |
4151 | struct ShutdownContext *shutdown_ctx; | 4477 | struct ShutdownContext *shutdown_ctx; |
4152 | 4478 | ||
4153 | GNUNET_assert(peer_shutdown_ctx != NULL); | 4479 | GNUNET_assert (peer_shutdown_ctx != NULL); |
4154 | shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; | 4480 | shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; |
4155 | GNUNET_assert(shutdown_ctx != NULL); | 4481 | GNUNET_assert (shutdown_ctx != NULL); |
4156 | 4482 | ||
4157 | if (shutdown_ctx->outstanding > MAX_CONCURRENT_SHUTDOWN) | 4483 | if (shutdown_ctx->outstanding > MAX_CONCURRENT_SHUTDOWN) |
4158 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &schedule_churn_shutdown_task, peer_shutdown_ctx); | 4484 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
4485 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | ||
4486 | &schedule_churn_shutdown_task, | ||
4487 | peer_shutdown_ctx); | ||
4159 | else | 4488 | else |
4160 | { | 4489 | { |
4161 | shutdown_ctx->outstanding++; | 4490 | shutdown_ctx->outstanding++; |
4162 | GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon, shutdown_ctx->timeout, shutdown_ctx->cb, shutdown_ctx, GNUNET_NO, GNUNET_YES); | 4491 | GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon, |
4163 | GNUNET_free(peer_shutdown_ctx); | 4492 | shutdown_ctx->timeout, shutdown_ctx->cb, |
4493 | shutdown_ctx, GNUNET_NO, GNUNET_YES); | ||
4494 | GNUNET_free (peer_shutdown_ctx); | ||
4164 | } | 4495 | } |
4165 | } | 4496 | } |
4166 | 4497 | ||
@@ -4211,57 +4542,61 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, | |||
4211 | running = 0; | 4542 | running = 0; |
4212 | stopped = 0; | 4543 | stopped = 0; |
4213 | 4544 | ||
4214 | if ((von == 0) && (voff == 0)) /* No peers at all? */ | 4545 | if ((von == 0) && (voff == 0)) /* No peers at all? */ |
4215 | { | 4546 | { |
4216 | cb(cb_cls, NULL); | 4547 | cb (cb_cls, NULL); |
4217 | return; | 4548 | return; |
4218 | } | 4549 | } |
4219 | 4550 | ||
4220 | for (i = 0; i < pg->total; i++) | 4551 | for (i = 0; i < pg->total; i++) |
4221 | { | ||
4222 | if (pg->peers[i].daemon->running == GNUNET_YES) | ||
4223 | { | 4552 | { |
4224 | GNUNET_assert(running != -1); | 4553 | if (pg->peers[i].daemon->running == GNUNET_YES) |
4225 | running++; | 4554 | { |
4226 | } | 4555 | GNUNET_assert (running != -1); |
4227 | else | 4556 | running++; |
4228 | { | 4557 | } |
4229 | GNUNET_assert(stopped != -1); | 4558 | else |
4230 | stopped++; | 4559 | { |
4560 | GNUNET_assert (stopped != -1); | ||
4561 | stopped++; | ||
4562 | } | ||
4231 | } | 4563 | } |
4232 | } | ||
4233 | 4564 | ||
4234 | if (voff > running) | 4565 | if (voff > running) |
4235 | { | 4566 | { |
4236 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Trying to stop more peers than are currently running!\n"); | 4567 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
4237 | cb(cb_cls, "Trying to stop more peers than are currently running!"); | 4568 | "Trying to stop more peers than are currently running!\n"); |
4238 | return; | 4569 | cb (cb_cls, "Trying to stop more peers than are currently running!"); |
4239 | } | 4570 | return; |
4571 | } | ||
4240 | 4572 | ||
4241 | if (von > stopped) | 4573 | if (von > stopped) |
4242 | { | 4574 | { |
4243 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Trying to start more peers than are currently stopped!\n"); | 4575 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
4244 | cb(cb_cls, "Trying to start more peers than are currently stopped!"); | 4576 | "Trying to start more peers than are currently stopped!\n"); |
4245 | return; | 4577 | cb (cb_cls, "Trying to start more peers than are currently stopped!"); |
4246 | } | 4578 | return; |
4579 | } | ||
4247 | 4580 | ||
4248 | churn_ctx = GNUNET_malloc(sizeof(struct ChurnContext)); | 4581 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); |
4249 | 4582 | ||
4250 | running_arr = NULL; | 4583 | running_arr = NULL; |
4251 | if (running > 0) | 4584 | if (running > 0) |
4252 | running_arr = GNUNET_malloc(running * sizeof(unsigned int)); | 4585 | running_arr = GNUNET_malloc (running * sizeof (unsigned int)); |
4253 | 4586 | ||
4254 | stopped_arr = NULL; | 4587 | stopped_arr = NULL; |
4255 | if (stopped > 0) | 4588 | if (stopped > 0) |
4256 | stopped_arr = GNUNET_malloc(stopped * sizeof(unsigned int)); | 4589 | stopped_arr = GNUNET_malloc (stopped * sizeof (unsigned int)); |
4257 | 4590 | ||
4258 | running_permute = NULL; | 4591 | running_permute = NULL; |
4259 | stopped_permute = NULL; | 4592 | stopped_permute = NULL; |
4260 | 4593 | ||
4261 | if (running > 0) | 4594 | if (running > 0) |
4262 | running_permute = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, running); | 4595 | running_permute = |
4596 | GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, running); | ||
4263 | if (stopped > 0) | 4597 | if (stopped > 0) |
4264 | stopped_permute = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, stopped); | 4598 | stopped_permute = |
4599 | GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, stopped); | ||
4265 | 4600 | ||
4266 | total_running = running; | 4601 | total_running = running; |
4267 | total_stopped = stopped; | 4602 | total_stopped = stopped; |
@@ -4271,28 +4606,28 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, | |||
4271 | churn_ctx->num_to_start = von; | 4606 | churn_ctx->num_to_start = von; |
4272 | churn_ctx->num_to_stop = voff; | 4607 | churn_ctx->num_to_stop = voff; |
4273 | churn_ctx->cb = cb; | 4608 | churn_ctx->cb = cb; |
4274 | churn_ctx->cb_cls = cb_cls; | 4609 | churn_ctx->cb_cls = cb_cls; |
4275 | 4610 | ||
4276 | for (i = 0; i < pg->total; i++) | 4611 | for (i = 0; i < pg->total; i++) |
4277 | { | ||
4278 | if (pg->peers[i].daemon->running == GNUNET_YES) | ||
4279 | { | 4612 | { |
4280 | GNUNET_assert((running_arr != NULL) && (total_running > running)); | 4613 | if (pg->peers[i].daemon->running == GNUNET_YES) |
4281 | running_arr[running] = i; | 4614 | { |
4282 | running++; | 4615 | GNUNET_assert ((running_arr != NULL) && (total_running > running)); |
4283 | } | 4616 | running_arr[running] = i; |
4284 | else | 4617 | running++; |
4285 | { | 4618 | } |
4286 | GNUNET_assert((stopped_arr != NULL) && (total_stopped > stopped)); | 4619 | else |
4287 | stopped_arr[stopped] = i; | 4620 | { |
4288 | stopped++; | 4621 | GNUNET_assert ((stopped_arr != NULL) && (total_stopped > stopped)); |
4622 | stopped_arr[stopped] = i; | ||
4623 | stopped++; | ||
4624 | } | ||
4289 | } | 4625 | } |
4290 | } | ||
4291 | 4626 | ||
4292 | GNUNET_assert(running >= voff); | 4627 | GNUNET_assert (running >= voff); |
4293 | if (voff > 0) | 4628 | if (voff > 0) |
4294 | { | 4629 | { |
4295 | shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext)); | 4630 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); |
4296 | shutdown_ctx->cb = &churn_stop_callback; | 4631 | shutdown_ctx->cb = &churn_stop_callback; |
4297 | shutdown_ctx->cb_cls = churn_ctx; | 4632 | shutdown_ctx->cb_cls = churn_ctx; |
4298 | shutdown_ctx->total_peers = voff; | 4633 | shutdown_ctx->total_peers = voff; |
@@ -4300,49 +4635,54 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, | |||
4300 | } | 4635 | } |
4301 | 4636 | ||
4302 | for (i = 0; i < voff; i++) | 4637 | for (i = 0; i < voff; i++) |
4303 | { | 4638 | { |
4304 | #if DEBUG_CHURN | 4639 | #if DEBUG_CHURN |
4305 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n", running_permute[i]); | 4640 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n", |
4641 | running_permute[i]); | ||
4306 | #endif | 4642 | #endif |
4307 | GNUNET_assert(running_arr != NULL); | 4643 | GNUNET_assert (running_arr != NULL); |
4308 | peer_shutdown_ctx = GNUNET_malloc(sizeof(struct PeerShutdownContext)); | 4644 | peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext)); |
4309 | peer_shutdown_ctx->daemon = pg->peers[running_arr[running_permute[i]]].daemon; | 4645 | peer_shutdown_ctx->daemon = |
4310 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; | 4646 | pg->peers[running_arr[running_permute[i]]].daemon; |
4311 | GNUNET_SCHEDULER_add_now(&schedule_churn_shutdown_task, peer_shutdown_ctx); | 4647 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; |
4312 | 4648 | GNUNET_SCHEDULER_add_now (&schedule_churn_shutdown_task, | |
4313 | /* | 4649 | peer_shutdown_ctx); |
4314 | GNUNET_TESTING_daemon_stop (pg->peers[running_arr[running_permute[i]]].daemon, | 4650 | |
4315 | timeout, | 4651 | /* |
4316 | &churn_stop_callback, churn_ctx, | 4652 | GNUNET_TESTING_daemon_stop (pg->peers[running_arr[running_permute[i]]].daemon, |
4317 | GNUNET_NO, GNUNET_YES); */ | 4653 | timeout, |
4318 | } | 4654 | &churn_stop_callback, churn_ctx, |
4319 | 4655 | GNUNET_NO, GNUNET_YES); */ | |
4320 | GNUNET_assert(stopped >= von); | 4656 | } |
4657 | |||
4658 | GNUNET_assert (stopped >= von); | ||
4321 | if (von > 0) | 4659 | if (von > 0) |
4322 | { | 4660 | { |
4323 | churn_startup_ctx = GNUNET_malloc(sizeof(struct ChurnRestartContext)); | 4661 | churn_startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext)); |
4324 | churn_startup_ctx->churn_ctx = churn_ctx; | 4662 | churn_startup_ctx->churn_ctx = churn_ctx; |
4325 | churn_startup_ctx->timeout = timeout; | 4663 | churn_startup_ctx->timeout = timeout; |
4326 | } | 4664 | } |
4327 | for (i = 0; i < von; i++) | 4665 | for (i = 0; i < von; i++) |
4328 | { | 4666 | { |
4329 | #if DEBUG_CHURN | 4667 | #if DEBUG_CHURN |
4330 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n", stopped_permute[i]); | 4668 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n", |
4669 | stopped_permute[i]); | ||
4331 | #endif | 4670 | #endif |
4332 | GNUNET_assert(stopped_arr != NULL); | 4671 | GNUNET_assert (stopped_arr != NULL); |
4333 | peer_restart_ctx = GNUNET_malloc(sizeof(struct PeerRestartContext)); | 4672 | peer_restart_ctx = GNUNET_malloc (sizeof (struct PeerRestartContext)); |
4334 | peer_restart_ctx->churn_restart_ctx = churn_startup_ctx; | 4673 | peer_restart_ctx->churn_restart_ctx = churn_startup_ctx; |
4335 | peer_restart_ctx->daemon = pg->peers[stopped_arr[stopped_permute[i]]].daemon; | 4674 | peer_restart_ctx->daemon = |
4336 | GNUNET_SCHEDULER_add_now(&schedule_churn_restart, peer_restart_ctx); | 4675 | pg->peers[stopped_arr[stopped_permute[i]]].daemon; |
4676 | GNUNET_SCHEDULER_add_now (&schedule_churn_restart, peer_restart_ctx); | ||
4337 | /* | 4677 | /* |
4338 | GNUNET_TESTING_daemon_start_stopped(pg->peers[stopped_arr[stopped_permute[i]]].daemon, | 4678 | GNUNET_TESTING_daemon_start_stopped(pg->peers[stopped_arr[stopped_permute[i]]].daemon, |
4339 | timeout, &churn_start_callback, churn_ctx);*/ | 4679 | timeout, &churn_start_callback, churn_ctx); */ |
4340 | } | 4680 | } |
4341 | 4681 | ||
4342 | GNUNET_free_non_null(running_arr); | 4682 | GNUNET_free_non_null (running_arr); |
4343 | GNUNET_free_non_null(stopped_arr); | 4683 | GNUNET_free_non_null (stopped_arr); |
4344 | GNUNET_free_non_null(running_permute); | 4684 | GNUNET_free_non_null (running_permute); |
4345 | GNUNET_free_non_null(stopped_permute); | 4685 | GNUNET_free_non_null (stopped_permute); |
4346 | } | 4686 | } |
4347 | 4687 | ||
4348 | 4688 | ||
@@ -4363,7 +4703,7 @@ GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg, | |||
4363 | 4703 | ||
4364 | if (pg->total > 0) | 4704 | if (pg->total > 0) |
4365 | { | 4705 | { |
4366 | restart_context = GNUNET_malloc(sizeof(struct RestartContext)); | 4706 | restart_context = GNUNET_malloc (sizeof (struct RestartContext)); |
4367 | restart_context->peer_group = pg; | 4707 | restart_context->peer_group = pg; |
4368 | restart_context->peers_restarted = 0; | 4708 | restart_context->peers_restarted = 0; |
4369 | restart_context->callback = callback; | 4709 | restart_context->callback = callback; |
@@ -4371,7 +4711,8 @@ GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg, | |||
4371 | 4711 | ||
4372 | for (off = 0; off < pg->total; off++) | 4712 | for (off = 0; off < pg->total; off++) |
4373 | { | 4713 | { |
4374 | GNUNET_TESTING_daemon_restart (pg->peers[off].daemon, &restart_callback, restart_context); | 4714 | GNUNET_TESTING_daemon_restart (pg->peers[off].daemon, |
4715 | &restart_callback, restart_context); | ||
4375 | } | 4716 | } |
4376 | } | 4717 | } |
4377 | } | 4718 | } |
@@ -4387,12 +4728,11 @@ GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg, | |||
4387 | * @param cb_cls closure for cb | 4728 | * @param cb_cls closure for cb |
4388 | */ | 4729 | */ |
4389 | void | 4730 | void |
4390 | GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, | 4731 | GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, |
4391 | unsigned int offset, | 4732 | unsigned int offset, |
4392 | int desired_status, | 4733 | int desired_status, |
4393 | struct GNUNET_TIME_Relative timeout, | 4734 | struct GNUNET_TIME_Relative timeout, |
4394 | GNUNET_TESTING_NotifyCompletion cb, | 4735 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) |
4395 | void *cb_cls) | ||
4396 | { | 4736 | { |
4397 | struct ShutdownContext *shutdown_ctx; | 4737 | struct ShutdownContext *shutdown_ctx; |
4398 | struct ChurnRestartContext *startup_ctx; | 4738 | struct ChurnRestartContext *startup_ctx; |
@@ -4401,33 +4741,34 @@ GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, | |||
4401 | if (GNUNET_NO == desired_status) | 4741 | if (GNUNET_NO == desired_status) |
4402 | { | 4742 | { |
4403 | if (NULL != pg->peers[offset].daemon) | 4743 | if (NULL != pg->peers[offset].daemon) |
4404 | { | 4744 | { |
4405 | shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext)); | 4745 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); |
4406 | churn_ctx = GNUNET_malloc(sizeof(struct ChurnContext)); | 4746 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); |
4407 | churn_ctx->num_to_start = 0; | 4747 | churn_ctx->num_to_start = 0; |
4408 | churn_ctx->num_to_stop = 1; | 4748 | churn_ctx->num_to_stop = 1; |
4409 | churn_ctx->cb = cb; | 4749 | churn_ctx->cb = cb; |
4410 | churn_ctx->cb_cls = cb_cls; | 4750 | churn_ctx->cb_cls = cb_cls; |
4411 | shutdown_ctx->cb_cls = churn_ctx; | 4751 | shutdown_ctx->cb_cls = churn_ctx; |
4412 | GNUNET_TESTING_daemon_stop(pg->peers[offset].daemon, | 4752 | GNUNET_TESTING_daemon_stop (pg->peers[offset].daemon, |
4413 | timeout, &churn_stop_callback, shutdown_ctx, | 4753 | timeout, &churn_stop_callback, |
4414 | GNUNET_NO, GNUNET_YES); | 4754 | shutdown_ctx, GNUNET_NO, GNUNET_YES); |
4415 | } | 4755 | } |
4416 | } | 4756 | } |
4417 | else if (GNUNET_YES == desired_status) | 4757 | else if (GNUNET_YES == desired_status) |
4418 | { | 4758 | { |
4419 | if (NULL == pg->peers[offset].daemon) | 4759 | if (NULL == pg->peers[offset].daemon) |
4420 | { | 4760 | { |
4421 | startup_ctx = GNUNET_malloc(sizeof(struct ChurnRestartContext)); | 4761 | startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext)); |
4422 | churn_ctx = GNUNET_malloc(sizeof(struct ChurnContext)); | 4762 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); |
4423 | churn_ctx->num_to_start = 1; | 4763 | churn_ctx->num_to_start = 1; |
4424 | churn_ctx->num_to_stop = 0; | 4764 | churn_ctx->num_to_stop = 0; |
4425 | churn_ctx->cb = cb; | 4765 | churn_ctx->cb = cb; |
4426 | churn_ctx->cb_cls = cb_cls; | 4766 | churn_ctx->cb_cls = cb_cls; |
4427 | startup_ctx->churn_ctx = churn_ctx; | 4767 | startup_ctx->churn_ctx = churn_ctx; |
4428 | GNUNET_TESTING_daemon_start_stopped(pg->peers[offset].daemon, | 4768 | GNUNET_TESTING_daemon_start_stopped (pg->peers[offset].daemon, |
4429 | timeout, &churn_start_callback, startup_ctx); | 4769 | timeout, &churn_start_callback, |
4430 | } | 4770 | startup_ctx); |
4771 | } | ||
4431 | } | 4772 | } |
4432 | else | 4773 | else |
4433 | GNUNET_break (0); | 4774 | GNUNET_break (0); |
@@ -4440,8 +4781,8 @@ GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, | |||
4440 | * @param cls closure (struct ShutdownContext) | 4781 | * @param cls closure (struct ShutdownContext) |
4441 | * @param emsg NULL on success | 4782 | * @param emsg NULL on success |
4442 | */ | 4783 | */ |
4443 | void internal_shutdown_callback (void *cls, | 4784 | void |
4444 | const char *emsg) | 4785 | internal_shutdown_callback (void *cls, const char *emsg) |
4445 | { | 4786 | { |
4446 | struct ShutdownContext *shutdown_ctx = cls; | 4787 | struct ShutdownContext *shutdown_ctx = cls; |
4447 | 4788 | ||
@@ -4455,13 +4796,16 @@ void internal_shutdown_callback (void *cls, | |||
4455 | shutdown_ctx->peers_failed++; | 4796 | shutdown_ctx->peers_failed++; |
4456 | } | 4797 | } |
4457 | 4798 | ||
4458 | if ((shutdown_ctx->cb != NULL) && (shutdown_ctx->peers_down + shutdown_ctx->peers_failed == shutdown_ctx->total_peers)) | 4799 | if ((shutdown_ctx->cb != NULL) |
4800 | && (shutdown_ctx->peers_down + shutdown_ctx->peers_failed == | ||
4801 | shutdown_ctx->total_peers)) | ||
4459 | { | 4802 | { |
4460 | if (shutdown_ctx->peers_failed > 0) | 4803 | if (shutdown_ctx->peers_failed > 0) |
4461 | shutdown_ctx->cb(shutdown_ctx->cb_cls, "Not all peers successfully shut down!"); | 4804 | shutdown_ctx->cb (shutdown_ctx->cb_cls, |
4805 | "Not all peers successfully shut down!"); | ||
4462 | else | 4806 | else |
4463 | shutdown_ctx->cb(shutdown_ctx->cb_cls, NULL); | 4807 | shutdown_ctx->cb (shutdown_ctx->cb_cls, NULL); |
4464 | GNUNET_free(shutdown_ctx); | 4808 | GNUNET_free (shutdown_ctx); |
4465 | } | 4809 | } |
4466 | } | 4810 | } |
4467 | 4811 | ||
@@ -4474,22 +4818,28 @@ void internal_shutdown_callback (void *cls, | |||
4474 | * to calling gnunet-arm N times all at once). | 4818 | * to calling gnunet-arm N times all at once). |
4475 | */ | 4819 | */ |
4476 | static void | 4820 | static void |
4477 | schedule_shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 4821 | schedule_shutdown_task (void *cls, |
4822 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
4478 | { | 4823 | { |
4479 | struct PeerShutdownContext *peer_shutdown_ctx = cls; | 4824 | struct PeerShutdownContext *peer_shutdown_ctx = cls; |
4480 | struct ShutdownContext *shutdown_ctx; | 4825 | struct ShutdownContext *shutdown_ctx; |
4481 | 4826 | ||
4482 | GNUNET_assert(peer_shutdown_ctx != NULL); | 4827 | GNUNET_assert (peer_shutdown_ctx != NULL); |
4483 | shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; | 4828 | shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; |
4484 | GNUNET_assert(shutdown_ctx != NULL); | 4829 | GNUNET_assert (shutdown_ctx != NULL); |
4485 | 4830 | ||
4486 | if (shutdown_ctx->outstanding > MAX_CONCURRENT_SHUTDOWN) | 4831 | if (shutdown_ctx->outstanding > MAX_CONCURRENT_SHUTDOWN) |
4487 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &schedule_shutdown_task, peer_shutdown_ctx); | 4832 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
4833 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | ||
4834 | &schedule_shutdown_task, peer_shutdown_ctx); | ||
4488 | else | 4835 | else |
4489 | { | 4836 | { |
4490 | shutdown_ctx->outstanding++; | 4837 | shutdown_ctx->outstanding++; |
4491 | GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon, shutdown_ctx->timeout, &internal_shutdown_callback, shutdown_ctx, GNUNET_YES, GNUNET_NO); | 4838 | GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon, |
4492 | GNUNET_free(peer_shutdown_ctx); | 4839 | shutdown_ctx->timeout, |
4840 | &internal_shutdown_callback, shutdown_ctx, | ||
4841 | GNUNET_YES, GNUNET_NO); | ||
4842 | GNUNET_free (peer_shutdown_ctx); | ||
4493 | } | 4843 | } |
4494 | } | 4844 | } |
4495 | 4845 | ||
@@ -4502,18 +4852,17 @@ schedule_shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * t | |||
4502 | * @param cb_cls closure for cb | 4852 | * @param cb_cls closure for cb |
4503 | */ | 4853 | */ |
4504 | void | 4854 | void |
4505 | GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, | 4855 | GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, |
4506 | struct GNUNET_TIME_Relative timeout, | 4856 | struct GNUNET_TIME_Relative timeout, |
4507 | GNUNET_TESTING_NotifyCompletion cb, | 4857 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) |
4508 | void *cb_cls) | ||
4509 | { | 4858 | { |
4510 | unsigned int off; | 4859 | unsigned int off; |
4511 | struct ShutdownContext *shutdown_ctx; | 4860 | struct ShutdownContext *shutdown_ctx; |
4512 | struct PeerShutdownContext *peer_shutdown_ctx; | 4861 | struct PeerShutdownContext *peer_shutdown_ctx; |
4513 | 4862 | ||
4514 | GNUNET_assert(pg->total > 0); | 4863 | GNUNET_assert (pg->total > 0); |
4515 | 4864 | ||
4516 | shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext)); | 4865 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); |
4517 | shutdown_ctx->cb = cb; | 4866 | shutdown_ctx->cb = cb; |
4518 | shutdown_ctx->cb_cls = cb_cls; | 4867 | shutdown_ctx->cb_cls = cb_cls; |
4519 | shutdown_ctx->total_peers = pg->total; | 4868 | shutdown_ctx->total_peers = pg->total; |
@@ -4522,20 +4871,21 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, | |||
4522 | 4871 | ||
4523 | for (off = 0; off < pg->total; off++) | 4872 | for (off = 0; off < pg->total; off++) |
4524 | { | 4873 | { |
4525 | GNUNET_assert(NULL != pg->peers[off].daemon); | 4874 | GNUNET_assert (NULL != pg->peers[off].daemon); |
4526 | peer_shutdown_ctx = GNUNET_malloc(sizeof(struct PeerShutdownContext)); | 4875 | peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext)); |
4527 | peer_shutdown_ctx->daemon = pg->peers[off].daemon; | 4876 | peer_shutdown_ctx->daemon = pg->peers[off].daemon; |
4528 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; | 4877 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; |
4529 | GNUNET_SCHEDULER_add_now(&schedule_shutdown_task, peer_shutdown_ctx); | 4878 | GNUNET_SCHEDULER_add_now (&schedule_shutdown_task, peer_shutdown_ctx); |
4530 | //GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, shutdown_cb, shutdown_ctx, GNUNET_YES, GNUNET_NO); | 4879 | //GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, shutdown_cb, shutdown_ctx, GNUNET_YES, GNUNET_NO); |
4531 | if (NULL != pg->peers[off].cfg) | 4880 | if (NULL != pg->peers[off].cfg) |
4532 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); | 4881 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); |
4533 | if (pg->peers[off].allowed_peers != NULL) | 4882 | if (pg->peers[off].allowed_peers != NULL) |
4534 | GNUNET_CONTAINER_multihashmap_destroy(pg->peers[off].allowed_peers); | 4883 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers); |
4535 | if (pg->peers[off].connect_peers != NULL) | 4884 | if (pg->peers[off].connect_peers != NULL) |
4536 | GNUNET_CONTAINER_multihashmap_destroy(pg->peers[off].connect_peers); | 4885 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].connect_peers); |
4537 | if (pg->peers[off].blacklisted_peers != NULL) | 4886 | if (pg->peers[off].blacklisted_peers != NULL) |
4538 | GNUNET_CONTAINER_multihashmap_destroy(pg->peers[off].blacklisted_peers); | 4887 | GNUNET_CONTAINER_multihashmap_destroy (pg-> |
4888 | peers[off].blacklisted_peers); | ||
4539 | } | 4889 | } |
4540 | GNUNET_free (pg->peers); | 4890 | GNUNET_free (pg->peers); |
4541 | for (off = 0; off < pg->num_hosts; off++) | 4891 | for (off = 0; off < pg->num_hosts; off++) |