diff options
author | Florian Dold <florian.dold@gmail.com> | 2014-02-17 15:54:59 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2014-02-17 15:54:59 +0000 |
commit | 1d6824b116658d2490aaa1a5d1662e3857e86d3f (patch) | |
tree | 261c8c08828cb21a09a8158f389bf3d802757f2d /src/secretsharing/test_secretsharing_api.c | |
parent | d559d7f1d52159cc757336e1890f0ad804a08f3f (diff) | |
download | gnunet-1d6824b116658d2490aaa1a5d1662e3857e86d3f.tar.gz gnunet-1d6824b116658d2490aaa1a5d1662e3857e86d3f.zip |
- secretsharing api test for single peer
- fixed wrong endianess conversion
Diffstat (limited to 'src/secretsharing/test_secretsharing_api.c')
-rw-r--r-- | src/secretsharing/test_secretsharing_api.c | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/src/secretsharing/test_secretsharing_api.c b/src/secretsharing/test_secretsharing_api.c index a6f3cb127..d131805e7 100644 --- a/src/secretsharing/test_secretsharing_api.c +++ b/src/secretsharing/test_secretsharing_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -24,10 +24,80 @@ | |||
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_util_lib.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 secret_ready_cb (void *cls, | ||
37 | struct GNUNET_SECRETSHARING_Share *my_share, | ||
38 | struct GNUNET_SECRETSHARING_PublicKey *public_key, | ||
39 | unsigned int num_ready_peers, | ||
40 | struct GNUNET_PeerIdentity *ready_peers) | ||
41 | { | ||
42 | keygen = NULL; | ||
43 | if (num_ready_peers == 1) | ||
44 | success = 1; | ||
45 | // FIXME: check that our share is valid, which we can do as there's only | ||
46 | // one peer. | ||
47 | GNUNET_SCHEDULER_shutdown (); | ||
48 | } | ||
49 | |||
50 | static void | ||
51 | handle_shutdown (void *cls, | ||
52 | const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
53 | { | ||
54 | if (NULL != keygen) | ||
55 | { | ||
56 | GNUNET_SECRETSHARING_session_destroy (keygen); | ||
57 | keygen = NULL; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | static void | ||
62 | run (void *cls, | ||
63 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
64 | struct GNUNET_TESTING_Peer *peer) | ||
65 | { | ||
66 | struct GNUNET_HashCode session_id; | ||
67 | struct GNUNET_TIME_Absolute start; | ||
68 | struct GNUNET_TIME_Absolute deadline; | ||
69 | |||
70 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
71 | handle_shutdown, NULL); | ||
72 | |||
73 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "testing secretsharing api\n"); | ||
74 | |||
75 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &session_id); | ||
76 | |||
77 | start = GNUNET_TIME_absolute_get (); | ||
78 | deadline = GNUNET_TIME_absolute_add (start, GNUNET_TIME_UNIT_SECONDS); | ||
79 | |||
80 | keygen = GNUNET_SECRETSHARING_create_session (cfg, | ||
81 | 0, NULL, /* only the local peer */ | ||
82 | &session_id, | ||
83 | start, deadline, | ||
84 | 1, | ||
85 | secret_ready_cb, NULL); | ||
86 | |||
87 | |||
88 | } | ||
89 | |||
27 | 90 | ||
28 | int | 91 | int |
29 | main (int argc, char **argv) | 92 | main (int argc, char **argv) |
30 | { | 93 | { |
31 | return 0; | 94 | |
95 | int ret; | ||
96 | ret = GNUNET_TESTING_peer_run ("test_secretsharing_api", | ||
97 | "test_secretsharing.conf", | ||
98 | &run, NULL); | ||
99 | if (0 != ret) | ||
100 | return ret; | ||
101 | return (GNUNET_YES == success) ? 0 : 1; | ||
32 | } | 102 | } |
33 | 103 | ||