2 * This file is part of GNUnet
3 * Copyright (C) 2013 GNUnet e.V.
5 * GNUnet is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 3, or (at your
8 * option) any later version.
10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNUnet; see the file COPYING. If not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 * @file psyc/test_psyc2.c
23 * @brief Testbed test for the PSYC API.
28 #include "gnunet_crypto_lib.h"
29 #include "gnunet_common.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_testbed_service.h"
32 #include "gnunet_psyc_util_lib.h"
33 #include "gnunet_psyc_service.h"
35 #define PEERS_REQUESTED 2
39 static struct GNUNET_SCHEDULER_Task *timeout_tid;
40 static struct pctx **pctx;
42 static struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key;
43 static struct GNUNET_CRYPTO_EddsaPublicKey channel_pub_key;
45 static struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_key;
46 static struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key;
49 * Task To perform tests
51 static struct GNUNET_SCHEDULER_Task *test_task;
56 static unsigned int pids;
61 struct GNUNET_TESTBED_Peer *peer;
62 const struct GNUNET_PeerIdentity *id;
64 struct GNUNET_TESTBED_Operation *op;
70 struct GNUNET_PSYC_Master *mst;
71 struct GNUNET_PSYC_Slave *slv;
74 * result for test on peer
80 shutdown_task (void *cls)
84 if (NULL != pctx[0]->mst)
85 GNUNET_PSYC_master_stop (pctx[0]->mst, GNUNET_NO, NULL, NULL);
87 for (int i=0; i < PEERS_REQUESTED; i++)
89 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Operation done.\n");
90 GNUNET_TESTBED_operation_done (pctx[i]->op);
91 GNUNET_free_non_null (pctx[i]);
96 if (NULL != timeout_tid)
97 GNUNET_SCHEDULER_cancel (timeout_tid);
101 timeout_task (void *cls)
103 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout!\n");
104 result = GNUNET_SYSERR;
105 GNUNET_SCHEDULER_shutdown ();
109 start_test (void *cls)
115 struct GNUNET_TESTBED_Operation *operation,
116 const struct GNUNET_TESTBED_PeerInformation *pinfo,
119 struct pctx *pc = (struct pctx*) cls;
121 pc->id = pinfo->result.id;
124 if (pids < (PEERS_REQUESTED - 1))
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got all IDs, starting test\n");
127 test_task = GNUNET_SCHEDULER_add_now (&start_test, NULL);
146 mst_message_part_cb ()
156 slv_message_part_cb ()
172 const struct GNUNET_CONFIGURATION_Handle *cfg)
174 struct GNUNET_PSYC_Message *join_msg = NULL;
175 struct pctx *pc = (struct pctx *) cls;
179 pc->mst = GNUNET_PSYC_master_start (cfg, channel_key,
180 GNUNET_PSYC_CHANNEL_PRIVATE,
181 &mst_start_cb, &join_request_cb,
182 &mst_message_cb, &mst_message_part_cb,
187 pc->slv = GNUNET_PSYC_slave_join (cfg, &channel_pub_key, slave_key,
188 GNUNET_PSYC_SLAVE_JOIN_NONE,
189 &pid, 0, NULL, &slv_message_cb,
190 &slv_message_part_cb,
191 &slv_connect_cb, &join_decision_cb,
200 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Disconnected from service.\n");
204 service_connect (void *cls,
205 struct GNUNET_TESTBED_Operation *op,
209 struct pctx *pc = (struct pctx *) cls;
211 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
212 "Connected to service\n");
214 if (NULL == ca_result)
216 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
217 "Connection adapter not created");
218 result = GNUNET_SYSERR;
219 GNUNET_SCHEDULER_shutdown();
222 // FIXME: we need a simple service handle to connect to the service, then
223 // get peer information and AFTER that make PSYC ops. Compare to CADET.
224 pc->psyc = ca_result;
226 GNUNET_TESTBED_peer_get_information (pc->peer,
227 GNUNET_TESTBED_PIT_IDENTITY,
232 testbed_master (void *cls,
233 struct GNUNET_TESTBED_RunHandle *h,
234 unsigned int num_peers,
235 struct GNUNET_TESTBED_Peer **p,
236 unsigned int links_succeeded,
237 unsigned int links_failed)
239 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to testbed_master()\n");
241 // Create ctx for peers
242 pctx = GNUNET_new_array (PEERS_REQUESTED, struct pctx*);
243 for (int i = 0; i<PEERS_REQUESTED; i++)
245 pctx[i] = GNUNET_new (struct pctx);
247 pctx[i]->peer = p[i];
251 pctx[i]->test_ok = GNUNET_NO;
254 channel_key = GNUNET_CRYPTO_eddsa_key_create ();
255 slave_key = GNUNET_CRYPTO_ecdsa_key_create ();
257 GNUNET_CRYPTO_eddsa_key_get_public (channel_key, &channel_pub_key);
258 GNUNET_CRYPTO_ecdsa_key_get_public (slave_key, &slave_pub_key);
261 GNUNET_TESTBED_service_connect (NULL, p[0], "psyc", service_connect,
262 pctx[0], psyc_ca, psyc_da, pctx[0]);
264 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
267 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
268 &timeout_task, NULL);
272 main (int argc, char *argv[])
276 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test\n");
278 result = GNUNET_SYSERR;
280 ret = GNUNET_TESTBED_test_run ("test-psyc2", "test_psyc.conf",
281 PEERS_REQUESTED, 0LL, NULL, NULL,
282 testbed_master, NULL);
284 if ((GNUNET_OK != ret) || (GNUNET_OK != result))
290 /* end of test-psyc2.c */