129 if (NULL != datastore)
131 if (NULL != file_handle)
154 do_get (
const uint64_t next_uid);
187 fprintf (stderr,
_ (
"Dumped %" PRIu64
" records\n"),
record_count);
201 dr.
size = htonl ((uint32_t) size);
202 dr.
type = htonl (type);
211 if (
sizeof(dr) != len)
214 _ (
"Short write to file: %zd bytes expecting %zd\n"),
226 _ (
"Short write to file: %zd bytes expecting %zd\n"),
257 fprintf (stderr,
_ (
"Error queueing datastore GET operation\n"));
280 if (NULL == file_handle)
282 fprintf (stderr,
_ (
"Unable to open dump file: %s\n"),
file_name);
319 fprintf (stderr,
_ (
"Failed to store item: %s, aborting\n"), msg);
331 fprintf (stderr,
_ (
"Inserted %" PRIu64
" records\n"),
record_count);
336 else if (
sizeof(dr) != len)
339 _ (
"Short read from file: %zd bytes expecting %zd\n"),
347 const size_t size = ntohl (dr.
size);
353 _ (
"Short read from file: %zd bytes expecting %zd\n"),
378 fprintf (stderr,
_ (
"Error queueing datastore PUT operation\n"));
398 if (NULL == file_handle)
400 fprintf (stderr,
_ (
"Unable to open dump file: %s\n"),
file_name);
417 fprintf (stderr,
_ (
"Input file is not of a supported format\n"));
440 if (NULL == datastore)
442 fprintf (stderr,
_ (
"Failed connecting to the datastore.\n"));
454 _ (
"Please choose at least one operation: %s, %s\n"),
471 main (
int argc,
char *
const *argv)
477 "Dump all records from the datastore"),
482 "Insert records into the datastore"),
static int ret
Global return value.
static struct GNUNET_TIME_Absolute min_expiration
Minimum time that content should have to not be discarded instantly (time stamp of any content that w...
Open the file for reading.
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
Create file if it doesn't exist.
struct GNUNET_MessageHeader * msg
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Any type of block, used as a wildcard when searching.
GNUNET_BLOCK_Type
Blocks in the datastore and the datacache must have a unique type.
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
static struct GNUNET_DISK_FileHandle * file_handle
Dump file handle.
uint32_t replication
Desired replication level (NBO).
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_put(struct GNUNET_DATASTORE_Handle *h, uint32_t rid, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the datastore.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
static char * file_name
Dump file name.
static struct GNUNET_DATASTORE_Handle * datastore
Handle for datastore.
Nobody is allowed to do anything to the file.
uint32_t type
Type of the item (NBO) (actually an enum GNUNET_BLOCK_Type)
Definition of a command line option.
struct GNUNET_HashCode key
Key under which the item can be found.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
static void do_shutdown(void *cls)
static uint64_t record_count
Record count.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_filename(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a filename (automatically path expanded).
Entry in our priority queue.
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.
static void start_insert(void)
Begin inserting into the database.
static GNUNET_NETWORK_STRUCT_END const size_t MAGIC_LEN
Length of our magic header.
static void start_dump(void)
Begin dumping the database.
uint32_t anonymity
Desired anonymity level (NBO).
static void get_cb(void *cls, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
Process a datum that was stored in the datastore.
uint32_t priority
Priority of the item (NBO).
#define GNUNET_free_nz(ptr)
Wrapper around free.
Open the file for writing.
int main(int argc, char *const *argv)
The main function to manipulate datastores.
uint32_t size
Number of bytes in the item (NBO).
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
void GNUNET_DATASTORE_cancel(struct GNUNET_DATASTORE_QueueEntry *qe)
Cancel a datastore operation.
struct GNUNET_TIME_AbsoluteNBO expiration
Expiration time (NBO).
#define GNUNET_PACKED
gcc-ism to get packed structs.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_int_fd(int fno)
Get a handle from a native integer FD.
void GNUNET_DATASTORE_disconnect(struct GNUNET_DATASTORE_Handle *h, int drop)
Disconnect from the datastore service (and free associated resources).
Handle to the datastore service.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
Time for absolute times used by GNUnet, in microseconds.
static void do_get(const uint64_t next_uid)
Perform next GET operation.
struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_get_key(struct GNUNET_DATASTORE_Handle *h, uint64_t next_uid, bool random, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls)
Get a result for a particular key from the datastore.
static int dump
Dump the database.
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.
struct GNUNET_DATASTORE_Handle * GNUNET_DATASTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the datastore service.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Handle used to access files (and pipes).
static int insert
Insert into the database.
static const uint8_t MAGIC_BYTES[16]
Magic header bytes.
static void put_cb(void *cls, int32_t success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
Continuation called to notify client about result of the operation.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
#define gettext_noop(String)