diff options
Diffstat (limited to 'src/consensus/test_consensus_api.c')
-rw-r--r-- | src/consensus/test_consensus_api.c | 62 |
1 files changed, 51 insertions, 11 deletions
diff --git a/src/consensus/test_consensus_api.c b/src/consensus/test_consensus_api.c index a6bd60119..53f04c8b1 100644 --- a/src/consensus/test_consensus_api.c +++ b/src/consensus/test_consensus_api.c | |||
@@ -27,18 +27,50 @@ | |||
27 | #include "gnunet_testing_lib-new.h" | 27 | #include "gnunet_testing_lib-new.h" |
28 | 28 | ||
29 | 29 | ||
30 | static struct GNUNET_CONSENSUS_Handle *consensus; | 30 | static struct GNUNET_CONSENSUS_Handle *consensus1; |
31 | static struct GNUNET_CONSENSUS_Handle *consensus2; | ||
32 | |||
33 | static int concluded1; | ||
34 | static int concluded2; | ||
35 | |||
36 | static int insert1; | ||
37 | static int insert2; | ||
31 | 38 | ||
32 | static struct GNUNET_HashCode session_id; | 39 | static struct GNUNET_HashCode session_id; |
33 | 40 | ||
34 | 41 | ||
35 | void | 42 | static void conclude_done (void *cls, |
43 | unsigned int num_peers_in_consensus, | ||
44 | const struct GNUNET_PeerIdentity *peers_in_consensus) | ||
45 | { | ||
46 | struct GNUNET_CONSENSUS_Handle *consensus; | ||
47 | consensus = (struct GNUNET_CONSENSUS_Handle *) cls; | ||
48 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "concluded\n"); | ||
49 | } | ||
50 | |||
51 | static void | ||
36 | on_new_element (void *cls, | 52 | on_new_element (void *cls, |
37 | struct GNUNET_CONSENSUS_Element *element) | 53 | struct GNUNET_CONSENSUS_Element *element) |
38 | { | 54 | { |
55 | struct GNUNET_CONSENSUS_Handle *consensus; | ||
56 | |||
57 | GNUNET_assert (NULL != element); | ||
58 | |||
59 | consensus = *(struct GNUNET_CONSENSUS_Handle **) cls; | ||
60 | |||
39 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "received new element\n"); | 61 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "received new element\n"); |
62 | |||
63 | GNUNET_CONSENSUS_conclude (consensus, GNUNET_TIME_UNIT_FOREVER_REL, &conclude_done, consensus); | ||
64 | |||
40 | } | 65 | } |
41 | 66 | ||
67 | static void | ||
68 | insert_done (void *cls, int success) | ||
69 | { | ||
70 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "insert done\n"); | ||
71 | } | ||
72 | |||
73 | |||
42 | 74 | ||
43 | static void | 75 | static void |
44 | run (void *cls, | 76 | run (void *cls, |
@@ -47,10 +79,24 @@ run (void *cls, | |||
47 | { | 79 | { |
48 | char *str = "foo"; | 80 | char *str = "foo"; |
49 | 81 | ||
82 | struct GNUNET_CONSENSUS_Element el1 = {"foo", 4, 0}; | ||
83 | struct GNUNET_CONSENSUS_Element el2 = {"bar", 4, 0}; | ||
84 | |||
85 | GNUNET_log_setup ("test_consensus_api", | ||
86 | "DEBUG", | ||
87 | NULL); | ||
88 | |||
89 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "testing consensus api\n"); | ||
90 | |||
50 | GNUNET_CRYPTO_hash (str, strlen (str), &session_id); | 91 | GNUNET_CRYPTO_hash (str, strlen (str), &session_id); |
51 | consensus = GNUNET_CONSENSUS_create (cfg, 0, NULL, &session_id, on_new_element, cls); | 92 | consensus1 = GNUNET_CONSENSUS_create (cfg, 0, NULL, &session_id, on_new_element, &consensus1); |
52 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to consensus service.\n"); | 93 | /* |
53 | GNUNET_assert (consensus != NULL); | 94 | consensus2 = GNUNET_CONSENSUS_create (cfg, 0, NULL, &session_id, on_new_element, &consensus2); |
95 | GNUNET_assert (consensus1 != NULL); | ||
96 | GNUNET_assert (consensus2 != NULL); | ||
97 | GNUNET_CONSENSUS_insert (consensus1, &el1, &insert_done, &consensus1); | ||
98 | GNUNET_CONSENSUS_insert (consensus2, &el2, &insert_done, &consensus2); | ||
99 | */ | ||
54 | } | 100 | } |
55 | 101 | ||
56 | 102 | ||
@@ -59,12 +105,6 @@ main (int argc, char **argv) | |||
59 | { | 105 | { |
60 | int ret; | 106 | int ret; |
61 | 107 | ||
62 | GNUNET_log_setup ("test_consensus_api", | ||
63 | "DEBUG", | ||
64 | NULL); | ||
65 | |||
66 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "testing consensus api\n"); | ||
67 | |||
68 | ret = GNUNET_TESTING_peer_run ("test_consensus_api", | 108 | ret = GNUNET_TESTING_peer_run ("test_consensus_api", |
69 | "test_consensus.conf", | 109 | "test_consensus.conf", |
70 | &run, NULL); | 110 | &run, NULL); |