diff options
Diffstat (limited to 'src/contrib/service/secretsharing/test_secretsharing_api.c')
-rw-r--r-- | src/contrib/service/secretsharing/test_secretsharing_api.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/contrib/service/secretsharing/test_secretsharing_api.c b/src/contrib/service/secretsharing/test_secretsharing_api.c new file mode 100644 index 000000000..470bfddf4 --- /dev/null +++ b/src/contrib/service/secretsharing/test_secretsharing_api.c | |||
@@ -0,0 +1,103 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2014 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your 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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file secretsharing/test_secretsharing_api.c | ||
23 | * @brief testcase for the secretsharing api | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | #include "gnunet_testing_lib.h" | ||
28 | #include "gnunet_secretsharing_service.h" | ||
29 | |||
30 | |||
31 | static int success; | ||
32 | |||
33 | static struct GNUNET_SECRETSHARING_Session *keygen; | ||
34 | |||
35 | |||
36 | static void | ||
37 | secret_ready_cb (void *cls, | ||
38 | struct GNUNET_SECRETSHARING_Share *my_share, | ||
39 | struct GNUNET_SECRETSHARING_PublicKey *public_key, | ||
40 | unsigned int num_ready_peers, | ||
41 | const struct GNUNET_PeerIdentity *ready_peers) | ||
42 | { | ||
43 | keygen = NULL; | ||
44 | if (num_ready_peers == 1) | ||
45 | success = 1; | ||
46 | // FIXME: check that our share is valid, which we can do as there's only | ||
47 | // one peer. | ||
48 | GNUNET_SECRETSHARING_share_destroy (my_share); | ||
49 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "secret ready, shutting down\n"); | ||
50 | GNUNET_SCHEDULER_shutdown (); | ||
51 | } | ||
52 | |||
53 | |||
54 | static void | ||
55 | handle_shutdown (void *cls) | ||
56 | { | ||
57 | if (NULL != keygen) | ||
58 | { | ||
59 | GNUNET_SECRETSHARING_session_destroy (keygen); | ||
60 | keygen = NULL; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | |||
65 | static void | ||
66 | run (void *cls, | ||
67 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
68 | struct GNUNET_TESTING_Peer *peer) | ||
69 | { | ||
70 | struct GNUNET_HashCode session_id; | ||
71 | struct GNUNET_TIME_Absolute start; | ||
72 | struct GNUNET_TIME_Absolute deadline; | ||
73 | |||
74 | GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL); | ||
75 | |||
76 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "testing secretsharing api\n"); | ||
77 | |||
78 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &session_id); | ||
79 | |||
80 | start = GNUNET_TIME_absolute_get (); | ||
81 | deadline = GNUNET_TIME_absolute_add (start, GNUNET_TIME_UNIT_SECONDS); | ||
82 | |||
83 | keygen = GNUNET_SECRETSHARING_create_session (cfg, | ||
84 | 0, NULL, /* only the local peer */ | ||
85 | &session_id, | ||
86 | start, deadline, | ||
87 | 1, | ||
88 | secret_ready_cb, NULL); | ||
89 | } | ||
90 | |||
91 | |||
92 | int | ||
93 | main (int argc, char **argv) | ||
94 | { | ||
95 | int ret; | ||
96 | |||
97 | ret = GNUNET_TESTING_peer_run ("test_secretsharing_api", | ||
98 | "test_secretsharing.conf", | ||
99 | &run, NULL); | ||
100 | if (0 != ret) | ||
101 | return ret; | ||
102 | return (GNUNET_YES == success) ? 0 : 1; | ||
103 | } | ||