WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
* Function called for each matching record.
*
* @param cls closure
- * @param serial unique serial number of the record
+ * @param serial unique serial number of the record, MUST NOT BE ZERO,
+ * and must be monotonically increasing while iterating
* @param zone_key private key of the zone
* @param label name that is being mapped (at most 255 characters long)
* @param rd_count number of entries in @a rd array
*
* @param cls closure (internal context for the plugin)
* @param zone private key of the zone, NULL for all zones
- * @param serial serial (to exclude) in the list of matching records
+ * @param serial serial (to exclude) in the list of matching records;
+ * 0 means to exclude nothing; results must be returned using
+ * the minimum possible sequence number first (ordered by serial)
* @param limit maximum number of results to return to @a iter
* @param iter function to call with the result
* @param iter_cls closure for @a iter
* message and free the data structure once @e cache_ops is zero.
*/
int send_end;
-
+
};
* for if applicable, can be NULL.
*/
struct ZoneIteration *zi;
-
+
/**
* Client's request ID.
*/
/**
* Entry in list of cached nick resolutions.
- */
+ */
struct NickCache
{
/**
* Zone the cache entry is for.
- */
+ */
struct GNUNET_CRYPTO_EcdsaPrivateKey zone;
/**
/**
- * We cache nick records to reduce DB load.
+ * We cache nick records to reduce DB load.
*/
static struct NickCache nick_cache[NC_SIZE];
* record, which (if found) is then copied to @a cls for future use.
*
* @param cls a `struct GNUNET_GNSRECORD_Data **` for storing the nick (if found)
- * @param seq sequence number of the record
+ * @param seq sequence number of the record, MUST NOT BE ZERO
* @param private_key the private key of the zone (unused)
* @param label should be #GNUNET_GNS_EMPTY_LABEL_AT
* @param rd_count number of records in @a rd
struct GNUNET_GNSRECORD_Data **res = cls;
(void) private_key;
- (void) seq;
+ GNUNET_assert (0 != seq);
if (0 != strcmp (label, GNUNET_GNS_EMPTY_LABEL_AT))
{
GNUNET_break (0);
return nick;
}
}
-
+
nick = NULL;
res = GSN_database->lookup_records (GSN_database->cls,
zone,
em->r_id = htonl (zi->request_id);
GNUNET_MQ_send (zi->nc->mq,
env);
-
+
GNUNET_CONTAINER_DLL_remove (zi->nc->op_head,
zi->nc->op_tail,
zi);
/**
- * FIXME.
+ * Function called by the namestore plugin when we are trying to lookup
+ * a record as part of #handle_record_lookup(). Merges all results into
+ * the context.
*
- * @param seq sequence number of the record
+ * @param cls closure with a `struct RecordLookupContext`
+ * @param seq unique serial number of the record, MUST NOT BE ZERO
+ * @param zone_key private key of the zone
+ * @param label name that is being mapped (at most 255 characters long)
+ * @param rd_count number of entries in @a rd array
+ * @param rd array of records with data to store
*/
static void
lookup_it (void *cls,
struct RecordLookupContext *rlc = cls;
(void) private_key;
- (void) seq;
+ GNUNET_assert (0 != seq);
if (0 != strcmp (label,
rlc->label))
return;
conv_name)) ||
(GNUNET_GNSRECORD_TYPE_NICK != rd[i].record_type) )
rd_clean_off++;
-
+
if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT,
conv_name)) &&
(GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) )
* Zone to name iterator
*
* @param cls struct ZoneToNameCtx *
- * @param seq sequence number of the record
+ * @param seq sequence number of the record, MUST NOT BE ZERO
* @param zone_key the zone key
* @param name name
* @param rd_count number of records in @a rd
char *name_tmp;
char *rd_tmp;
- (void) seq;
+ GNUNET_assert (0 != seq);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Found result for zone-to-name lookup: `%s'\n",
name);
* Process results for zone iteration from database
*
* @param cls struct ZoneIterationProcResult
- * @param seq sequence number of the record
+ * @param seq sequence number of the record, MUST NOT BE ZERO
* @param zone_key the zone key
* @param name name
* @param rd_count number of records for this name
struct ZoneIterationProcResult *proc = cls;
int do_refresh_block;
+ GNUNET_assert (0 != seq);
if ( (NULL == zone_key) &&
(NULL == name) )
{
do_refresh_block = GNUNET_YES;
break;
}
- if (GNUNET_YES == do_refresh_block)
+ if (GNUNET_YES == do_refresh_block)
refresh_block (NULL,
proc->zi,
0,
* A #GNUNET_NAMESTORE_RecordIterator for monitors.
*
* @param cls a 'struct ZoneMonitor *' with information about the monitor
- * @param seq sequence number of the record
+ * @param seq sequence number of the record, MUST NOT BE ZERO
* @param zone_key zone key of the zone
* @param name name
* @param rd_count number of records in @a rd
{
struct ZoneMonitor *zm = cls;
+ GNUNET_assert (0 != seq);
zm->seq = seq;
GNUNET_assert (NULL != name);
GNUNET_STATISTICS_update (statistics,
*/
char *label;
-
};
+/**
+ * Hash contactenation of @a pkey and @a label into @a h
+ *
+ * @param pkey a key
+ * @param label a label
+ * @param h[out] initialized hash
+ */
+static void
+hash_pkey_and_label (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
+ const char *label,
+ struct GNUNET_HashCode *h)
+{
+ char *key;
+ size_t label_len;
+ size_t key_len;
+
+ label_len = strlen (label);
+ key_len = label_len + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
+ key = GNUNET_malloc (key_len);
+ GNUNET_memcpy (key,
+ label,
+ label_len);
+ GNUNET_memcpy (key + label_len,
+ pkey,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
+ GNUNET_CRYPTO_hash (key,
+ key_len,
+ h);
+ GNUNET_free (key);
+}
+
+
/**
* Initialize the database connections and associated
* data structures (create tables and indices
GNUNET_free (private_key);
}
- {
- char *key;
- size_t key_len;
-
- key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
- key = GNUNET_malloc (strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
- GNUNET_memcpy (key,
- label,
- strlen (label));
- GNUNET_memcpy (key+strlen(label),
- &entry->private_key,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
- GNUNET_CRYPTO_hash (key,
- key_len,
- &hkey);
- GNUNET_free (key);
- }
+ hash_pkey_and_label (&entry->private_key,
+ label,
+ &hkey);
if (GNUNET_OK !=
GNUNET_CONTAINER_multihashmap_put (plugin->hm,
&hkey,
{
struct Plugin *plugin = cls;
uint64_t rvalue;
- size_t key_len;
- char *key;
struct GNUNET_HashCode hkey;
struct FlatFileEntry *entry;
rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
UINT64_MAX);
- key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
- key = GNUNET_malloc (key_len);
- GNUNET_memcpy (key,
- label,
- strlen (label));
- GNUNET_memcpy (key + strlen(label),
- zone_key,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
- GNUNET_CRYPTO_hash (key,
- key_len,
- &hkey);
+ hash_pkey_and_label (zone_key,
+ label,
+ &hkey);
GNUNET_CONTAINER_multihashmap_remove_all (plugin->hm,
&hkey);
if (0 == rd_count)
struct Plugin *plugin = cls;
struct FlatFileEntry *entry;
struct GNUNET_HashCode hkey;
- char *key;
- size_t key_len;
if (NULL == zone)
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
- key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
- key = GNUNET_malloc (key_len);
- GNUNET_memcpy (key,
- label,
- strlen (label));
- GNUNET_memcpy (key+strlen(label),
- zone,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
- GNUNET_CRYPTO_hash (key,
- key_len,
- &hkey);
- GNUNET_free (key);
-
+ hash_pkey_and_label (zone,
+ label,
+ &hkey);
entry = GNUNET_CONTAINER_multihashmap_get (plugin->hm,
&hkey);
return GNUNET_NO;
if (NULL != iter)
iter (iter_cls,
- 0,
+ 1, /* zero is illegal */
&entry->private_key,
entry->label,
entry->record_count,
}
ic->iter (ic->iter_cls,
ic->pos,
- (NULL == ic->zone)
+ (NULL == ic->zone)
? &entry->private_key
: ic->zone,
entry->label,
sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
{
ztn->iter (ztn->iter_cls,
- 0,
+ i + 1, /* zero is illegal! */
&entry->private_key,
entry->label,
entry->record_count,
{
struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(record_count)];
+ GNUNET_assert (0 != serial);
if (GNUNET_OK !=
GNUNET_GNSRECORD_records_deserialize (data_size,
data,
{
struct GNUNET_GNSRECORD_Data rd[record_count];
+ GNUNET_assert (0 != seq);
if (GNUNET_OK !=
GNUNET_GNSRECORD_records_deserialize (data_size,
data,