diff options
Diffstat (limited to 'src/sensor/test_gnunet-service-sensor_reporting.c')
-rw-r--r-- | src/sensor/test_gnunet-service-sensor_reporting.c | 88 |
1 files changed, 81 insertions, 7 deletions
diff --git a/src/sensor/test_gnunet-service-sensor_reporting.c b/src/sensor/test_gnunet-service-sensor_reporting.c index 969ab16ec..3905e8876 100644 --- a/src/sensor/test_gnunet-service-sensor_reporting.c +++ b/src/sensor/test_gnunet-service-sensor_reporting.c | |||
@@ -40,6 +40,12 @@ | |||
40 | #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) | 40 | #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * How long to wait between starting everything and forcing anomalies to give | ||
44 | * the peer enough time to stabilize. | ||
45 | */ | ||
46 | #define ANOMALY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) | ||
47 | |||
48 | /** | ||
43 | * Information about a test peer | 49 | * Information about a test peer |
44 | */ | 50 | */ |
45 | struct TestPeer | 51 | struct TestPeer |
@@ -75,6 +81,16 @@ struct TestPeer | |||
75 | */ | 81 | */ |
76 | struct GNUNET_TESTBED_Operation *sensor_op; | 82 | struct GNUNET_TESTBED_Operation *sensor_op; |
77 | 83 | ||
84 | /** | ||
85 | * Sensor service handle | ||
86 | */ | ||
87 | struct GNUNET_SENSOR_Handle *sensor; | ||
88 | |||
89 | /** | ||
90 | * GNUNET scheduler task that forces the anomaly after a stabilization delay | ||
91 | */ | ||
92 | GNUNET_SCHEDULER_TaskIdentifier delay_task; | ||
93 | |||
78 | }; | 94 | }; |
79 | 95 | ||
80 | /** | 96 | /** |
@@ -119,14 +135,19 @@ static struct TestPeer *peer_tail; | |||
119 | static int started_peers = 0; | 135 | static int started_peers = 0; |
120 | 136 | ||
121 | /** | 137 | /** |
138 | * Number of peers reported anomalies with full list of anomalous neighbors | ||
139 | */ | ||
140 | static int reported_peers = 0; | ||
141 | |||
142 | /** | ||
122 | * TESTBED operation connecting us to peerstore service | 143 | * TESTBED operation connecting us to peerstore service |
123 | */ | 144 | */ |
124 | struct GNUNET_TESTBED_Operation *peerstore_op; | 145 | static struct GNUNET_TESTBED_Operation *peerstore_op; |
125 | 146 | ||
126 | /** | 147 | /** |
127 | * Handle to the peerstore service | 148 | * Handle to the peerstore service |
128 | */ | 149 | */ |
129 | struct GNUNET_PEERSTORE_Handle *peerstore; | 150 | static struct GNUNET_PEERSTORE_Handle *peerstore; |
130 | 151 | ||
131 | /** | 152 | /** |
132 | * Task used to shutdown / expire the test | 153 | * Task used to shutdown / expire the test |
@@ -139,6 +160,28 @@ static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; | |||
139 | static int ok = 1; | 160 | static int ok = 1; |
140 | 161 | ||
141 | 162 | ||
163 | static void | ||
164 | destroy_peer (struct TestPeer *peer) | ||
165 | { | ||
166 | if (GNUNET_SCHEDULER_NO_TASK != peer->delay_task) | ||
167 | { | ||
168 | GNUNET_SCHEDULER_cancel (peer->delay_task); | ||
169 | peer->delay_task = GNUNET_SCHEDULER_NO_TASK; | ||
170 | } | ||
171 | if (NULL != peer->sensor_op) | ||
172 | { | ||
173 | GNUNET_TESTBED_operation_done (peer->sensor_op); | ||
174 | peer->sensor_op = NULL; | ||
175 | } | ||
176 | if (NULL != peer->wc) | ||
177 | { | ||
178 | GNUNET_PEERSTORE_watch_cancel (peer->wc); | ||
179 | peer->wc = NULL; | ||
180 | } | ||
181 | GNUNET_free (peer); | ||
182 | } | ||
183 | |||
184 | |||
142 | /** | 185 | /** |
143 | * Shutdown task | 186 | * Shutdown task |
144 | * | 187 | * |
@@ -148,7 +191,15 @@ static int ok = 1; | |||
148 | static void | 191 | static void |
149 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 192 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
150 | { | 193 | { |
151 | //TODO: destroy list of peers | 194 | struct TestPeer *peer; |
195 | |||
196 | peer = peer_head; | ||
197 | while (NULL != peer) | ||
198 | { | ||
199 | GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, peer); | ||
200 | destroy_peer (peer); | ||
201 | peer = peer_head; | ||
202 | } | ||
152 | if (NULL != peerstore_op) | 203 | if (NULL != peerstore_op) |
153 | { | 204 | { |
154 | GNUNET_TESTBED_operation_done (peerstore_op); | 205 | GNUNET_TESTBED_operation_done (peerstore_op); |
@@ -162,7 +213,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
162 | * Write new temp sensor directory with a sensor updated with collection point | 213 | * Write new temp sensor directory with a sensor updated with collection point |
163 | * peer id | 214 | * peer id |
164 | */ | 215 | */ |
165 | void | 216 | static void |
166 | write_new_sensor_dir (struct TestPeer *cp_peer) | 217 | write_new_sensor_dir (struct TestPeer *cp_peer) |
167 | { | 218 | { |
168 | struct GNUNET_CONFIGURATION_Handle *sensorcfg; | 219 | struct GNUNET_CONFIGURATION_Handle *sensorcfg; |
@@ -208,12 +259,33 @@ peerstore_watch_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, | |||
208 | "Anomalous: %d\n" "Anomalous neigbors: %f.\n", | 259 | "Anomalous: %d\n" "Anomalous neigbors: %f.\n", |
209 | GNUNET_i2s (&peer->peer_id), anomaly->anomalous, | 260 | GNUNET_i2s (&peer->peer_id), anomaly->anomalous, |
210 | anomaly->anomalous_neighbors); | 261 | anomaly->anomalous_neighbors); |
211 | //TODO | 262 | if (1 == anomaly->anomalous_neighbors) |
263 | reported_peers++; | ||
264 | if (reported_peers == NUM_PEERS) | ||
265 | { | ||
266 | ok = 0; | ||
267 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
268 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
269 | } | ||
212 | return GNUNET_YES; | 270 | return GNUNET_YES; |
213 | } | 271 | } |
214 | 272 | ||
215 | 273 | ||
216 | /** | 274 | /** |
275 | * Task that pushes fake anomalies to running peers | ||
276 | */ | ||
277 | static void | ||
278 | force_anomaly_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
279 | { | ||
280 | struct TestPeer *peer = cls; | ||
281 | |||
282 | peer->delay_task = GNUNET_SCHEDULER_NO_TASK; | ||
283 | GNUNET_SENSOR_force_anomaly (peer->sensor, (char *) sensor_name, GNUNET_YES, | ||
284 | NULL, NULL); | ||
285 | } | ||
286 | |||
287 | |||
288 | /** | ||
217 | * Callback to be called when sensor service connect operation is completed | 289 | * Callback to be called when sensor service connect operation is completed |
218 | * | 290 | * |
219 | * @param cls the callback closure from functions generating an operation | 291 | * @param cls the callback closure from functions generating an operation |
@@ -229,8 +301,9 @@ sensor_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
229 | struct TestPeer *peer = cls; | 301 | struct TestPeer *peer = cls; |
230 | struct GNUNET_SENSOR_Handle *sensor = ca_result; | 302 | struct GNUNET_SENSOR_Handle *sensor = ca_result; |
231 | 303 | ||
232 | GNUNET_SENSOR_force_anomaly (sensor, (char *) sensor_name, GNUNET_YES, NULL, | 304 | peer->sensor = sensor; |
233 | NULL); | 305 | peer->delay_task = |
306 | GNUNET_SCHEDULER_add_delayed (ANOMALY_DELAY, &force_anomaly_task, peer); | ||
234 | } | 307 | } |
235 | 308 | ||
236 | 309 | ||
@@ -399,6 +472,7 @@ peer_info_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op, | |||
399 | peer = GNUNET_new (struct TestPeer); | 472 | peer = GNUNET_new (struct TestPeer); |
400 | 473 | ||
401 | peer->testbed_peer = testbed_peer; | 474 | peer->testbed_peer = testbed_peer; |
475 | peer->delay_task = GNUNET_SCHEDULER_NO_TASK; | ||
402 | GNUNET_CRYPTO_get_peer_identity (pinfo->result.cfg, &peer->peer_id); | 476 | GNUNET_CRYPTO_get_peer_identity (pinfo->result.cfg, &peer->peer_id); |
403 | if (NULL == peer_head) /* First peer (collection point) */ | 477 | if (NULL == peer_head) /* First peer (collection point) */ |
404 | { | 478 | { |