*/
const struct GNUNET_PeerIdentity *id;
+ /**
+ * Hash of @e id.
+ */
+ struct GNUNET_HashCode phash;
+
+ /**
+ * Which bucket is this peer in?
+ */
+ int peer_bucket;
+
};
&mh);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n",
- GNUNET_i2s (key), ctx->bf_mutator);
- GNUNET_CONTAINER_bloomfilter_add (ctx->bloom, &mh);
+ GNUNET_i2s (key),
+ ctx->bf_mutator);
+ GNUNET_CONTAINER_bloomfilter_add (ctx->bloom,
+ &mh);
return GNUNET_YES;
}
const struct GNUNET_PeerIdentity *peer,
struct GNUNET_MQ_Handle *mq)
{
- struct PeerInfo *ret;
- struct GNUNET_HashCode phash;
- int peer_bucket;
+ struct PeerInfo *pi;
/* Check for connect to self message */
if (0 == memcmp (&my_identity,
gettext_noop ("# peers connected"),
1,
GNUNET_NO);
+ pi = GNUNET_new (struct PeerInfo);
+ pi->id = peer;
+ pi->mq = mq;
GNUNET_CRYPTO_hash (peer,
sizeof (struct GNUNET_PeerIdentity),
- &phash);
- peer_bucket = find_bucket (&phash);
- GNUNET_assert ((peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS));
- ret = GNUNET_new (struct PeerInfo);
- ret->id = peer;
- ret->mq = mq;
- GNUNET_CONTAINER_DLL_insert_tail (k_buckets[peer_bucket].head,
- k_buckets[peer_bucket].tail,
- ret);
- k_buckets[peer_bucket].peers_size++;
+ &pi->phash);
+ pi->peer_bucket = find_bucket (&pi->phash);
+ GNUNET_assert ( (pi->peer_bucket >= 0) &&
+ (pi->peer_bucket < MAX_BUCKETS) );
+ GNUNET_CONTAINER_DLL_insert_tail (k_buckets[pi->peer_bucket].head,
+ k_buckets[pi->peer_bucket].tail,
+ pi);
+ k_buckets[pi->peer_bucket].peers_size++;
closest_bucket = GNUNET_MAX (closest_bucket,
- peer_bucket);
+ pi->peer_bucket);
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multipeermap_put (all_connected_peers,
- ret->id,
- ret,
+ pi->id,
+ pi,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- if ( (peer_bucket > 0) &&
- (k_buckets[peer_bucket].peers_size <= bucket_size))
+ if ( (pi->peer_bucket > 0) &&
+ (k_buckets[pi->peer_bucket].peers_size <= bucket_size))
{
update_connect_preferences ();
newly_found_peers++;
find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message,
NULL);
}
- return ret;
+ return pi;
}
void *internal_cls)
{
struct PeerInfo *to_remove = internal_cls;
- int current_bucket;
- struct GNUNET_HashCode phash;
/* Check for disconnect from self message */
if (NULL == to_remove)
GNUNET_SCHEDULER_cancel (find_peer_task);
find_peer_task = NULL;
}
- GNUNET_CRYPTO_hash (peer,
- sizeof (struct GNUNET_PeerIdentity),
- &phash);
- current_bucket = find_bucket (&phash);
- GNUNET_assert (current_bucket >= 0);
- GNUNET_CONTAINER_DLL_remove (k_buckets[current_bucket].head,
- k_buckets[current_bucket].tail,
+ GNUNET_assert (to_remove->peer_bucket >= 0);
+ GNUNET_CONTAINER_DLL_remove (k_buckets[to_remove->peer_bucket].head,
+ k_buckets[to_remove->peer_bucket].tail,
to_remove);
- GNUNET_assert (k_buckets[current_bucket].peers_size > 0);
- k_buckets[current_bucket].peers_size--;
+ GNUNET_assert (k_buckets[to_remove->peer_bucket].peers_size > 0);
+ k_buckets[to_remove->peer_bucket].peers_size--;
while ( (closest_bucket > 0) &&
- (0 == k_buckets[closest_bucket].peers_size) )
+ (0 == k_buckets[to_remove->peer_bucket].peers_size) )
closest_bucket--;
- if (k_buckets[current_bucket].peers_size < bucket_size)
+ if (k_buckets[to_remove->peer_bucket].peers_size < bucket_size)
update_connect_preferences ();
GNUNET_free (to_remove);
}
/* first, calculate the most significant 9 bits of our
* result, aka the number of LSBs */
- bucket = GNUNET_CRYPTO_hash_matching_bits (target, have);
+ bucket = GNUNET_CRYPTO_hash_matching_bits (target,
+ have);
/* bucket is now a value between 0 and 512 */
if (bucket == 512)
return 0; /* perfect match */
int bucket_num;
int count;
struct PeerInfo *pos;
- struct GNUNET_HashCode phash;
if (0 == memcmp (&my_identity_hash, key, sizeof (struct GNUNET_HashCode)))
return GNUNET_YES;
bucket_num = find_bucket (key);
GNUNET_assert (bucket_num >= 0);
- bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, key);
+ bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash,
+ key);
pos = k_buckets[bucket_num].head;
count = 0;
while ((NULL != pos) && (count < bucket_size))
{
- GNUNET_CRYPTO_hash (pos->id,
- sizeof (struct GNUNET_PeerIdentity),
- &phash);
if ((NULL != bloom) &&
(GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &phash)))
+ GNUNET_CONTAINER_bloomfilter_test (bloom,
+ &pos->phash)))
{
pos = pos->next;
continue; /* Skip already checked entries */
}
- other_bits = GNUNET_CRYPTO_hash_matching_bits (&phash, key);
+ other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->phash,
+ key);
if (other_bits > bits)
return GNUNET_NO;
if (other_bits == bits) /* We match the same number of bits */
unsigned int dist;
unsigned int smallest_distance;
struct PeerInfo *chosen;
- struct GNUNET_HashCode phash;
if (hops >= GDS_NSE_get ())
{
count = 0;
while ((pos != NULL) && (count < bucket_size))
{
- GNUNET_CRYPTO_hash (pos->id,
- sizeof (struct GNUNET_PeerIdentity),
- &phash);
if ((bloom == NULL) ||
(GNUNET_NO ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &phash)))
+ GNUNET_CONTAINER_bloomfilter_test (bloom,
+ &pos->phash)))
{
- dist = get_distance (key, &phash);
+ dist = get_distance (key,
+ &pos->phash);
if (dist < smallest_distance)
{
chosen = pos;
GNUNET_i2s (pos->id),
GNUNET_h2s (key));
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop
- ("# Peers excluded from routing due to Bloomfilter"),
- 1, GNUNET_NO);
- dist = get_distance (key, &phash);
+ gettext_noop ("# Peers excluded from routing due to Bloomfilter"),
+ 1,
+ GNUNET_NO);
+ dist = get_distance (key,
+ &pos->phash);
if (dist < smallest_distance)
{
chosen = NULL;
pos = k_buckets[bc].head;
while ((pos != NULL) && (count < bucket_size))
{
- GNUNET_CRYPTO_hash (pos->id,
- sizeof (struct GNUNET_PeerIdentity),
- &phash);
if ((bloom != NULL) &&
(GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &phash)))
+ GNUNET_CONTAINER_bloomfilter_test (bloom,
+ &pos->phash)))
{
GNUNET_STATISTICS_update (GDS_stats,
gettext_noop
return NULL;
}
/* Now actually choose a peer */
- selected = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, count);
+ selected = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ count);
count = 0;
for (bc = 0; bc <= closest_bucket; bc++)
{
for (pos = k_buckets[bc].head; ((pos != NULL) && (count < bucket_size)); pos = pos->next)
{
- GNUNET_CRYPTO_hash (pos->id,
- sizeof (struct GNUNET_PeerIdentity),
- &phash);
if ((bloom != NULL) &&
(GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &phash)))
+ GNUNET_CONTAINER_bloomfilter_test (bloom,
+ &pos->phash)))
{
continue; /* Ignore bloomfiltered peers */
}
unsigned int off;
struct PeerInfo **rtargets;
struct PeerInfo *nxt;
- struct GNUNET_HashCode nhash;
GNUNET_assert (NULL != bloom);
ret = get_forward_count (hop_count,
if (NULL == nxt)
break;
rtargets[off] = nxt;
- GNUNET_CRYPTO_hash (nxt->id,
- sizeof (struct GNUNET_PeerIdentity),
- &nhash);
GNUNET_break (GNUNET_NO ==
GNUNET_CONTAINER_bloomfilter_test (bloom,
- &nhash));
- GNUNET_CONTAINER_bloomfilter_add (bloom, &nhash);
+ &nxt->phash));
+ GNUNET_CONTAINER_bloomfilter_add (bloom,
+ &nxt->phash);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Selected %u/%u peers at hop %u for %s (target was %u)\n",
struct GNUNET_MQ_Envelope *env;
struct PeerPutMessage *ppm;
struct GNUNET_PeerIdentity *pp;
- struct GNUNET_HashCode thash;
unsigned int skip_count;
GNUNET_assert (NULL != bf);
ppm->desired_replication_level = htonl (desired_replication_level);
ppm->put_path_length = htonl (put_path_length);
ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
- GNUNET_CRYPTO_hash (target->id,
- sizeof (struct GNUNET_PeerIdentity),
- &thash);
GNUNET_break (GNUNET_YES ==
GNUNET_CONTAINER_bloomfilter_test (bf,
- &thash));
+ &target->phash));
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_bloomfilter_get_raw_data (bf,
ppm->bloomfilter,
struct PeerGetMessage *pgm;
char *xq;
size_t reply_bf_size;
- struct GNUNET_HashCode thash;
unsigned int skip_count;
GNUNET_assert (NULL != peer_bf);
pgm->desired_replication_level = htonl (desired_replication_level);
pgm->xquery_size = htonl (xquery_size);
pgm->bf_mutator = reply_bf_mutator;
- GNUNET_CRYPTO_hash (target->id,
- sizeof (struct GNUNET_PeerIdentity),
- &thash);
GNUNET_break (GNUNET_YES ==
GNUNET_CONTAINER_bloomfilter_test (peer_bf,
- &thash));
+ &target->phash));
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf,
pgm->bloomfilter,
enum GNUNET_DHT_RouteOption options;
struct GNUNET_CONTAINER_BloomFilter *bf;
struct GNUNET_HashCode test_key;
- struct GNUNET_HashCode phash;
int forwarded;
msize = ntohs (put->header.size);
"PUT for `%s' from %s\n",
GNUNET_h2s (&put->key),
GNUNET_i2s (peer->id));
- GNUNET_CRYPTO_hash (peer->id,
- sizeof (struct GNUNET_PeerIdentity),
- &phash);
if (GNUNET_YES == log_route_details_stderr)
{
char *tmp;
GNUNET_i2s (peer->id),
tmp,
ntohl(put->hop_count),
- GNUNET_CRYPTO_hash_matching_bits (&phash,
+ GNUNET_CRYPTO_hash_matching_bits (&peer->phash,
&put->key),
GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash,
&put->key)
GNUNET_CONSTANTS_BLOOMFILTER_K);
GNUNET_break_op (GNUNET_YES ==
GNUNET_CONTAINER_bloomfilter_test (bf,
- &phash));
+ &peer->phash));
{
struct GNUNET_PeerIdentity pp[putlen + 1];
struct PeerBucket *bucket;
struct PeerInfo *peer;
unsigned int choice;
- struct GNUNET_HashCode phash;
struct GNUNET_HashCode mhash;
const struct GNUNET_HELLO_Message *hello;
return; /* no non-masked peer available */
if (NULL == peer)
peer = bucket->head;
- GNUNET_CRYPTO_hash (peer->id,
- sizeof (struct GNUNET_PeerIdentity),
- &phash);
- GNUNET_BLOCK_mingle_hash (&phash,
+ GNUNET_BLOCK_mingle_hash (&peer->phash,
bf_mutator,
&mhash);
hello = GDS_HELLO_get (peer->id);
struct GNUNET_CONTAINER_BloomFilter *reply_bf;
struct GNUNET_CONTAINER_BloomFilter *peer_bf;
const char *xquery;
- struct GNUNET_HashCode phash;
int forwarded;
if (NULL == peer)
gettext_noop ("# P2P GET bytes received"),
msize,
GNUNET_NO);
- GNUNET_CRYPTO_hash (peer->id,
- sizeof (struct GNUNET_PeerIdentity),
- &phash);
if (GNUNET_YES == log_route_details_stderr)
{
char *tmp;
GNUNET_i2s (peer->id),
tmp,
ntohl(get->hop_count),
- GNUNET_CRYPTO_hash_matching_bits (&phash,
+ GNUNET_CRYPTO_hash_matching_bits (&peer->phash,
&get->key),
GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash,
&get->key),
GNUNET_CONSTANTS_BLOOMFILTER_K);
GNUNET_break_op (GNUNET_YES ==
GNUNET_CONTAINER_bloomfilter_test (peer_bf,
- &phash));
+ &peer->phash));
/* remember request for routing replies */
GDS_ROUTING_add (peer->id,
type,
}
return GNUNET_OK;
}
-
+
/**
* Core handler for p2p result messages.