summaryrefslogtreecommitdiff
path: root/src/secretsharing/test_secretsharing_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/secretsharing/test_secretsharing_api.c')
-rw-r--r--src/secretsharing/test_secretsharing_api.c68
1 files changed, 33 insertions, 35 deletions
diff --git a/src/secretsharing/test_secretsharing_api.c b/src/secretsharing/test_secretsharing_api.c
index a217bafcc..08533f703 100644
--- a/src/secretsharing/test_secretsharing_api.c
+++ b/src/secretsharing/test_secretsharing_api.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file secretsharing/test_secretsharing_api.c 22 * @file secretsharing/test_secretsharing_api.c
@@ -34,70 +34,68 @@ static struct GNUNET_SECRETSHARING_Session *keygen;
34 34
35 35
36static void 36static void
37secret_ready_cb (void *cls, 37secret_ready_cb(void *cls,
38 struct GNUNET_SECRETSHARING_Share *my_share, 38 struct GNUNET_SECRETSHARING_Share *my_share,
39 struct GNUNET_SECRETSHARING_PublicKey *public_key, 39 struct GNUNET_SECRETSHARING_PublicKey *public_key,
40 unsigned int num_ready_peers, 40 unsigned int num_ready_peers,
41 const struct GNUNET_PeerIdentity *ready_peers) 41 const struct GNUNET_PeerIdentity *ready_peers)
42{ 42{
43 keygen = NULL; 43 keygen = NULL;
44 if (num_ready_peers == 1) 44 if (num_ready_peers == 1)
45 success = 1; 45 success = 1;
46 // FIXME: check that our share is valid, which we can do as there's only 46 // FIXME: check that our share is valid, which we can do as there's only
47 // one peer. 47 // one peer.
48 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "secret ready, shutting down\n"); 48 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "secret ready, shutting down\n");
49 GNUNET_SCHEDULER_shutdown (); 49 GNUNET_SCHEDULER_shutdown();
50} 50}
51 51
52 52
53static void 53static void
54handle_shutdown (void *cls) 54handle_shutdown(void *cls)
55{ 55{
56 if (NULL != keygen) 56 if (NULL != keygen)
57 { 57 {
58 GNUNET_SECRETSHARING_session_destroy (keygen); 58 GNUNET_SECRETSHARING_session_destroy(keygen);
59 keygen = NULL; 59 keygen = NULL;
60 } 60 }
61} 61}
62 62
63 63
64static void 64static void
65run (void *cls, 65run(void *cls,
66 const struct GNUNET_CONFIGURATION_Handle *cfg, 66 const struct GNUNET_CONFIGURATION_Handle *cfg,
67 struct GNUNET_TESTING_Peer *peer) 67 struct GNUNET_TESTING_Peer *peer)
68{ 68{
69 struct GNUNET_HashCode session_id; 69 struct GNUNET_HashCode session_id;
70 struct GNUNET_TIME_Absolute start; 70 struct GNUNET_TIME_Absolute start;
71 struct GNUNET_TIME_Absolute deadline; 71 struct GNUNET_TIME_Absolute deadline;
72 72
73 GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL); 73 GNUNET_SCHEDULER_add_shutdown(&handle_shutdown, NULL);
74
75 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "testing secretsharing api\n");
76 74
77 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &session_id); 75 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "testing secretsharing api\n");
78 76
79 start = GNUNET_TIME_absolute_get (); 77 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &session_id);
80 deadline = GNUNET_TIME_absolute_add (start, GNUNET_TIME_UNIT_SECONDS);
81
82 keygen = GNUNET_SECRETSHARING_create_session (cfg,
83 0, NULL, /* only the local peer */
84 &session_id,
85 start, deadline,
86 1,
87 secret_ready_cb, NULL);
88 78
79 start = GNUNET_TIME_absolute_get();
80 deadline = GNUNET_TIME_absolute_add(start, GNUNET_TIME_UNIT_SECONDS);
89 81
82 keygen = GNUNET_SECRETSHARING_create_session(cfg,
83 0, NULL, /* only the local peer */
84 &session_id,
85 start, deadline,
86 1,
87 secret_ready_cb, NULL);
90} 88}
91 89
92 90
93int 91int
94main (int argc, char **argv) 92main(int argc, char **argv)
95{ 93{
96
97 int ret; 94 int ret;
98 ret = GNUNET_TESTING_peer_run ("test_secretsharing_api", 95
99 "test_secretsharing.conf", 96 ret = GNUNET_TESTING_peer_run("test_secretsharing_api",
100 &run, NULL); 97 "test_secretsharing.conf",
98 &run, NULL);
101 if (0 != ret) 99 if (0 != ret)
102 return ret; 100 return ret;
103 return (GNUNET_YES == success) ? 0 : 1; 101 return (GNUNET_YES == success) ? 0 : 1;