}
if (GNUNET_YES != GNUNET_DISK_file_lock (fd, 0, sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded), GNUNET_YES))
+ {
+ GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
return GNUNET_SYSERR;
+ }
enc = GNUNET_CRYPTO_rsa_encode_key (ret);
GNUNET_assert (enc != NULL);
GNUNET_assert (ntohs (enc->len) == GNUNET_DISK_file_write (fd, enc, ntohs (enc->len)));
}
- GNUNET_CONTAINER_multihashmap_remove (zonekeys, key, value);
+ GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (zonekeys, key, value));
GNUNET_CRYPTO_rsa_key_free (c->privkey);
GNUNET_free (c->pubkey);
GNUNET_free (c->filename);
int rd_count_new = 0;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u existing records for `%s'\n", rd_count, crc->name);
-
for (c = 0; c < rd_count; c++)
{
-
- if ((crc->rd->record_type == rd[c].record_type) &&
+ if ((crc->rd->record_type == GNUNET_NAMESTORE_TYPE_PKEY) && (rd[c].record_type == GNUNET_NAMESTORE_TYPE_PKEY))
+ {
+ /* Update unique PKEY */
+ exist = c;
+ update = GNUNET_YES;
+ break;
+ }
+ else if ((crc->rd->record_type == GNUNET_NAMESTORE_TYPE_PSEU) && (rd[c].record_type == GNUNET_NAMESTORE_TYPE_PSEU))
+ {
+ /* Update unique PSEU */
+ exist = c;
+ update = GNUNET_YES;
+ break;
+ }
+ else if ((crc->rd->record_type == rd[c].record_type) &&
(crc->rd->data_size == rd[c].data_size) &&
(0 == memcmp (crc->rd->data, rd[c].data, rd[c].data_size)))
{
memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
rd_count_new = rd_count;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating expiration from %llu to %llu!\n", rd_new[exist].expiration.abs_value, crc->rd->expiration.abs_value);
- rd_new[exist].expiration = crc->rd->expiration;
+ rd_new[exist] = *(crc->rd);
}
block_expiration = GNUNET_TIME_absolute_max(crc->expire, expire);
case GNUNET_YES:
/* database operations OK */
if (GNUNET_YES == update)
+ {
/* we updated an existing record */
crc->res = GNUNET_NO;
+ }
else
+ {
/* we created a new record */
crc->res = GNUNET_YES;
+ }
break;
case GNUNET_NO:
/* identical entry existed, so we did nothing */
+ GNUNET_break(0);
crc->res = GNUNET_NO;
break;
default:
GNUNET_break_op (0);
goto send;
}
-
/* Extracting and converting private key */
pkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len);
GNUNET_assert (pkey != NULL);
{
struct GNUNET_NAMESTORE_RecordData *rd;
struct GNUNET_CRYPTO_RsaPrivateKey *pkey;
+ int remove_name;
uint16_t op_res;
};
found = GNUNET_SYSERR;
for (c = 0; c < rd_count; c++)
{
- if ((rd[c].expiration.abs_value == rrc->rd->expiration.abs_value) &&
- (rd[c].flags == rrc->rd->flags) &&
- (rd[c].record_type == rrc->rd->record_type) &&
- (rd[c].data_size == rrc->rd->data_size) &&
- (0 == memcmp (rd[c].data, rrc->rd->data, rrc->rd->data_size)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found record to remove!\n", rd_count);
- found = c;
- break;
- }
+ GNUNET_break(0);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SENT FLAGES: %u \n",rd[c].flags);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STORED FLAGES: %u \n",rrc->rd->flags);
+ /*
+ if (rd[c].flags != rrc->rd->flags)
+ continue;*/
+ GNUNET_break(0);
+ if (rd[c].record_type != rrc->rd->record_type)
+ continue;
+ GNUNET_break(0);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SENT FLAGES: %u \n",rd[c].data_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STORED FLAGES: %u \n",rrc->rd->data_size);
+ /*
+ if (rd[c].data_size != rrc->rd->data_size)
+ continue;
+ GNUNET_break(0);
+ if (0 != memcmp (rd[c].data, rrc->rd->data, rrc->rd->data_size))
+ continue;
+ GNUNET_break(0); */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found record to remove!\n", rd_count);
+ found = c;
+ break;
}
if (GNUNET_SYSERR == found)
{
return;
}
+ if (rd_count-1 == 0)
+ {
+ struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
+ GNUNET_CRYPTO_short_hash (zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash);
+ res = GSN_database->remove_records (GSN_database->cls,
+ &pubkey_hash,
+ name);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No records left for name `%s', removing name\n",
+ name, res);
+ if (GNUNET_OK != res)
+ {
+ /* Could put records into database */
+ rrc->op_res = 4;
+ return;
+ }
+ rrc->op_res = 0;
+ return;
+ }
+
rd_count_new = rd_count -1;
struct GNUNET_NAMESTORE_RecordData rd_new[rd_count_new];
return;
}
- if ((rd_count != 1) || (rd_ser_len < 1) || (name_len >=256) || (name_len == 0))
+ if ((name_len >=256) || (name_len == 0))
{
GNUNET_break_op (0);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
- if ((rd_count != 1) || (rd_ser_len < 1) || (name_len >=256) || (name_len == 0))
- {
- GNUNET_break_op (0);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
-
pkey_tmp = (char *) &rr_msg[1];
name_tmp = &pkey_tmp[key_len];
rd_ser = &name_tmp[name_len];
GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
}
+
struct GNUNET_NAMESTORE_RecordData rd[rd_count];
res = GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_ser, rd_count, rd);
- if ((res != GNUNET_OK) || (rd_count != 1))
+ if ((res != GNUNET_OK) || (rd_count > 1))
{
GNUNET_break_op (0);
goto send;
}
- struct RemoveRecordContext rrc;
- rrc.rd = rd;
- rrc.pkey = pkey;
+ if (0 == rd_count)
+ {
+ /* remove the whole name and all records */
+ /* Database operation */
+ res = GSN_database->remove_records (GSN_database->cls,
+ &pubkey_hash,
+ name_tmp);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing name `%s': %s\n",
+ name_tmp, (GNUNET_OK == res) ? "OK" : "FAIL");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing record for name `%s' in zone `%s'\n", name_tmp, GNUNET_short_h2s(&pubkey_hash));
+ if (GNUNET_OK != res)
+ /* Could not remove entry from database */
+ res = 4;
+ else
+ res = 0;
+ }
+ else
+ {
+ /* remove a single record */
+ struct RemoveRecordContext rrc;
+ rrc.rd = rd;
+ rrc.pkey = pkey;
- /* Database operation */
- res = GSN_database->iterate_records (GSN_database->cls,
- &pubkey_hash,
- name_tmp,
- 0,
- handle_record_remove_it, &rrc);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing record for name `%s' in zone `%s'\n", name_tmp, GNUNET_short_h2s(&pubkey_hash));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing record for name `%s': %s\n",
- name_tmp, (rrc.op_res == 0) ? "OK" : "FAIL");
- res = rrc.op_res;
+ /* Database operation */
+ res = GSN_database->iterate_records (GSN_database->cls,
+ &pubkey_hash,
+ name_tmp,
+ 0,
+ handle_record_remove_it, &rrc);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing record for name `%s': %s\n",
+ name_tmp, (rrc.op_res == 0) ? "OK" : "FAIL");
+ res = rrc.op_res;
+ }
/* Send response */
send:
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_REMOVE_RESPONSE");
ztn_ctx.rid = rid;
ztn_ctx.nc = nc;
- char * z_tmp = strdup (GNUNET_short_h2s (&ztn_msg->zone));
+ struct GNUNET_CRYPTO_ShortHashAsciiEncoded z_tmp;
+ GNUNET_CRYPTO_short_hash_to_enc(&ztn_msg->zone, &z_tmp);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up name for zone `%s' in zone `%s'\n",
- z_tmp,
+ (char *) &z_tmp,
GNUNET_short_h2s (&ztn_msg->value_zone));
- GNUNET_free (z_tmp);
GSN_database->zone_to_name (GSN_database->cls, &ztn_msg->zone, &ztn_msg->value_zone, &handle_zone_to_name_it, &ztn_ctx);
GNUNET_HashCode long_hash;
int authoritative = GNUNET_NO;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ZONE RESULT `%s'\n", name);
+
if ((zone_key == NULL) && (name == NULL))
{
struct ZoneIterationResponseMessage zir_msg;
authoritative = GNUNET_YES;
}
-
zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
zir_msg->gns_header.header.size = htons (msg_size);
zir_msg->gns_header.r_id = htonl(zi->request_id);
GNUNET_CRYPTO_rsa_key_get_public(privkey, c->pubkey);
GNUNET_CRYPTO_short_hash(c->pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &c->zone);
- //GNUNET_CRYPTO_short_hash_to_enc (&name_hase, &name_enc);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found zonefile for zone `%s'\n", GNUNET_short_h2s (&c->zone));
GNUNET_CRYPTO_short_hash_double (&c->zone, &long_hash);
GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, c, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);