remove protocol violation
[oweals/gnunet.git] / src / psycstore / plugin_psycstore_sqlite.c
index e9cc76e70e60c9819eee0505be13d587b4c62c61..6ca0236d59040c0ec5f792b872cf36c66610bc15 100644 (file)
@@ -143,14 +143,14 @@ struct Plugin
   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()
@@ -435,7 +435,7 @@ database_setup (struct Plugin *plugin)
                &plugin->select_membership);
 
   sql_prepare (plugin->dbh,
-               "INSERT INTO messages\n"
+               "INSERT OR IGNORE INTO messages\n"
                " (channel_id, hop_counter, signature, purpose,\n"
                "  fragment_id, fragment_offset, message_id,\n"
                "  group_generation, multicast_flags, psycstore_flags, data)\n"
@@ -482,13 +482,13 @@ database_setup (struct Plugin *plugin)
                "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"
@@ -610,18 +610,18 @@ database_shutdown (struct Plugin *plugin)
   GNUNET_free_non_null (plugin->fn);
 }
 
-/** 
+/**
  * Execute a prepared statement with a @a channel_key argument.
  *
  * @param plugin Plugin handle.
  * @param stmt Statement to execute.
  * @param channel_key Public key of the channel.
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
 exec_channel (struct Plugin *plugin, sqlite3_stmt *stmt,
-              const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key)
+              const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key)
 {
   if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key,
                                       sizeof (*channel_key), SQLITE_STATIC))
@@ -721,7 +721,7 @@ transaction_rollback (struct Plugin *plugin)
 
 static int
 channel_key_store (struct Plugin *plugin,
-                   const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key)
+                   const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key)
 {
   sqlite3_stmt *stmt = plugin->insert_channel_key;
 
@@ -750,7 +750,7 @@ channel_key_store (struct Plugin *plugin,
 
 static int
 slave_key_store (struct Plugin *plugin,
-                 const struct GNUNET_CRYPTO_EccPublicSignKey *slave_key)
+                 const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key)
 {
   sqlite3_stmt *stmt = plugin->insert_slave_key;
 
@@ -778,7 +778,7 @@ slave_key_store (struct Plugin *plugin,
 }
 
 
-/** 
+/**
  * Store join/leave events for a PSYC channel in order to be able to answer
  * membership test queries later.
  *
@@ -788,8 +788,8 @@ slave_key_store (struct Plugin *plugin,
  */
 static int
 membership_store (void *cls,
-                  const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
-                  const struct GNUNET_CRYPTO_EccPublicSignKey *slave_key,
+                  const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
+                  const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
                   int did_join,
                   uint64_t announced_at,
                   uint64_t effective_since,
@@ -840,18 +840,18 @@ membership_store (void *cls,
   return GNUNET_OK;
 }
 
-/** 
+/**
  * Test if a member was admitted to the channel at the given message ID.
  *
  * @see GNUNET_PSYCSTORE_membership_test()
- * 
+ *
  * @return #GNUNET_YES if the member was admitted, #GNUNET_NO if not,
  *         #GNUNET_SYSERR if there was en error.
  */
 static int
 membership_test (void *cls,
-                 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
-                 const struct GNUNET_CRYPTO_EccPublicSignKey *slave_key,
+                 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
+                 const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
                  uint64_t message_id)
 {
   struct Plugin *plugin = cls;
@@ -888,16 +888,16 @@ membership_test (void *cls,
   return ret;
 }
 
-/** 
+/**
  * Store a message fragment sent to a channel.
  *
  * @see GNUNET_PSYCSTORE_fragment_store()
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
 fragment_store (void *cls,
-                const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+                const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
                 const struct GNUNET_MULTICAST_MessageHeader *msg,
                 uint32_t psycstore_flags)
 {
@@ -961,16 +961,16 @@ fragment_store (void *cls,
   return GNUNET_OK;
 }
 
-/** 
+/**
  * Set additional flags for a given message.
  *
  * They are OR'd with any existing flags set.
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
 message_add_flags (void *cls,
-                   const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+                   const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
                    uint64_t message_id,
                    uint64_t psycstore_flags)
 {
@@ -1036,16 +1036,16 @@ fragment_row (sqlite3_stmt *stmt, GNUNET_PSYCSTORE_FragmentCallback cb,
   return cb (cb_cls, (void *) msg, sqlite3_column_int64 (stmt, 8));
 }
 
-/** 
+/**
  * Retrieve a message fragment by fragment ID.
  *
  * @see GNUNET_PSYCSTORE_fragment_get()
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
 fragment_get (void *cls,
-              const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+              const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
               uint64_t fragment_id,
               GNUNET_PSYCSTORE_FragmentCallback cb,
               void *cb_cls)
@@ -1087,16 +1087,16 @@ fragment_get (void *cls,
   return ret;
 }
 
-/** 
+/**
  * Retrieve all fragments of a message.
  *
  * @see GNUNET_PSYCSTORE_message_get()
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
 message_get (void *cls,
-             const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+             const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
              uint64_t message_id,
              uint64_t *returned_fragments,
              GNUNET_PSYCSTORE_FragmentCallback cb,
@@ -1150,17 +1150,17 @@ message_get (void *cls,
   return ret;
 }
 
-/** 
+/**
  * Retrieve a fragment of message specified by its message ID and fragment
  * offset.
  *
  * @see GNUNET_PSYCSTORE_message_get_fragment()
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
 message_get_fragment (void *cls,
-                      const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+                      const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
                       uint64_t message_id,
                       uint64_t fragment_offset,
                       GNUNET_PSYCSTORE_FragmentCallback cb,
@@ -1204,22 +1204,22 @@ message_get_fragment (void *cls,
   return ret;
 }
 
-/** 
- * Retrieve latest values of counters for a channel master.
+/**
+ * Retrieve the max. values of message counters for a channel.
+ *
+ * @see GNUNET_PSYCSTORE_counters_get()
  *
- * @see GNUNET_PSYCSTORE_counters_get_master()
- * 
  * @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_EddsaPublicKey *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 @@ counters_get_master (void *cls,
       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:
@@ -1257,20 +1257,20 @@ counters_get_master (void *cls,
   return ret;
 }
 
-/** 
- * Retrieve latest values of counters for a channel slave.
+/**
+ * Retrieve the max. values of state counters for a channel.
+ *
+ * @see GNUNET_PSYCSTORE_counters_get()
  *
- * @see GNUNET_PSYCSTORE_counters_get_slave()
- * 
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
-counters_get_slave (void *cls,
-                    const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
-                    uint64_t *max_state_msg_id)
+counters_state_get (void *cls,
+                    const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
+                    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 @@ counters_get_slave (void *cls,
       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:
@@ -1307,14 +1307,14 @@ counters_get_slave (void *cls,
 }
 
 
-/** 
+/**
  * Set a state variable to the given value.
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
 state_set (struct Plugin *plugin, sqlite3_stmt *stmt,
-           const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+           const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
            const char *name, const void *value, size_t value_size)
 {
   int ret = GNUNET_SYSERR;
@@ -1354,7 +1354,7 @@ state_set (struct Plugin *plugin, sqlite3_stmt *stmt,
 
 static int
 update_message_id (struct Plugin *plugin, sqlite3_stmt *stmt,
-                   const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+                   const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
                    uint64_t message_id)
 {
   if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, message_id)
@@ -1384,7 +1384,7 @@ update_message_id (struct Plugin *plugin, sqlite3_stmt *stmt,
  */
 static int
 state_modify_begin (void *cls,
-                    const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+                    const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
                     uint64_t message_id, uint64_t state_delta)
 {
   struct Plugin *plugin = cls;
@@ -1440,16 +1440,16 @@ state_modify_begin (void *cls,
 }
 
 
-/** 
+/**
  * Set the current value of state variable.
  *
  * @see GNUNET_PSYCSTORE_state_modify()
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
 state_modify_set (void *cls,
-                  const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+                  const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
                   const char *name, const void *value, size_t value_size)
 {
   struct Plugin *plugin = cls;
@@ -1466,7 +1466,7 @@ state_modify_set (void *cls,
  */
 static int
 state_modify_end (void *cls,
-                  const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+                  const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
                   uint64_t message_id)
 {
   struct Plugin *plugin = cls;
@@ -1487,23 +1487,23 @@ state_modify_end (void *cls,
  */
 static int
 state_sync_begin (void *cls,
-                  const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key)
+                  const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key)
 {
   struct Plugin *plugin = cls;
   return exec_channel (plugin, plugin->delete_state_sync, channel_key);
 }
 
 
-/** 
+/**
  * Set the current value of state variable.
  *
  * @see GNUNET_PSYCSTORE_state_modify()
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
 state_sync_set (void *cls,
-                const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+                const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
                 const char *name, const void *value, size_t value_size)
 {
   struct Plugin *plugin = cls;
@@ -1517,7 +1517,7 @@ state_sync_set (void *cls,
  */
 static int
 state_sync_end (void *cls,
-                const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+                const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
                 uint64_t message_id)
 {
   struct Plugin *plugin = cls;
@@ -1539,46 +1539,46 @@ state_sync_end (void *cls,
 }
 
 
-/** 
+/**
  * Reset the state of a channel.
  *
  * @see GNUNET_PSYCSTORE_state_reset()
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
-state_reset (void *cls, const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key)
+state_reset (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key)
 {
   struct Plugin *plugin = cls;
   return exec_channel (plugin, plugin->delete_state, channel_key);
 }
 
 
-/** 
+/**
  * Update signed values of state variables in the state store.
  *
  * @see GNUNET_PSYCSTORE_state_hash_update()
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
 state_update_signed (void *cls,
-                     const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key)
+                     const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key)
 {
   struct Plugin *plugin = cls;
   return exec_channel (plugin, plugin->update_state_signed, channel_key);
 }
 
 
-/** 
+/**
  * Retrieve a state variable by name.
  *
  * @see GNUNET_PSYCSTORE_state_get()
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
-state_get (void *cls, const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+state_get (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
            const char *name, GNUNET_PSYCSTORE_StateCallback cb, void *cb_cls)
 {
   struct Plugin *plugin = cls;
@@ -1621,15 +1621,15 @@ state_get (void *cls, const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
 }
 
 
-/** 
+/**
  * Retrieve all state variables for a channel with the given prefix.
  *
  * @see GNUNET_PSYCSTORE_state_get_prefix()
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
-state_get_prefix (void *cls, const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+state_get_prefix (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
                   const char *name, GNUNET_PSYCSTORE_StateCallback cb,
                   void *cb_cls)
 {
@@ -1688,16 +1688,16 @@ state_get_prefix (void *cls, const struct GNUNET_CRYPTO_EccPublicSignKey *channe
 }
 
 
-/** 
+/**
  * Retrieve all signed state variables for a channel.
  *
  * @see GNUNET_PSYCSTORE_state_get_signed()
- * 
+ *
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
 state_get_signed (void *cls,
-                  const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
+                  const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
                   GNUNET_PSYCSTORE_StateCallback cb, void *cb_cls)
 {
   struct Plugin *plugin = cls;
@@ -1748,7 +1748,7 @@ state_get_signed (void *cls,
 }
 
 
-/** 
+/**
  * Entry point for the plugin.
  *
  * @param cls The struct GNUNET_CONFIGURATION_Handle.
@@ -1779,8 +1779,8 @@ libgnunet_plugin_psycstore_sqlite_init (void *cls)
   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;