summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-03-08 17:06:49 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-03-08 17:06:49 +0000
commitd336aef5c16128f72d4d6e226148e2520841049f (patch)
tree22dc982b681a412bd7d719ffe8d9fb475a350ea5
parenta61c2d6c9375867837816f62ca13c474026fd2f1 (diff)
- cleanup peers after shutdown operation
-rw-r--r--src/testbed/testbed_api.c3
-rw-r--r--src/testbed/testbed_api_peers.c53
-rw-r--r--src/testbed/testbed_api_peers.h35
3 files changed, 91 insertions, 0 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index 7011e6506..0c891b447 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -258,6 +258,7 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
struct GNUNET_TESTBED_Peer *peer;
peer = opc->data;
+ GNUNET_TESTBED_peer_deregister_ (peer);
GNUNET_free (peer);
opc->data = NULL;
//PEERDESTROYDATA
@@ -270,6 +271,7 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
data = opc->data;
GNUNET_free (data); /* FIXME: Decide whether we call data->op_cb */
opc->data = NULL;
+ GNUNET_TESTBED_cleanup_peers_ ();
}
break;
default:
@@ -330,6 +332,7 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
peer = data->peer;
GNUNET_assert (peer->unique_id == ntohl (msg->peer_id));
peer->state = PS_CREATED;
+ GNUNET_TESTBED_peer_register_ (peer);
cb = data->cb;
cls = data->cls;
GNUNET_free (opc->data);
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 39e4b596a..9ad8366f2 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -33,6 +33,59 @@
#include "testbed_api_hosts.h"
#include "testbed_api_operations.h"
+
+/**
+ * Peer list DLL head
+ */
+static struct GNUNET_TESTBED_Peer *peer_list_head;
+
+/**
+ * Peer list DLL tail
+ */
+static struct GNUNET_TESTBED_Peer *peer_list_tail;
+
+
+/**
+ * Adds a peer to the peer list
+ *
+ * @param peer the peer to add to the peer list
+ */
+void
+GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer)
+{
+ GNUNET_CONTAINER_DLL_insert_tail (peer_list_head, peer_list_tail, peer);
+}
+
+
+/**
+ * Removes a peer from the peer list
+ *
+ * @param peer the peer to remove
+ */
+void
+GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer)
+{
+ GNUNET_CONTAINER_DLL_remove (peer_list_head, peer_list_tail, peer);
+}
+
+
+/**
+ * Frees all peers
+ */
+void
+GNUNET_TESTBED_cleanup_peers_ (void)
+{
+ struct GNUNET_TESTBED_Peer *peer;
+
+ while (NULL != (peer = peer_list_head))
+ {
+ GNUNET_TESTBED_peer_deregister_ (peer);
+ GNUNET_free (peer);
+ }
+}
+
+
+
/**
* Function to call to start a peer_create type operation once all
* queues the operation is part of declare that the
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h
index 8598cc177..49f875607 100644
--- a/src/testbed/testbed_api_peers.h
+++ b/src/testbed/testbed_api_peers.h
@@ -66,6 +66,16 @@ enum PeerState
struct GNUNET_TESTBED_Peer
{
/**
+ * peer list DLL
+ */
+ struct GNUNET_TESTBED_Peer *next;
+
+ /**
+ * peer list DLL
+ */
+ struct GNUNET_TESTBED_Peer *prev;
+
+ /**
* Our controller context (not necessarily the controller
* that is responsible for starting/running the peer!).
*/
@@ -248,5 +258,30 @@ struct GNUNET_TESTBED_PeerGetConfigurationMessage *
GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id,
uint64_t operation_id);
+
+/**
+ * Adds a peer to the peer list
+ *
+ * @param peer the peer to add to the peer list
+ */
+void
+GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer);
+
+
+/**
+ * Removes a peer from the peer list
+ *
+ * @param peer the peer to remove
+ */
+void
+GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer);
+
+
+/**
+ * Frees all peers
+ */
+void
+GNUNET_TESTBED_cleanup_peers_ (void);
+
#endif
/* end of testbed_api_peers.h */