[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r29563 - in gnunet/src: include psycstore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r29563 - in gnunet/src: include psycstore |
Date: |
Wed, 25 Sep 2013 19:46:03 +0200 |
Author: tg
Date: 2013-09-25 19:46:03 +0200 (Wed, 25 Sep 2013)
New Revision: 29563
Modified:
gnunet/src/include/gnunet_psycstore_plugin.h
gnunet/src/include/gnunet_psycstore_service.h
gnunet/src/psycstore/gnunet-service-psycstore.c
gnunet/src/psycstore/plugin_psycstore_sqlite.c
gnunet/src/psycstore/psycstore.h
gnunet/src/psycstore/psycstore_api.c
gnunet/src/psycstore/test_plugin_psycstore.c
gnunet/src/psycstore/test_psycstore.c
Log:
psycstore: single counters function for master & slave
Modified: gnunet/src/include/gnunet_psycstore_plugin.h
===================================================================
--- gnunet/src/include/gnunet_psycstore_plugin.h 2013-09-25 17:45:59 UTC
(rev 29562)
+++ gnunet/src/include/gnunet_psycstore_plugin.h 2013-09-25 17:46:03 UTC
(rev 29563)
@@ -158,30 +158,30 @@
void *cb_cls);
/**
- * Retrieve latest values of counters for a channel master.
+ * Retrieve the max. values of message counters for a channel.
*
- * @see GNUNET_PSYCSTORE_counters_get_master()
+ * @see GNUNET_PSYCSTORE_counters_get()
*
* @return #GNUNET_OK on success, else #GNUNET_SYSERR
*/
int
- (*counters_get_master) (void *cls,
- const struct GNUNET_CRYPTO_EccPublicSignKey
*channel_key,
- uint64_t *fragment_id,
- uint64_t *message_id,
- uint64_t *group_generation);
+ (*counters_message_get) (void *cls,
+ const struct GNUNET_CRYPTO_EccPublicSignKey
*channel_key,
+ uint64_t *max_fragment_id,
+ uint64_t *max_message_id,
+ uint64_t *max_group_generation);
/**
- * Retrieve latest values of counters for a channel slave.
+ * Retrieve the max. values of state counters for a channel.
*
- * @see GNUNET_PSYCSTORE_counters_get_slave()
+ * @see GNUNET_PSYCSTORE_counters_get()
*
* @return #GNUNET_OK on success, else #GNUNET_SYSERR
*/
int
- (*counters_get_slave) (void *cls,
+ (*counters_state_get) (void *cls,
const struct GNUNET_CRYPTO_EccPublicSignKey
*channel_key,
- uint64_t *max_state_msg_id);
+ uint64_t *max_state_message_id);
/**
Modified: gnunet/src/include/gnunet_psycstore_service.h
===================================================================
--- gnunet/src/include/gnunet_psycstore_service.h 2013-09-25 17:45:59 UTC
(rev 29562)
+++ gnunet/src/include/gnunet_psycstore_service.h 2013-09-25 17:46:03 UTC
(rev 29563)
@@ -282,75 +282,46 @@
/**
* Callback used to return the latest value of counters for the channel master.
*
- * @see GNUNET_PSYCSTORE_counters_get_master()
+ * @see GNUNET_PSYCSTORE_counters_get()
*
* @param cls Closure.
- * @param fragment_id Latest message fragment ID, used by multicast.
- * @param message_id Latest message ID, used by PSYC.
- * @param group_generation Latest group generation, used by PSYC.
+ * @param max_fragment_id Latest message fragment ID, used by multicast.
+ * @param max_message_id Latest message ID, used by PSYC.
+ * @param max_group_generation Latest group generation, used by PSYC.
+ * @param max_state_message_id Latest message ID containing state modifiers
that
+ * was applied to the state store. Used for the state sync process.
*/
typedef void
-(*GNUNET_PSYCSTORE_MasterCountersCallback) (void *cls,
- uint64_t fragment_id,
- uint64_t message_id,
- uint64_t group_generation);
+(*GNUNET_PSYCSTORE_CountersCallback) (void *cls,
+ uint64_t max_fragment_id,
+ uint64_t max_message_id,
+ uint64_t max_group_generation,
+ uint64_t max_state_message_id);
/**
- * Callback used to return the latest value of counters for a channel slave.
+ * Retrieve latest values of counters for a channel.
*
- * @see GNUNET_PSYCSTORE_counters_get_slave()
+ * The current value of counters are needed
+ * - when a channel master is restarted, so that it can continue incrementing
+ * the counters from their last value.
+ * - when a channel slave rejoins and starts the state synchronization process.
*
- * @param cls Closure.
- * @param max_state_msg_id Latest message ID containing state modifiers that
was
- * applied to the state store. Used for the state sync process.
- */
-typedef void
-(*GNUNET_PSYCSTORE_SlaveCountersCallback) (void *cls,
- uint64_t max_state_msg_id);
-
-
-/**
- * Retrieve latest values of counters for a channel master.
- *
- * The current value of counters are needed when a channel master is restarted,
- * so that it can continue incrementing the counters from their last value.
- *
* @param h Handle for the PSYCstore.
* @param channel_key Public key that identifies the channel.
- * @param mccb Callback to call with the result.
- * @param mccb_cls Closure for the callback.
+ * @param ccb Callback to call with the result.
+ * @param ccb_cls Closure for the callback.
*
* @return Handle that can be used to cancel the operation.
*/
struct GNUNET_PSYCSTORE_OperationHandle *
-GNUNET_PSYCSTORE_counters_get_master (struct GNUNET_PSYCSTORE_Handle *h,
- struct GNUNET_CRYPTO_EccPublicSignKey
*channel_key,
- GNUNET_PSYCSTORE_MasterCountersCallback
mccb,
- void *mccb_cls);
+GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
+ struct GNUNET_CRYPTO_EccPublicSignKey
*channel_key,
+ GNUNET_PSYCSTORE_CountersCallback ccb,
+ void *ccb_cls);
/**
- * Retrieve latest values of counters for a channel slave.
- *
- * The current value of counters are needed when a channel slave rejoins
- * and starts the state synchronization process.
- *
- * @param h Handle for the PSYCstore.
- * @param channel_key Public key that identifies the channel.
- * @param sccb Callback to call with the result.
- * @param sccb_cls Closure for the callback.
- *
- * @return Handle that can be used to cancel the operation.
- */
-struct GNUNET_PSYCSTORE_OperationHandle *
-GNUNET_PSYCSTORE_counters_get_slave (struct GNUNET_PSYCSTORE_Handle *h,
- struct GNUNET_CRYPTO_EccPublicSignKey
*channel_key,
- GNUNET_PSYCSTORE_SlaveCountersCallback
sccb,
- void *sccb_cls);
-
-
-/**
* Apply modifiers of a message to the current channel state.
*
* An error is returned if there are missing messages containing state
Modified: gnunet/src/psycstore/gnunet-service-psycstore.c
===================================================================
--- gnunet/src/psycstore/gnunet-service-psycstore.c 2013-09-25 17:45:59 UTC
(rev 29562)
+++ gnunet/src/psycstore/gnunet-service-psycstore.c 2013-09-25 17:46:03 UTC
(rev 29563)
@@ -170,7 +170,7 @@
res->op_id = sc->op_id;
res->name_size = htons (name_size);
memcpy (&res[1], name, name_size);
- memcpy ((void *) &res[1] + name_size, value, value_size);
+ memcpy ((char *) &res[1] + name_size, value, value_size);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending state variable %s to client\n", name);
GNUNET_SERVER_notification_context_add (nc, sc->client);
@@ -334,19 +334,21 @@
static void
-handle_counters_get_master (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *msg)
+handle_counters_get (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *msg)
{
const struct OperationRequest *req = (const struct OperationRequest *) msg;
- struct MasterCountersResult res = { {0} };
+ struct CountersResult res = { {0} };
- int ret = db->counters_get_master (db->cls, &req->channel_key,
- &res.fragment_id, &res.message_id,
- &res.group_generation);
+ int ret = db->counters_message_get (db->cls, &req->channel_key,
+ &res.max_fragment_id,
&res.max_message_id,
+ &res.max_group_generation);
switch (ret)
{
case GNUNET_YES:
+ ret = db->counters_state_get (db->cls, &req->channel_key,
+ &res.max_state_message_id);
case GNUNET_NO:
break;
default:
@@ -354,14 +356,14 @@
_("Failed to get master counters!\n"));
}
- res.header.type
- = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_MASTER);
+ res.header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS);
res.header.size = htons (sizeof (res));
res.result_code = htonl (ret);
res.op_id = req->op_id;
- res.fragment_id = GNUNET_htonll (res.fragment_id);
- res.message_id = GNUNET_htonll (res.message_id);
- res.group_generation = GNUNET_htonll (res.group_generation);
+ res.max_fragment_id = GNUNET_htonll (res.max_fragment_id);
+ res.max_message_id = GNUNET_htonll (res.max_message_id);
+ res.max_group_generation = GNUNET_htonll (res.max_group_generation);
+ res.max_state_message_id = GNUNET_htonll (res.max_state_message_id);
GNUNET_SERVER_notification_context_add (nc, client);
GNUNET_SERVER_notification_context_unicast (nc, client, &res.header,
@@ -371,42 +373,6 @@
}
-static void
-handle_counters_get_slave (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *msg)
-{
- const struct OperationRequest *req = (const struct OperationRequest *) msg;
- struct SlaveCountersResult res = { {0} };
-
- int ret = db->counters_get_slave (db->cls, &req->channel_key,
- &res.max_known_msg_id);
-
- switch (ret)
- {
- case GNUNET_YES:
- case GNUNET_NO:
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to get slave counters!\n"));
- }
-
- res.header.type
- = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_SLAVE);
- res.header.size = htons (sizeof (res));
- res.result_code = htonl (ret);
- res.op_id = req->op_id;
- res.max_known_msg_id = GNUNET_htonll (res.max_known_msg_id);
-
- GNUNET_SERVER_notification_context_add (nc, client);
- GNUNET_SERVER_notification_context_unicast (nc, client, &res.header,
- GNUNET_NO);
-
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
-}
-
-
/* FIXME: stop processing further state modify messages after an error */
static void
handle_state_modify (void *cls,
@@ -697,14 +663,10 @@
GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET_FRAGMENT,
sizeof (struct MessageGetFragmentRequest) },
- { &handle_counters_get_master, NULL,
- GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET_MASTER,
+ { &handle_counters_get, NULL,
+ GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET,
sizeof (struct OperationRequest) },
- { &handle_counters_get_slave, NULL,
- GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET_SLAVE,
- sizeof (struct OperationRequest) },
-
{ &handle_state_modify, NULL,
GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY, 0 },
Modified: gnunet/src/psycstore/plugin_psycstore_sqlite.c
===================================================================
--- gnunet/src/psycstore/plugin_psycstore_sqlite.c 2013-09-25 17:45:59 UTC
(rev 29562)
+++ gnunet/src/psycstore/plugin_psycstore_sqlite.c 2013-09-25 17:46:03 UTC
(rev 29563)
@@ -143,14 +143,14 @@
sqlite3_stmt *select_message_fragment;
/**
- * Precompiled SQL for counters_get_master()
+ * Precompiled SQL for counters_get_message()
*/
- sqlite3_stmt *select_counters_master;
+ sqlite3_stmt *select_counters_message;
/**
- * Precompiled SQL for counters_get_slave()
+ * Precompiled SQL for counters_get_state()
*/
- sqlite3_stmt *select_max_state_message_id;
+ sqlite3_stmt *select_counters_state;
/**
* Precompiled SQL for state_modify_end()
@@ -482,13 +482,13 @@
"FROM messages\n"
"WHERE channel_id = (SELECT id FROM channels WHERE pub_key =
?)\n"
"ORDER BY fragment_id DESC LIMIT 1;",
- &plugin->select_counters_master);
+ &plugin->select_counters_message);
sql_prepare (plugin->dbh,
"SELECT max_state_message_id\n"
"FROM channels\n"
"WHERE pub_key = ? AND max_state_message_id IS NOT NULL;",
- &plugin->select_max_state_message_id);
+ &plugin->select_counters_state);
sql_prepare (plugin->dbh,
"UPDATE channels\n"
@@ -1205,21 +1205,21 @@
}
/**
- * Retrieve latest values of counters for a channel master.
+ * Retrieve the max. values of message counters for a channel.
*
- * @see GNUNET_PSYCSTORE_counters_get_master()
+ * @see GNUNET_PSYCSTORE_counters_get()
*
* @return #GNUNET_OK on success, else #GNUNET_SYSERR
*/
static int
-counters_get_master (void *cls,
- const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
- uint64_t *fragment_id,
- uint64_t *message_id,
- uint64_t *group_generation)
+counters_message_get (void *cls,
+ const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+ uint64_t *max_fragment_id,
+ uint64_t *max_message_id,
+ uint64_t *max_group_generation)
{
struct Plugin *plugin = cls;
- sqlite3_stmt *stmt = plugin->select_counters_master;
+ sqlite3_stmt *stmt = plugin->select_counters_message;
int ret = GNUNET_SYSERR;
if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key,
@@ -1237,9 +1237,9 @@
ret = GNUNET_NO;
break;
case SQLITE_ROW:
- *fragment_id = sqlite3_column_int64 (stmt, 0);
- *message_id = sqlite3_column_int64 (stmt, 1);
- *group_generation = sqlite3_column_int64 (stmt, 2);
+ *max_fragment_id = sqlite3_column_int64 (stmt, 0);
+ *max_message_id = sqlite3_column_int64 (stmt, 1);
+ *max_group_generation = sqlite3_column_int64 (stmt, 2);
ret = GNUNET_OK;
break;
default:
@@ -1258,19 +1258,19 @@
}
/**
- * Retrieve latest values of counters for a channel slave.
+ * Retrieve the max. values of state counters for a channel.
*
- * @see GNUNET_PSYCSTORE_counters_get_slave()
+ * @see GNUNET_PSYCSTORE_counters_get()
*
* @return #GNUNET_OK on success, else #GNUNET_SYSERR
*/
static int
-counters_get_slave (void *cls,
+counters_state_get (void *cls,
const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
- uint64_t *max_state_msg_id)
+ uint64_t *max_state_message_id)
{
struct Plugin *plugin = cls;
- sqlite3_stmt *stmt = plugin->select_max_state_message_id;
+ sqlite3_stmt *stmt = plugin->select_counters_state;
int ret = GNUNET_SYSERR;
if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key,
@@ -1288,7 +1288,7 @@
ret = GNUNET_NO;
break;
case SQLITE_ROW:
- *max_state_msg_id = sqlite3_column_int64 (stmt, 0);
+ *max_state_message_id = sqlite3_column_int64 (stmt, 0);
ret = GNUNET_OK;
break;
default:
@@ -1779,8 +1779,8 @@
api->fragment_get = &fragment_get;
api->message_get = &message_get;
api->message_get_fragment = &message_get_fragment;
- api->counters_get_master = &counters_get_master;
- api->counters_get_slave = &counters_get_slave;
+ api->counters_message_get = &counters_message_get;
+ api->counters_state_get = &counters_state_get;
api->state_modify_begin = &state_modify_begin;
api->state_modify_set = &state_modify_set;
api->state_modify_end = &state_modify_end;
Modified: gnunet/src/psycstore/psycstore.h
===================================================================
--- gnunet/src/psycstore/psycstore.h 2013-09-25 17:45:59 UTC (rev 29562)
+++ gnunet/src/psycstore/psycstore.h 2013-09-25 17:46:03 UTC (rev 29563)
@@ -43,12 +43,15 @@
struct GNUNET_MessageHeader header;
/**
+ * Operation ID.
+ */
+ uint32_t op_id GNUNET_PACKED;
+
+ /**
* Status code for the operation.
*/
int64_t result_code GNUNET_PACKED;
- uint32_t op_id GNUNET_PACKED;
-
/* followed by 0-terminated error message (on error) */
};
@@ -57,52 +60,32 @@
/**
* Answer from service to client about master counters.
*
- * @see GNUNET_PSYCSTORE_counters_get_master()
+ * @see GNUNET_PSYCSTORE_counters_get()
*/
-struct MasterCountersResult
+struct CountersResult
{
/**
- * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_MASTER
+ * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS
*/
struct GNUNET_MessageHeader header;
- uint64_t fragment_id GNUNET_PACKED;
-
- uint64_t message_id GNUNET_PACKED;
-
- uint64_t group_generation GNUNET_PACKED;
-
/**
- * Status code for the operation.
+ * Operation ID.
*/
- int64_t result_code GNUNET_PACKED;
-
uint32_t op_id GNUNET_PACKED;
-};
-
-
-/**
- * Answer from service to client about slave counters.
- *
- * @see GNUNET_PSYCSTORE_counters_get_slave()
- */
-struct SlaveCountersResult
-{
/**
- * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_SLAVE
- */
- struct GNUNET_MessageHeader header;
-
- uint64_t max_known_msg_id GNUNET_PACKED;
-
- /**
* Status code for the operation.
*/
int64_t result_code GNUNET_PACKED;
- uint32_t op_id GNUNET_PACKED;
+ uint64_t max_fragment_id GNUNET_PACKED;
+ uint64_t max_message_id GNUNET_PACKED;
+
+ uint64_t max_group_generation GNUNET_PACKED;
+
+ uint64_t max_state_message_id GNUNET_PACKED;
};
@@ -116,6 +99,9 @@
*/
struct GNUNET_MessageHeader header;
+ /**
+ * Operation ID.
+ */
uint32_t op_id GNUNET_PACKED;
uint32_t psycstore_flags GNUNET_PACKED;
@@ -135,6 +121,9 @@
*/
struct GNUNET_MessageHeader header;
+ /**
+ * Operation ID.
+ */
uint32_t op_id GNUNET_PACKED;
uint16_t name_size GNUNET_PACKED;
@@ -150,9 +139,13 @@
{
struct GNUNET_MessageHeader header;
+ /**
+ * Operation ID.
+ */
+ uint32_t op_id GNUNET_PACKED;
+
struct GNUNET_CRYPTO_EccPublicSignKey channel_key;
- uint32_t op_id GNUNET_PACKED;
};
@@ -167,6 +160,11 @@
struct GNUNET_MessageHeader header;
/**
+ * Operation ID.
+ */
+ uint32_t op_id GNUNET_PACKED;
+
+ /**
* Channel's public key.
*/
struct GNUNET_CRYPTO_EccPublicSignKey channel_key;
@@ -176,12 +174,10 @@
*/
struct GNUNET_CRYPTO_EccPublicSignKey slave_key;
- int did_join;
- uint64_t announced_at;
- uint64_t effective_since;
- uint64_t group_generation;
-
- uint32_t op_id GNUNET_PACKED;
+ uint64_t announced_at GNUNET_PACKED;
+ uint64_t effective_since GNUNET_PACKED;
+ uint64_t group_generation GNUNET_PACKED;
+ int did_join GNUNET_PACKED;
};
@@ -196,6 +192,11 @@
struct GNUNET_MessageHeader header;
/**
+ * Operation ID.
+ */
+ uint32_t op_id GNUNET_PACKED;
+
+ /**
* Channel's public key.
*/
struct GNUNET_CRYPTO_EccPublicSignKey channel_key;
@@ -208,8 +209,6 @@
uint64_t message_id GNUNET_PACKED;
uint64_t group_generation GNUNET_PACKED;
-
- uint32_t op_id GNUNET_PACKED;
};
@@ -224,13 +223,16 @@
struct GNUNET_MessageHeader header;
/**
+ * Operation ID.
+ */
+ uint32_t op_id GNUNET_PACKED;
+
+ /**
* Channel's public key.
*/
struct GNUNET_CRYPTO_EccPublicSignKey channel_key;
uint32_t psycstore_flags GNUNET_PACKED;
-
- uint32_t op_id GNUNET_PACKED;
};
@@ -245,13 +247,16 @@
struct GNUNET_MessageHeader header;
/**
+ * Operation ID.
+ */
+ uint32_t op_id GNUNET_PACKED;
+
+ /**
* Channel's public key.
*/
struct GNUNET_CRYPTO_EccPublicSignKey channel_key;
- uint64_t fragment_id;
-
- uint32_t op_id GNUNET_PACKED;
+ uint64_t fragment_id GNUNET_PACKED;
};
@@ -266,13 +271,16 @@
struct GNUNET_MessageHeader header;
/**
+ * Operation ID.
+ */
+ uint32_t op_id GNUNET_PACKED;
+
+ /**
* Channel's public key.
*/
struct GNUNET_CRYPTO_EccPublicSignKey channel_key;
- uint64_t message_id;
-
- uint32_t op_id GNUNET_PACKED;
+ uint64_t message_id GNUNET_PACKED;
};
@@ -287,15 +295,18 @@
struct GNUNET_MessageHeader header;
/**
+ * Operation ID.
+ */
+ uint32_t op_id GNUNET_PACKED;
+
+ /**
* Channel's public key.
*/
struct GNUNET_CRYPTO_EccPublicSignKey channel_key;
- uint64_t message_id;
+ uint64_t message_id GNUNET_PACKED;
- uint64_t fragment_offset;
-
- uint32_t op_id GNUNET_PACKED;
+ uint64_t fragment_offset GNUNET_PACKED;
};
@@ -310,13 +321,16 @@
struct GNUNET_MessageHeader header;
/**
+ * Operation ID.
+ */
+ uint32_t op_id GNUNET_PACKED;
+
+ /**
* Channel's public key.
*/
struct GNUNET_CRYPTO_EccPublicSignKey channel_key;
struct GNUNET_HashCode hash;
-
- uint32_t op_id GNUNET_PACKED;
};
enum StateOpFlags
@@ -336,6 +350,11 @@
struct GNUNET_MessageHeader header;
/**
+ * Operation ID.
+ */
+ uint32_t op_id GNUNET_PACKED;
+
+ /**
* Channel's public key.
*/
struct GNUNET_CRYPTO_EccPublicSignKey channel_key;
@@ -344,8 +363,6 @@
uint64_t state_delta GNUNET_PACKED;
- uint32_t op_id GNUNET_PACKED;
-
/**
* Size of name, including NUL terminator.
*/
@@ -376,14 +393,17 @@
struct GNUNET_MessageHeader header;
/**
+ * Operation ID.
+ */
+ uint32_t op_id GNUNET_PACKED;
+
+ /**
* Channel's public key.
*/
struct GNUNET_CRYPTO_EccPublicSignKey channel_key;
uint64_t message_id GNUNET_PACKED;
- uint32_t op_id GNUNET_PACKED;
-
/**
* Size of name, including NUL terminator.
*/
Modified: gnunet/src/psycstore/psycstore_api.c
===================================================================
--- gnunet/src/psycstore/psycstore_api.c 2013-09-25 17:45:59 UTC (rev
29562)
+++ gnunet/src/psycstore/psycstore_api.c 2013-09-25 17:46:03 UTC (rev
29563)
@@ -188,8 +188,7 @@
* @param tc scheduler context
*/
static void
-reconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -239,18 +238,15 @@
* @param msg message received, NULL on timeout or fatal error
*/
static void
-message_handler (void *cls,
- const struct GNUNET_MessageHeader *msg)
+message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_PSYCSTORE_Handle *h = cls;
struct GNUNET_PSYCSTORE_OperationHandle *op;
const struct OperationResult *opres;
- const struct MasterCountersResult *mcres;
- const struct SlaveCountersResult *scres;
+ const struct CountersResult *cres;
const struct FragmentResult *fres;
const struct StateResult *sres;
const char *str;
- uint16_t size;
if (NULL == msg)
{
@@ -260,8 +256,9 @@
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received message of type %d from PSYCstore service\n",
ntohs (msg->type));
- size = ntohs (msg->size);
- switch (ntohs (msg->type))
+ uint16_t size = ntohs (msg->size);
+ uint16_t type = ntohs (msg->type);
+ switch (type)
{
case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE:
if (size < sizeof (struct OperationResult))
@@ -269,7 +266,7 @@
LOG (GNUNET_ERROR_TYPE_ERROR,
"Received message of type %d with length %lu bytes. "
"Expected >= %lu\n",
- ntohs (msg->type), size, sizeof (struct OperationResult));
+ type, size, sizeof (struct OperationResult));
GNUNET_break (0);
reschedule_connect (h);
return;
@@ -291,8 +288,9 @@
if (NULL == op)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- "Received result of an unkown operation ID: %ld\n",
- ntohl (opres->op_id));
+ "Received result message (type %d) "
+ "with an unknown operation ID: %ld\n",
+ type, ntohl (opres->op_id));
}
else
{
@@ -323,78 +321,49 @@
}
break;
- case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_MASTER:
- if (size != sizeof (struct MasterCountersResult))
+ case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS:
+ if (size != sizeof (struct CountersResult))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
"Received message of type %d with length %lu bytes. "
"Expected %lu\n",
- ntohs (msg->type), size, sizeof (struct MasterCountersResult));
+ type, size, sizeof (struct CountersResult));
GNUNET_break (0);
reschedule_connect (h);
return;
}
- mcres = (const struct MasterCountersResult *) msg;
+ cres = (const struct CountersResult *) msg;
- op = find_op_by_id (h, ntohl (mcres->op_id));
+ op = find_op_by_id (h, ntohl (cres->op_id));
if (NULL == op)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- "Received result of an unkown operation ID: %ld\n",
- ntohl (mcres->op_id));
+ "Received counters result message (type %d) "
+ "with an unknown operation ID: %ld\n",
+ ntohl (cres->op_id));
}
else
{
GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
if (NULL != op->data_cb)
- ((GNUNET_PSYCSTORE_MasterCountersCallback)
+ ((GNUNET_PSYCSTORE_CountersCallback)
op->data_cb) (op->cls,
- GNUNET_ntohll (mcres->fragment_id),
- GNUNET_ntohll (mcres->message_id),
- GNUNET_ntohll (mcres->group_generation));
+ GNUNET_ntohll (cres->max_fragment_id),
+ GNUNET_ntohll (cres->max_message_id),
+ GNUNET_ntohll (cres->max_group_generation),
+ GNUNET_ntohll (cres->max_state_message_id));
GNUNET_free (op);
}
break;
- case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_SLAVE:
- if (size != sizeof (struct SlaveCountersResult))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Received message of type %d with length %lu bytes. "
- "Expected %lu\n",
- ntohs (msg->type), size, sizeof (struct SlaveCountersResult));
- GNUNET_break (0);
- reschedule_connect (h);
- return;
- }
-
- scres = (const struct SlaveCountersResult *) msg;
-
- op = find_op_by_id (h, ntohl (scres->op_id));
- if (NULL == op)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Received result of an unkown operation ID: %ld\n",
- ntohl (scres->op_id));
- }
- else
- {
- GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
- if (NULL != op->data_cb)
- ((GNUNET_PSYCSTORE_SlaveCountersCallback)
- op->data_cb) (op->cls, GNUNET_ntohll (scres->max_known_msg_id));
- GNUNET_free (op);
- }
- break;
-
case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_FRAGMENT:
if (size < sizeof (struct FragmentResult))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
"Received message of type %d with length %lu bytes. "
"Expected >= %lu\n",
- ntohs (msg->type), size, sizeof (struct FragmentResult));
+ type, size, sizeof (struct FragmentResult));
GNUNET_break (0);
reschedule_connect (h);
return;
@@ -408,7 +377,7 @@
LOG (GNUNET_ERROR_TYPE_ERROR,
"Received message of type %d with length %lu bytes. "
"Expected = %lu\n",
- ntohs (msg->type), size,
+ type, size,
sizeof (struct FragmentResult) + ntohs (mmsg->header.size));
GNUNET_break (0);
reschedule_connect (h);
@@ -419,8 +388,9 @@
if (NULL == op)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- "Received result of an unkown operation ID: %ld\n",
- ntohl (fres->op_id));
+ "Received fragment result message (type %d) "
+ "with an unknown operation ID: %ld\n",
+ type, ntohl (fres->op_id));
}
else
{
@@ -436,7 +406,7 @@
LOG (GNUNET_ERROR_TYPE_ERROR,
"Received message of type %d with length %lu bytes. "
"Expected >= %lu\n",
- ntohs (msg->type), size, sizeof (struct StateResult));
+ type, size, sizeof (struct StateResult));
GNUNET_break (0);
reschedule_connect (h);
return;
@@ -450,7 +420,7 @@
{
LOG (GNUNET_ERROR_TYPE_ERROR,
"Received state result message (type %d) with invalid name.\n",
- ntohs (msg->type), name_size, name);
+ type);
GNUNET_break (0);
reschedule_connect (h);
return;
@@ -460,14 +430,15 @@
if (NULL == op)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- "Received result of an unkown operation ID: %ld\n",
- ntohl (sres->op_id));
+ "Received state result message (type %d) "
+ "with an unknown operation ID: %ld\n",
+ type, ntohl (sres->op_id));
}
else
{
if (NULL != op->data_cb)
((GNUNET_PSYCSTORE_StateCallback)
- op->data_cb) (op->cls, name, (void *) &sres[1] + name_size,
+ op->data_cb) (op->cls, name, (char *) &sres[1] + name_size,
ntohs (sres->header.size) - sizeof (*sres) - name_size);
}
break;
@@ -590,9 +561,8 @@
struct GNUNET_PSYCSTORE_Handle *
GNUNET_PSYCSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- struct GNUNET_PSYCSTORE_Handle *h;
-
- h = GNUNET_new (struct GNUNET_PSYCSTORE_Handle);
+ struct GNUNET_PSYCSTORE_Handle *h
+ = GNUNET_new (struct GNUNET_PSYCSTORE_Handle);
h->cfg = cfg;
h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
h->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, h);
@@ -609,7 +579,6 @@
GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h)
{
GNUNET_assert (NULL != h);
- GNUNET_assert (h->op_head == h->op_tail);
if (h->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (h->reconnect_task);
@@ -985,21 +954,21 @@
* @return Handle that can be used to cancel the operation.
*/
struct GNUNET_PSYCSTORE_OperationHandle *
-GNUNET_PSYCSTORE_counters_get_master (struct GNUNET_PSYCSTORE_Handle *h,
- struct GNUNET_CRYPTO_EccPublicSignKey
*channel_key,
- GNUNET_PSYCSTORE_MasterCountersCallback
mccb,
- void *mccb_cls)
+GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h,
+ struct GNUNET_CRYPTO_EccPublicSignKey
*channel_key,
+ GNUNET_PSYCSTORE_CountersCallback ccb,
+ void *mccb_cls)
{
struct OperationRequest *req;
struct GNUNET_PSYCSTORE_OperationHandle *op
= GNUNET_malloc (sizeof (*op) + sizeof (*req));
op->h = h;
- op->data_cb = mccb;
+ op->data_cb = ccb;
op->cls = mccb_cls;
req = (struct OperationRequest *) &op[1];
op->msg = (struct GNUNET_MessageHeader *) req;
- req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET_MASTER);
+ req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET);
req->header.size = htons (sizeof (*req));
req->channel_key = *channel_key;
@@ -1013,50 +982,7 @@
}
-
/**
- * Retrieve latest values of counters for a channel slave.
- *
- * The current value of counters are needed when a channel slave rejoins
- * and starts the state synchronization process.
- *
- * @param h Handle for the PSYCstore.
- * @param channel_key Public key that identifies the channel.
- * @param sccb Callback to call with the result.
- * @param sccb_cls Closure for the callback.
- *
- * @return Handle that can be used to cancel the operation.
- */
-struct GNUNET_PSYCSTORE_OperationHandle *
-GNUNET_PSYCSTORE_counters_get_slave (struct GNUNET_PSYCSTORE_Handle *h,
- struct GNUNET_CRYPTO_EccPublicSignKey
*channel_key,
- GNUNET_PSYCSTORE_SlaveCountersCallback
sccb,
- void *sccb_cls)
-{
- struct OperationRequest *req;
- struct GNUNET_PSYCSTORE_OperationHandle *op
- = GNUNET_malloc (sizeof (*op) + sizeof (*req));
- op->h = h;
- op->data_cb = sccb;
- op->cls = sccb_cls;
-
- req = (struct OperationRequest *) &op[1];
- op->msg = (struct GNUNET_MessageHeader *) req;
- req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET_SLAVE);
- req->header.size = htons (sizeof (*req));
- req->channel_key = *channel_key;
-
- op->op_id = get_next_op_id (h);
- req->op_id = htonl (op->op_id);
-
- GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op);
- transmit_next (h);
-
- return op;
-}
-
-
-/**
* Apply modifiers of a message to the current channel state.
*
* An error is returned if there are missing messages containing state
@@ -1114,7 +1040,7 @@
: 0;
memcpy (&req[1], modifiers[i].name, name_size);
- memcpy ((void *) &req[1] + name_size, modifiers[i].value,
modifiers[i].value_size);
+ memcpy ((char *) &req[1] + name_size, modifiers[i].value,
modifiers[i].value_size);
op->op_id = get_next_op_id (h);
req->op_id = htonl (op->op_id);
@@ -1180,7 +1106,7 @@
: 0;
memcpy (&req[1], modifiers[i].name, name_size);
- memcpy ((void *) &req[1] + name_size, modifiers[i].value,
modifiers[i].value_size);
+ memcpy ((char *) &req[1] + name_size, modifiers[i].value,
modifiers[i].value_size);
op->op_id = get_next_op_id (h);
req->op_id = htonl (op->op_id);
Modified: gnunet/src/psycstore/test_plugin_psycstore.c
===================================================================
--- gnunet/src/psycstore/test_plugin_psycstore.c 2013-09-25 17:45:59 UTC
(rev 29562)
+++ gnunet/src/psycstore/test_plugin_psycstore.c 2013-09-25 17:46:03 UTC
(rev 29563)
@@ -276,13 +276,13 @@
&retfrags, fragment_cb, &fcls));
GNUNET_assert (fcls.n == 2 && retfrags == 2);
- /* Master counters */
+ /* Message counters */
uint64_t fragment_id = 0, message_id = 0, group_generation = 0;
GNUNET_assert (
- GNUNET_OK == db->counters_get_master (db->cls, &channel_pub_key,
- &fragment_id, &message_id,
- &group_generation)
+ GNUNET_OK == db->counters_message_get (db->cls, &channel_pub_key,
+ &fragment_id, &message_id,
+ &group_generation)
&& fragment_id == GNUNET_ntohll (msg1->fragment_id)
&& message_id == GNUNET_ntohll (msg1->message_id)
&& group_generation == GNUNET_ntohll (msg1->group_generation));
@@ -334,12 +334,12 @@
state_cb, &scls));
GNUNET_assert (scls.n == 2);
- /* Slave counters */
+ /* State counters */
uint64_t max_state_msg_id = 0;
- GNUNET_assert (GNUNET_OK == db->counters_get_slave (db->cls,
&channel_pub_key,
- &max_state_msg_id)
- && max_state_msg_id == message_id);
+ GNUNET_assert (GNUNET_OK == db->counters_state_get (db->cls,
&channel_pub_key,
+ &max_state_msg_id)
+ && max_state_msg_id == message_id);
/* State sync */
Modified: gnunet/src/psycstore/test_psycstore.c
===================================================================
--- gnunet/src/psycstore/test_psycstore.c 2013-09-25 17:45:59 UTC (rev
29562)
+++ gnunet/src/psycstore/test_psycstore.c 2013-09-25 17:46:03 UTC (rev
29563)
@@ -28,8 +28,8 @@
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_util_lib.h"
+#include "gnunet_testing_lib.h"
#include "gnunet_psycstore_service.h"
-#include "gnunet_testing_lib.h"
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
@@ -231,16 +231,20 @@
void
-counters_slave_result (void *cls, uint64_t max_state_msg_id)
+counters_result (void *cls, uint64_t max_fragment_id, uint64_t max_message_id,
+ uint64_t max_group_generation, uint64_t max_state_message_id)
{
struct FragmentClosure *fcls = cls;
int result = 0;
op = NULL;
- if (max_state_msg_id == GNUNET_ntohll (fcls->msg[0]->message_id))
+ if (max_fragment_id == GNUNET_ntohll (fcls->msg[2]->fragment_id)
+ && max_message_id == GNUNET_ntohll (fcls->msg[2]->message_id)
+ && max_group_generation == GNUNET_ntohll (fcls->msg[2]->group_generation)
+ && max_state_message_id == GNUNET_ntohll (fcls->msg[0]->message_id))
result = 1;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "counters_get_slave:\t%d\n", result);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "counters_get:\t%d\n", result);
GNUNET_assert (result == 1);
scls.n = 0;
@@ -260,8 +264,8 @@
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_modify_result:\t%d\n", result);
GNUNET_assert (GNUNET_OK == result);
- op = GNUNET_PSYCSTORE_counters_get_slave (h, &channel_pub_key,
- &counters_slave_result, cls);
+ op = GNUNET_PSYCSTORE_counters_get (h, &channel_pub_key,
+ &counters_result, cls);
}
@@ -292,41 +296,6 @@
}
-void
-counters_master_result (void *cls, uint64_t fragment_id, uint64_t message_id,
- uint64_t group_generation)
-{
- struct FragmentClosure *fcls = cls;
- int result = 0;
- op = NULL;
-
- if (fragment_id == GNUNET_ntohll (fcls->msg[2]->fragment_id) &&
- message_id == GNUNET_ntohll (fcls->msg[2]->message_id) &&
- group_generation == GNUNET_ntohll (fcls->msg[2]->group_generation))
- result = 1;
-
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "counters_get_master:\t%d\n", result);
- GNUNET_assert (result == 1);
-
- modifiers[0] = (struct GNUNET_ENV_Modifier) {
- .oper = '=',
- .name = "_sync_foo",
- .value = "three two one",
- .value_size = sizeof ("three two one") - 1
- };
- modifiers[1] = (struct GNUNET_ENV_Modifier) {
- .oper = '=',
- .name = "_sync_bar",
- .value = "ten eleven twelve",
- .value_size = sizeof ("ten eleven twelve") - 1
- };
-
- op = GNUNET_PSYCSTORE_state_sync (h, &channel_pub_key,
- GNUNET_ntohll (fcls->msg[0]->message_id) +
1,
- 2, modifiers, state_sync_result, fcls);
-}
-
-
int
fragment_result (void *cls,
struct GNUNET_MULTICAST_MessageHeader *msg,
@@ -361,8 +330,24 @@
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "message_get:\t%d\n", result);
GNUNET_assert (result > 0 && fcls->n && fcls->n_expected);
- op = GNUNET_PSYCSTORE_counters_get_master (h, &channel_pub_key,
- &counters_master_result, fcls);
+
+
+ modifiers[0] = (struct GNUNET_ENV_Modifier) {
+ .oper = '=',
+ .name = "_sync_foo",
+ .value = "three two one",
+ .value_size = sizeof ("three two one") - 1
+ };
+ modifiers[1] = (struct GNUNET_ENV_Modifier) {
+ .oper = '=',
+ .name = "_sync_bar",
+ .value = "ten eleven twelve",
+ .value_size = sizeof ("ten eleven twelve") - 1
+ };
+
+ op = GNUNET_PSYCSTORE_state_sync (h, &channel_pub_key,
+ GNUNET_ntohll (fcls->msg[0]->message_id) +
1,
+ 2, modifiers, state_sync_result, fcls);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r29563 - in gnunet/src: include psycstore,
gnunet <=