/*
This file is part of GNUnet.
- Copyright (C) 2009-2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2009-2015 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
#include "gnunet-service-dht_neighbours.h"
#include "gnunet-service-dht_nse.h"
#include "gnunet-service-dht_routing.h"
-#include <fenv.h>
#include "dht.h"
#define LOG_TRAFFIC(kind,...) GNUNET_log_from (kind, "dht-traffic",__VA_ARGS__)
/**
* Task for scheduling preference updates
*/
- struct GNUNET_SCHEDULER_Task * preference_task;
+ struct GNUNET_SCHEDULER_Task *preference_task;
/**
* What is the identity of the peer?
static int disable_try_connect;
/**
- * The buckets. Array of size MAX_BUCKET_SIZE. Offset 0 means 0 bits matching.
+ * The buckets. Array of size #MAX_BUCKETS. Offset 0 means 0 bits matching.
*/
static struct PeerBucket k_buckets[MAX_BUCKETS];
/**
- * Hash map of all known peers, for easy removal from k_buckets on disconnect.
+ * Hash map of all CORE-connected peers, for easy removal from
+ * #k_buckets on disconnect.
*/
-static struct GNUNET_CONTAINER_MultiPeerMap *all_known_peers;
+static struct GNUNET_CONTAINER_MultiPeerMap *all_connected_peers;
/**
* Maximum size for each bucket.
/**
* Task that sends FIND PEER requests.
*/
-static struct GNUNET_SCHEDULER_Task * find_peer_task;
+static struct GNUNET_SCHEDULER_Task *find_peer_task;
/**
* Identity of this peer.
static struct GNUNET_CORE_Handle *core_api;
/**
- * Handle to ATS.
+ * Handle to ATS performance monitoring.
*/
-static struct GNUNET_ATS_PerformanceHandle *atsAPI;
+static struct GNUNET_ATS_PerformanceHandle *ats_perf;
+
+/**
+ * Handle to ATS connectivity.
+ */
+static struct GNUNET_ATS_ConnectivityHandle *ats_ch;
GNUNET_STATISTICS_update (GDS_stats,
gettext_noop ("# Preference updates given to core"),
1, GNUNET_NO);
- GNUNET_ATS_performance_change_preference (atsAPI, &peer->id,
- GNUNET_ATS_PREFERENCE_BANDWIDTH,
- (double) preference, GNUNET_ATS_PREFERENCE_END);
+ GNUNET_ATS_performance_change_preference (ats_perf,
+ &peer->id,
+ GNUNET_ATS_PREFERENCE_BANDWIDTH,
+ (double) preference,
+ GNUNET_ATS_PREFERENCE_END);
peer->preference_task =
GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
&update_core_preference, peer);
bcc.bloom =
GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
GNUNET_CONSTANTS_BLOOMFILTER_K);
- GNUNET_CONTAINER_multipeermap_iterate (all_known_peers, &add_known_to_bloom,
+ GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers,
+ &add_known_to_bloom,
&bcc);
GNUNET_STATISTICS_update (GDS_stats,
gettext_noop ("# FIND PEER messages initiated"), 1,
* @param peer peer identity this notification is about
*/
static void
-handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
+handle_core_connect (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
struct PeerInfo *ret;
struct GNUNET_HashCode phash;
"Connected to %s\n",
GNUNET_i2s (peer));
if (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_contains (all_known_peers,
+ GNUNET_CONTAINER_multipeermap_contains (all_connected_peers,
peer))
{
GNUNET_break (0);
#endif
ret->id = *peer;
GNUNET_CONTAINER_DLL_insert_tail (k_buckets[peer_bucket].head,
- k_buckets[peer_bucket].tail, ret);
+ k_buckets[peer_bucket].tail,
+ ret);
k_buckets[peer_bucket].peers_size++;
closest_bucket = GNUNET_MAX (closest_bucket, peer_bucket);
if ((peer_bucket > 0) && (k_buckets[peer_bucket].peers_size <= bucket_size))
newly_found_peers++;
}
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_put (all_known_peers,
- peer, ret,
+ GNUNET_CONTAINER_multipeermap_put (all_connected_peers,
+ peer,
+ ret,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- if (1 == GNUNET_CONTAINER_multipeermap_size (all_known_peers) &&
+ if (1 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers) &&
(GNUNET_YES != disable_try_connect))
{
/* got a first connection, good time to start with FIND PEER requests... */
- find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, NULL);
+ find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message,
+ NULL);
}
}
"Disconnected %s\n",
GNUNET_i2s (peer));
to_remove =
- GNUNET_CONTAINER_multipeermap_get (all_known_peers, peer);
+ GNUNET_CONTAINER_multipeermap_get (all_connected_peers,
+ peer);
if (NULL == to_remove)
{
GNUNET_break (0);
GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# peers connected"), -1,
GNUNET_NO);
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove (all_known_peers,
+ GNUNET_CONTAINER_multipeermap_remove (all_connected_peers,
peer,
to_remove));
if (NULL != to_remove->preference_task)
memcpy (&cbuf[off], pending->msg, msize);
off += msize;
peer->pending_count--;
- GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending);
+ GNUNET_CONTAINER_DLL_remove (peer->head,
+ peer->tail,
+ pending);
GNUNET_free (pending);
}
- if (peer->head != NULL)
+ if (NULL != (pending = peer->head))
{
+ /* technically redundant, but easier to read and
+ avoids bogus gcc warning... */
+ msize = ntohs (pending->msg->size);
peer->th =
- GNUNET_CORE_notify_transmit_ready (core_api, GNUNET_NO,
- GNUNET_CORE_PRIO_BEST_EFFORT,
- GNUNET_TIME_absolute_get_remaining
- (pending->timeout), &peer->id, msize,
- &core_transmit_notify, peer);
+ GNUNET_CORE_notify_transmit_ready (core_api,
+ GNUNET_NO,
+ GNUNET_CORE_PRIO_BEST_EFFORT,
+ GNUNET_TIME_absolute_get_remaining (pending->timeout),
+ &peer->id,
+ msize,
+ &core_transmit_notify,
+ peer);
GNUNET_break (NULL != peer->th);
}
return off;
GNUNET_CONTAINER_bloomfilter_add (bloom, &nhash);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Selected %u/%u peers at hop %u for %s (target was %u)\n", off,
- GNUNET_CONTAINER_multipeermap_size (all_known_peers),
- (unsigned int) hop_count, GNUNET_h2s (key), ret);
+ "Selected %u/%u peers at hop %u for %s (target was %u)\n",
+ off,
+ GNUNET_CONTAINER_multipeermap_size (all_connected_peers),
+ (unsigned int) hop_count,
+ GNUNET_h2s (key),
+ ret);
if (0 == off)
{
GNUNET_free (rtargets);
GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
enum GNUNET_BLOCK_Type type,
struct GNUNET_TIME_Absolute expiration_time,
- const struct GNUNET_HashCode * key,
+ const struct GNUNET_HashCode *key,
unsigned int put_path_length,
const struct GNUNET_PeerIdentity *put_path,
unsigned int get_path_length,
const struct GNUNET_PeerIdentity *get_path,
- const void *data, size_t data_size)
+ const void *data,
+ size_t data_size)
{
struct PeerInfo *pi;
struct P2PPendingMessage *pending;
GNUNET_break (0);
return;
}
- pi = GNUNET_CONTAINER_multipeermap_get (all_known_peers, target);
+ pi = GNUNET_CONTAINER_multipeermap_get (all_connected_peers,
+ target);
if (NULL == pi)
{
/* peer disconnected in the meantime, drop reply */
{
switch (GNUNET_BLOCK_evaluate (GDS_block_context,
ntohl (put->type),
+ GNUNET_BLOCK_EO_NONE,
NULL, /* query */
NULL, 0, /* bloom filer */
NULL, 0, /* xquery */
GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size], reply_bf_size,
GNUNET_CONSTANTS_BLOOMFILTER_K);
eval =
- GNUNET_BLOCK_evaluate (GDS_block_context, type, &get->key, &reply_bf,
- get->bf_mutator, xquery, xquery_size, NULL, 0);
+ GNUNET_BLOCK_evaluate (GDS_block_context,
+ type,
+ GNUNET_BLOCK_EO_NONE,
+ &get->key,
+ &reply_bf,
+ get->bf_mutator,
+ xquery,
+ xquery_size,
+ NULL,
+ 0);
if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID)
{
/* request invalid or block type not supported */
* @return #GNUNET_YES (do not cut p2p connection)
*/
static int
-handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
+handle_dht_p2p_result (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message)
{
const struct PeerResultMessage *prm;
GNUNET_free (tmp);
}
/* if we got a HELLO, consider it for our own routing table */
- if (type == GNUNET_BLOCK_TYPE_DHT_HELLO)
+ if (GNUNET_BLOCK_TYPE_DHT_HELLO == type)
{
const struct GNUNET_MessageHeader *h;
struct GNUNET_PeerIdentity pid;
return GNUNET_YES;
}
if (GNUNET_OK !=
- GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) h, &pid))
+ GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) h,
+ &pid))
{
GNUNET_break_op (0);
return GNUNET_YES;
}
- if ((GNUNET_YES != disable_try_connect) &&
- 0 != memcmp (&my_identity, &pid, sizeof (struct GNUNET_PeerIdentity)))
+ if ( (GNUNET_YES != disable_try_connect) &&
+ (0 != memcmp (&my_identity,
+ &pid,
+ sizeof (struct GNUNET_PeerIdentity))) )
{
struct GNUNET_HashCode pid_hash;
- GNUNET_CRYPTO_hash (&pid, sizeof (struct GNUNET_PeerIdentity), &pid_hash);
+ GNUNET_CRYPTO_hash (&pid,
+ sizeof (struct GNUNET_PeerIdentity),
+ &pid_hash);
bucket = find_bucket (&pid_hash);
- if ((bucket >= 0) &&
- (k_buckets[bucket].peers_size < bucket_size) &&
- (NULL != GDS_transport_handle))
+ if ( (bucket >= 0) &&
+ (k_buckets[bucket].peers_size < bucket_size) &&
+ (NULL != GDS_transport_handle) )
{
- GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, h, NULL, NULL);
- GNUNET_TRANSPORT_try_connect (GDS_transport_handle, &pid, NULL, NULL); /*FIXME TRY_CONNECT change */
+ GNUNET_TRANSPORT_offer_hello (GDS_transport_handle,
+ h,
+ NULL,
+ NULL);
+ GNUNET_TRANSPORT_try_connect (GDS_transport_handle,
+ &pid,
+ NULL,
+ NULL); /*FIXME TRY_CONNECT change */
}
}
}
log_route_details_stderr =
(NULL != getenv("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO;
- atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL);
+ ats_perf = GNUNET_ATS_performance_init (GDS_cfg,
+ NULL,
+ NULL);
+ ats_ch = GNUNET_ATS_connectivity_init (GDS_cfg);
core_api =
GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect,
&handle_core_disconnect, NULL, GNUNET_NO, NULL,
GNUNET_NO, core_handlers);
if (core_api == NULL)
return GNUNET_SYSERR;
- all_known_peers = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO);
+ all_connected_peers = GNUNET_CONTAINER_multipeermap_create (256,
+ GNUNET_NO);
return GNUNET_OK;
}
return;
GNUNET_CORE_disconnect (core_api);
core_api = NULL;
- GNUNET_ATS_performance_done (atsAPI);
- atsAPI = NULL;
- GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (all_known_peers));
- GNUNET_CONTAINER_multipeermap_destroy (all_known_peers);
- all_known_peers = NULL;
+ GNUNET_ATS_performance_done (ats_perf);
+ ats_perf = NULL;
+ GNUNET_ATS_connectivity_done (ats_ch);
+ ats_ch = NULL;
+ GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers));
+ GNUNET_CONTAINER_multipeermap_destroy (all_connected_peers);
+ all_connected_peers = NULL;
if (NULL != find_peer_task)
{
GNUNET_SCHEDULER_cancel (find_peer_task);