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 GNUNET_assert (NULL != ca_result);
216 // FIXME: we need a simple service handle to connect to the service, then
217 // get peer information and AFTER that make PSYC ops. Compare to CADET.
218 pc->psyc = ca_result;
220 GNUNET_TESTBED_peer_get_information (pc->peer,
221 GNUNET_TESTBED_PIT_IDENTITY,
226 testbed_master (void *cls,
227 struct GNUNET_TESTBED_RunHandle *h,
228 unsigned int num_peers,
229 struct GNUNET_TESTBED_Peer **p,
230 unsigned int links_succeeded,
231 unsigned int links_failed)
233 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to testbed_master()\n");
235 // Create ctx for peers
236 pctx = GNUNET_new_array (PEERS_REQUESTED, struct pctx*);
237 for (int i = 0; i<PEERS_REQUESTED; i++)
239 pctx[i] = GNUNET_new (struct pctx);
241 pctx[i]->peer = p[i];
245 pctx[i]->test_ok = GNUNET_NO;
248 channel_key = GNUNET_CRYPTO_eddsa_key_create ();
249 slave_key = GNUNET_CRYPTO_ecdsa_key_create ();
251 GNUNET_CRYPTO_eddsa_key_get_public (channel_key, &channel_pub_key);
252 GNUNET_CRYPTO_ecdsa_key_get_public (slave_key, &slave_pub_key);
255 GNUNET_TESTBED_service_connect (NULL, p[0], "psyc", service_connect,
256 pctx[0], psyc_ca, psyc_da, pctx[0]);
258 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
261 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
262 &timeout_task, NULL);
266 main (int argc, char *argv[])
270 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test\n");
272 result = GNUNET_SYSERR;
274 ret = GNUNET_TESTBED_test_run ("test-psyc2", "test_psyc.conf",
275 PEERS_REQUESTED, 0LL, NULL, NULL,
276 testbed_master, NULL);
278 if ((GNUNET_OK != ret) || (GNUNET_OK != result))
284 /* end of test-psyc2.c */