};
+struct ConnectionContext
+{
+
+ struct PeerInfo *p1;
+
+ struct PeerInfo *p2;
+
+};
+
/**
* Name of the configuration file used
prompt_peer_disconnection ();
+/**
+ * Destroy a DisconnectionContext struct
+ */
+static void
+destroy_dc (struct DisconnectionContext *dc)
+{
+ if (NULL != dc->blacklist)
+ {
+ GNUNET_TRANSPORT_blacklist_cancel (dc->blacklist);
+ dc->blacklist = NULL;
+ }
+ if (NULL != dc->p1_transport_op)
+ {
+ GNUNET_TESTBED_operation_done (dc->p1_transport_op);
+ dc->p1_transport_op = NULL;
+ }
+ GNUNET_free (dc);
+}
+
+
/**
* Do clean up and shutdown scheduler
*/
while (NULL != dc)
{
GNUNET_CONTAINER_DLL_remove (dc_head, dc_tail, dc);
- if (NULL != dc->blacklist)
- {
- GNUNET_TRANSPORT_blacklist_cancel (dc->blacklist);
- dc->blacklist = NULL;
- }
- if (NULL != dc->p1_transport_op)
- {
- GNUNET_TESTBED_operation_done (dc->p1_transport_op);
- dc->p1_transport_op = NULL;
- }
- GNUNET_free (dc);
+ destroy_dc (dc);
dc = dc_head;
}
if (NULL != peerstore_op)
/**************************** END DISCONNECT PEERS ***************************/
/*****************************************************************************/
+/*****************************************************************************/
+/******************************* CONNECT PEERS *******************************/
+/*****************************************************************************/
+
+/**
+ * Callback to be called when overlay connection operation is completed
+ *
+ * @param cls the callback closure from functions generating an operation
+ * @param op the operation that has been finished
+ * @param emsg error message in case the operation has failed; will be NULL if
+ * operation has executed successfully.
+ */
+static void
+overlay_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
+ const char *emsg)
+{
+ struct ConnectionContext *cc = cls;
+
+ if (NULL != emsg)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR: %s.\n", emsg);
+ GNUNET_assert (0);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer connection request sent: %d,%d\n",
+ cc->p1->index, cc->p2->index);
+ GNUNET_free (cc);
+ GNUNET_TESTBED_operation_done (op);
+}
+
+
+/**
+ * Connect two peers together
+ */
+static void
+connect_peers (struct PeerInfo *p1, struct PeerInfo *p2)
+{
+ struct DisconnectionContext *dc;
+ struct ConnectionContext *cc;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connect_peers()\n");
+ /* Check if we have a disconnection request before */
+ dc = dc_head;
+ while (NULL != dc)
+ {
+ if ((dc->p1 == p1 && dc->p2 == p2) || (dc->p1 == p2 && dc->p2 == p1))
+ break;
+ dc = dc_head->next;
+ }
+ if (NULL != dc)
+ {
+ GNUNET_CONTAINER_DLL_remove (dc_head, dc_tail, dc);
+ destroy_dc (dc);
+ }
+ /* Connect peers using testbed */
+ cc = GNUNET_new (struct ConnectionContext);
+ cc->p1 = p1;
+ cc->p2 = p2;
+ GNUNET_TESTBED_overlay_connect (cc, &overlay_connect_cb, cc,
+ p1->testbed_peer, p2->testbed_peer);
+}
+
+/*****************************************************************************/
+/****************************** END CONNECT PEERS ****************************/
+/*****************************************************************************/
/**
* Function called with each file/folder inside a directory that is being copied.
}
+/**
+ * Prompty the user to reconnect two peers
+ */
+static void
+prompt_peer_reconnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ int p1;
+ int p2;
+ char line[10];
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connect peers (e.g. '0,2') or empty line to execute:\n");
+ if (NULL == fgets (line, sizeof (line), stdin) || 1 == strlen (line))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Continuing.\n");
+ return;
+ }
+ if (2 != sscanf (line, "%d,%d", &p1, &p2) || p1 >= num_peers ||
+ p2 >= num_peers || p1 < 0 || p2 < 0 || p1 == p2)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Invalid input.\n");
+ prompt_peer_reconnection (NULL, NULL);
+ return;
+ }
+ connect_peers (&all_peers_info[p1], &all_peers_info[p2]);
+ prompt_peer_reconnection (NULL, NULL);
+}
+
+
/**
* Prompt the user to disconnect two peers
*/
"Disconnect peers (e.g. '0,2') or empty line to execute:\n");
if (NULL == fgets (line, sizeof (line), stdin) || 1 == strlen (line))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Continuing.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will prompt for reconnection in 1 min.\n");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1) ,&prompt_peer_reconnection, NULL);
return;
}
if (2 != sscanf (line, "%d,%d", &p1, &p2) || p1 >= num_peers ||
{
model->anomalous = GNUNET_YES;
LOG (GNUNET_ERROR_TYPE_WARNING,
- "Anomaly state started for sensor `%s'.\n", model->sensor->name);
+ "Anomaly state started for sensor `%s', value: %f.\n",
+ model->sensor->name, val);
SENSOR_reporting_anomaly_update (model->sensor, model->anomalous);
}
}
model->negative_count >= confirmation_count)
{
model->anomalous = GNUNET_NO;
- LOG (GNUNET_ERROR_TYPE_INFO, "Anomaly state stopped for sensor `%s'.\n",
- model->sensor->name);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Anomaly state stopped for sensor `%s', value: %f.\n",
+ model->sensor->name, val);
SENSOR_reporting_anomaly_update (model->sensor, model->anomalous);
}
}