GNUnet  0.10.x
gnsrecord_misc.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2009-2013 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19 */
20 
28 #include "platform.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_constants.h"
31 #include "gnunet_signatures.h"
32 #include "gnunet_arm_service.h"
33 #include "gnunet_gnsrecord_lib.h"
34 #include "gnunet_dnsparser_lib.h"
35 #include "gnunet_tun_lib.h"
36 
37 
38 #define LOG(kind,...) GNUNET_log_from (kind, "gnsrecord",__VA_ARGS__)
39 
45 char *
47 {
48  char *res;
49 
50  res = GNUNET_strdup (src);
51  GNUNET_STRINGS_utf8_tolower (src, res);
52  return res;
53 }
54 
55 
64 const char *
66 {
67  static char buf[sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) * 8];
68  char *end;
69 
70  end = GNUNET_STRINGS_data_to_string ((const unsigned char *) z,
71  sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
72  buf, sizeof (buf));
73  if (NULL == end)
74  {
75  GNUNET_break (0);
76  return NULL;
77  }
78  *end = '\0';
79  return buf;
80 }
81 
82 
92 int
94  const struct GNUNET_GNSRECORD_Data *b)
95 {
97  "Comparing records\n");
98  if (a->record_type != b->record_type)
99  {
101  "Record type %lu != %lu\n", a->record_type, b->record_type);
102  return GNUNET_NO;
103  }
104  if ((a->expiration_time != b->expiration_time) &&
105  ((a->expiration_time != 0) && (b->expiration_time != 0)))
106  {
108  "Expiration time %llu != %llu\n",
109  a->expiration_time,
110  b->expiration_time);
111  return GNUNET_NO;
112  }
115  {
117  "Flags %lu (%lu) != %lu (%lu)\n", a->flags,
120  return GNUNET_NO;
121  }
122  if (a->data_size != b->data_size)
123  {
125  "Data size %lu != %lu\n",
126  a->data_size,
127  b->data_size);
128  return GNUNET_NO;
129  }
130  if (0 != memcmp (a->data, b->data, a->data_size))
131  {
133  "Data contents do not match\n");
134  return GNUNET_NO;
135  }
137  "Records are equal\n");
138  return GNUNET_YES;
139 }
140 
141 
153  const struct GNUNET_GNSRECORD_Data *rd)
154 {
155  struct GNUNET_TIME_Absolute expire;
156  struct GNUNET_TIME_Absolute at;
157  struct GNUNET_TIME_Relative rt;
158  struct GNUNET_TIME_Absolute at_shadow;
159  struct GNUNET_TIME_Relative rt_shadow;
160 
161  if (NULL == rd)
164  for (unsigned int c = 0; c < rd_count; c++)
165  {
166  if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
167  {
168  rt.rel_value_us = rd[c].expiration_time;
170  }
171  else
172  {
173  at.abs_value_us = rd[c].expiration_time;
174  }
175 
176  for (unsigned int c2 = 0; c2 < rd_count; c2++)
177  {
178  /* Check for shadow record */
179  if ( (c == c2) ||
180  (rd[c].record_type != rd[c2].record_type) ||
181  (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) )
182  continue;
183  /* We have a shadow record */
184  if (0 != (rd[c2].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
185  {
186  rt_shadow.rel_value_us = rd[c2].expiration_time;
187  at_shadow = GNUNET_TIME_relative_to_absolute (rt_shadow);
188  }
189  else
190  {
191  at_shadow.abs_value_us = rd[c2].expiration_time;
192  }
193  at = GNUNET_TIME_absolute_max (at,
194  at_shadow);
195  }
196  expire = GNUNET_TIME_absolute_min (at,
197  expire);
198  }
200  "Determined expiration time for block with %u records to be %s\n",
201  rd_count,
203  return expire;
204 }
205 
206 
213 int
215 {
216  struct GNUNET_TIME_Absolute at;
217 
219  return GNUNET_NO;
220  at.abs_value_us = rd->expiration_time;
221  return (0 == GNUNET_TIME_absolute_get_remaining (at).rel_value_us) ? GNUNET_YES : GNUNET_NO;
222 }
223 
224 
235 const char *
237 {
238  static char ret[128];
239  char *pkeys;
240 
242  GNUNET_snprintf (ret,
243  sizeof (ret),
244  "%s",
245  pkeys);
246  GNUNET_free (pkeys);
247  return ret;
248 }
249 
250 
260 int
263 {
264  if (GNUNET_OK !=
266  strlen (zkey),
267  pkey))
268  return GNUNET_SYSERR;
269  return GNUNET_OK;
270 }
271 
272 
273 /* end of gnsrecord_misc.c */
This record should not be used unless all (other) records with an absolute expiration time have expir...
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
char * GNUNET_GNSRECORD_string_to_lowercase(const char *src)
Convert a UTF-8 string to UTF-8 lowercase.
uint64_t rel_value_us
The actual value.
static char * pkey
Public key of the zone to look in, in ASCII.
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
static void expire(void *cls)
Expire a PooledConnection object.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:245
int GNUNET_GNSRECORD_zkey_to_pkey(const char *zkey, struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert an absolute domain name to the respective public key.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
size_t data_size
Number of bytes in data.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
uint64_t abs_value_us
The actual value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
const void * data
Binary value stored in the DNS record.
#define LOG(kind,...)
uint64_t expiration_time
Expiration time for the DNS record.
static char buf[2048]
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the maximum of two absolute time values.
Definition: time.c:317
const char * GNUNET_GNSRECORD_z2s(const struct GNUNET_CRYPTO_EcdsaPublicKey *z)
Convert a zone key to a string (for printing debug messages).
static int res
struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_record_get_expiration_time(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Returns the expiration time of the given block of records.
char * GNUNET_CRYPTO_ecdsa_public_key_to_string(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:334
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_GNSRECORD_RF_RCMP_FLAGS
int GNUNET_GNSRECORD_records_cmp(const struct GNUNET_GNSRECORD_Data *a, const struct GNUNET_GNSRECORD_Data *b)
Compares if two records are equal (ignoring flags such as authority, private and pending, but not relative vs.
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
int GNUNET_GNSRECORD_is_expired(const struct GNUNET_GNSRECORD_Data *rd)
Test if a given record is expired.
int GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:468
uint32_t record_type
Type of the GNS/DNS record.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the minimum of two absolute time values.
Definition: time.c:302
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
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?
Definition: time.c:331
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:80
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
This flag is currently unused; former RF_PENDING flag.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:792
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
Definition: strings.c:924
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
void GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:558