diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-08-28 16:06:42 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-08-28 16:06:42 +0000 |
commit | 19d2226cb1957fbe7e5f825b87849b6028615a19 (patch) | |
tree | 5123f6e091b80aced39ac6560231e99d90c9907b /src/sensor | |
parent | ee52d059da01c8a7e76b08e0e3ae1c078a2a0695 (diff) | |
download | gnunet-19d2226cb1957fbe7e5f825b87849b6028615a19.tar.gz gnunet-19d2226cb1957fbe7e5f825b87849b6028615a19.zip |
sensor: towards profiler
Diffstat (limited to 'src/sensor')
-rw-r--r-- | src/sensor/Makefile.am | 4 | ||||
-rw-r--r-- | src/sensor/gnunet-sensor-profiler.c | 174 |
2 files changed, 175 insertions, 3 deletions
diff --git a/src/sensor/Makefile.am b/src/sensor/Makefile.am index 9febc02fa..ec9de1d1c 100644 --- a/src/sensor/Makefile.am +++ b/src/sensor/Makefile.am | |||
@@ -118,8 +118,10 @@ test_pow_sign_LDADD = \ | |||
118 | gnunet_sensor_profiler_SOURCES = \ | 118 | gnunet_sensor_profiler_SOURCES = \ |
119 | gnunet-sensor-profiler.c | 119 | gnunet-sensor-profiler.c |
120 | gnunet_sensor_profiler_LDADD = \ | 120 | gnunet_sensor_profiler_LDADD = \ |
121 | libgnunetsensor.la \ | ||
121 | $(top_builddir)/src/util/libgnunetutil.la \ | 122 | $(top_builddir)/src/util/libgnunetutil.la \ |
122 | $(top_builddir)/src/testbed/libgnunettestbed.la | 123 | $(top_builddir)/src/testbed/libgnunettestbed.la \ |
124 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la | ||
123 | 125 | ||
124 | pkgsensordir = sensors | 126 | pkgsensordir = sensors |
125 | 127 | ||
diff --git a/src/sensor/gnunet-sensor-profiler.c b/src/sensor/gnunet-sensor-profiler.c index 9f4682b70..21a96b7a3 100644 --- a/src/sensor/gnunet-sensor-profiler.c +++ b/src/sensor/gnunet-sensor-profiler.c | |||
@@ -36,6 +36,8 @@ | |||
36 | #include "platform.h" | 36 | #include "platform.h" |
37 | #include "gnunet_util_lib.h" | 37 | #include "gnunet_util_lib.h" |
38 | #include "gnunet_testbed_service.h" | 38 | #include "gnunet_testbed_service.h" |
39 | #include "gnunet_peerstore_service.h" | ||
40 | #include "gnunet_sensor_service.h" | ||
39 | 41 | ||
40 | /** | 42 | /** |
41 | * Information about a single peer | 43 | * Information about a single peer |
@@ -53,6 +55,11 @@ struct PeerInfo | |||
53 | */ | 55 | */ |
54 | struct GNUNET_TESTBED_Peer *testbed_peer; | 56 | struct GNUNET_TESTBED_Peer *testbed_peer; |
55 | 57 | ||
58 | /** | ||
59 | * TESTBED operation connecting us to sensor service on this peer | ||
60 | */ | ||
61 | struct GNUNET_TESTBED_Operation *sensor_op; | ||
62 | |||
56 | }; | 63 | }; |
57 | 64 | ||
58 | 65 | ||
@@ -96,6 +103,16 @@ static struct PeerInfo *all_peers_info; | |||
96 | */ | 103 | */ |
97 | static int peers_known = 0; | 104 | static int peers_known = 0; |
98 | 105 | ||
106 | /** | ||
107 | * TESTBED operation connecting us to peerstore service on collection point | ||
108 | */ | ||
109 | static struct GNUNET_TESTBED_Operation *peerstore_op; | ||
110 | |||
111 | /** | ||
112 | * Handle to peerstore service on collection point | ||
113 | */ | ||
114 | static struct GNUNET_PEERSTORE_Handle *peerstore; | ||
115 | |||
99 | 116 | ||
100 | /** | 117 | /** |
101 | * Copy directory recursively | 118 | * Copy directory recursively |
@@ -114,7 +131,22 @@ copy_dir (const char *src, const char *dst); | |||
114 | static void | 131 | static void |
115 | do_shutdown () // TODO: schedule timeout shutdown | 132 | do_shutdown () // TODO: schedule timeout shutdown |
116 | { | 133 | { |
134 | int i; | ||
135 | |||
117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down.\n"); | 136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down.\n"); |
137 | for (i = 0; i < num_peers; i++) | ||
138 | { | ||
139 | if (NULL != all_peers_info[i].sensor_op) | ||
140 | { | ||
141 | GNUNET_TESTBED_operation_done (all_peers_info[i].sensor_op); | ||
142 | all_peers_info[i].sensor_op = NULL; | ||
143 | } | ||
144 | } | ||
145 | if (NULL != peerstore_op) | ||
146 | { | ||
147 | GNUNET_TESTBED_operation_done (peerstore_op); | ||
148 | peerstore_op = NULL; | ||
149 | } | ||
118 | if (NULL != all_peers_info) | 150 | if (NULL != all_peers_info) |
119 | { | 151 | { |
120 | GNUNET_free (all_peers_info); | 152 | GNUNET_free (all_peers_info); |
@@ -262,6 +294,124 @@ dashboard_started (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
262 | 294 | ||
263 | 295 | ||
264 | /** | 296 | /** |
297 | * Callback to be called when peerstore service connect operation is completed | ||
298 | * | ||
299 | * @param cls the callback closure from functions generating an operation | ||
300 | * @param op the operation that has been finished | ||
301 | * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() | ||
302 | * @param emsg error message in case the operation has failed; will be NULL if | ||
303 | * operation has executed successfully. | ||
304 | */ | ||
305 | static void | ||
306 | peerstore_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | ||
307 | void *ca_result, const char *emsg) | ||
308 | { | ||
309 | if (NULL != emsg) | ||
310 | { | ||
311 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR: %s.\n", emsg); | ||
312 | GNUNET_assert (0); | ||
313 | } | ||
314 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peerstore service.\n"); | ||
315 | //TODO | ||
316 | } | ||
317 | |||
318 | |||
319 | /** | ||
320 | * Adapter function called to establish a connection to peerstore service. | ||
321 | * | ||
322 | * @param cls closure | ||
323 | * @param cfg configuration of the peer to connect to; will be available until | ||
324 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
325 | * from GNUNET_TESTBED_service_connect() | ||
326 | * @return service handle to return in 'op_result', NULL on error | ||
327 | */ | ||
328 | static void * | ||
329 | peerstore_connect_adapter (void *cls, | ||
330 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
331 | { | ||
332 | peerstore = GNUNET_PEERSTORE_connect (cfg); | ||
333 | GNUNET_assert (NULL != peerstore); | ||
334 | return peerstore; | ||
335 | } | ||
336 | |||
337 | |||
338 | /** | ||
339 | * Adapter function called to destroy a connection to peerstore service. | ||
340 | * | ||
341 | * @param cls closure | ||
342 | * @param op_result service handle returned from the connect adapter | ||
343 | */ | ||
344 | static void | ||
345 | peerstore_disconnect_adapter (void *cls, void *op_result) | ||
346 | { | ||
347 | GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_NO); | ||
348 | peerstore = NULL; | ||
349 | peerstore_op = NULL; | ||
350 | } | ||
351 | |||
352 | |||
353 | /** | ||
354 | * Callback to be called when sensor service connect operation is completed | ||
355 | * | ||
356 | * @param cls the callback closure from functions generating an operation | ||
357 | * @param op the operation that has been finished | ||
358 | * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() | ||
359 | * @param emsg error message in case the operation has failed; will be NULL if | ||
360 | * operation has executed successfully. | ||
361 | */ | ||
362 | static void | ||
363 | sensor_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | ||
364 | void *ca_result, const char *emsg) | ||
365 | { | ||
366 | struct PeerInfo *peer = cls; | ||
367 | |||
368 | if (NULL != emsg) | ||
369 | { | ||
370 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR: %s.\n", emsg); | ||
371 | GNUNET_assert (0); | ||
372 | } | ||
373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sensor service started on peer `%s'.\n", | ||
374 | GNUNET_i2s (&peer->peer_id)); | ||
375 | //TODO: | ||
376 | } | ||
377 | |||
378 | |||
379 | /** | ||
380 | * Adapter function called to establish a connection to sensor service. | ||
381 | * | ||
382 | * @param cls closure | ||
383 | * @param cfg configuration of the peer to connect to; will be available until | ||
384 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
385 | * from GNUNET_TESTBED_service_connect() | ||
386 | * @return service handle to return in 'op_result', NULL on error | ||
387 | */ | ||
388 | static void * | ||
389 | sensor_connect_adapter (void *cls, | ||
390 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
391 | { | ||
392 | struct GNUNET_SENSOR_Handle *sensor; | ||
393 | |||
394 | sensor = GNUNET_SENSOR_connect (cfg); | ||
395 | return sensor; | ||
396 | } | ||
397 | |||
398 | |||
399 | /** | ||
400 | * Adapter function called to destroy a connection to sensor service. | ||
401 | * | ||
402 | * @param cls closure | ||
403 | * @param op_result service handle returned from the connect adapter | ||
404 | */ | ||
405 | static void | ||
406 | sensor_disconnect_adapter (void *cls, void *op_result) | ||
407 | { | ||
408 | struct GNUNET_SENSOR_Handle *sensor = op_result; | ||
409 | |||
410 | GNUNET_SENSOR_disconnect (sensor); | ||
411 | } | ||
412 | |||
413 | |||
414 | /** | ||
265 | * Callback to be called when the requested peer information is available | 415 | * Callback to be called when the requested peer information is available |
266 | * | 416 | * |
267 | * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information() | 417 | * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information() |
@@ -278,9 +428,15 @@ peer_info_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op, | |||
278 | struct GNUNET_TESTBED_Peer *testbed_peer = cb_cls; | 428 | struct GNUNET_TESTBED_Peer *testbed_peer = cb_cls; |
279 | struct PeerInfo *peer = &all_peers_info[peers_known]; | 429 | struct PeerInfo *peer = &all_peers_info[peers_known]; |
280 | 430 | ||
431 | if (NULL != emsg) | ||
432 | { | ||
433 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR: %s.\n", emsg); | ||
434 | GNUNET_assert (0); | ||
435 | } | ||
281 | peer->testbed_peer = testbed_peer; | 436 | peer->testbed_peer = testbed_peer; |
282 | GNUNET_CRYPTO_get_peer_identity (pinfo->result.cfg, &peer->peer_id); | 437 | GNUNET_CRYPTO_get_peer_identity (pinfo->result.cfg, &peer->peer_id); |
283 | if (0 == peers_known) /* First peer is collection point */ | 438 | peers_known++; |
439 | if (1 == peers_known) /* First peer is collection point */ | ||
284 | { | 440 | { |
285 | /* Rewrite sensors */ | 441 | /* Rewrite sensors */ |
286 | rewrite_sensors (); | 442 | rewrite_sensors (); |
@@ -288,7 +444,21 @@ peer_info_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op, | |||
288 | GNUNET_TESTBED_peer_manage_service (NULL, testbed_peer, "sensordashboard", | 444 | GNUNET_TESTBED_peer_manage_service (NULL, testbed_peer, "sensordashboard", |
289 | &dashboard_started, NULL, 1); | 445 | &dashboard_started, NULL, 1); |
290 | } | 446 | } |
291 | peers_known++; | 447 | /* Start sensor service on every peer */ |
448 | peer->sensor_op = | ||
449 | GNUNET_TESTBED_service_connect (NULL, testbed_peer, "sensor", | ||
450 | &sensor_connect_cb, peer, | ||
451 | &sensor_connect_adapter, | ||
452 | &sensor_disconnect_adapter, NULL); | ||
453 | if (num_peers == peers_known) /* Last peer */ | ||
454 | { | ||
455 | /* Connect to peerstore on first peer (collection point) */ | ||
456 | peerstore_op = | ||
457 | GNUNET_TESTBED_service_connect (NULL, all_peers_info[0].testbed_peer, | ||
458 | "peerstore", &peerstore_connect_cb, | ||
459 | NULL, &peerstore_connect_adapter, | ||
460 | &peerstore_disconnect_adapter, NULL); | ||
461 | } | ||
292 | GNUNET_TESTBED_operation_done (op); | 462 | GNUNET_TESTBED_operation_done (op); |
293 | } | 463 | } |
294 | 464 | ||