aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_barriers.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-27 14:06:26 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-27 14:06:26 +0000
commit24680d0c69d4a14e207b20051c34ee48dbafdc1f (patch)
treefa08440f2b84f8400b41c2f632fd2f9fce0ea26e /src/testbed/testbed_api_barriers.c
parent68a09c195d33239193f160dfabef54a6dbf0d239 (diff)
downloadgnunet-24680d0c69d4a14e207b20051c34ee48dbafdc1f.tar.gz
gnunet-24680d0c69d4a14e207b20051c34ee48dbafdc1f.zip
move functions unrelated to TESTBED_BarrierWaitHandle out of testbed_api_barriers.c
Diffstat (limited to 'src/testbed/testbed_api_barriers.c')
-rw-r--r--src/testbed/testbed_api_barriers.c139
1 files changed, 0 insertions, 139 deletions
diff --git a/src/testbed/testbed_api_barriers.c b/src/testbed/testbed_api_barriers.c
index 0163c0ce4..deb8ca97f 100644
--- a/src/testbed/testbed_api_barriers.c
+++ b/src/testbed/testbed_api_barriers.c
@@ -43,145 +43,6 @@
43 43
44 44
45/** 45/**
46 * Remove a barrier and it was the last one in the barrier hash map, destroy the
47 * hash map
48 *
49 * @param barrier the barrier to remove
50 */
51void
52GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier)
53{
54 struct GNUNET_TESTBED_Controller *c = barrier->c;
55
56 GNUNET_assert (NULL != c->barrier_map); /* No barriers present */
57 GNUNET_assert (GNUNET_OK ==
58 GNUNET_CONTAINER_multihashmap_remove (c->barrier_map,
59 &barrier->key,
60 barrier));
61 GNUNET_free (barrier->name);
62 GNUNET_free (barrier);
63 if (0 == GNUNET_CONTAINER_multihashmap_size (c->barrier_map))
64 {
65 GNUNET_CONTAINER_multihashmap_destroy (c->barrier_map);
66 c->barrier_map = NULL;
67 }
68}
69
70
71/**
72 * Initialise a barrier and call the given callback when the required percentage
73 * of peers (quorum) reach the barrier OR upon error.
74 *
75 * @param controller the handle to the controller
76 * @param name identification name of the barrier
77 * @param quorum the percentage of peers that is required to reach the barrier.
78 * Peers signal reaching a barrier by calling
79 * GNUNET_TESTBED_barrier_reached().
80 * @param cb the callback to call when the barrier is reached or upon error.
81 * Cannot be NULL.
82 * @param cls closure for the above callback
83 * @param echo GNUNET_YES to echo the barrier crossed status message back to the
84 * controller
85 * @return barrier handle; NULL upon error
86 */
87struct GNUNET_TESTBED_Barrier *
88GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller,
89 const char *name,
90 unsigned int quorum,
91 GNUNET_TESTBED_barrier_status_cb cb, void *cls,
92 int echo)
93{
94 struct GNUNET_TESTBED_BarrierInit *msg;
95 struct GNUNET_TESTBED_Barrier *barrier;
96 struct GNUNET_HashCode key;
97 size_t name_len;
98 uint16_t msize;
99
100 GNUNET_assert (quorum <= 100);
101 GNUNET_assert (NULL != cb);
102 name_len = strlen (name);
103 GNUNET_assert (0 < name_len);
104 GNUNET_CRYPTO_hash (name, name_len, &key);
105 if (NULL == controller->barrier_map)
106 controller->barrier_map = GNUNET_CONTAINER_multihashmap_create (3, GNUNET_YES);
107 if (GNUNET_YES ==
108 GNUNET_CONTAINER_multihashmap_contains (controller->barrier_map,
109 &key))
110 {
111 GNUNET_break (0);
112 return NULL;
113 }
114 LOG_DEBUG ("Initialising barrier `%s'\n", name);
115 barrier = GNUNET_new (struct GNUNET_TESTBED_Barrier);
116 barrier->c = controller;
117 barrier->name = GNUNET_strdup (name);
118 barrier->cb = cb;
119 barrier->cls = cls;
120 barrier->echo = echo;
121 (void) memcpy (&barrier->key, &key, sizeof (struct GNUNET_HashCode));
122 GNUNET_assert (GNUNET_OK ==
123 GNUNET_CONTAINER_multihashmap_put (controller->barrier_map,
124 &barrier->key,
125 barrier,
126 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
127 msize = name_len + sizeof (struct GNUNET_TESTBED_BarrierInit);
128 msg = GNUNET_malloc (msize);
129 msg->header.size = htons (msize);
130 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT);
131 msg->quorum = (uint8_t) quorum;
132 (void) memcpy (msg->name, barrier->name, name_len);
133 GNUNET_TESTBED_queue_message_ (barrier->c, &msg->header);
134 return barrier;
135}
136
137
138/**
139 * Initialise a barrier and call the given callback when the required percentage
140 * of peers (quorum) reach the barrier OR upon error.
141 *
142 * @param controller the handle to the controller
143 * @param name identification name of the barrier
144 * @param quorum the percentage of peers that is required to reach the barrier.
145 * Peers signal reaching a barrier by calling
146 * GNUNET_TESTBED_barrier_reached().
147 * @param cb the callback to call when the barrier is reached or upon error.
148 * Cannot be NULL.
149 * @param cls closure for the above callback
150 * @return barrier handle; NULL upon error
151 */
152struct GNUNET_TESTBED_Barrier *
153GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller,
154 const char *name,
155 unsigned int quorum,
156 GNUNET_TESTBED_barrier_status_cb cb, void *cls)
157{
158 return GNUNET_TESTBED_barrier_init_ (controller,
159 name, quorum, cb, cls, GNUNET_YES);
160}
161
162
163/**
164 * Cancel a barrier.
165 *
166 * @param barrier the barrier handle
167 */
168void
169GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier)
170{
171 struct GNUNET_TESTBED_BarrierCancel *msg;
172 uint16_t msize;
173
174 msize = sizeof (struct GNUNET_TESTBED_BarrierCancel) + strlen (barrier->name);
175 msg = GNUNET_malloc (msize);
176 msg->header.size = htons (msize);
177 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL);
178 (void) memcpy (msg->name, barrier->name, strlen (barrier->name));
179 GNUNET_TESTBED_queue_message_ (barrier->c, &msg->header);
180 GNUNET_TESTBED_barrier_remove_ (barrier);
181}
182
183
184/**
185 * Barrier wait handle 46 * Barrier wait handle
186 */ 47 */
187struct GNUNET_TESTBED_BarrierWaitHandle 48struct GNUNET_TESTBED_BarrierWaitHandle