diff options
author | xrs <xrs@mail36.net> | 2018-01-02 17:08:01 +0100 |
---|---|---|
committer | xrs <xrs@mail36.net> | 2018-01-02 17:08:01 +0100 |
commit | e513aaf8b7c039c59c4e04422e5ddb17dc1085dc (patch) | |
tree | 4e10d1cb1191f30960ffbe1f59fe1ee80f07cb0a /src/psyc | |
parent | f4f75ed70d46464bf613d87d71552770fab8b6bf (diff) | |
download | gnunet-e513aaf8b7c039c59c4e04422e5ddb17dc1085dc.tar.gz gnunet-e513aaf8b7c039c59c4e04422e5ddb17dc1085dc.zip |
add testbed test for psyc
Diffstat (limited to 'src/psyc')
-rw-r--r-- | src/psyc/Makefile.am | 12 | ||||
-rw-r--r-- | src/psyc/test_psyc2.c | 290 |
2 files changed, 300 insertions, 2 deletions
diff --git a/src/psyc/Makefile.am b/src/psyc/Makefile.am index a16128624..61618d176 100644 --- a/src/psyc/Makefile.am +++ b/src/psyc/Makefile.am | |||
@@ -33,7 +33,7 @@ libgnunetpsyc_la_LDFLAGS = \ | |||
33 | bin_PROGRAMS = | 33 | bin_PROGRAMS = |
34 | 34 | ||
35 | libexec_PROGRAMS = \ | 35 | libexec_PROGRAMS = \ |
36 | gnunet-service-psyc | 36 | gnunet-service-psyc |
37 | 37 | ||
38 | gnunet_service_psyc_SOURCES = \ | 38 | gnunet_service_psyc_SOURCES = \ |
39 | gnunet-service-psyc.c | 39 | gnunet-service-psyc.c |
@@ -49,7 +49,8 @@ gnunet_service_psyc_CFLAGS = $(AM_CFLAGS) | |||
49 | 49 | ||
50 | if HAVE_TESTING | 50 | if HAVE_TESTING |
51 | check_PROGRAMS = \ | 51 | check_PROGRAMS = \ |
52 | test_psyc | 52 | test_psyc2 |
53 | # test_psyc | ||
53 | endif | 54 | endif |
54 | 55 | ||
55 | if ENABLE_TEST_RUN | 56 | if ENABLE_TEST_RUN |
@@ -64,6 +65,13 @@ test_psyc_LDADD = \ | |||
64 | $(top_builddir)/src/psycutil/libgnunetpsycutil.la \ | 65 | $(top_builddir)/src/psycutil/libgnunetpsycutil.la \ |
65 | $(top_builddir)/src/testing/libgnunettesting.la \ | 66 | $(top_builddir)/src/testing/libgnunettesting.la \ |
66 | $(top_builddir)/src/util/libgnunetutil.la | 67 | $(top_builddir)/src/util/libgnunetutil.la |
68 | test_psyc2_SOURCES = \ | ||
69 | test_psyc2.c | ||
70 | test_psyc2_LDADD = \ | ||
71 | libgnunetpsyc.la \ | ||
72 | $(top_builddir)/src/psycutil/libgnunetpsycutil.la \ | ||
73 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | ||
74 | $(top_builddir)/src/util/libgnunetutil.la | ||
67 | 75 | ||
68 | EXTRA_DIST = \ | 76 | EXTRA_DIST = \ |
69 | test_psyc.conf | 77 | test_psyc.conf |
diff --git a/src/psyc/test_psyc2.c b/src/psyc/test_psyc2.c new file mode 100644 index 000000000..b8ed0132e --- /dev/null +++ b/src/psyc/test_psyc2.c | |||
@@ -0,0 +1,290 @@ | |||
1 | /* | ||
2 | * This file is part of GNUnet | ||
3 | * Copyright (C) 2013 GNUnet e.V. | ||
4 | * | ||
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. | ||
9 | * | ||
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. | ||
14 | * | ||
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. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file psyc/test_psyc2.c | ||
23 | * @brief Testbed test for the PSYC API. | ||
24 | * @author xrs | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
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" | ||
34 | |||
35 | #define PEERS_REQUESTED 2 | ||
36 | |||
37 | static int result; | ||
38 | |||
39 | static struct GNUNET_SCHEDULER_Task *timeout_tid; | ||
40 | static struct pctx **pctx; | ||
41 | |||
42 | static struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key; | ||
43 | static struct GNUNET_CRYPTO_EddsaPublicKey channel_pub_key; | ||
44 | |||
45 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_key; | ||
46 | static struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key; | ||
47 | |||
48 | /** | ||
49 | * Task To perform tests | ||
50 | */ | ||
51 | static struct GNUNET_SCHEDULER_Task *test_task; | ||
52 | |||
53 | /** | ||
54 | * Peer id couter | ||
55 | */ | ||
56 | static unsigned int pids; | ||
57 | |||
58 | struct pctx | ||
59 | { | ||
60 | int idx; | ||
61 | struct GNUNET_TESTBED_Peer *peer; | ||
62 | const struct GNUNET_PeerIdentity *id; | ||
63 | |||
64 | struct GNUNET_TESTBED_Operation *op; | ||
65 | |||
66 | /** | ||
67 | * psyc service handle | ||
68 | */ | ||
69 | void *psyc; | ||
70 | struct GNUNET_PSYC_Master *mst; | ||
71 | struct GNUNET_PSYC_Slave *slv; | ||
72 | |||
73 | /** | ||
74 | * result for test on peer | ||
75 | */ | ||
76 | int test_ok; | ||
77 | }; | ||
78 | |||
79 | static void | ||
80 | shutdown_task (void *cls) | ||
81 | { | ||
82 | if (NULL != pctx) | ||
83 | { | ||
84 | if (NULL != pctx[0]->mst) | ||
85 | GNUNET_PSYC_master_stop (pctx[0]->mst, GNUNET_NO, NULL, NULL); | ||
86 | |||
87 | for (int i=0; i < PEERS_REQUESTED; i++) | ||
88 | { | ||
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]); | ||
92 | } | ||
93 | GNUNET_free (pctx); | ||
94 | } | ||
95 | |||
96 | if (NULL != timeout_tid) | ||
97 | GNUNET_SCHEDULER_cancel (timeout_tid); | ||
98 | } | ||
99 | |||
100 | static void | ||
101 | timeout_task (void *cls) | ||
102 | { | ||
103 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout!\n"); | ||
104 | result = GNUNET_SYSERR; | ||
105 | GNUNET_SCHEDULER_shutdown (); | ||
106 | } | ||
107 | |||
108 | static void | ||
109 | start_test (void *cls) | ||
110 | { | ||
111 | } | ||
112 | |||
113 | static void | ||
114 | pinfo_cb (void *cls, | ||
115 | struct GNUNET_TESTBED_Operation *operation, | ||
116 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
117 | const char *emsg) | ||
118 | { | ||
119 | struct pctx *pc = (struct pctx*) cls; | ||
120 | |||
121 | pc->id = pinfo->result.id; | ||
122 | |||
123 | pids++; | ||
124 | if (pids < (PEERS_REQUESTED - 1)) | ||
125 | return; | ||
126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got all IDs, starting test\n"); | ||
127 | test_task = GNUNET_SCHEDULER_add_now (&start_test, NULL); | ||
128 | } | ||
129 | |||
130 | static void | ||
131 | mst_start_cb () | ||
132 | { | ||
133 | } | ||
134 | |||
135 | static void | ||
136 | join_request_cb () | ||
137 | { | ||
138 | } | ||
139 | |||
140 | static void | ||
141 | mst_message_cb () | ||
142 | { | ||
143 | } | ||
144 | |||
145 | static void | ||
146 | mst_message_part_cb () | ||
147 | { | ||
148 | } | ||
149 | |||
150 | static void | ||
151 | slv_message_cb () | ||
152 | { | ||
153 | } | ||
154 | |||
155 | static void | ||
156 | slv_message_part_cb () | ||
157 | { | ||
158 | } | ||
159 | |||
160 | static void | ||
161 | slv_connect_cb () | ||
162 | { | ||
163 | } | ||
164 | |||
165 | static void | ||
166 | join_decision_cb () | ||
167 | { | ||
168 | } | ||
169 | |||
170 | static void * | ||
171 | psyc_ca (void *cls, | ||
172 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
173 | { | ||
174 | struct GNUNET_PSYC_Message *join_msg = NULL; | ||
175 | struct pctx *pc = (struct pctx *) cls; | ||
176 | |||
177 | if (0 == pc->idx) | ||
178 | { | ||
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, | ||
183 | NULL); | ||
184 | return pc->mst; | ||
185 | } | ||
186 | |||
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, | ||
192 | NULL, join_msg); | ||
193 | return pc->slv; | ||
194 | } | ||
195 | |||
196 | static void | ||
197 | psyc_da (void *cls, | ||
198 | void *op_result) | ||
199 | { | ||
200 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Disconnected from service.\n"); | ||
201 | } | ||
202 | |||
203 | static void | ||
204 | service_connect (void *cls, | ||
205 | struct GNUNET_TESTBED_Operation *op, | ||
206 | void *ca_result, | ||
207 | const char *emsg) | ||
208 | { | ||
209 | struct pctx *pc = (struct pctx *) cls; | ||
210 | |||
211 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
212 | "Connected to service\n"); | ||
213 | |||
214 | if (NULL == ca_result) | ||
215 | { | ||
216 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
217 | "Connection adapter not created"); | ||
218 | result = GNUNET_SYSERR; | ||
219 | GNUNET_SCHEDULER_shutdown(); | ||
220 | } | ||
221 | |||
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; | ||
225 | |||
226 | GNUNET_TESTBED_peer_get_information (pc->peer, | ||
227 | GNUNET_TESTBED_PIT_IDENTITY, | ||
228 | pinfo_cb, pc); | ||
229 | } | ||
230 | |||
231 | static void | ||
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) | ||
238 | { | ||
239 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to testbed_master()\n"); | ||
240 | |||
241 | // Create ctx for peers | ||
242 | pctx = GNUNET_new_array (PEERS_REQUESTED, struct pctx*); | ||
243 | for (int i = 0; i<PEERS_REQUESTED; i++) | ||
244 | { | ||
245 | pctx[i] = GNUNET_new (struct pctx); | ||
246 | pctx[i]->idx = i; | ||
247 | pctx[i]->peer = p[i]; | ||
248 | pctx[i]->id = NULL; | ||
249 | pctx[i]->mst = NULL; | ||
250 | pctx[i]->op = NULL; | ||
251 | pctx[i]->test_ok = GNUNET_NO; | ||
252 | } | ||
253 | |||
254 | channel_key = GNUNET_CRYPTO_eddsa_key_create (); | ||
255 | slave_key = GNUNET_CRYPTO_ecdsa_key_create (); | ||
256 | |||
257 | GNUNET_CRYPTO_eddsa_key_get_public (channel_key, &channel_pub_key); | ||
258 | GNUNET_CRYPTO_ecdsa_key_get_public (slave_key, &slave_pub_key); | ||
259 | |||
260 | pctx[0]->op = | ||
261 | GNUNET_TESTBED_service_connect (NULL, p[0], "psyc", service_connect, | ||
262 | pctx[0], psyc_ca, psyc_da, pctx[0]); | ||
263 | |||
264 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | ||
265 | |||
266 | timeout_tid = | ||
267 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), | ||
268 | &timeout_task, NULL); | ||
269 | } | ||
270 | |||
271 | int | ||
272 | main (int argc, char *argv[]) | ||
273 | { | ||
274 | int ret; | ||
275 | |||
276 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test\n"); | ||
277 | |||
278 | result = GNUNET_SYSERR; | ||
279 | |||
280 | ret = GNUNET_TESTBED_test_run ("test-psyc2", "test_psyc.conf", | ||
281 | PEERS_REQUESTED, 0LL, NULL, NULL, | ||
282 | testbed_master, NULL); | ||
283 | |||
284 | if ((GNUNET_OK != ret) || (GNUNET_OK != result)) | ||
285 | return 1; | ||
286 | |||
287 | return 0; | ||
288 | } | ||
289 | |||
290 | /* end of test-psyc2.c */ | ||