aboutsummaryrefslogtreecommitdiff
path: root/src/psycstore/plugin_psycstore_sqlite.c
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2013-09-25 17:46:03 +0000
committerGabor X Toth <*@tg-x.net>2013-09-25 17:46:03 +0000
commit303d6a97bc552a337c992944c3151ea53c1f74dc (patch)
tree295d478fd8e82879830588da0c47778512ffad9b /src/psycstore/plugin_psycstore_sqlite.c
parentffc11bb1c2c09cda9e7bed84e56cedb8ed49d46c (diff)
downloadgnunet-303d6a97bc552a337c992944c3151ea53c1f74dc.tar.gz
gnunet-303d6a97bc552a337c992944c3151ea53c1f74dc.zip
psycstore: single counters function for master & slave
Diffstat (limited to 'src/psycstore/plugin_psycstore_sqlite.c')
-rw-r--r--src/psycstore/plugin_psycstore_sqlite.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/src/psycstore/plugin_psycstore_sqlite.c b/src/psycstore/plugin_psycstore_sqlite.c
index e9cc76e70..592eaf384 100644
--- a/src/psycstore/plugin_psycstore_sqlite.c
+++ b/src/psycstore/plugin_psycstore_sqlite.c
@@ -143,14 +143,14 @@ struct Plugin
143 sqlite3_stmt *select_message_fragment; 143 sqlite3_stmt *select_message_fragment;
144 144
145 /** 145 /**
146 * Precompiled SQL for counters_get_master() 146 * Precompiled SQL for counters_get_message()
147 */ 147 */
148 sqlite3_stmt *select_counters_master; 148 sqlite3_stmt *select_counters_message;
149 149
150 /** 150 /**
151 * Precompiled SQL for counters_get_slave() 151 * Precompiled SQL for counters_get_state()
152 */ 152 */
153 sqlite3_stmt *select_max_state_message_id; 153 sqlite3_stmt *select_counters_state;
154 154
155 /** 155 /**
156 * Precompiled SQL for state_modify_end() 156 * Precompiled SQL for state_modify_end()
@@ -482,13 +482,13 @@ database_setup (struct Plugin *plugin)
482 "FROM messages\n" 482 "FROM messages\n"
483 "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n" 483 "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n"
484 "ORDER BY fragment_id DESC LIMIT 1;", 484 "ORDER BY fragment_id DESC LIMIT 1;",
485 &plugin->select_counters_master); 485 &plugin->select_counters_message);
486 486
487 sql_prepare (plugin->dbh, 487 sql_prepare (plugin->dbh,
488 "SELECT max_state_message_id\n" 488 "SELECT max_state_message_id\n"
489 "FROM channels\n" 489 "FROM channels\n"
490 "WHERE pub_key = ? AND max_state_message_id IS NOT NULL;", 490 "WHERE pub_key = ? AND max_state_message_id IS NOT NULL;",
491 &plugin->select_max_state_message_id); 491 &plugin->select_counters_state);
492 492
493 sql_prepare (plugin->dbh, 493 sql_prepare (plugin->dbh,
494 "UPDATE channels\n" 494 "UPDATE channels\n"
@@ -1205,21 +1205,21 @@ message_get_fragment (void *cls,
1205} 1205}
1206 1206
1207/** 1207/**
1208 * Retrieve latest values of counters for a channel master. 1208 * Retrieve the max. values of message counters for a channel.
1209 * 1209 *
1210 * @see GNUNET_PSYCSTORE_counters_get_master() 1210 * @see GNUNET_PSYCSTORE_counters_get()
1211 * 1211 *
1212 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 1212 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
1213 */ 1213 */
1214static int 1214static int
1215counters_get_master (void *cls, 1215counters_message_get (void *cls,
1216 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key, 1216 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
1217 uint64_t *fragment_id, 1217 uint64_t *max_fragment_id,
1218 uint64_t *message_id, 1218 uint64_t *max_message_id,
1219 uint64_t *group_generation) 1219 uint64_t *max_group_generation)
1220{ 1220{
1221 struct Plugin *plugin = cls; 1221 struct Plugin *plugin = cls;
1222 sqlite3_stmt *stmt = plugin->select_counters_master; 1222 sqlite3_stmt *stmt = plugin->select_counters_message;
1223 int ret = GNUNET_SYSERR; 1223 int ret = GNUNET_SYSERR;
1224 1224
1225 if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key, 1225 if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key,
@@ -1237,9 +1237,9 @@ counters_get_master (void *cls,
1237 ret = GNUNET_NO; 1237 ret = GNUNET_NO;
1238 break; 1238 break;
1239 case SQLITE_ROW: 1239 case SQLITE_ROW:
1240 *fragment_id = sqlite3_column_int64 (stmt, 0); 1240 *max_fragment_id = sqlite3_column_int64 (stmt, 0);
1241 *message_id = sqlite3_column_int64 (stmt, 1); 1241 *max_message_id = sqlite3_column_int64 (stmt, 1);
1242 *group_generation = sqlite3_column_int64 (stmt, 2); 1242 *max_group_generation = sqlite3_column_int64 (stmt, 2);
1243 ret = GNUNET_OK; 1243 ret = GNUNET_OK;
1244 break; 1244 break;
1245 default: 1245 default:
@@ -1258,19 +1258,19 @@ counters_get_master (void *cls,
1258} 1258}
1259 1259
1260/** 1260/**
1261 * Retrieve latest values of counters for a channel slave. 1261 * Retrieve the max. values of state counters for a channel.
1262 * 1262 *
1263 * @see GNUNET_PSYCSTORE_counters_get_slave() 1263 * @see GNUNET_PSYCSTORE_counters_get()
1264 * 1264 *
1265 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 1265 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
1266 */ 1266 */
1267static int 1267static int
1268counters_get_slave (void *cls, 1268counters_state_get (void *cls,
1269 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key, 1269 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
1270 uint64_t *max_state_msg_id) 1270 uint64_t *max_state_message_id)
1271{ 1271{
1272 struct Plugin *plugin = cls; 1272 struct Plugin *plugin = cls;
1273 sqlite3_stmt *stmt = plugin->select_max_state_message_id; 1273 sqlite3_stmt *stmt = plugin->select_counters_state;
1274 int ret = GNUNET_SYSERR; 1274 int ret = GNUNET_SYSERR;
1275 1275
1276 if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key, 1276 if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key,
@@ -1288,7 +1288,7 @@ counters_get_slave (void *cls,
1288 ret = GNUNET_NO; 1288 ret = GNUNET_NO;
1289 break; 1289 break;
1290 case SQLITE_ROW: 1290 case SQLITE_ROW:
1291 *max_state_msg_id = sqlite3_column_int64 (stmt, 0); 1291 *max_state_message_id = sqlite3_column_int64 (stmt, 0);
1292 ret = GNUNET_OK; 1292 ret = GNUNET_OK;
1293 break; 1293 break;
1294 default: 1294 default:
@@ -1779,8 +1779,8 @@ libgnunet_plugin_psycstore_sqlite_init (void *cls)
1779 api->fragment_get = &fragment_get; 1779 api->fragment_get = &fragment_get;
1780 api->message_get = &message_get; 1780 api->message_get = &message_get;
1781 api->message_get_fragment = &message_get_fragment; 1781 api->message_get_fragment = &message_get_fragment;
1782 api->counters_get_master = &counters_get_master; 1782 api->counters_message_get = &counters_message_get;
1783 api->counters_get_slave = &counters_get_slave; 1783 api->counters_state_get = &counters_state_get;
1784 api->state_modify_begin = &state_modify_begin; 1784 api->state_modify_begin = &state_modify_begin;
1785 api->state_modify_set = &state_modify_set; 1785 api->state_modify_set = &state_modify_set;
1786 api->state_modify_end = &state_modify_end; 1786 api->state_modify_end = &state_modify_end;