From 900b48c3aa80d693fd79b6ef9a3dce323ac61a57 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 4 Oct 2013 07:22:37 +0000 Subject: -do set expiration time when storing records, works better that way... --- src/namestore/gnunet-namestore.c | 9 ++ src/namestore/gnunet-service-namestore.c | 12 +-- src/namestore/namestore_api.c | 5 +- src/namestore/namestore_api_common.c | 145 +++++++++++++++++-------------- 4 files changed, 100 insertions(+), 71 deletions(-) (limited to 'src/namestore') diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 47018e2ec..37995e8c6 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c @@ -428,6 +428,15 @@ get_existing_record (void *cls, rde->flags |= GNUNET_NAMESTORE_RF_SHADOW_RECORD; if (1 != public) rde->flags |= GNUNET_NAMESTORE_RF_PRIVATE; + if (GNUNET_YES == etime_is_rel) + { + rde->expiration_time = etime_rel.rel_value_us; + rde->flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION; + } + else if (GNUNET_NO == etime_is_rel) + rde->expiration_time = etime_abs.abs_value_us; + else + rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; GNUNET_assert (NULL != name); add_qe = GNUNET_NAMESTORE_records_store (ns, &zone_pkey, diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 7ca043d8a..8251a41fa 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c @@ -372,8 +372,9 @@ handle_lookup_block_it (void *cls, r->derived_key = block->derived_key; memcpy (&r[1], &block[1], esize); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending `%s' message\n", - "NAMESTORE_LOOKUP_BLOCK_RESPONSE"); + "Sending `%s' message with expiration time %s\n", + "NAMESTORE_LOOKUP_BLOCK_RESPONSE", + GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (r->expire))); GNUNET_SERVER_notification_context_unicast (snc, lnc->nc->client, &r->gns_header.header, @@ -458,9 +459,6 @@ handle_block_cache (void *cls, size_t esize; int res; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received `%s' message\n", - "NAMESTORE_BLOCK_CACHE"); nc = client_lookup (client); if (ntohs (message->size) < sizeof (struct BlockCacheMessage)) { @@ -477,6 +475,10 @@ handle_block_cache (void *cls, sizeof (struct GNUNET_TIME_AbsoluteNBO) + esize); block->expiration_time = rp_msg->expire; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received `%s' message with expiration time %s\n", + "NAMESTORE_BLOCK_CACHE", + GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (block->expiration_time))); memcpy (&block[1], &rp_msg[1], esize); res = GSN_database->cache_block (GSN_database->cls, block); diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 1832d83f7..a1d17835f 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c @@ -1056,9 +1056,10 @@ GNUNET_NAMESTORE_block_cache (struct GNUNET_NAMESTORE_Handle *h, msg->derived_key = block->derived_key; memcpy (&msg[1], &block[1], blen); LOG (GNUNET_ERROR_TYPE_DEBUG, - "Sending `%s' message with size %u\n", + "Sending `%s' message with size %u and expiration %s\n", "NAMESTORE_BLOCK_CACHE", - (unsigned int) msg_size); + (unsigned int) msg_size, + GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (msg->expire))); GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); do_transmit (h); return qe; diff --git a/src/namestore/namestore_api_common.c b/src/namestore/namestore_api_common.c index e9d15b205..5ba8e6f37 100644 --- a/src/namestore/namestore_api_common.c +++ b/src/namestore/namestore_api_common.c @@ -36,7 +36,7 @@ #include "namestore.h" -#define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__) +#define LOG(kind,...) GNUNET_log_from (kind, "namestore-api",__VA_ARGS__) GNUNET_NETWORK_STRUCT_BEGIN @@ -162,6 +162,11 @@ GNUNET_NAMESTORE_records_serialize (unsigned int rd_count, off = 0; for (i=0;irecord_type != b->record_type) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Record type %lu != %lu\n", a->record_type, b->record_type); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Record type %lu != %lu\n", a->record_type, b->record_type); return GNUNET_NO; } if ((a->expiration_time != b->expiration_time) && ((a->expiration_time != 0) && (b->expiration_time != 0))) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Expiration time %llu != %llu\n", a->expiration_time, b->expiration_time); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Expiration time %llu != %llu\n", + a->expiration_time, + b->expiration_time); return GNUNET_NO; } if ((a->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS) != (b->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Flags %lu (%lu) != %lu (%lu)\n", a->flags, - a->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS, b->flags, - b->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Flags %lu (%lu) != %lu (%lu)\n", a->flags, + a->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS, b->flags, + b->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS); return GNUNET_NO; } if (a->data_size != b->data_size) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Data size %lu != %lu\n", a->data_size, b->data_size); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Data size %lu != %lu\n", + a->data_size, + b->data_size); return GNUNET_NO; } if (0 != memcmp (a->data, b->data, a->data_size)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Data contents do not match\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Data contents do not match\n"); return GNUNET_NO; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Records are equal\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Records are equal\n"); return GNUNET_YES; } @@ -264,11 +273,15 @@ GNUNET_NAMESTORE_records_deserialize (size_t len, dest[i].record_type = ntohl (rec.record_type); dest[i].flags = ntohl (rec.flags); off += sizeof (rec); - if (off + dest[i].data_size > len) return GNUNET_SYSERR; dest[i].data = &src[off]; off += dest[i].data_size; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Deserialized record %u with flags %d and expiration time %llu\n", + i, + dest[i].flags, + (unsigned long long) dest[i].expiration_time); } return GNUNET_OK; } @@ -308,6 +321,10 @@ GNUNET_NAMESTORE_record_get_expiration_time (unsigned int rd_count, } expire = GNUNET_TIME_absolute_min (at, expire); } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Determined expiration time for block with %u records to be %s\n", + rd_count, + GNUNET_STRINGS_absolute_time_to_string (expire)); return expire; } @@ -763,16 +780,16 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, switch (type) { case 0: - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Unsupported record type %d\n"), - (int) type); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Unsupported record type %d\n"), + (int) type); return GNUNET_SYSERR; case GNUNET_DNSPARSER_TYPE_A: if (1 != inet_pton (AF_INET, s, &value_a)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Unable to parse IPv4 address `%s'\n"), - s); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Unable to parse IPv4 address `%s'\n"), + s); return GNUNET_SYSERR; } *data = GNUNET_malloc (sizeof (struct in_addr)); @@ -791,9 +808,9 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, &off, s)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to serialize NS record with value `%s'\n"), - s); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Failed to serialize NS record with value `%s'\n"), + s); return GNUNET_SYSERR; } *data_size = off; @@ -813,9 +830,9 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, &off, s)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to serialize CNAME record with value `%s'\n"), - s); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Failed to serialize CNAME record with value `%s'\n"), + s); return GNUNET_SYSERR; } *data_size = off; @@ -841,9 +858,9 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, soa_rname, soa_mname, &soa_serial, &soa_refresh, &soa_retry, &soa_expire, &soa_min)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Unable to parse SOA record `%s'\n"), - s); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Unable to parse SOA record `%s'\n"), + s); return GNUNET_SYSERR; } soa.mname = soa_mname; @@ -860,10 +877,10 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, &off, &soa)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to serialize SOA record with mname `%s' and rname `%s'\n"), - soa_mname, - soa_rname); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Failed to serialize SOA record with mname `%s' and rname `%s'\n"), + soa_mname, + soa_rname); return GNUNET_SYSERR; } *data_size = off; @@ -883,9 +900,9 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, &off, s)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to serialize PTR record with value `%s'\n"), - s); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Failed to serialize PTR record with value `%s'\n"), + s); return GNUNET_SYSERR; } *data_size = off; @@ -903,9 +920,9 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, if (2 != SSCANF(s, "%hu,%253s", &mx_pref, mxhost)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Unable to parse MX record `%s'\n"), - s); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Unable to parse MX record `%s'\n"), + s); return GNUNET_SYSERR; } mx.preference = mx_pref; @@ -918,9 +935,9 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, &off, &mx)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to serialize MX record with hostname `%s'\n"), - mxhost); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Failed to serialize MX record with hostname `%s'\n"), + mxhost); return GNUNET_SYSERR; } *data_size = off; @@ -935,9 +952,9 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, case GNUNET_DNSPARSER_TYPE_AAAA: if (1 != inet_pton (AF_INET6, s, &value_aaaa)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Unable to parse IPv6 address `%s'\n"), - s); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Unable to parse IPv6 address `%s'\n"), + s); return GNUNET_SYSERR; } *data = GNUNET_malloc (sizeof (struct in6_addr)); @@ -948,9 +965,9 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, if (GNUNET_OK != GNUNET_CRYPTO_ecc_public_sign_key_from_string (s, strlen (s), &pkey)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Unable to parse PKEY record `%s'\n"), - s); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Unable to parse PKEY record `%s'\n"), + s); return GNUNET_SYSERR; } *data = GNUNET_new (struct GNUNET_CRYPTO_EccPublicSignKey); @@ -969,9 +986,9 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, if (3 != SSCANF (s,"%u %103s %253s", &proto, s_peer, s_serv)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Unable to parse VPN record string `%s'\n"), - s); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Unable to parse VPN record string `%s'\n"), + s); return GNUNET_SYSERR; } *data_size = sizeof (struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1; @@ -999,9 +1016,9 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, &off, s)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to serialize GNS2DNS record with value `%s'\n"), - s); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Failed to serialize GNS2DNS record with value `%s'\n"), + s); return GNUNET_SYSERR; } *data_size = off; @@ -1018,18 +1035,18 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, &tlsa->matching_type, (char*)&tlsa[1])) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Unable to parse TLSA record string `%s'\n"), - s); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Unable to parse TLSA record string `%s'\n"), + s); *data_size = 0; GNUNET_free (tlsa); return GNUNET_SYSERR; } return GNUNET_OK; default: - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Unsupported record type %d\n"), - (int) type); + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Unsupported record type %d\n"), + (int) type); return GNUNET_SYSERR; } } -- cgit v1.2.3