[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r34166 - gnunet/src/sensor
From: |
gnunet |
Subject: |
[GNUnet-SVN] r34166 - gnunet/src/sensor |
Date: |
Mon, 18 Aug 2014 13:57:41 +0200 |
Author: otarabai
Date: 2014-08-18 13:57:41 +0200 (Mon, 18 Aug 2014)
New Revision: 34166
Modified:
gnunet/src/sensor/Makefile.am
gnunet/src/sensor/gnunet-service-sensor_reporting.c
gnunet/src/sensor/test_gnunet-service-sensor_reporting.c
gnunet/src/sensor/test_gnunet-service-sensor_reporting.conf
Log:
sensor: update to test case + fix
Modified: gnunet/src/sensor/Makefile.am
===================================================================
--- gnunet/src/sensor/Makefile.am 2014-08-18 10:52:40 UTC (rev 34165)
+++ gnunet/src/sensor/Makefile.am 2014-08-18 11:57:41 UTC (rev 34166)
@@ -83,7 +83,8 @@
libgnunetsensor.la
check_PROGRAMS = \
- test_sensor_api
+ test_sensor_api \
+ test_gnunet-service-sensor_reporting
if ENABLE_TEST_RUN
AM_TESTS_ENVIRONMENT=export
GNUNET_PREFIX=$${GNUNET_PREFIX:address@hidden@};export
PATH=$${GNUNET_PREFIX:address@hidden@}/bin:$$PATH;
Modified: gnunet/src/sensor/gnunet-service-sensor_reporting.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor_reporting.c 2014-08-18 10:52:40 UTC
(rev 34165)
+++ gnunet/src/sensor/gnunet-service-sensor_reporting.c 2014-08-18 11:57:41 UTC
(rev 34166)
@@ -480,7 +480,7 @@
cadetp->channel =
GNUNET_CADET_channel_create (cadet, cadetp, &pid,
GNUNET_APPLICATION_TYPE_SENSORDASHBOARD,
- GNUNET_CADET_OPTION_DEFAULT);
+ GNUNET_CADET_OPTION_RELIABLE);
cadetp->mq = GNUNET_CADET_mq_create (cadetp->channel);
GNUNET_CONTAINER_DLL_insert (cadetp_head, cadetp_tail, cadetp);
return cadetp;
@@ -585,9 +585,10 @@
{
struct GNUNET_SENSOR_AnomalyReportMessage *arm;
struct GNUNET_SENSOR_SensorInfo *sensor;
- struct AnomalyInfo *ai;
+ struct AnomalyInfo *my_anomaly_info;
struct CadetPeer *cadetp;
- int peer_in_list;
+ int peer_anomalous;
+ int peer_in_anomalous_list;
arm = (struct GNUNET_SENSOR_AnomalyReportMessage *) message;
sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &arm->sensorname_hash);
@@ -600,34 +601,39 @@
GNUNET_i2s (other));
return GNUNET_OK;
}
- ai = get_anomaly_info_by_sensor (sensor);
- GNUNET_assert (NULL != ai);
- peer_in_list =
- GNUNET_CONTAINER_multipeermap_contains (ai->anomalous_neighbors, other);
- if (GNUNET_YES == ai->anomalous)
+ my_anomaly_info = get_anomaly_info_by_sensor (sensor);
+ GNUNET_assert (NULL != my_anomaly_info);
+ peer_in_anomalous_list =
+ GNUNET_CONTAINER_multipeermap_contains
+ (my_anomaly_info->anomalous_neighbors, other);
+ peer_anomalous = ntohs (arm->anomalous);
+ if (GNUNET_YES == peer_anomalous)
{
- if (GNUNET_YES == peer_in_list)
+ if (GNUNET_YES == peer_in_anomalous_list) /* repeated positive report */
GNUNET_break_op (0);
else
- GNUNET_CONTAINER_multipeermap_put (ai->anomalous_neighbors, other, NULL,
+ GNUNET_CONTAINER_multipeermap_put (my_anomaly_info->anomalous_neighbors,
+ other, NULL,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
}
else
{
- if (GNUNET_NO == peer_in_list)
+ if (GNUNET_NO == peer_in_anomalous_list) /* repeated negative report */
GNUNET_break_op (0);
else
- GNUNET_CONTAINER_multipeermap_remove_all (ai->anomalous_neighbors,
other);
+ GNUNET_CONTAINER_multipeermap_remove_all
+ (my_anomaly_info->anomalous_neighbors, other);
}
- /* Send anomaly update to collection point */
- if (NULL != ai->sensor->collection_point &&
- GNUNET_YES == ai->sensor->report_anomalies)
+ /* Send anomaly update to collection point only if I have the same anomaly */
+ if (GNUNET_YES == my_anomaly_info->anomalous &&
+ NULL != sensor->collection_point &&
+ GNUNET_YES == sensor->report_anomalies)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending anomaly report to collection point `%s'.\n",
- GNUNET_i2s (ai->sensor->collection_point));
- cadetp = get_cadet_peer (*ai->sensor->collection_point);
- send_anomaly_report (cadetp->mq, ai, GNUNET_NO);
+ "Neighbor update triggered sending anomaly report to collection point
`%s'.\n",
+ GNUNET_i2s (sensor->collection_point));
+ cadetp = get_cadet_peer (*sensor->collection_point);
+ send_anomaly_report (cadetp->mq, my_anomaly_info, GNUNET_NO);
}
return GNUNET_OK;
}
@@ -687,6 +693,8 @@
if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer))
return;
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Core peer `%s' disconnected.\n",
+ GNUNET_i2s (peer));
neighborhood--;
corep = corep_head;
while (NULL != corep)
@@ -716,6 +724,8 @@
if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer))
return;
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to core peer `%s'.\n",
+ GNUNET_i2s (peer));
neighborhood++;
corep = GNUNET_new (struct CorePeer);
corep->peer_id = (struct GNUNET_PeerIdentity *) peer;
@@ -725,11 +735,13 @@
ai = ai_head;
while (NULL != ai)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Updating newly connected neighbor `%s' with anomalous sensor.\n",
- GNUNET_i2s (peer));
if (GNUNET_YES == ai->anomalous)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Updating newly connected neighbor `%s' with anomalous sensor.\n",
+ GNUNET_i2s (peer));
send_anomaly_report (corep->mq, ai, GNUNET_YES);
+ }
ai = ai->next;
}
}
@@ -839,7 +851,7 @@
GNUNET_YES == ai->sensor->report_anomalies)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending anomaly report to collection point `%s'.\n",
+ "Local anomaly update triggered sending anomaly report to collection
point `%s'.\n",
GNUNET_i2s (ai->sensor->collection_point));
cadetp = get_cadet_peer (*ai->sensor->collection_point);
send_anomaly_report (cadetp->mq, ai, GNUNET_NO);
Modified: gnunet/src/sensor/test_gnunet-service-sensor_reporting.c
===================================================================
--- gnunet/src/sensor/test_gnunet-service-sensor_reporting.c 2014-08-18
10:52:40 UTC (rev 34165)
+++ gnunet/src/sensor/test_gnunet-service-sensor_reporting.c 2014-08-18
11:57:41 UTC (rev 34166)
@@ -40,6 +40,12 @@
#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES,
1)
/**
+ * How long to wait between starting everything and forcing anomalies to give
+ * the peer enough time to stabilize.
+ */
+#define ANOMALY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3)
+
+/**
* Information about a test peer
*/
struct TestPeer
@@ -75,6 +81,16 @@
*/
struct GNUNET_TESTBED_Operation *sensor_op;
+ /**
+ * Sensor service handle
+ */
+ struct GNUNET_SENSOR_Handle *sensor;
+
+ /**
+ * GNUNET scheduler task that forces the anomaly after a stabilization delay
+ */
+ GNUNET_SCHEDULER_TaskIdentifier delay_task;
+
};
/**
@@ -119,14 +135,19 @@
static int started_peers = 0;
/**
+ * Number of peers reported anomalies with full list of anomalous neighbors
+ */
+static int reported_peers = 0;
+
+/**
* TESTBED operation connecting us to peerstore service
*/
-struct GNUNET_TESTBED_Operation *peerstore_op;
+static struct GNUNET_TESTBED_Operation *peerstore_op;
/**
* Handle to the peerstore service
*/
-struct GNUNET_PEERSTORE_Handle *peerstore;
+static struct GNUNET_PEERSTORE_Handle *peerstore;
/**
* Task used to shutdown / expire the test
@@ -139,6 +160,28 @@
static int ok = 1;
+static void
+destroy_peer (struct TestPeer *peer)
+{
+ if (GNUNET_SCHEDULER_NO_TASK != peer->delay_task)
+ {
+ GNUNET_SCHEDULER_cancel (peer->delay_task);
+ peer->delay_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (NULL != peer->sensor_op)
+ {
+ GNUNET_TESTBED_operation_done (peer->sensor_op);
+ peer->sensor_op = NULL;
+ }
+ if (NULL != peer->wc)
+ {
+ GNUNET_PEERSTORE_watch_cancel (peer->wc);
+ peer->wc = NULL;
+ }
+ GNUNET_free (peer);
+}
+
+
/**
* Shutdown task
*
@@ -148,7 +191,15 @@
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- //TODO: destroy list of peers
+ struct TestPeer *peer;
+
+ peer = peer_head;
+ while (NULL != peer)
+ {
+ GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, peer);
+ destroy_peer (peer);
+ peer = peer_head;
+ }
if (NULL != peerstore_op)
{
GNUNET_TESTBED_operation_done (peerstore_op);
@@ -162,7 +213,7 @@
* Write new temp sensor directory with a sensor updated with collection point
* peer id
*/
-void
+static void
write_new_sensor_dir (struct TestPeer *cp_peer)
{
struct GNUNET_CONFIGURATION_Handle *sensorcfg;
@@ -208,12 +259,33 @@
"Anomalous: %d\n" "Anomalous neigbors: %f.\n",
GNUNET_i2s (&peer->peer_id), anomaly->anomalous,
anomaly->anomalous_neighbors);
- //TODO
+ if (1 == anomaly->anomalous_neighbors)
+ reported_peers++;
+ if (reported_peers == NUM_PEERS)
+ {
+ ok = 0;
+ GNUNET_SCHEDULER_cancel (shutdown_task);
+ shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ }
return GNUNET_YES;
}
/**
+ * Task that pushes fake anomalies to running peers
+ */
+static void
+force_anomaly_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct TestPeer *peer = cls;
+
+ peer->delay_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SENSOR_force_anomaly (peer->sensor, (char *) sensor_name, GNUNET_YES,
+ NULL, NULL);
+}
+
+
+/**
* Callback to be called when sensor service connect operation is completed
*
* @param cls the callback closure from functions generating an operation
@@ -229,8 +301,9 @@
struct TestPeer *peer = cls;
struct GNUNET_SENSOR_Handle *sensor = ca_result;
- GNUNET_SENSOR_force_anomaly (sensor, (char *) sensor_name, GNUNET_YES, NULL,
- NULL);
+ peer->sensor = sensor;
+ peer->delay_task =
+ GNUNET_SCHEDULER_add_delayed (ANOMALY_DELAY, &force_anomaly_task, peer);
}
@@ -399,6 +472,7 @@
peer = GNUNET_new (struct TestPeer);
peer->testbed_peer = testbed_peer;
+ peer->delay_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_CRYPTO_get_peer_identity (pinfo->result.cfg, &peer->peer_id);
if (NULL == peer_head) /* First peer (collection point) */
{
Modified: gnunet/src/sensor/test_gnunet-service-sensor_reporting.conf
===================================================================
--- gnunet/src/sensor/test_gnunet-service-sensor_reporting.conf 2014-08-18
10:52:40 UTC (rev 34165)
+++ gnunet/src/sensor/test_gnunet-service-sensor_reporting.conf 2014-08-18
11:57:41 UTC (rev 34166)
@@ -2,7 +2,7 @@
OVERLAY_TOPOLOGY = CLIQUE
[arm]
-DEFAULTSERVICES = core
+DEFAULTSERVICES = topology dht cadet
[sensor]
SENSOR_DIR = /tmp/test-gnunet-service-sensor-reporting/
@@ -10,4 +10,10 @@
START_MONITORING = NO
START_REPORTING = YES
START_ANALYSIS = NO
-START_UPDATE = NO
\ No newline at end of file
+START_UPDATE = NO
+
+[transport]
+PLUGINS = unix
+
+[nat]
+USE_LOCALADDR = YES
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r34166 - gnunet/src/sensor,
gnunet <=