97 label_len = strlen (label);
126 char *zone_private_key;
127 char *record_data_b64;
133 size_t record_data_size;
163 plugin->
fn = flatdbfile;
176 _ (
"Unable to initialize file: %s.\n"),
187 _ (
"Unable to get filesize: %s.\n"),
195 _ (
"File too big to map: %llu bytes.\n"),
196 (
unsigned long long) size);
216 if (
'\0' != buffer[size - 1])
219 _ (
"Namestore database file `%s' malformed\n"),
226 line = strtok (buffer,
"\n");
229 zone_private_key = strtok (line,
",");
230 if (NULL == zone_private_key)
232 rvalue = strtok (NULL,
",");
235 record_count = strtok (NULL,
",");
236 if (NULL == record_count)
238 record_data_b64 = strtok (NULL,
",");
239 if (NULL == record_data_b64)
241 label = strtok (NULL,
",");
244 line = strtok (NULL,
"\n");
247 unsigned long long ll;
249 if (1 != sscanf (rvalue,
254 "Error parsing entry\n");
258 entry->
rvalue = (uint64_t) ll;
263 if (1 != sscanf (record_count,
268 "Error parsing entry\n");
277 strlen (record_data_b64),
278 (
void **) &record_data);
289 "Unable to deserialize record %s\n",
302 strlen (zone_private_key),
303 (
void **) &private_key);
342 char *zone_private_key;
343 char *record_data_b64;
358 if (data_size >= UINT16_MAX)
384 "%s,%llu,%u,%s,%s\n",
386 (
unsigned long long) entry->
rvalue,
424 _ (
"Unable to initialize file: %s.\n"),
457 unsigned int rd_count,
490 for (
unsigned int i = 0; i < rd_count; i++)
610 if ((NULL != ic->
zone) &&
752 "Performing reverse lookup for `%s'\n",
770 static struct Plugin plugin;
774 if (NULL != plugin.
cfg)
792 _ (
"Flat file database running\n"));
813 "Flat file plugin is finished\n");
Create file if it doesn't exist.
GNUNET_NETWORK_STRUCT_END ssize_t GNUNET_GNSRECORD_records_get_size(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Calculate how many bytes we will need to serialize the given records.
static char * pkey
Public key of the zone to look in, in ASCII.
const struct GNUNET_IDENTITY_PublicKey * value_zone
uint32_t type
Type of public key.
void * libgnunet_plugin_namestore_flat_init(void *cls)
Entry point for the plugin.
const struct GNUNET_IDENTITY_PrivateKey * zone
Target zone.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
ssize_t GNUNET_GNSRECORD_records_serialize(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
Serialize the given records to the given destination buffer.
static int iterate_zones(void *cls, const struct GNUNET_HashCode *key, void *value)
Helper function for namestore_flat_iterate_records().
uint64_t offset
How many more records should we skip before returning results?
static size_t data_size
Number of bytes in data.
static struct GNUNET_CADET_Handle * mh
Cadet handle.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
GNUNET_NAMESTORE_RecordIterator iter
static int namestore_flat_zone_to_name(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const struct GNUNET_IDENTITY_PublicKey *value_zone, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Look for an existing PKEY delegation record for a given public key.
void * GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, enum GNUNET_DISK_MapType access, size_t len)
Map a file into memory.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void database_shutdown(struct Plugin *plugin)
Shutdown database connection and associate data structures.
static int namestore_flat_lookup_records(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Lookup records in the datastore for which we are the authority.
A private key for an identity as per LSD0001.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
size_t data_size
Number of bytes in data.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
int GNUNET_CONTAINER_multihashmap_remove_all(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Remove all entries for the given key from the map.
static int namestore_flat_store_records(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone_key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Store a record in the datastore.
int GNUNET_GNSRECORD_records_deserialize(size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
Deserialize the given records to the given destination.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
Internal representation of the hash map.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static int namestore_flat_iterate_records(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, uint64_t serial, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Iterate over the results for a particular key and zone in the datastore.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
Closure for iterate_zones.
uint64_t limit
How many more records should we return?
common internal definitions for namestore service
static char * zone
Name of the zone we manage.
void * cls
Closure to pass to all plugin functions.
static uint64_t record_count
Record count.
GNUNET_NAMESTORE_RecordIterator iter
Function to call on each record.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
const struct GNUNET_IDENTITY_PrivateKey * zone
const void * data
Binary value stored in the DNS record.
static char * line
Desired phone line (string to be converted to a hash).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_zonekey_type(uint32_t type)
Check if this type is one of the supported GNS zone types.
static char * value
Value of the record to add/remove.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Truncate file if it exists.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
uint64_t expiration_time
Expiration time for the DNS record.
static void hash_pkey_and_label(const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, struct GNUNET_HashCode *h)
Hash contactenation of pkey and label into h.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
Closure for zone_to_name.
static int fh
Handle to the unique file.
static char * plugin
Solver plugin name as string.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
int(* lookup_records)(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Lookup records in the datastore for which we are the authority.
int(* zone_to_name)(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const struct GNUNET_IDENTITY_PublicKey *value_zone, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Look for an existing PKEY delegation record for a given public key.
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
void * iter_cls
Iterator cls.
uint32_t record_count
Record cound.
void * iter_cls
Closure for iter.
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
void * libgnunet_plugin_namestore_flat_done(void *cls)
Exit point from the plugin.
char * fn
Filename used for the DB.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
struct GNUNET_GNSRECORD_Data * record_data
Record data.
int(* store_records)(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Store a record in the datastore for which we are the authority.
An identity key as per LSD0001.
uint32_t record_type
Type of the GNS/DNS record.
unsigned long long size
Size of all values we're storing.
void(* GNUNET_NAMESTORE_RecordIterator)(void *cls, uint64_t serial, const struct GNUNET_IDENTITY_PrivateKey *private_key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Function called for each matching record.
#define GNUNET_log(kind,...)
Open the file for both reading and writing.
static int database_setup(struct Plugin *plugin)
Initialize the database connections and associated data structures (create tables and indices as need...
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
struct GNUNET_IDENTITY_PrivateKey private_key
Entry zone.
int(* iterate_records)(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, uint64_t serial, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Iterate over the results for a particular zone in the datastore.
#define GNUNET_log_from(kind, comp,...)
sqlite3_stmt * zone_to_name
Precompiled SQL to for reverse lookup based on PKEY.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
uint32_t data
The data value.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
const char * GNUNET_GNSRECORD_z2s(const struct GNUNET_IDENTITY_PublicKey *z)
Convert a zone key to a string (for printing debug messages).
GNUNET_PEERSTORE_Processor iter
Iterator.
struct returned by the initialization function of the plugin
Handle used to access files (and pipes).
static int store_and_free_entries(void *cls, const struct GNUNET_HashCode *key, void *value)
Store values in hashmap in file and free data.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory)...
#define GNUNET_malloc(size)
Wrapper around malloc.
Handle for a memory-mapping operation.
#define GNUNET_free(ptr)
Wrapper around free.
uint64_t pos
What is the position of the current entry, counting starts from 1.