aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_cmd_start_peer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport_api_cmd_start_peer.c')
-rw-r--r--src/transport/transport_api_cmd_start_peer.c101
1 files changed, 47 insertions, 54 deletions
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
index f4e92944b..dc19f10eb 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -65,7 +65,7 @@ hello_iter_cb (void *cb_cls,
65 65
66 GNUNET_PEERSTORE_iterate_cancel (sps->pic); 66 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
67 sps->pic = NULL; 67 sps->pic = NULL;
68 sps->finished = GNUNET_YES; 68 GNUNET_TESTING_async_finish (&sps->ac);
69} 69}
70 70
71 71
@@ -90,26 +90,6 @@ retrieve_hello (void *cls)
90 90
91 91
92/** 92/**
93 * This function checks StartPeerState#finished, which is set when the hello was retrieved.
94 *
95 */
96static int
97start_peer_finish (void *cls,
98 GNUNET_SCHEDULER_TaskCallback cont,
99 void *cont_cls)
100{
101 struct StartPeerState *sps = cls;
102
103 if (GNUNET_YES == sps->finished)
104 {
105 cont (cont_cls);
106 }
107
108 return sps->finished;
109}
110
111
112/**
113 * Disconnect callback for the connection to the core service. 93 * Disconnect callback for the connection to the core service.
114 * 94 *
115 */ 95 */
@@ -141,7 +121,7 @@ notify_connect (void *cls,
141 struct StartPeerState *sps = cls; 121 struct StartPeerState *sps = cls;
142 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); 122 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
143 struct GNUNET_HashCode hc; 123 struct GNUNET_HashCode hc;
144 int node_number; 124 struct GNUNET_CRYPTO_EddsaPublicKey public_key = peer->public_key;
145 125
146 void *ret = NULL; 126 void *ret = NULL;
147 127
@@ -152,9 +132,7 @@ notify_connect (void *cls,
152 sps->no, 132 sps->no,
153 GNUNET_i2s (&sps->id)); 133 GNUNET_i2s (&sps->id));
154 134
155 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node. 135 GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc);
156 node_number = 1;
157 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
158 136
159 137
160 memcpy (key, 138 memcpy (key,
@@ -166,6 +144,11 @@ notify_connect (void *cls,
166 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 144 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
167 145
168 GNUNET_free (key); 146 GNUNET_free (key);
147
148 sps->notify_connect (cls,
149 peer,
150 mq);
151
169 // TODO what does the handler function need? 152 // TODO what does the handler function need?
170 return ret; 153 return ret;
171} 154}
@@ -177,7 +160,6 @@ notify_connect (void *cls,
177 */ 160 */
178static void 161static void
179start_peer_run (void *cls, 162start_peer_run (void *cls,
180 const struct GNUNET_TESTING_Command *cmd,
181 struct GNUNET_TESTING_Interpreter *is) 163 struct GNUNET_TESTING_Interpreter *is)
182{ 164{
183 struct StartPeerState *sps = cls; 165 struct StartPeerState *sps = cls;
@@ -187,7 +169,8 @@ start_peer_run (void *cls,
187 struct GNUNET_TESTING_System *tl_system; 169 struct GNUNET_TESTING_System *tl_system;
188 char *home; 170 char *home;
189 char *transport_unix_path; 171 char *transport_unix_path;
190 char *communicator_unix_path; 172 char *tcp_communicator_unix_path;
173 char *udp_communicator_unix_path;
191 char *bindto; 174 char *bindto;
192 175
193 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname)) 176 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
@@ -195,7 +178,7 @@ start_peer_run (void *cls,
195 LOG (GNUNET_ERROR_TYPE_ERROR, 178 LOG (GNUNET_ERROR_TYPE_ERROR,
196 "File not found: `%s'\n", 179 "File not found: `%s'\n",
197 sps->cfgname); 180 sps->cfgname);
198 GNUNET_TESTING_interpreter_fail (); 181 GNUNET_TESTING_interpreter_fail (is);
199 return; 182 return;
200 } 183 }
201 184
@@ -212,7 +195,11 @@ start_peer_run (void *cls,
212 "$GNUNET_RUNTIME_DIR/tng-p%u.sock", 195 "$GNUNET_RUNTIME_DIR/tng-p%u.sock",
213 sps->no); 196 sps->no);
214 197
215 GNUNET_asprintf (&communicator_unix_path, 198 GNUNET_asprintf (&tcp_communicator_unix_path,
199 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
200 sps->no);
201
202 GNUNET_asprintf (&udp_communicator_unix_path,
216 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock", 203 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
217 sps->no); 204 sps->no);
218 205
@@ -220,6 +207,9 @@ start_peer_run (void *cls,
220 "%s:60002", 207 "%s:60002",
221 sps->node_ip); 208 sps->node_ip);
222 209
210 LOG (GNUNET_ERROR_TYPE_ERROR,
211 "node_ip %s\n",
212 bindto);
223 213
224 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME", 214 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
225 home); 215 home);
@@ -228,11 +218,18 @@ start_peer_run (void *cls,
228 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", 218 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
229 "BINDTO", 219 "BINDTO",
230 bindto); 220 bindto);
221 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
222 "BINDTO",
223 bindto);
231 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", 224 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
232 "UNIXPATH", 225 "UNIXPATH",
233 communicator_unix_path); 226 tcp_communicator_unix_path);
227 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
228 "UNIXPATH",
229 udp_communicator_unix_path);
234 230
235 system_cmd = GNUNET_TESTING_interpreter_lookup_command (sps->system_label); 231 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
232 sps->system_label);
236 GNUNET_TESTING_get_trait_test_system (system_cmd, 233 GNUNET_TESTING_get_trait_test_system (system_cmd,
237 &tl_system); 234 &tl_system);
238 235
@@ -246,7 +243,7 @@ start_peer_run (void *cls,
246 "Testing library failed to create unique configuration based on `%s'\n", 243 "Testing library failed to create unique configuration based on `%s'\n",
247 sps->cfgname); 244 sps->cfgname);
248 GNUNET_CONFIGURATION_destroy (sps->cfg); 245 GNUNET_CONFIGURATION_destroy (sps->cfg);
249 GNUNET_TESTING_interpreter_fail (); 246 GNUNET_TESTING_interpreter_fail (is);
250 return; 247 return;
251 } 248 }
252 249
@@ -262,7 +259,7 @@ start_peer_run (void *cls,
262 sps->cfgname, 259 sps->cfgname,
263 emsg); 260 emsg);
264 GNUNET_free (emsg); 261 GNUNET_free (emsg);
265 GNUNET_TESTING_interpreter_fail (); 262 GNUNET_TESTING_interpreter_fail (is);
266 return; 263 return;
267 } 264 }
268 265
@@ -272,7 +269,7 @@ start_peer_run (void *cls,
272 "Testing library failed to create unique configuration based on `%s'\n", 269 "Testing library failed to create unique configuration based on `%s'\n",
273 sps->cfgname); 270 sps->cfgname);
274 GNUNET_free (emsg); 271 GNUNET_free (emsg);
275 GNUNET_TESTING_interpreter_fail (); 272 GNUNET_TESTING_interpreter_fail (is);
276 return; 273 return;
277 } 274 }
278 275
@@ -291,7 +288,7 @@ start_peer_run (void *cls,
291 "Testing library failed to obtain peer identity for peer %u\n", 288 "Testing library failed to obtain peer identity for peer %u\n",
292 sps->no); 289 sps->no);
293 GNUNET_free (emsg); 290 GNUNET_free (emsg);
294 GNUNET_TESTING_interpreter_fail (); 291 GNUNET_TESTING_interpreter_fail (is);
295 return; 292 return;
296 } 293 }
297 LOG (GNUNET_ERROR_TYPE_DEBUG, 294 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -312,7 +309,7 @@ start_peer_run (void *cls,
312 sps->cfgname, 309 sps->cfgname,
313 emsg); 310 emsg);
314 GNUNET_free (emsg); 311 GNUNET_free (emsg);
315 GNUNET_TESTING_interpreter_fail (); 312 GNUNET_TESTING_interpreter_fail (is);
316 return; 313 return;
317 } 314 }
318 315
@@ -324,7 +321,7 @@ start_peer_run (void *cls,
324 sps->cfgname, 321 sps->cfgname,
325 emsg); 322 emsg);
326 GNUNET_free (emsg); 323 GNUNET_free (emsg);
327 GNUNET_TESTING_interpreter_fail (); 324 GNUNET_TESTING_interpreter_fail (is);
328 return; 325 return;
329 } 326 }
330 327
@@ -336,7 +333,7 @@ start_peer_run (void *cls,
336 sps->cfgname, 333 sps->cfgname,
337 emsg); 334 emsg);
338 GNUNET_free (emsg); 335 GNUNET_free (emsg);
339 GNUNET_TESTING_interpreter_fail (); 336 GNUNET_TESTING_interpreter_fail (is);
340 return; 337 return;
341 } 338 }
342 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); 339 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
@@ -348,8 +345,7 @@ start_peer_run (void *cls,
348 * 345 *
349 */ 346 */
350static void 347static void
351start_peer_cleanup (void *cls, 348start_peer_cleanup (void *cls)
352 const struct GNUNET_TESTING_Command *cmd)
353{ 349{
354 struct StartPeerState *sps = cls; 350 struct StartPeerState *sps = cls;
355 351
@@ -437,10 +433,9 @@ start_peer_traits (void *cls,
437 * 433 *
438 */ 434 */
439int 435int
440GNUNET_TRANSPORT_get_trait_state (const struct 436GNUNET_TRANSPORT_get_trait_state (
441 GNUNET_TESTING_Command 437 const struct GNUNET_TESTING_Command *cmd,
442 *cmd, 438 struct StartPeerState **sps)
443 struct StartPeerState **sps)
444{ 439{
445 return cmd->traits (cmd->cls, 440 return cmd->traits (cmd->cls,
446 (const void **) sps, 441 (const void **) sps,
@@ -501,7 +496,8 @@ GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
501 GNUNET_TESTING_Command 496 GNUNET_TESTING_Command
502 *cmd, 497 *cmd,
503 struct 498 struct
504 GNUNET_CONTAINER_MultiShortmap * 499 GNUNET_CONTAINER_MultiShortmap
500 *
505 * 501 *
506 connected_peers_map) 502 connected_peers_map)
507{ 503{
@@ -565,12 +561,11 @@ GNUNET_TRANSPORT_get_trait_peer_id (const struct
565struct GNUNET_TESTING_Command 561struct GNUNET_TESTING_Command
566GNUNET_TRANSPORT_cmd_start_peer (const char *label, 562GNUNET_TRANSPORT_cmd_start_peer (const char *label,
567 const char *system_label, 563 const char *system_label,
568 char *m, 564 uint32_t no,
569 char *n,
570 char *local_m,
571 char *node_ip, 565 char *node_ip,
572 struct GNUNET_MQ_MessageHandler *handlers, 566 struct GNUNET_MQ_MessageHandler *handlers,
573 const char *cfgname) 567 const char *cfgname,
568 GNUNET_TRANSPORT_NotifyConnect notify_connect)
574{ 569{
575 struct StartPeerState *sps; 570 struct StartPeerState *sps;
576 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map = 571 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
@@ -578,14 +573,12 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
578 unsigned int i; 573 unsigned int i;
579 574
580 sps = GNUNET_new (struct StartPeerState); 575 sps = GNUNET_new (struct StartPeerState);
581 sps->m = m; 576 sps->no = no;
582 sps->n = n;
583 sps->local_m = local_m;
584 sps->no = (atoi (n) - 1) * atoi (sps->local_m) + atoi (m);
585 sps->system_label = system_label; 577 sps->system_label = system_label;
586 sps->connected_peers_map = connected_peers_map; 578 sps->connected_peers_map = connected_peers_map;
587 sps->cfgname = cfgname; 579 sps->cfgname = cfgname;
588 sps->node_ip = node_ip; 580 sps->node_ip = node_ip;
581 sps->notify_connect = notify_connect;
589 582
590 if (NULL != handlers) 583 if (NULL != handlers)
591 { 584 {
@@ -602,7 +595,7 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
602 .cls = sps, 595 .cls = sps,
603 .label = label, 596 .label = label,
604 .run = &start_peer_run, 597 .run = &start_peer_run,
605 .finish = &start_peer_finish, 598 .ac = &sps->ac,
606 .cleanup = &start_peer_cleanup, 599 .cleanup = &start_peer_cleanup,
607 .traits = &start_peer_traits 600 .traits = &start_peer_traits
608 }; 601 };