44#define MAX_RECORDS_PER_NAME 50
49#define MAX_ZONEFILE_LINE_LEN 4096
54#define MAX_ZONEFILE_RECORD_DATA_LEN 2048
71 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10)
364 void *rd_ptr = (
void*)
rd[i].
data;
378 char *ltrimmed =
line;
383 while (*ltrimmed ==
' ')
385 ltrimmed_len = strlen (ltrimmed);
387 for (
int i = 0; i < ltrimmed_len; i++)
389 if (ltrimmed[i] ==
'"')
391 if ((ltrimmed[i] !=
';') || quoted)
395 ltrimmed_len = strlen (ltrimmed);
397 for (
int i = ltrimmed_len; i > 0; i--)
399 if (ltrimmed[i - 1] !=
' ')
401 ltrimmed[i - 1] =
'\0';
403 ltrimmed_len = strlen (ltrimmed);
404 if (ltrimmed[ltrimmed_len - 1] ==
'\n')
405 ltrimmed[ltrimmed_len - 1] =
' ';
424 unsigned int ttl_tmp;
426 next = strchr (token,
';');
429 next = strchr (token,
' ');
432 if (1 != sscanf (token,
"%u", &ttl_tmp))
434 fprintf (stderr,
"Unable to parse TTL `%s'\n", token);
447 next = strchr (token,
';');
450 next = strchr (token,
' ');
453 strcpy (porigin, token);
474 "Created missing ego `%s'\n",
497 "$ORIGIN %s does not exist, creating...\n",
ego_name);
517 _ (
"Failed to store records...\n"));
529 "Changing origin to %s\n",
ego_name);
562 "Requesting store for `%s'\n",
578 "Stopped processing queue (%u+%u/%u)]\n",
588 "Stopped processing queue: empty queue\n");
628 hlen = strlen (label) + 1;
673 int bracket_unclosed = 0;
679 while ((
res = fgets (buf,
sizeof(buf), stdin)))
685 "Trimmed line (bracket %s): `%s'\n",
686 (bracket_unclosed > 0) ?
"unclosed" :
"closed",
688 if ((0 == strlen (token)) ||
689 ((1 == strlen (token)) && (
' ' == *token)))
691 if (bracket_unclosed == 0)
696 next = strchr (token,
' ');
699 fprintf (stderr,
"Error at line %u: %s\n", ln, token);
706 if (0 == (strcmp (token,
"$ORIGIN")))
711 else if (0 == (strcmp (token,
"$TTL")))
718 if (0 == strcmp (token,
"IN"))
721 "Old name: %s\n", lastname);
722 strcpy (newname, lastname);
723 token[strlen (token)] =
' ';
725 else if (token[strlen (token) - 1] !=
'.')
731 _ (
"Name `%s' is too long\n"),
737 strcpy (newname, token);
740 else if (0 == strcmp (token,
origin))
743 strcpy (newname,
"@");
748 if (strlen (token) < strlen (
origin))
750 fprintf (stderr,
"Wrong origin: %s (expected %s)\n", token,
origin);
753 if (0 != strcmp (token + (strlen (token) - strlen (
origin)),
origin))
755 fprintf (stderr,
"Wrong origin: %s (expected %s)\n", token,
origin);
758 token[strlen (token) - strlen (
origin) - 1] =
'\0';
763 _ (
"Name `%s' is too long\n"),
769 strcpy (newname, token);
772 if (0 != strcmp (newname, lastname) &&
776 "Name changed %s->%s, storing record set of %u elements\n",
783 strcpy (lastname, newname);
791 fprintf (stderr,
_ (
"Failed to parse $TTL\n"));
802 fprintf (stderr,
_ (
"Failed to parse $ORIGIN from %s\n"), token);
813 "You must provide $ORIGIN in your zonefile or via arguments (--zone)!\n"));
822 _ (
"Only %u records per unique name supported.\n"),
830 next = strchr (token,
' ');
833 fprintf (stderr,
"Error, last token: %s\n", token);
844 next = strchr (token,
' ');
847 fprintf (stderr,
"Error\n");
859 for (
int i = 0; i < strlen (token); i++)
863 if ((token[i] ==
'(') && ! quoted)
865 if ((token[i] ==
')') && ! quoted)
869 memcpy (payload_pos, token, strlen (token));
870 payload_pos += strlen (token);
871 if (bracket_unclosed > 0)
885 _ (
"Data `%s' invalid\n"),
902 idna_to_unicode_8z8z (lastname,
904 IDNA_ALLOW_UNASSIGNED);
906 "Queueing %d records\n",
908 queue (lastname_utf8,
923 strcpy (lastname, newname);
936 "Changing origin to %s\n",
ego_name);
953 "Changing origin to %s\n",
ego_name);
959 printf (
"Published %u records sets with total %u records\n",
991 "Zone `%s' not found\n",
1024 const char *cfgfile,
1034 _ (
"Failed to connect to NAMESTORE\n"));
1041 _ (
"Failed to connect to IDENTITY\n"));
1063 "name of the ego controlling the zone"),
1074 "gnunet-namestore-zonefile",
1076 "GNUnet namestore database manipulation tool"),
struct GNUNET_GETOPT_CommandLineOption options[]
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
#define gettext_noop(String)
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
static struct GNUNET_SCHEDULER_Task * job
Task for main job.
static char * line
Desired phone line (string to be converted to a hash).
static char * data
The data to insert into the dht.
static struct GNUNET_FS_Handle * ctx
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static char * name
Name (label) of the records to list.
static struct GNUNET_NAMESTORE_QueueEntry * ns_qe
Queue entry for the 'add' operation.
#define THRESH
Maximum number of queries pending at the same time.
static struct GNUNET_IDENTITY_Operation * id_op
Origin create operations.
static void insert_sorted(struct Job *job)
Insert req into DLL sorted by next fetch time.
static struct Job * req_tail
Active requests are kept in a DLL.
static struct Zone * zone_tail
Tail of list of zones we are managing.
static struct GNUNET_CONTAINER_Heap * req_heap
Heap of all requests to perform, sorted by the time we should next do the request (i....
static void process_queue(void *cls)
Process as many requests as possible from the queue.
static void parse(void *cls)
Main function that will be run.
static unsigned int published_records
Statistics, how many records published in aggregate.
static unsigned int pending
The number of DNS queries that are outstanding.
static void queue(const char *label, uint32_t rd_count, struct GNUNET_GNSRECORD_Data *rd, const struct Zone *zone)
Add hostname to the list of requests to be made.
static void origin_create_cb(void *cls, const struct GNUNET_CRYPTO_PrivateKey *pk, enum GNUNET_ErrorCode ec)
static const struct GNUNET_CONFIGURATION_Handle * cfg
Current configurataion.
static struct GNUNET_TIME_Relative ttl
Current record $TTL to use.
#define MAX_RECORDS_PER_NAME
static struct GNUNET_TIME_Absolute sleep_time_reg_proc
Last time we worked before going idle.
static struct GNUNET_SCHEDULER_Task * t
Main task.
static struct Zone * zone_head
Head of list of zones we are managing.
static int ret
Return code.
static char * ego_name
Name of the ego.
#define MAX_ZONEFILE_LINE_LEN
Maximum length of a zonefile line.
static char origin[GNUNET_DNSPARSER_MAX_NAME_LENGTH]
Current origin.
#define MAX_ZONEFILE_RECORD_DATA_LEN
FIXME: Soft limit this?
static int state
The current state of the parser.
static void add_continuation(void *cls, enum GNUNET_ErrorCode ec)
static unsigned int rd_count
Number of records for currently parsed set.
static int parse_origin(char *token, char *porigin)
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *_cfg)
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
static struct Job * req_head
Active requests are kept in a DLL.
static char * res
Currently read line or NULL on EOF.
static struct Zone * current_zone
Private key for the our zone.
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
static unsigned int pending_rs
The number of NAMESTORE record store operations that are outstanding.
static char * trim(char *line)
static void identity_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
static void ensure_ego_and_continue(const char *ego_name)
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static int parse_ttl(char *token, struct GNUNET_TIME_Relative *pttl)
static char * next_token(char *token)
#define SERIES_DELAY
How long do we wait at least between series of requests?
static unsigned int published_sets
Statistics, how many published record sets.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
static unsigned long long payload
How much data are we currently storing in the database?
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
GNUNET_ErrorCode
Taler error codes.
@ GNUNET_EC_NONE
No error (success).
Plugin API for the namestore database backend.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_DNSPARSER_MAX_LABEL_LENGTH
Maximum length of a label in DNS.
#define GNUNET_DNSPARSER_MAX_NAME_LENGTH
Maximum length of a name in DNS.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (e.g.
int GNUNET_GNSRECORD_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of the value s of a record of type type to the respective binary repre...
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
void * GNUNET_CONTAINER_heap_peek(const struct GNUNET_CONTAINER_Heap *heap)
Get element stored at the root of heap.
void * GNUNET_CONTAINER_heap_remove_root(struct GNUNET_CONTAINER_Heap *heap)
Remove root of the heap.
struct GNUNET_CONTAINER_HeapNode * GNUNET_CONTAINER_heap_insert(struct GNUNET_CONTAINER_Heap *heap, void *element, GNUNET_CONTAINER_HeapCostType cost)
Inserts a new element into the heap.
struct GNUNET_CONTAINER_Heap * GNUNET_CONTAINER_heap_create(enum GNUNET_CONTAINER_HeapOrder order)
Create a new heap.
@ GNUNET_CONTAINER_HEAP_ORDER_MIN
Heap with the minimum cost at the root.
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *id, const char *name, const struct GNUNET_CRYPTO_PrivateKey *privkey, enum GNUNET_CRYPTO_KeyType ktype, GNUNET_IDENTITY_CreateContinuation cont, void *cont_cls)
Create a new ego with the given name.
const struct GNUNET_CRYPTO_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
void GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op)
Cancel an identity operation.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_record_set_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, 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,...
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
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,...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Handle to a node in a heap.
A private key for an identity as per LSD0001.
Definition of a command line option.
uint32_t record_type
Type of the GNS/DNS record.
const void * data
Binary value stored in the DNS record.
size_t data_size
Number of bytes in data.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
uint64_t expiration_time
Expiration time for the DNS record.
Handle for an operation with the identity service.
Connection to the NAMESTORE service.
An QueueEntry used to store information for a pending NAMESTORE record operation.
Entry in list of pending tasks.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
struct Job * next
Active requests are kept in a DLL.
struct GNUNET_GNSRECORD_Data * rd
struct GNUNET_TIME_Absolute op_start_time
While we are fetching the record, the value is set to the starting time of the DNS operation.
struct Record * rec_tail
Tail of records that should be published in GNS for this hostname.
struct Job * prev
Active requests are kept in a DLL.
const struct Zone * zone
Zone responsible for this request.
struct Record * rec_head
Head of records that should be published in GNS for this hostname.
struct GNUNET_NAMESTORE_QueueEntry * qe
Namestore operation pending for this record.
char label[GNUNET_DNSPARSER_MAX_NAME_LENGTH]
Hostname we are resolving.
struct GNUNET_TIME_Absolute expires
At what time does the (earliest) of the returned records for this name expire? At this point,...
struct GNUNET_CONTAINER_HeapNode * hn
Requests are kept in a heap while waiting to be resolved.
Missing identity creation context.
struct MissingZoneCreationCtx * prev
struct MissingZoneCreationCtx * next
struct GNUNET_IDENTITY_Operation * id_op
struct GNUNET_NAMESTORE_QueueEntry * ns_qe
Record for the request to be stored by GNS.
struct Zone * prev
Kept in a DLL.
struct GNUNET_CRYPTO_PrivateKey key
Private key of the zone.
struct Zone * next
Kept in a DLL.
char * domain
Domain of the zone (i.e.