aboutsummaryrefslogtreecommitdiff
path: root/src/nse/test_nse_multipeer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nse/test_nse_multipeer.c')
-rw-r--r--src/nse/test_nse_multipeer.c155
1 files changed, 72 insertions, 83 deletions
diff --git a/src/nse/test_nse_multipeer.c b/src/nse/test_nse_multipeer.c
index 0f5edeb48..29e5cd6cc 100644
--- a/src/nse/test_nse_multipeer.c
+++ b/src/nse/test_nse_multipeer.c
@@ -70,40 +70,38 @@ static void
70shutdown_callback (void *cls, const char *emsg) 70shutdown_callback (void *cls, const char *emsg)
71{ 71{
72 if (emsg != NULL) 72 if (emsg != NULL)
73 { 73 {
74#if VERBOSE 74#if VERBOSE
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
76 "Shutdown of peers failed: %s!\n", 76 "Shutdown of peers failed: %s!\n", emsg);
77 emsg);
78#endif 77#endif
79 if (ok == 0) 78 if (ok == 0)
80 ok = 666; 79 ok = 666;
81 } 80 }
82 else 81 else
83 { 82 {
84#if VERBOSE 83#if VERBOSE
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n");
86 "All peers successfully shut down!\n");
87#endif 85#endif
88 ok = 0; 86 ok = 0;
89 } 87 }
90} 88}
91 89
92static void 90static void
93shutdown_task (void *cls, 91shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
94 const struct GNUNET_SCHEDULER_TaskContext *tc)
95{ 92{
96 struct NSEPeer *pos; 93 struct NSEPeer *pos;
94
97#if VERBOSE 95#if VERBOSE
98 fprintf(stderr, "Ending test.\n"); 96 fprintf (stderr, "Ending test.\n");
99#endif 97#endif
100 98
101 while (NULL != (pos = peer_head)) 99 while (NULL != (pos = peer_head))
102 { 100 {
103 GNUNET_NSE_disconnect(pos->nse_handle); 101 GNUNET_NSE_disconnect (pos->nse_handle);
104 GNUNET_CONTAINER_DLL_remove(peer_head, peer_tail, pos); 102 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
105 GNUNET_free(pos); 103 GNUNET_free (pos);
106 } 104 }
107 105
108 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 106 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
109} 107}
@@ -120,64 +118,61 @@ shutdown_task (void *cls,
120 */ 118 */
121static void 119static void
122handle_estimate (void *cls, 120handle_estimate (void *cls,
123 struct GNUNET_TIME_Absolute timestamp, 121 struct GNUNET_TIME_Absolute timestamp,
124 double estimate, double std_dev) 122 double estimate, double std_dev)
125{ 123{
126 struct NSEPeer *peer = cls; 124 struct NSEPeer *peer = cls;
127 125
128 fprintf (stderr, 126 fprintf (stderr,
129 "Received network size estimate from peer %s. logSize: %f std.dev. %f (%f/%u)\n", 127 "Received network size estimate from peer %s. logSize: %f std.dev. %f (%f/%u)\n",
130 GNUNET_i2s(&peer->daemon->id), 128 GNUNET_i2s (&peer->daemon->id),
131 estimate, 129 estimate,
132 std_dev, 130 std_dev, GNUNET_NSE_log_estimate_to_n (estimate), num_peers);
133 GNUNET_NSE_log_estimate_to_n (estimate),
134 num_peers);
135} 131}
136 132
137 133
138static void 134static void
139connect_nse_service (void *cls, 135connect_nse_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
140 const struct GNUNET_SCHEDULER_TaskContext *tc)
141{ 136{
142 struct NSEPeer *current_peer; 137 struct NSEPeer *current_peer;
143 unsigned int i; 138 unsigned int i;
139
144#if VERBOSE 140#if VERBOSE
145 fprintf(stderr, "TEST_NSE_MULTIPEER: connecting to nse service of peers\n"); 141 fprintf (stderr, "TEST_NSE_MULTIPEER: connecting to nse service of peers\n");
146#endif 142#endif
147 for (i = 0; i < num_peers; i++) 143 for (i = 0; i < num_peers; i++)
148 { 144 {
149 current_peer = GNUNET_malloc(sizeof(struct NSEPeer)); 145 current_peer = GNUNET_malloc (sizeof (struct NSEPeer));
150 current_peer->daemon = GNUNET_TESTING_daemon_get(pg, i); 146 current_peer->daemon = GNUNET_TESTING_daemon_get (pg, i);
151 current_peer->nse_handle = GNUNET_NSE_connect (current_peer->daemon->cfg, 147 current_peer->nse_handle = GNUNET_NSE_connect (current_peer->daemon->cfg,
152 &handle_estimate, 148 &handle_estimate,
153 current_peer); 149 current_peer);
154 GNUNET_assert(current_peer->nse_handle != NULL); 150 GNUNET_assert (current_peer->nse_handle != NULL);
155 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer); 151 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
156 } 152 }
157} 153}
158 154
159 155
160static void 156static void
161my_cb (void *cls, 157my_cb (void *cls, const char *emsg)
162 const char *emsg)
163{ 158{
164 if (emsg != NULL) 159 if (emsg != NULL)
165 { 160 {
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
167 "Peergroup callback called with error, aborting test!\n"); 162 "Peergroup callback called with error, aborting test!\n");
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); 163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
169 ok = 1; 164 ok = 1;
170 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 165 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
171 return; 166 return;
172 } 167 }
173#if VERBOSE 168#if VERBOSE
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "Peer Group started successfully, connecting to NSE service for each peer!\n"); 170 "Peer Group started successfully, connecting to NSE service for each peer!\n");
176#endif 171#endif
177 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 172 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
178 "Have %u connections\n", total_connections); 173 "Have %u connections\n", total_connections);
179 174
180 GNUNET_SCHEDULER_add_now(&connect_nse_service, NULL); 175 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
181} 176}
182 177
183 178
@@ -195,22 +190,21 @@ my_cb (void *cls,
195 * @param second_daemon handle for the second daemon 190 * @param second_daemon handle for the second daemon
196 * @param emsg error message (NULL on success) 191 * @param emsg error message (NULL on success)
197 */ 192 */
198static void 193static void
199connect_cb (void *cls, 194connect_cb (void *cls,
200 const struct GNUNET_PeerIdentity *first, 195 const struct GNUNET_PeerIdentity *first,
201 const struct GNUNET_PeerIdentity *second, 196 const struct GNUNET_PeerIdentity *second,
202 uint32_t distance, 197 uint32_t distance,
203 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 198 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
204 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 199 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
205 struct GNUNET_TESTING_Daemon *first_daemon, 200 struct GNUNET_TESTING_Daemon *first_daemon,
206 struct GNUNET_TESTING_Daemon *second_daemon, 201 struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
207 const char *emsg)
208{ 202{
209 if (emsg == NULL) 203 if (emsg == NULL)
210 { 204 {
211 //fprintf(stderr, "Connected %s -> %s\n", GNUNET_i2s(first), second_id); 205 //fprintf(stderr, "Connected %s -> %s\n", GNUNET_i2s(first), second_id);
212 total_connections++; 206 total_connections++;
213 } 207 }
214} 208}
215 209
216 210
@@ -224,30 +218,26 @@ run (void *cls,
224 unsigned long long total_peers; 218 unsigned long long total_peers;
225 219
226 ok = 1; 220 ok = 1;
227 testing_cfg = GNUNET_CONFIGURATION_create(); 221 testing_cfg = GNUNET_CONFIGURATION_create ();
228 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(testing_cfg, cfgfile)); 222 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (testing_cfg, cfgfile));
229 223
230#if VERBOSE 224#if VERBOSE
231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); 225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
232 GNUNET_CONFIGURATION_set_value_string (testing_cfg, 226 GNUNET_CONFIGURATION_set_value_string (testing_cfg,
233 "testing", 227 "testing", "use_progressbars", "YES");
234 "use_progressbars",
235 "YES");
236#endif 228#endif
237 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 229 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
238 "testing", 230 "testing",
239 "num_peers", 231 "num_peers",
240 &total_peers)) 232 &total_peers))
241 total_peers = NUM_PEERS; 233 total_peers = NUM_PEERS;
242 234
243 peers_left = total_peers; 235 peers_left = total_peers;
244 num_peers = peers_left; 236 num_peers = peers_left;
245 pg = GNUNET_TESTING_peergroup_start(testing_cfg, 237 pg = GNUNET_TESTING_peergroup_start (testing_cfg,
246 peers_left, 238 peers_left,
247 TIMEOUT, 239 TIMEOUT,
248 &connect_cb, 240 &connect_cb, &my_cb, NULL, NULL);
249 &my_cb, NULL,
250 NULL);
251 GNUNET_assert (pg != NULL); 241 GNUNET_assert (pg != NULL);
252 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL); 242 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL);
253} 243}
@@ -268,8 +258,7 @@ check ()
268 GNUNET_GETOPT_OPTION_END 258 GNUNET_GETOPT_OPTION_END
269 }; 259 };
270 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 260 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
271 argv, "test-nse-multipeer", "nohelp", 261 argv, "test-nse-multipeer", "nohelp", options, &run, &ok);
272 options, &run, &ok);
273 return ok; 262 return ok;
274} 263}
275 264