#include "gnunet_fs_service.h"
#include "gnunet_protocols.h"
#include "fs_api.h"
+#include "fs_publish_ublock.h"
/**
pi->value.search.sc = sc;
pi->value.search.cctx = (NULL != sc) ? sc->client_info : NULL;
pi->value.search.pctx =
- ((NULL == sc) || (NULL == sc->psearch_result))
- ? NULL
+ ((NULL == sc) || (NULL == sc->psearch_result))
+ ? NULL
: sc->psearch_result->client_info;
pi->value.search.query = (NULL != sc) ? sc->uri : NULL;
- pi->value.search.duration = (NULL != sc)
+ pi->value.search.duration = (NULL != sc)
? GNUNET_TIME_absolute_get_duration (sc->start_time)
: GNUNET_TIME_UNIT_ZERO;
pi->value.search.anonymity = (NULL != sc) ? sc->anonymity : 0;
+ pi->fsh = h;
ret = h->upcb (h->upcb_cls, pi);
return ret;
}
struct GNUNET_FS_SearchResult *sr)
{
struct GNUNET_FS_ProgressInfo pi;
-
+
pi.status = GNUNET_FS_STATUS_SEARCH_UPDATE;
pi.value.search.specifics.update.cctx = sr->client_info;
pi.value.search.specifics.update.meta = sr->meta;
pi.value.search.specifics.update.availability_certainty =
sr->availability_trials;
pi.value.search.specifics.update.applicability_rank = sr->optional_support;
- pi.value.search.specifics.update.current_probe_time
+ pi.value.search.specifics.update.current_probe_time
= GNUNET_TIME_absolute_get_duration (sr->probe_active_time);
sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc);
}
pi.value.search.specifics.update.cctx = sr->client_info;
pi.value.search.specifics.update.meta = sr->meta;
pi.value.search.specifics.update.uri = sr->uri;
- pi.value.search.specifics.update.availability_rank
+ pi.value.search.specifics.update.availability_rank
= 2 * sr->availability_success - sr->availability_trials;
- pi.value.search.specifics.update.availability_certainty
+ pi.value.search.specifics.update.availability_certainty
= sr->availability_trials;
pi.value.search.specifics.update.applicability_rank = sr->optional_support;
- pi.value.search.specifics.update.current_probe_time
+ pi.value.search.specifics.update.current_probe_time
= GNUNET_TIME_absolute_get_duration (sr->probe_active_time);
sr->client_info = GNUNET_FS_search_make_status_ (&pi, sr->h, sr->sc);
GNUNET_FS_search_start_probe_ (sr);
{
/* should only happen if the cancel task was already
created on 'DOWNLOAD_INACTIVE' as we were out of time */
- GNUNET_break (0 == sr->remaining_probe_time.rel_value);
+ GNUNET_break (0 == sr->remaining_probe_time.rel_value_us);
}
break;
case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time);
sr->remaining_probe_time =
GNUNET_TIME_relative_subtract (sr->remaining_probe_time, dur);
- if (0 == sr->remaining_probe_time.rel_value)
+ if (0 == sr->remaining_probe_time.rel_value_us)
sr->probe_cancel_task =
GNUNET_SCHEDULER_add_now (&probe_failure_handler, sr);
GNUNET_FS_search_result_sync_ (sr);
struct GNUNET_FS_SearchResult *sr = cls;
signal_probe_result (sr);
- sr->probe_ping_task
+ sr->probe_ping_task
= GNUNET_SCHEDULER_add_delayed (GNUNET_FS_PROBE_UPDATE_FREQUENCY,
&probe_ping_task,
sr);
len, sr->anonymity,
GNUNET_FS_DOWNLOAD_NO_TEMPORARIES |
GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL);
- sr->probe_ping_task
+ sr->probe_ping_task
= GNUNET_SCHEDULER_add_now (&probe_ping_task,
sr);
}
{
struct GNUNET_FS_SearchResult *sr;
+ GNUNET_assert (NULL != h);
sr = GNUNET_new (struct GNUNET_FS_SearchResult);
sr->h = h;
sr->uri = GNUNET_FS_uri_dup (uri);
sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
sr->client_info = client_info;
- sr->anonymity = anonymity;
+ sr->anonymity = anonymity;
GNUNET_FS_search_start_probe_ (sr);
return sr;
}
/**
* Stop probing activity associated with a search result.
- *
- * @param sr search result
+ *
+ * @param sr search result
*/
static void
GNUNET_FS_search_stop_probe_ (struct GNUNET_FS_SearchResult *sr)
is_new = (NULL == sr) || (sr->mandatory_missing > 0);
if (NULL == sr)
{
- sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
+ sr = GNUNET_new (struct GNUNET_FS_SearchResult);
sr->h = sc->h;
sr->sc = sc;
sr->anonymity = sc->anonymity;
&test_result_present,
(void *) uri))
return; /* duplicate result */
- sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
+ sr = GNUNET_new (struct GNUNET_FS_SearchResult);
sr->h = sc->h;
sr->sc = sc;
sr->anonymity = sc->anonymity;
* given ciphertext block.
*
* @param sc search context with the keywords
- * @param verification_key public key to use to lookup the keyword
+ * @param dpub derived public key used for the search
* @param edata encrypted data
- * @param edata_size number of bytes in 'edata' (and 'data')
+ * @param edata_size number of bytes in @a edata (and @a data)
* @param data where to store the plaintext
- * @return keyword index on success, GNUNET_SYSERR on error (no such
+ * @return keyword index on success, #GNUNET_SYSERR on error (no such
* keyword, internal error)
*/
static int
decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc,
- const struct GNUNET_FS_PseudonymIdentifier *verification_key,
+ const struct GNUNET_CRYPTO_EccPublicSignKey *dpub,
const void *edata,
size_t edata_size,
char *data)
-{
- struct GNUNET_HashCode q;
- struct GNUNET_CRYPTO_AesSessionKey skey;
- struct GNUNET_CRYPTO_AesInitializationVector iv;
- int i;
+{
+ const struct GNUNET_CRYPTO_EccPrivateKey *anon;
+ struct GNUNET_CRYPTO_EccPublicSignKey anon_pub;
+ unsigned int i;
- GNUNET_CRYPTO_hash (verification_key,
- sizeof (struct GNUNET_FS_PseudonymIdentifier),
- &q);
/* find key */
for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
- if (0 == memcmp (&q, &sc->requests[i].uquery, sizeof (struct GNUNET_HashCode)))
+ if (0 == memcmp (dpub,
+ &sc->requests[i].dpub,
+ sizeof (struct GNUNET_CRYPTO_EccPublicSignKey)))
break;
if (i == sc->uri->data.ksk.keywordCount)
{
return GNUNET_SYSERR;
}
/* decrypt */
- GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].ukey, &skey, &iv);
- if (-1 ==
- GNUNET_CRYPTO_aes_decrypt (edata, edata_size, &skey,
- &iv, data))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ anon = GNUNET_CRYPTO_ecc_key_get_anonymous ();
+ GNUNET_CRYPTO_ecc_key_get_public_for_signature (anon, &anon_pub);
+ GNUNET_FS_ublock_decrypt_ (edata, edata_size,
+ &anon_pub,
+ sc->requests[i].keyword,
+ data);
return i;
}
*
* @param sc our search context
* @param ub the ublock with the keyword search result
- * @param size size of nb
+ * @param size size of @a ub
*/
static void
-process_kblock (struct GNUNET_FS_SearchContext *sc, const struct UBlock *ub,
+process_kblock (struct GNUNET_FS_SearchContext *sc,
+ const struct UBlock *ub,
size_t size)
{
size_t j;
if (NULL == (uri = GNUNET_FS_uri_parse (&pt[1], &emsg)))
{
GNUNET_break_op (0); /* ublock malformed */
- GNUNET_free_non_null (emsg);
+ GNUNET_free_non_null (emsg);
return;
}
j = eos - pt + 1;
* @param size size of sb
*/
static void
-process_sblock (struct GNUNET_FS_SearchContext *sc,
+process_sblock (struct GNUNET_FS_SearchContext *sc,
const struct UBlock *ub,
size_t size)
{
size_t len = size - sizeof (struct UBlock);
char pt[len];
- struct GNUNET_CRYPTO_AesSessionKey skey;
- struct GNUNET_CRYPTO_AesInitializationVector iv;
struct GNUNET_FS_Uri *uri;
struct GNUNET_CONTAINER_MetaData *meta;
const char *id;
const char *uris;
size_t off;
char *emsg;
- struct GNUNET_HashCode key;
- struct GNUNET_HashCode id_hash;
- struct GNUNET_HashCode ns_hash;
- char *identifier;
- /* decrypt */
- identifier = sc->uri->data.sks.identifier;
- GNUNET_CRYPTO_hash (identifier, strlen (identifier), &id_hash);
- GNUNET_CRYPTO_hash (&sc->uri->data.sks.ns,
- sizeof (sc->uri->data.sks.ns), &ns_hash);
- GNUNET_CRYPTO_hash_xor (&id_hash, &ns_hash, &key);
- GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
- if (-1 == GNUNET_CRYPTO_aes_decrypt (&ub[1], len, &skey, &iv, pt))
- {
- GNUNET_break (0);
- return;
- }
+ GNUNET_FS_ublock_decrypt_ (&ub[1], len,
+ &sc->uri->data.sks.ns,
+ sc->uri->data.sks.identifier,
+ pt);
/* parse */
if (0 == (off = GNUNET_STRINGS_buffer_tokenize (pt, len, 2, &id, &uris)))
{
}
if (NULL == (uri = GNUNET_FS_uri_parse (uris, &emsg)))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to parse URI `%s': %s\n"),
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to parse URI `%s': %s\n"),
uris, emsg);
GNUNET_break_op (0); /* ublock malformed */
GNUNET_free_non_null (emsg);
* @param type type of the result
* @param expiration when it will expire
* @param data the (encrypted) response
- * @param size size of data
+ * @param size size of @a data
*/
static void
-process_result (struct GNUNET_FS_SearchContext *sc, enum GNUNET_BLOCK_Type type,
- struct GNUNET_TIME_Absolute expiration,
+process_result (struct GNUNET_FS_SearchContext *sc,
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_TIME_Absolute expiration,
const void *data,
size_t size)
{
- if (GNUNET_TIME_absolute_get_duration (expiration).rel_value > 0)
+ if (GNUNET_TIME_absolute_get_duration (expiration).rel_value_us > 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Result received has already expired.\n");
struct MessageBuilderContext mbc;
size_t msize;
struct SearchMessage *sm;
- const char *identifier;
- struct GNUNET_HashCode key;
- struct GNUNET_HashCode signing_key;
- struct GNUNET_HashCode ns_hash;
- struct GNUNET_HashCode id_hash;
- struct GNUNET_FS_PseudonymIdentifier verification_key;
+ struct GNUNET_CRYPTO_EccPublicSignKey dpub;
unsigned int sqms;
uint32_t options;
sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK);
sm->anonymity_level = htonl (sc->anonymity);
memset (&sm->target, 0, sizeof (struct GNUNET_HashCode));
-
- identifier = sc->uri->data.sks.identifier;
- GNUNET_CRYPTO_hash (identifier, strlen (identifier), &id_hash);
- GNUNET_CRYPTO_hash (&sc->uri->data.sks.ns,
- sizeof (sc->uri->data.sks.ns), &ns_hash);
- GNUNET_CRYPTO_hash_xor (&id_hash, &ns_hash, &key);
- GNUNET_CRYPTO_hash (&key, sizeof (struct GNUNET_HashCode), &signing_key);
- GNUNET_FS_pseudonym_derive_verification_key (&sc->uri->data.sks.ns,
- &signing_key,
- &verification_key);
- GNUNET_CRYPTO_hash (&verification_key,
- sizeof (verification_key),
+ GNUNET_CRYPTO_ecc_public_key_derive (&sc->uri->data.sks.ns,
+ sc->uri->data.sks.identifier,
+ "fs-ublock",
+ &dpub);
+ GNUNET_CRYPTO_hash (&dpub,
+ sizeof (dpub),
&sm->query);
mbc.put_cnt = (size - msize) / sizeof (struct GNUNET_HashCode);
sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map);
}
sc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (sc->reconnect_backoff);
sc->task =
- GNUNET_SCHEDULER_add_delayed (sc->reconnect_backoff,
+ GNUNET_SCHEDULER_add_delayed (sc->reconnect_backoff,
&do_reconnect,
sc);
}
{
unsigned int i;
const char *keyword;
- struct GNUNET_HashCode signing_key;
- struct GNUNET_FS_PseudonymHandle *ph;
- struct GNUNET_FS_PseudonymIdentifier anon;
- struct GNUNET_FS_PseudonymIdentifier verification_key;
+ const struct GNUNET_CRYPTO_EccPrivateKey *anon;
+ struct GNUNET_CRYPTO_EccPublicSignKey anon_pub;
+ struct SearchRequestEntry *sre;
GNUNET_assert (NULL == sc->client);
if (GNUNET_FS_uri_test_ksk (sc->uri))
{
GNUNET_assert (0 != sc->uri->data.ksk.keywordCount);
- ph = GNUNET_FS_pseudonym_get_anonymous_pseudonym_handle ();
- GNUNET_FS_pseudonym_get_identifier (ph, &anon);
- GNUNET_FS_pseudonym_destroy (ph);
+ anon = GNUNET_CRYPTO_ecc_key_get_anonymous ();
+ GNUNET_CRYPTO_ecc_key_get_public_for_signature (anon, &anon_pub);
sc->requests =
GNUNET_malloc (sizeof (struct SearchRequestEntry) *
sc->uri->data.ksk.keywordCount);
for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
{
keyword = &sc->uri->data.ksk.keywords[i][1];
- GNUNET_CRYPTO_hash (keyword, strlen (keyword), &sc->requests[i].ukey);
- GNUNET_CRYPTO_hash (&sc->requests[i].ukey, sizeof (struct GNUNET_HashCode), &signing_key);
- GNUNET_FS_pseudonym_derive_verification_key (&anon,
- &signing_key,
- &verification_key);
- GNUNET_CRYPTO_hash (&verification_key, sizeof (struct GNUNET_FS_PseudonymIdentifier),
- &sc->requests[i].uquery);
- sc->requests[i].mandatory = (sc->uri->data.ksk.keywords[i][0] == '+');
- if (sc->requests[i].mandatory)
+ sre = &sc->requests[i];
+ sre->keyword = GNUNET_strdup (keyword);
+ GNUNET_CRYPTO_ecc_public_key_derive (&anon_pub,
+ keyword,
+ "fs-ublock",
+ &sre->dpub);
+ GNUNET_CRYPTO_hash (&sre->dpub,
+ sizeof (struct GNUNET_CRYPTO_EccPublicSignKey),
+ &sre->uquery);
+ sre->mandatory = (sc->uri->data.ksk.keywords[i][0] == '+');
+ if (sre->mandatory)
sc->mandatory_count++;
- sc->requests[i].results = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
+ sre->results = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
}
}
sc->client = GNUNET_CLIENT_connect ("fs", sc->h->cfg);
{
GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
+ {
GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
+ GNUNET_free (sc->requests[i].keyword);
+ }
}
GNUNET_free_non_null (sc->requests);
GNUNET_free_non_null (sc->emsg);