[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r28949 - in gnunet/src: include testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r28949 - in gnunet/src: include testbed |
Date: |
Mon, 2 Sep 2013 16:25:55 +0200 |
Author: harsha
Date: 2013-09-02 16:25:54 +0200 (Mon, 02 Sep 2013)
New Revision: 28949
Modified:
gnunet/src/include/gnunet_protocols.h
gnunet/src/testbed/gnunet-service-testbed.c
gnunet/src/testbed/gnunet-service-testbed_barriers.c
gnunet/src/testbed/testbed.h
gnunet/src/testbed/testbed_api_barriers.c
Log:
- more barrier code
Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h 2013-09-02 13:57:17 UTC (rev
28948)
+++ gnunet/src/include/gnunet_protocols.h 2013-09-02 14:25:54 UTC (rev
28949)
@@ -1572,21 +1572,26 @@
#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT 484
/**
+ * Message to cancel a barrier. This message is flooded to all sub-controllers
+ */
+#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL 485
+
+/**
* Message for signalling status of a barrier
*/
-#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS 485
+#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS 486
/**
* Message sent by a peer when it has reached a barrier and is waiting for it
to
* be crossed
*/
-#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT 486
+#define GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT 487
/**
* Not really a message, but for careful checks on the testbed messages; Should
* always be the maximum and never be used to send messages with this type
*/
-#define GNUNET_MESSAGE_TYPE_TESTBED_MAX 487
+#define GNUNET_MESSAGE_TYPE_TESTBED_MAX 488
/**
* The initialization message towards gnunet-testbed-helper
Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2013-09-02 13:57:17 UTC (rev
28948)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2013-09-02 14:25:54 UTC (rev
28949)
@@ -25,8 +25,8 @@
*/
#include "gnunet-service-testbed.h"
+#include "gnunet-service-testbed_barriers.h"
-
/***********/
/* Globals */
/***********/
@@ -896,8 +896,12 @@
sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
{&GST_handle_shutdown_peers, NULL,
GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS,
sizeof (struct GNUNET_TESTBED_ShutdownPeersMessage)},
- {&GST_handle_peer_reconfigure, NULL,
+ {&GST_handle_peer_reconfigure, NULL,
GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, 0},
+ {&GST_handle_barrier_init, NULL,
+ GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, 0},
+ {&GST_handle_barrier_cancel, NULL,
+ GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, 0},
{NULL, NULL, 0, 0}
};
char *logfile;
Modified: gnunet/src/testbed/gnunet-service-testbed_barriers.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed_barriers.c 2013-09-02
13:57:17 UTC (rev 28948)
+++ gnunet/src/testbed/gnunet-service-testbed_barriers.c 2013-09-02
14:25:54 UTC (rev 28949)
@@ -25,7 +25,9 @@
*/
#include "gnunet-service-testbed.h"
+#include "gnunet-service-testbed_barriers.h"
+
/**
* timeout for outgoing message transmissions in seconds
*/
@@ -320,8 +322,7 @@
&barrier->hash,
barrier));
GNUNET_free (barrier->name);
- if (NULL != barrier->client)
- GNUNET_SERVER_client_drop (barrier->client);
+ GNUNET_SERVER_client_drop (barrier->client);
GNUNET_free (barrier);
}
@@ -346,38 +347,56 @@
/**
- * Sends a barrier failed message
+ * Send a status message about a barrier to the given client
*
- * @param barrier the corresponding barrier
+ * @param client the client to send the message to
+ * @param name the barrier name
* @param status the status of the barrier
* @param emsg the error message; should be non-NULL for
* status=BARRIER_STATUS_ERROR
*/
static void
-send_barrier_status_msg (struct Barrier *barrier,
- enum GNUNET_TESTBED_BarrierStatus status,
- const char *emsg)
+send_client_status_msg (struct GNUNET_SERVER_Client *client,
+ const char *name,
+ enum GNUNET_TESTBED_BarrierStatus status,
+ const char *emsg)
{
struct GNUNET_TESTBED_BarrierStatusMsg *msg;
size_t name_len;
uint16_t msize;
GNUNET_assert ((NULL == emsg) || (BARRIER_STATUS_ERROR == status));
- name_len = strlen (barrier->name) + 1;
+ name_len = strlen (name) + 1;
msize = sizeof (struct GNUNET_TESTBED_BarrierStatusMsg)
+ name_len
+ (NULL == emsg) ? 0 : strlen (emsg) + 1;
msg = GNUNET_malloc (msize);
msg->status = htons (status);
- msg->name_len = htons (name_len);
- (void) memcpy (msg->data, barrier->name, name_len);
+ msg->name_len = htons ((uint16_t) name_len);
+ (void) memcpy (msg->data, name, name_len);
if (NULL != emsg)
(void) memcpy (msg->data + name_len, emsg, strlen (emsg) + 1);
- GST_queue_message (barrier->client, &msg->header);
+ GST_queue_message (client, &msg->header);
}
+/**
+ * Sends a barrier failed message
+ *
+ * @param barrier the corresponding barrier
+ * @param emsg the error message; should be non-NULL for
+ * status=BARRIER_STATUS_ERROR
+ */
+static void
+send_barrier_status_msg (struct Barrier *barrier, const char *emsg)
+{
+ GNUNET_assert (0 != barrier->status);
+ send_client_status_msg (barrier->client, barrier->name,
+ barrier->status, emsg);
+}
+
+
/**
* Task for sending barrier crossed notifications to waiting client
*
@@ -501,7 +520,6 @@
GNUNET_CONTAINER_DLL_remove (barrier->head, barrier->tail, client_ctx);
if (NULL != client_ctx->tx)
GNUNET_SERVER_notify_transmit_ready_cancel (client_ctx->tx);
-
}
@@ -573,21 +591,38 @@
cancel_wrappers (barrier);
if (NULL == emsg)
emsg = "Initialisation failed at a sub-controller";
- send_barrier_status_msg (barrier, BARRIER_STATUS_ERROR, emsg);
+ barrier->status = BARRIER_STATUS_ERROR;
+ send_barrier_status_msg (barrier, emsg);
return;
}
switch (status)
{
case BARRIER_STATUS_CROSSED:
+ if (BARRIER_STATUS_INITIALISED != barrier->status)
+ {
+ GNUNET_break_op (0);
+ return;
+ }
barrier->num_wbarriers_reached++;
if ((barrier->num_wbarriers_reached == barrier->num_wbarriers)
&& (LOCAL_QUORUM_REACHED (barrier)))
- send_barrier_status_msg (barrier, BARRIER_STATUS_CROSSED, NULL);
+ {
+ barrier->status = BARRIER_STATUS_CROSSED;
+ send_barrier_status_msg (barrier, NULL);
+ }
break;
case BARRIER_STATUS_INITIALISED:
+ if (0 != barrier->status)
+ {
+ GNUNET_break_op (0);
+ return;
+ }
barrier->num_wbarriers_inited++;
if (barrier->num_wbarriers_inited == barrier->num_wbarriers)
- send_barrier_status_msg (barrier, BARRIER_STATUS_INITIALISED, NULL);
+ {
+ barrier->status = BARRIER_STATUS_INITIALISED;
+ send_barrier_status_msg (barrier, NULL);
+ }
break;
case BARRIER_STATUS_ERROR:
GNUNET_assert (0);
@@ -611,7 +646,8 @@
barrier->nslaves--;
barrier->timedout = GNUNET_YES;
cancel_wrappers (barrier);
- send_barrier_status_msg (barrier, BARRIER_STATUS_ERROR,
+ barrier->status = BARRIER_STATUS_ERROR;
+ send_barrier_status_msg (barrier,
"Timedout while propagating barrier
initialisation\n");
remove_barrier (barrier);
}
@@ -634,13 +670,12 @@
const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_TESTBED_BarrierInit *msg;
- const char *name;
+ char *name;
struct Barrier *barrier;
struct Slave *slave;
struct WBarrier *wrapper;
struct GNUNET_HashCode hash;
size_t name_len;
- uint64_t op_id;
unsigned int cnt;
uint16_t msize;
@@ -664,22 +699,24 @@
return;
}
msg = (const struct GNUNET_TESTBED_BarrierInit *) message;
- op_id = GNUNET_ntohll (msg->op_id);
- name = msg->name;
name_len = (size_t) msize - sizeof (struct GNUNET_TESTBED_BarrierInit);
+ name = GNUNET_malloc (name_len + 1);
+ (void) memcpy (name, msg->name, name_len);
+ name[name_len] = '\0';
GNUNET_CRYPTO_hash (name, name_len, &hash);
if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (barrier_map,
&hash))
{
- GST_send_operation_fail_msg (client, op_id, "Barrier already initialised");
+
+ send_client_status_msg (client, name, BARRIER_STATUS_ERROR,
+ "A barrier with the same name already exists");
+ GNUNET_free (name);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
barrier = GNUNET_malloc (sizeof (struct Barrier));
(void) memcpy (&barrier->hash, &hash, sizeof (struct GNUNET_HashCode));
barrier->quorum = msg->quorum;
- barrier->name = GNUNET_malloc (name_len + 1);
- barrier->name[name_len] = '\0';
- (void) memcpy (barrier->name, name, name_len);
+ barrier->name = name;
barrier->client = client;
GNUNET_SERVER_client_keep (client);
GNUNET_assert (GNUNET_OK ==
@@ -697,7 +734,7 @@
{
GNUNET_break (0);/* May happen when we are connecting to the controller
*/
continue;
- }
+ }
wrapper = GNUNET_malloc (sizeof (struct WBarrier));
wrapper->barrier = barrier;
GNUNET_CONTAINER_DLL_insert_tail (barrier->whead, barrier->wtail, wrapper);
@@ -708,11 +745,33 @@
wrapper);
}
if (NULL == barrier->whead) /* No further propagation */
- send_barrier_status_msg (barrier, BARRIER_STATUS_INITIALISED, NULL);
- else
+ {
+ barrier->status = BARRIER_STATUS_INITIALISED;
+ send_barrier_status_msg (barrier, NULL);
+ }else
barrier->tout_task = GNUNET_SCHEDULER_add_delayed (MESSAGE_SEND_TIMEOUT
(30),
&fwd_tout_barrier_init,
barrier);
}
+
+/**
+ * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL messages.
This
+ * message should always come from a parent controller or the testbed API if we
+ * are the root controller.
+ *
+ * This handler is queued in the main service and will handle the messages sent
+ * either from the testbed driver or from a high level controller
+ *
+ * @param cls NULL
+ * @param client identification of the client
+ * @param message the actual message
+ */
+void
+GST_handle_barrier_cancel (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
+ GNUNET_break (0);
+}
+
/* end of gnunet-service-testbed_barriers.c */
Modified: gnunet/src/testbed/testbed.h
===================================================================
--- gnunet/src/testbed/testbed.h 2013-09-02 13:57:17 UTC (rev 28948)
+++ gnunet/src/testbed/testbed.h 2013-09-02 14:25:54 UTC (rev 28949)
@@ -784,22 +784,29 @@
struct GNUNET_MessageHeader header;
/**
- * Unused. Only of alignment.
+ * The quorum percentage needed for crossing the barrier
*/
- uint32_t unused;
-
+ uint8_t quorum;
+
/**
- * The operation id
+ * name of the barrier. Non NULL-terminated.
*/
- uint64_t op_id;
-
+ char name[0];
+};
+
+
+/**
+ * Message to cancel a barrier
+ */
+struct GNUNET_TESTBED_BarrierCancel
+{
/**
- * The quorum percentage needed for crossing the barrier
+ * Type is GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL
*/
- uint8_t quorum;
+ struct GNUNET_MessageHeader header;
/**
- * name of the barrier. Non NULL-terminated.
+ * The barrier name. Non NULL terminated
*/
char name[0];
};
Modified: gnunet/src/testbed/testbed_api_barriers.c
===================================================================
--- gnunet/src/testbed/testbed_api_barriers.c 2013-09-02 13:57:17 UTC (rev
28948)
+++ gnunet/src/testbed/testbed_api_barriers.c 2013-09-02 14:25:54 UTC (rev
28949)
@@ -181,9 +181,11 @@
unsigned int quorum,
GNUNET_TESTBED_barrier_status_cb cb, void *cls)
{
+ struct GNUNET_TESTBED_BarrierInit *msg;
struct GNUNET_TESTBED_Barrier *barrier;
struct GNUNET_HashCode key;
size_t name_len;
+ uint16_t msize;
GNUNET_assert (quorum <= 100);
GNUNET_assert (NULL != cb);
@@ -199,6 +201,7 @@
return NULL;
}
barrier = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Barrier));
+ barrier->c = controller;
barrier->name = GNUNET_strdup (name);
barrier->cb = cb;
barrier->cls = cls;
@@ -207,6 +210,13 @@
GNUNET_CONTAINER_multihashmap_put (barrier_map, &barrier->key,
barrier,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ msize = name_len + sizeof (struct GNUNET_TESTBED_BarrierInit);
+ msg = GNUNET_malloc (msize);
+ msg->header.size = htons (msize);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT);
+ msg->quorum = (uint8_t) quorum;
+ (void) memcpy (msg->name, barrier->name, name_len);
+ GNUNET_TESTBED_queue_message_ (barrier->c, &msg->header);
return barrier;
}
@@ -219,6 +229,15 @@
void
GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier)
{
+ struct GNUNET_TESTBED_BarrierCancel *msg;
+ uint16_t msize;
+
+ msize = sizeof (struct GNUNET_TESTBED_BarrierCancel) + strlen
(barrier->name);
+ msg = GNUNET_malloc (msize);
+ msg->header.size = htons (msize);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL);
+ (void) memcpy (msg->name, barrier->name, strlen (barrier->name));
+ GNUNET_TESTBED_queue_message_ (barrier->c, &msg->header);
barrier_remove (barrier);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r28949 - in gnunet/src: include testbed,
gnunet <=