diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-09-02 15:27:44 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-09-02 15:27:44 +0000 |
commit | 77d6764807df338fbbe0758e378ac23d1ac63862 (patch) | |
tree | dd067e4efe5cace9ffce6c73fa0f3ff2fc77b741 /src/sensor | |
parent | e1adb869951412b5a60a7e7e686d1477f8f4af71 (diff) | |
download | gnunet-77d6764807df338fbbe0758e378ac23d1ac63862.tar.gz gnunet-77d6764807df338fbbe0758e378ac23d1ac63862.zip |
sensor profiler: disconnect peers functionality
Diffstat (limited to 'src/sensor')
-rw-r--r-- | src/sensor/Makefile.am | 3 | ||||
-rw-r--r-- | src/sensor/gnunet-sensor-profiler.c | 209 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor_monitoring.c | 1 |
3 files changed, 199 insertions, 14 deletions
diff --git a/src/sensor/Makefile.am b/src/sensor/Makefile.am index ec9de1d1c..af8293cca 100644 --- a/src/sensor/Makefile.am +++ b/src/sensor/Makefile.am | |||
@@ -121,7 +121,8 @@ gnunet_sensor_profiler_LDADD = \ | |||
121 | libgnunetsensor.la \ | 121 | libgnunetsensor.la \ |
122 | $(top_builddir)/src/util/libgnunetutil.la \ | 122 | $(top_builddir)/src/util/libgnunetutil.la \ |
123 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | 123 | $(top_builddir)/src/testbed/libgnunettestbed.la \ |
124 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la | 124 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ |
125 | $(top_builddir)/src/transport/libgnunettransport.la | ||
125 | 126 | ||
126 | pkgsensordir = sensors | 127 | pkgsensordir = sensors |
127 | 128 | ||
diff --git a/src/sensor/gnunet-sensor-profiler.c b/src/sensor/gnunet-sensor-profiler.c index ba9ba28dd..356e94da8 100644 --- a/src/sensor/gnunet-sensor-profiler.c +++ b/src/sensor/gnunet-sensor-profiler.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "gnunet_peerstore_service.h" | 29 | #include "gnunet_peerstore_service.h" |
30 | #include "gnunet_sensor_service.h" | 30 | #include "gnunet_sensor_service.h" |
31 | #include "gnunet_sensor_util_lib.h" | 31 | #include "gnunet_sensor_util_lib.h" |
32 | #include "gnunet_transport_service.h" | ||
32 | 33 | ||
33 | /** | 34 | /** |
34 | * Time to wait for the peer to startup completely | 35 | * Time to wait for the peer to startup completely |
@@ -53,6 +54,23 @@ struct PeerInfo | |||
53 | 54 | ||
54 | }; | 55 | }; |
55 | 56 | ||
57 | struct DisconnectionContext | ||
58 | { | ||
59 | |||
60 | struct DisconnectionContext *prev; | ||
61 | |||
62 | struct DisconnectionContext *next; | ||
63 | |||
64 | struct PeerInfo *p1; | ||
65 | |||
66 | struct PeerInfo *p2; | ||
67 | |||
68 | struct GNUNET_TESTBED_Operation *p1_transport_op; | ||
69 | |||
70 | struct GNUNET_TRANSPORT_Blacklist *blacklist; | ||
71 | |||
72 | }; | ||
73 | |||
56 | 74 | ||
57 | /** | 75 | /** |
58 | * Name of the configuration file used | 76 | * Name of the configuration file used |
@@ -72,7 +90,7 @@ static const char *sensor_dst_dir = "/tmp/gnunet-sensor-profiler"; | |||
72 | /** | 90 | /** |
73 | * GNUnet configuration | 91 | * GNUnet configuration |
74 | */ | 92 | */ |
75 | struct GNUNET_CONFIGURATION_Handle *cfg; | 93 | static struct GNUNET_CONFIGURATION_Handle *cfg; |
76 | 94 | ||
77 | /** | 95 | /** |
78 | * Return value of the program | 96 | * Return value of the program |
@@ -139,6 +157,16 @@ static unsigned int sensor_names_size = 0; | |||
139 | */ | 157 | */ |
140 | static GNUNET_SCHEDULER_TaskIdentifier delayed_task = GNUNET_SCHEDULER_NO_TASK; | 158 | static GNUNET_SCHEDULER_TaskIdentifier delayed_task = GNUNET_SCHEDULER_NO_TASK; |
141 | 159 | ||
160 | /** | ||
161 | * Head of list of disconnection contexts | ||
162 | */ | ||
163 | static struct DisconnectionContext *dc_head; | ||
164 | |||
165 | /* | ||
166 | * Tail of list of disconnection contexts | ||
167 | */ | ||
168 | static struct DisconnectionContext *dc_tail; | ||
169 | |||
142 | 170 | ||
143 | /** | 171 | /** |
144 | * Copy directory recursively | 172 | * Copy directory recursively |
@@ -158,6 +186,7 @@ static void | |||
158 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 186 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
159 | { | 187 | { |
160 | int i; | 188 | int i; |
189 | struct DisconnectionContext *dc; | ||
161 | 190 | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down.\n"); | 191 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down.\n"); |
163 | if (GNUNET_SCHEDULER_NO_TASK != delayed_task) | 192 | if (GNUNET_SCHEDULER_NO_TASK != delayed_task) |
@@ -165,16 +194,22 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
165 | GNUNET_SCHEDULER_cancel (delayed_task); | 194 | GNUNET_SCHEDULER_cancel (delayed_task); |
166 | delayed_task = GNUNET_SCHEDULER_NO_TASK; | 195 | delayed_task = GNUNET_SCHEDULER_NO_TASK; |
167 | } | 196 | } |
168 | if (NULL != cfg) | 197 | dc = dc_head; |
169 | { | 198 | while (NULL != dc) |
170 | GNUNET_CONFIGURATION_destroy (cfg); | ||
171 | cfg = NULL; | ||
172 | } | ||
173 | if (NULL != sensor_names) | ||
174 | { | 199 | { |
175 | for (i = 0; i < sensor_names_size; i++) | 200 | GNUNET_CONTAINER_DLL_remove (dc_head, dc_tail, dc); |
176 | GNUNET_free (sensor_names[i]); | 201 | if (NULL != dc->blacklist) |
177 | GNUNET_array_grow (sensor_names, sensor_names_size, 0); | 202 | { |
203 | GNUNET_TRANSPORT_blacklist_cancel (dc->blacklist); | ||
204 | dc->blacklist = NULL; | ||
205 | } | ||
206 | if (NULL != dc->p1_transport_op) | ||
207 | { | ||
208 | GNUNET_TESTBED_operation_done (dc->p1_transport_op); | ||
209 | dc->p1_transport_op = NULL; | ||
210 | } | ||
211 | GNUNET_free (dc); | ||
212 | dc = dc_head; | ||
178 | } | 213 | } |
179 | if (NULL != peerstore_op) | 214 | if (NULL != peerstore_op) |
180 | { | 215 | { |
@@ -186,10 +221,157 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
186 | GNUNET_free (all_peers_info); | 221 | GNUNET_free (all_peers_info); |
187 | all_peers_info = NULL; | 222 | all_peers_info = NULL; |
188 | } | 223 | } |
224 | if (NULL != cfg) | ||
225 | { | ||
226 | GNUNET_CONFIGURATION_destroy (cfg); | ||
227 | cfg = NULL; | ||
228 | } | ||
229 | if (NULL != sensor_names) | ||
230 | { | ||
231 | for (i = 0; i < sensor_names_size; i++) | ||
232 | GNUNET_free (sensor_names[i]); | ||
233 | GNUNET_array_grow (sensor_names, sensor_names_size, 0); | ||
234 | } | ||
189 | GNUNET_SCHEDULER_shutdown (); | 235 | GNUNET_SCHEDULER_shutdown (); |
190 | } | 236 | } |
191 | 237 | ||
192 | 238 | ||
239 | /*****************************************************************************/ | ||
240 | /****************************** DISCONNECT PEERS *****************************/ | ||
241 | /*****************************************************************************/ | ||
242 | |||
243 | |||
244 | /** | ||
245 | * Function to call with result of the TRANSPORT try disconnect request. | ||
246 | * | ||
247 | * @param cls closure | ||
248 | * @param result #GNUNET_OK if message was transmitted to transport service | ||
249 | * #GNUNET_SYSERR if message was not transmitted to transport service | ||
250 | */ | ||
251 | static void | ||
252 | transport_disconnect_cb (void *cls, const int result) | ||
253 | { | ||
254 | struct DisconnectionContext *dc = cls; | ||
255 | |||
256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnection request between `%s' and `%s' sent.\n", | ||
257 | GNUNET_i2s (&dc->p1->peer_id), GNUNET_i2s (&dc->p2->peer_id)); | ||
258 | } | ||
259 | |||
260 | |||
261 | /** | ||
262 | * Callback to be called when transport service connect operation is completed | ||
263 | * | ||
264 | * @param cls the callback closure from functions generating an operation | ||
265 | * @param op the operation that has been finished | ||
266 | * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() | ||
267 | * @param emsg error message in case the operation has failed; will be NULL if | ||
268 | * operation has executed successfully. | ||
269 | */ | ||
270 | static void | ||
271 | transport_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | ||
272 | void *ca_result, const char *emsg) | ||
273 | { | ||
274 | struct DisconnectionContext *dc = cls; | ||
275 | struct GNUNET_TRANSPORT_Handle *transport = ca_result; | ||
276 | |||
277 | if (NULL != emsg) | ||
278 | { | ||
279 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR: %s.\n", emsg); | ||
280 | GNUNET_assert (0); | ||
281 | } | ||
282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %d: %s\n", 0, GNUNET_i2s (&dc->p1->peer_id)); | ||
283 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %d: %s\n", 1, GNUNET_i2s (&dc->p2->peer_id)); | ||
284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "transport_connect_cb().\n"); | ||
285 | GNUNET_TRANSPORT_try_disconnect (transport, &dc->p2->peer_id, &transport_disconnect_cb, dc); | ||
286 | } | ||
287 | |||
288 | |||
289 | /** | ||
290 | * Callback from TRANSPORT service to ask if the given peer ID is blacklisted. | ||
291 | * | ||
292 | * @param cls closure, DisconnectionContext | ||
293 | * @param pid peer to approve or disapproave | ||
294 | * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not | ||
295 | */ | ||
296 | static int | ||
297 | blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *pid) | ||
298 | { | ||
299 | struct DisconnectionContext *dc = cls; | ||
300 | |||
301 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&dc->p2->peer_id, pid)) | ||
302 | return GNUNET_SYSERR; | ||
303 | return GNUNET_OK; | ||
304 | } | ||
305 | |||
306 | |||
307 | /** | ||
308 | * Adapter function called to establish a connection to transport service. | ||
309 | * | ||
310 | * @param cls closure | ||
311 | * @param cfg configuration of the peer to connect to; will be available until | ||
312 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
313 | * from GNUNET_TESTBED_service_connect() | ||
314 | * @return service handle to return in 'op_result', NULL on error | ||
315 | */ | ||
316 | static void * | ||
317 | transport_connect_adapter (void *cls, | ||
318 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
319 | { | ||
320 | struct DisconnectionContext *dc = cls; | ||
321 | struct GNUNET_TRANSPORT_Handle *transport; | ||
322 | |||
323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "transport_connect_adapter().\n"); | ||
324 | dc-> blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, dc); | ||
325 | GNUNET_assert (NULL != dc->blacklist); | ||
326 | transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL); | ||
327 | GNUNET_assert (NULL != transport); | ||
328 | return transport; | ||
329 | } | ||
330 | |||
331 | |||
332 | /** | ||
333 | * Adapter function called to destroy a connection to transport service. | ||
334 | * | ||
335 | * @param cls closure | ||
336 | * @param op_result service handle returned from the connect adapter | ||
337 | */ | ||
338 | static void | ||
339 | transport_disconnect_adapter (void *cls, void *op_result) | ||
340 | { | ||
341 | struct GNUNET_TRANSPORT_Handle *transport = op_result; | ||
342 | |||
343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "transport_disconnect_adapter().\n"); | ||
344 | GNUNET_TRANSPORT_disconnect(transport); | ||
345 | } | ||
346 | |||
347 | |||
348 | /** | ||
349 | * Kill any connection between two peers. Has no effect if the peers are not | ||
350 | * connected. | ||
351 | */ | ||
352 | static void | ||
353 | disconnect_peers (struct PeerInfo *p1, struct PeerInfo *p2) | ||
354 | { | ||
355 | struct DisconnectionContext *dc; | ||
356 | |||
357 | GNUNET_assert (p1 != p2); | ||
358 | dc = GNUNET_new (struct DisconnectionContext); | ||
359 | dc->p1 = p1; | ||
360 | dc->p2 = p2; | ||
361 | GNUNET_CONTAINER_DLL_insert (dc_head, dc_tail, dc); | ||
362 | dc->p1_transport_op = | ||
363 | GNUNET_TESTBED_service_connect (NULL, p1->testbed_peer, | ||
364 | "transport", &transport_connect_cb, | ||
365 | dc, &transport_connect_adapter, | ||
366 | &transport_disconnect_adapter, dc); | ||
367 | } | ||
368 | |||
369 | |||
370 | /*****************************************************************************/ | ||
371 | /**************************** END DISCONNECT PEERS ***************************/ | ||
372 | /*****************************************************************************/ | ||
373 | |||
374 | |||
193 | /** | 375 | /** |
194 | * Function called with each file/folder inside a directory that is being copied. | 376 | * Function called with each file/folder inside a directory that is being copied. |
195 | * | 377 | * |
@@ -214,6 +396,8 @@ copy_dir_scanner (void *cls, const char *filename) | |||
214 | if (GNUNET_YES == GNUNET_DISK_file_test (dst)) | 396 | if (GNUNET_YES == GNUNET_DISK_file_test (dst)) |
215 | GNUNET_DISK_directory_remove (dst); | 397 | GNUNET_DISK_directory_remove (dst); |
216 | copy_result = GNUNET_DISK_file_copy (filename, dst); | 398 | copy_result = GNUNET_DISK_file_copy (filename, dst); |
399 | if (GNUNET_OK == copy_result) | ||
400 | GNUNET_DISK_fix_permissions (dst, GNUNET_NO, GNUNET_NO); | ||
217 | } | 401 | } |
218 | GNUNET_free (dst); | 402 | GNUNET_free (dst); |
219 | return copy_result; | 403 | return copy_result; |
@@ -437,6 +621,7 @@ peerstore_disconnect_adapter (void *cls, void *op_result) | |||
437 | static void | 621 | static void |
438 | simulate_anomalies (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 622 | simulate_anomalies (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
439 | { | 623 | { |
624 | delayed_task = GNUNET_SCHEDULER_NO_TASK; | ||
440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 625 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
441 | "Training period over, simulating anomalies now.\n"); | 626 | "Training period over, simulating anomalies now.\n"); |
442 | //TODO | 627 | //TODO |
@@ -603,11 +788,11 @@ test_master (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num, | |||
603 | static int | 788 | static int |
604 | verify_args () | 789 | verify_args () |
605 | { | 790 | { |
606 | if (num_peers < 3) | 791 | if (num_peers < 2) |
607 | { | 792 | { |
608 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 793 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
609 | _ | 794 | _ |
610 | ("Invalid or missing number of peers. Set at least 3 peers.\n")); | 795 | ("Invalid or missing number of peers. Set at least 2 peers.\n")); |
611 | return GNUNET_SYSERR; | 796 | return GNUNET_SYSERR; |
612 | } | 797 | } |
613 | if (NULL == topology_file || | 798 | if (NULL == topology_file || |
diff --git a/src/sensor/gnunet-service-sensor_monitoring.c b/src/sensor/gnunet-service-sensor_monitoring.c index c3d5b8007..38b5f65da 100644 --- a/src/sensor/gnunet-service-sensor_monitoring.c +++ b/src/sensor/gnunet-service-sensor_monitoring.c | |||
@@ -353,7 +353,6 @@ sensor_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
353 | GNUNET_asprintf (&process_path, "%s%s-files%s%s", sensor_dir, | 353 | GNUNET_asprintf (&process_path, "%s%s-files%s%s", sensor_dir, |
354 | sensorinfo->name, DIR_SEPARATOR_STR, | 354 | sensorinfo->name, DIR_SEPARATOR_STR, |
355 | sensorinfo->ext_process); | 355 | sensorinfo->ext_process); |
356 | GNUNET_free (sensor_dir); | ||
357 | check_result = | 356 | check_result = |
358 | GNUNET_OS_check_helper_binary (process_path, GNUNET_NO, NULL); | 357 | GNUNET_OS_check_helper_binary (process_path, GNUNET_NO, NULL); |
359 | } | 358 | } |