aboutsummaryrefslogtreecommitdiff
path: root/src/consensus/test_consensus_api.c
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2013-01-17 00:53:11 +0000
committerFlorian Dold <florian.dold@gmail.com>2013-01-17 00:53:11 +0000
commit21273cba1880b1081b4152ee45b2f4ad6768e639 (patch)
tree325c93f75c67456b6729e581b9b69cc0bc52df48 /src/consensus/test_consensus_api.c
parentbdee53dd2cb760e9acd601e251ba59c42c98c02f (diff)
downloadgnunet-21273cba1880b1081b4152ee45b2f4ad6768e639.tar.gz
gnunet-21273cba1880b1081b4152ee45b2f4ad6768e639.zip
- gnunet-consensus now profiling tool
- work on service implementation, not working yet
Diffstat (limited to 'src/consensus/test_consensus_api.c')
-rw-r--r--src/consensus/test_consensus_api.c53
1 files changed, 40 insertions, 13 deletions
diff --git a/src/consensus/test_consensus_api.c b/src/consensus/test_consensus_api.c
index e752983c2..c79a6221c 100644
--- a/src/consensus/test_consensus_api.c
+++ b/src/consensus/test_consensus_api.c
@@ -17,6 +17,7 @@
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20
20/** 21/**
21 * @file consensus/test_consensus_api.c 22 * @file consensus/test_consensus_api.c
22 * @brief testcase for consensus_api.c 23 * @brief testcase for consensus_api.c
@@ -29,18 +30,20 @@
29 30
30static struct GNUNET_CONSENSUS_Handle *consensus; 31static struct GNUNET_CONSENSUS_Handle *consensus;
31 32
32static int insert;
33
34static struct GNUNET_HashCode session_id; 33static struct GNUNET_HashCode session_id;
35 34
36 35
37static void conclude_done (void *cls, 36static int
38 unsigned int num_peers_in_consensus, 37conclude_done (void *cls, const struct GNUNET_CONSENSUS_Group *group)
39 const struct GNUNET_PeerIdentity *peers_in_consensus)
40{ 38{
41 struct GNUNET_CONSENSUS_Handle *consensus; 39 if (NULL == group)
42 consensus = (struct GNUNET_CONSENSUS_Handle *) cls; 40 {
43 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "concluded\n"); 41 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "conclude over\n");
42 GNUNET_SCHEDULER_shutdown ();
43 return GNUNET_NO;
44 }
45 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "concluded\n");
46 return GNUNET_YES;
44} 47}
45 48
46static int 49static int
@@ -54,7 +57,30 @@ on_new_element (void *cls,
54static void 57static void
55insert_done (void *cls, int success) 58insert_done (void *cls, int success)
56{ 59{
60 /* make sure cb is only called once */
61 static int called = GNUNET_NO;
62 GNUNET_assert (GNUNET_NO == called);
63 called = GNUNET_YES;
57 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "insert done\n"); 64 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "insert done\n");
65 GNUNET_CONSENSUS_conclude (consensus, GNUNET_TIME_UNIT_SECONDS, 0, &conclude_done, NULL);
66}
67
68
69/**
70 * Signature of the main function of a task.
71 *
72 * @param cls closure
73 * @param tc context information (why was this task triggered now)
74 */
75static void
76on_shutdown (void *cls,
77 const struct GNUNET_SCHEDULER_TaskContext *tc)
78{
79 if (NULL != consensus)
80 {
81 GNUNET_CONSENSUS_destroy (consensus);
82 consensus = NULL;
83 }
58} 84}
59 85
60 86
@@ -69,18 +95,19 @@ run (void *cls,
69 struct GNUNET_CONSENSUS_Element el2 = {"bar", 4, 0}; 95 struct GNUNET_CONSENSUS_Element el2 = {"bar", 4, 0};
70 96
71 GNUNET_log_setup ("test_consensus_api", 97 GNUNET_log_setup ("test_consensus_api",
72 "DEBUG", 98 "INFO",
73 NULL); 99 NULL);
74 100
75 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "testing consensus api\n"); 101 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "testing consensus api\n");
76 102
103 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &on_shutdown, NULL);
104
77 GNUNET_CRYPTO_hash (str, strlen (str), &session_id); 105 GNUNET_CRYPTO_hash (str, strlen (str), &session_id);
78 consensus = GNUNET_CONSENSUS_create (cfg, 0, NULL, &session_id, on_new_element, &consensus); 106 consensus = GNUNET_CONSENSUS_create (cfg, 0, NULL, &session_id, on_new_element, &consensus);
79 GNUNET_assert (consensus != NULL); 107 GNUNET_assert (consensus != NULL);
80 /* 108
81 GNUNET_CONSENSUS_insert (consensus1, &el1, &insert_done, &consensus1); 109 GNUNET_CONSENSUS_insert (consensus, &el1, NULL, &consensus);
82 GNUNET_CONSENSUS_insert (consensus2, &el2, &insert_done, &consensus2); 110 GNUNET_CONSENSUS_insert (consensus, &el2, &insert_done, &consensus);
83 */
84} 111}
85 112
86 113