#include "gnunet_util_lib.h"
#include "gnunet_namestore_plugin.h"
-#define VERBOSE GNUNET_EXTRA_LOGGING
+#define VERBOSE GNUNET_NO
#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0)
* Function called by for each matching record.
*
* @param cls closure
- * @param zone hash of the public key of the zone
- * @param loc location of the signature for this record
+ * @param zone_key public key of the zone
+ * @param expire when does the corresponding block in the DHT expire (until
+ * when should we never do a DHT lookup for the same name again)?
* @param name name that is being mapped (at most 255 characters long)
- * @param record_type type of the record (A, AAAA, PKEY, etc.)
- * @param expiration expiration time for the content
- * @param flags flags for the content
- * @param data_size number of bytes in data
- * @param data value, semantics depend on 'record_type' (see RFCs for DNS and
- * GNS specification for GNS extensions)
+ * @param rd_count number of entries in 'rd' array
+ * @param rd array of records with data to store
+ * @param signature signature of the record block, NULL if signature is unavailable (i.e.
+ * because the user queried for a particular record type only)
*/
static void
test_record (void *cls,
- const GNUNET_HashCode *zone,
- const struct GNUNET_NAMESTORE_SignatureLocation *loc,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+ struct GNUNET_TIME_Absolute expire,
const char *name,
- uint32_t record_type,
- struct GNUNET_TIME_Absolute expiration,
- enum GNUNET_NAMESTORE_RecordFlags flags,
- size_t data_size,
- const void *data)
+ unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_RsaSignature *signature)
{
int *idp = cls;
int id = *idp;
- size_t tdata_size = id * 17;
- char tdata[tdata_size];
- GNUNET_HashCode tzone;
- char tname[32];
- uint32_t trecord_type;
- struct GNUNET_NAMESTORE_SignatureLocation tloc;
- enum GNUNET_NAMESTORE_RecordFlags tflags;
-
- memset (&tzone, 42, sizeof (tzone));
- memset (tdata, id % 255, sizeof (tdata));
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tzone_key;
+ char tname[64];
+ unsigned int trd_count = 1 + (id % 1024);
+ struct GNUNET_CRYPTO_RsaSignature tsignature;
+ unsigned int i;
+
GNUNET_snprintf (tname, sizeof (tname),
- "aa%u", (unsigned int) id);
- trecord_type = id % 4;
- tloc.depth = (id % 10);
- tloc.offset = (id % 3);
- tloc.revision = id % 1024;
- tflags = GNUNET_NAMESTORE_RF_AUTHORITY;
-
- GNUNET_assert (0 == memcmp (&tzone, zone, sizeof (GNUNET_HashCode)));
- GNUNET_assert (trecord_type == record_type);
- GNUNET_assert (0 == strcmp (tname, name));
- GNUNET_assert (tdata_size == data_size);
- GNUNET_assert (0 == memcmp (data, tdata, data_size));
- GNUNET_assert (flags == tflags);
- GNUNET_assert (0 == memcmp (loc, &tloc, sizeof (struct GNUNET_NAMESTORE_SignatureLocation)));
+ "a%u", (unsigned int ) id);
+ for (i=0;i<trd_count;i++)
+ {
+ GNUNET_assert (rd[i].data_size == id % 10);
+ GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10));
+ GNUNET_assert (rd[i].record_type == 1 + (id % 13));
+ GNUNET_assert (rd[i].flags == (id % 7));
+ }
+ memset (&tzone_key, (id % 241), sizeof (tzone_key));
+ memset (&tsignature, (id % 243), sizeof (tsignature));
+ GNUNET_assert (0 == strcmp (name, tname));
+ GNUNET_assert (0 == memcmp (&tzone_key, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)));
+ GNUNET_assert (0 == memcmp (&tsignature, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)));
}
static void
get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
{
- GNUNET_HashCode zone;
- GNUNET_HashCode nh;
- char name[32];
-
- memset (&zone, 42, sizeof (zone));
- GNUNET_snprintf (name, sizeof (name),
- "aa%u", (unsigned int) id);
- GNUNET_CRYPTO_hash (name, strlen (name), &nh);
GNUNET_assert (1 == nsp->iterate_records (nsp->cls,
- &zone,
- &nh,
+ NULL, NULL, 0,
&test_record, &id));
}
-/**
- * Function called with the matching node.
- *
- * @param cls closure
- * @param zone hash of public key of the zone
- * @param loc location in the B-tree
- * @param ploc parent's location in the B-tree (must have depth = loc.depth - 1), NULL for root
- * @param num_entries number of entries at this node in the B-tree
- * @param entries the 'num_entries' entries to store (hashes over the
- * records)
- */
-static void
-test_node (void *cls,
- const GNUNET_HashCode *zone,
- const struct GNUNET_NAMESTORE_SignatureLocation *loc,
- const struct GNUNET_NAMESTORE_SignatureLocation *ploc,
- unsigned int num_entries,
- const GNUNET_HashCode *entries)
-{
- int *idp = cls;
- int id = *idp;
- struct GNUNET_NAMESTORE_SignatureLocation tloc;
- struct GNUNET_NAMESTORE_SignatureLocation tploc;
- unsigned int tnum_entries = 1 + (id % 15);
- GNUNET_HashCode tentries[num_entries];
- unsigned int i;
-
- tloc.depth = (id % 10);
- tloc.offset = (id % 3);
- tloc.revision = id % 1024;
- tploc.depth = tloc.depth + 1;
- tploc.offset = (id % 5);
- tploc.revision = tloc.revision;
- for (i=0;i<tnum_entries;i++)
- memset (&tentries[i], (id+i) % 255, sizeof (GNUNET_HashCode));
- GNUNET_assert (0 == memcmp (&tloc, loc,
- sizeof (const struct GNUNET_NAMESTORE_SignatureLocation)));
- GNUNET_assert (0 == memcmp (&tploc, ploc,
- sizeof (const struct GNUNET_NAMESTORE_SignatureLocation)));
- GNUNET_assert (num_entries == tnum_entries);
- GNUNET_assert (0 == memcmp (entries, tentries, sizeof (tentries)));
-}
-
-
-static void
-get_node (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
-{
- GNUNET_HashCode zone;
- struct GNUNET_NAMESTORE_SignatureLocation loc;
-
- memset (&zone, 42, sizeof (zone));
- loc.depth = (id % 10);
- loc.offset = (id % 3);
- loc.revision = id % 1024;
- GNUNET_assert (GNUNET_OK ==
- nsp->get_node (nsp->cls,
- &zone,
- &loc,
- &test_node,
- &id));
-}
-
-
-/**
- * Function called with the matching signature.
- *
- * @param cls closure
- * @param zone public key of the zone
- * @param loc location of the root in the B-tree (depth, revision)
- * @param top_sig signature signing the zone
- * @param zone_time time the signature was created
- * @param root_hash top level hash that is being signed
- */
-static void
-test_signature (void *cls,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
- const struct GNUNET_NAMESTORE_SignatureLocation *loc,
- const struct GNUNET_CRYPTO_RsaSignature *top_sig,
- struct GNUNET_TIME_Absolute zone_time,
- const GNUNET_HashCode *root_hash)
-{
- int *idp = cls;
- int id = *idp;
- struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tzone_key;
- struct GNUNET_NAMESTORE_SignatureLocation tloc;
- struct GNUNET_CRYPTO_RsaSignature ttop_sig;
- GNUNET_HashCode troot_hash;
-
- memset (&tzone_key, 13, sizeof (tzone_key));
- tloc.depth = (id % 10);
- tloc.offset = 0;
- tloc.revision = id % 1024;
- memset (&ttop_sig, 24, sizeof (ttop_sig));
- memset (&troot_hash, 42, sizeof (troot_hash));
-
- GNUNET_assert (0 == memcmp (&tzone_key, zone_key, sizeof (GNUNET_HashCode)));
- GNUNET_assert (0 == memcmp (&tloc, loc, sizeof (struct GNUNET_NAMESTORE_SignatureLocation)));
- GNUNET_assert (0 == memcmp (&ttop_sig, top_sig, sizeof (struct GNUNET_CRYPTO_RsaSignature)));
- GNUNET_assert (0 == memcmp (&troot_hash, root_hash, sizeof (GNUNET_HashCode)));
-}
-
-
-static void
-get_signature (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
-{
- struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
- GNUNET_HashCode zone;
-
- memset (&zone_key, 13, sizeof (zone_key));
- GNUNET_CRYPTO_hash (&zone_key, sizeof (zone_key), &zone);
- GNUNET_assert (GNUNET_OK ==
- nsp->get_signature (nsp->cls,
- &zone,
- test_signature,
- &id));
-}
-
-
static void
put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
-{
- size_t data_size = id * 17;
- char data[data_size];
- GNUNET_HashCode zone;
- char name[32];
- uint32_t record_type;
- struct GNUNET_NAMESTORE_SignatureLocation loc;
- struct GNUNET_TIME_Absolute expiration;
- enum GNUNET_NAMESTORE_RecordFlags flags;
-
- memset (&zone, 42, sizeof (zone));
- memset (data, id % 255, sizeof (data));
- GNUNET_snprintf (name, sizeof (name),
- "aa%u", (unsigned int) id);
- record_type = id % 4;
- loc.depth = (id % 10);
- loc.offset = (id % 3);
- loc.revision = id % 1024;
- expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
- flags = GNUNET_NAMESTORE_RF_AUTHORITY;
-
- GNUNET_assert (GNUNET_OK ==
- nsp->put_record (nsp->cls,
- &zone,
- name,
- record_type,
- &loc,
- expiration,
- flags,
- data_size,
- data));
-}
-
-
-static void
-put_node (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
- int id)
-{
- GNUNET_HashCode zone;
- struct GNUNET_NAMESTORE_SignatureLocation loc;
- struct GNUNET_NAMESTORE_SignatureLocation ploc;
- unsigned int num_entries = 1 + (id % 15);
- GNUNET_HashCode entries[num_entries];
- unsigned int i;
-
- memset (&zone, 42, sizeof (zone));
- loc.depth = (id % 10);
- loc.offset = (id % 3);
- loc.revision = id % 1024;
- ploc.depth = loc.depth + 1;
- ploc.offset = (id % 5);
- ploc.revision = loc.revision;
- for (i=0;i<num_entries;i++)
- memset (&entries[i], (id+i) % 255, sizeof (GNUNET_HashCode));
- GNUNET_assert (GNUNET_OK ==
- nsp->put_node (nsp->cls,
- &zone,
- &loc,
- &ploc,
- num_entries,
- entries));
-}
-
-
-static void
-put_signature (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
- int id)
{
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
- struct GNUNET_NAMESTORE_SignatureLocation loc;
- struct GNUNET_CRYPTO_RsaSignature top_sig;
- GNUNET_HashCode root_hash;
- struct GNUNET_TIME_Absolute zone_time;
+ struct GNUNET_TIME_Absolute expire;
+ char name[64];
+ unsigned int rd_count = 1 + (id % 1024);
+ struct GNUNET_NAMESTORE_RecordData rd[rd_count];
+ struct GNUNET_CRYPTO_RsaSignature signature;
+ unsigned int i;
- memset (&zone_key, 13, sizeof (zone_key));
- loc.depth = (id % 10);
- loc.offset = 0;
- loc.revision = id % 1024;
- memset (&top_sig, 24, sizeof (top_sig));
- memset (&root_hash, 42, sizeof (root_hash));
- zone_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
-
- GNUNET_assert (GNUNET_OK ==
- nsp->put_signature (nsp->cls,
- &zone_key,
- &loc,
- &top_sig,
- &root_hash,
- zone_time));
+ GNUNET_snprintf (name, sizeof (name),
+ "a%u", (unsigned int ) id);
+ expire = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
+ for (i=0;i<rd_count;i++)
+ {
+ rd[i].data = "Hello World";
+ rd[i].data_size = id % 10;
+ rd[i].expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
+ rd[i].record_type = 1 + (id % 13);
+ rd[i].flags = (id % 7);
+ }
+ memset (&zone_key, (id % 241), sizeof (zone_key));
+ memset (&signature, (id % 243), sizeof (signature));
+ GNUNET_assert (GNUNET_OK == nsp->put_records (nsp->cls,
+ &zone_key,
+ expire,
+ name,
+ rd_count,
+ rd,
+ &signature));
}
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_NAMESTORE_PluginFunctions *nsp;
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
GNUNET_HashCode zone;
ok = 0;
}
put_record (nsp, 1);
get_record (nsp, 1);
- put_node (nsp, 1);
- get_node (nsp, 1);
- put_signature (nsp, 1);
- get_signature (nsp, 1);
- memset (&zone, 42, sizeof (zone));
+ memset (&zone_key, 1, sizeof (zone_key));
+ GNUNET_CRYPTO_hash (&zone_key, sizeof (zone_key), &zone);
nsp->delete_zone (nsp->cls, &zone);
unload_plugin (nsp);
}
GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_plugin_namestore_%s.conf",
plugin_name);
- if (pos != plugin_name)
- pos[0] = '.';
GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
"test-plugin-namestore", "nohelp", options, &run, NULL);
if (ok != 0)