diff options
Diffstat (limited to 'src/consensus/test_consensus_api.c')
-rw-r--r-- | src/consensus/test_consensus_api.c | 77 |
1 files changed, 39 insertions, 38 deletions
diff --git a/src/consensus/test_consensus_api.c b/src/consensus/test_consensus_api.c index 46e582afe..a2ae36222 100644 --- a/src/consensus/test_consensus_api.c +++ b/src/consensus/test_consensus_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 consensus/test_consensus_api.c | 22 | * @file consensus/test_consensus_api.c |
@@ -36,30 +36,31 @@ static unsigned int elements_received; | |||
36 | 36 | ||
37 | 37 | ||
38 | static void | 38 | static void |
39 | conclude_done (void *cls) | 39 | conclude_done(void *cls) |
40 | { | 40 | { |
41 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "conclude over\n"); | 41 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "conclude over\n"); |
42 | if (2 != elements_received) | 42 | if (2 != elements_received) |
43 | GNUNET_assert (0); | 43 | GNUNET_assert(0); |
44 | GNUNET_SCHEDULER_shutdown (); | 44 | GNUNET_SCHEDULER_shutdown(); |
45 | } | 45 | } |
46 | 46 | ||
47 | static void | 47 | static void |
48 | on_new_element (void *cls, | 48 | on_new_element(void *cls, |
49 | const struct GNUNET_SET_Element *element) | 49 | const struct GNUNET_SET_Element *element) |
50 | { | 50 | { |
51 | elements_received++; | 51 | elements_received++; |
52 | } | 52 | } |
53 | 53 | ||
54 | static void | 54 | static void |
55 | insert_done (void *cls, int success) | 55 | insert_done(void *cls, int success) |
56 | { | 56 | { |
57 | /* make sure cb is only called once */ | 57 | /* make sure cb is only called once */ |
58 | static int called = GNUNET_NO; | 58 | static int called = GNUNET_NO; |
59 | GNUNET_assert (GNUNET_NO == called); | 59 | |
60 | GNUNET_assert(GNUNET_NO == called); | ||
60 | called = GNUNET_YES; | 61 | called = GNUNET_YES; |
61 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "insert done\n"); | 62 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "insert done\n"); |
62 | GNUNET_CONSENSUS_conclude (consensus, &conclude_done, NULL); | 63 | GNUNET_CONSENSUS_conclude(consensus, &conclude_done, NULL); |
63 | } | 64 | } |
64 | 65 | ||
65 | 66 | ||
@@ -69,47 +70,47 @@ insert_done (void *cls, int success) | |||
69 | * @param cls closure | 70 | * @param cls closure |
70 | */ | 71 | */ |
71 | static void | 72 | static void |
72 | on_shutdown (void *cls) | 73 | on_shutdown(void *cls) |
73 | { | 74 | { |
74 | if (NULL != consensus) | 75 | if (NULL != consensus) |
75 | { | 76 | { |
76 | GNUNET_CONSENSUS_destroy (consensus); | 77 | GNUNET_CONSENSUS_destroy(consensus); |
77 | consensus = NULL; | 78 | consensus = NULL; |
78 | } | 79 | } |
79 | } | 80 | } |
80 | 81 | ||
81 | 82 | ||
82 | static void | 83 | static void |
83 | run (void *cls, | 84 | run(void *cls, |
84 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 85 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
85 | struct GNUNET_TESTING_Peer *peer) | 86 | struct GNUNET_TESTING_Peer *peer) |
86 | { | 87 | { |
87 | char *str = "foo"; | 88 | char *str = "foo"; |
88 | 89 | ||
89 | struct GNUNET_SET_Element el1 = {4, 0, "foo"}; | 90 | struct GNUNET_SET_Element el1 = { 4, 0, "foo" }; |
90 | struct GNUNET_SET_Element el2 = {5, 0, "quux"}; | 91 | struct GNUNET_SET_Element el2 = { 5, 0, "quux" }; |
91 | 92 | ||
92 | GNUNET_log_setup ("test_consensus_api", | 93 | GNUNET_log_setup("test_consensus_api", |
93 | "INFO", | 94 | "INFO", |
94 | NULL); | 95 | NULL); |
95 | GNUNET_SCHEDULER_add_shutdown (&on_shutdown, NULL); | 96 | GNUNET_SCHEDULER_add_shutdown(&on_shutdown, NULL); |
96 | 97 | ||
97 | GNUNET_CRYPTO_hash (str, strlen (str), &session_id); | 98 | GNUNET_CRYPTO_hash(str, strlen(str), &session_id); |
98 | consensus = GNUNET_CONSENSUS_create (cfg, 0, NULL, &session_id, | 99 | consensus = GNUNET_CONSENSUS_create(cfg, 0, NULL, &session_id, |
99 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS), | 100 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_SECONDS), |
100 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES), | 101 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES), |
101 | on_new_element, &consensus); | 102 | on_new_element, &consensus); |
102 | GNUNET_assert (consensus != NULL); | 103 | GNUNET_assert(consensus != NULL); |
103 | 104 | ||
104 | GNUNET_CONSENSUS_insert (consensus, &el1, NULL, &consensus); | 105 | GNUNET_CONSENSUS_insert(consensus, &el1, NULL, &consensus); |
105 | GNUNET_CONSENSUS_insert (consensus, &el2, &insert_done, &consensus); | 106 | GNUNET_CONSENSUS_insert(consensus, &el2, &insert_done, &consensus); |
106 | } | 107 | } |
107 | 108 | ||
108 | 109 | ||
109 | int | 110 | int |
110 | main (int argc, char **argv) | 111 | main(int argc, char **argv) |
111 | { | 112 | { |
112 | return GNUNET_TESTING_peer_run ("test_consensus_api", | 113 | return GNUNET_TESTING_peer_run("test_consensus_api", |
113 | "test_consensus.conf", | 114 | "test_consensus.conf", |
114 | &run, NULL); | 115 | &run, NULL); |
115 | } | 116 | } |