aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-10-18 14:06:40 +0000
committerChristian Grothoff <christian@grothoff.org>2015-10-18 14:06:40 +0000
commit2439ed1c3b02f1f4300576369a392b80e87e5ce7 (patch)
tree7dbe64fbf2a3570a98e1a6fd30965630ff108bf7
parent30bab20b8d41f9c9187153a6aacec549a70e35d1 (diff)
downloadgnunet-2439ed1c3b02f1f4300576369a392b80e87e5ce7.tar.gz
gnunet-2439ed1c3b02f1f4300576369a392b80e87e5ce7.zip
-cosmetics, and preparations for try_connect change
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c76
1 files changed, 50 insertions, 26 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 66a41bfb9..f2897f1fa 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009-2013 Christian Grothoff (and other contributing authors) 3 Copyright (C) 2009-2015 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -333,7 +333,7 @@ struct PeerInfo
333 /** 333 /**
334 * Task for scheduling preference updates 334 * Task for scheduling preference updates
335 */ 335 */
336 struct GNUNET_SCHEDULER_Task * preference_task; 336 struct GNUNET_SCHEDULER_Task *preference_task;
337 337
338 /** 338 /**
339 * What is the identity of the peer? 339 * What is the identity of the peer?
@@ -421,7 +421,7 @@ static unsigned int bucket_size = DEFAULT_BUCKET_SIZE;
421/** 421/**
422 * Task that sends FIND PEER requests. 422 * Task that sends FIND PEER requests.
423 */ 423 */
424static struct GNUNET_SCHEDULER_Task * find_peer_task; 424static struct GNUNET_SCHEDULER_Task *find_peer_task;
425 425
426/** 426/**
427 * Identity of this peer. 427 * Identity of this peer.
@@ -439,9 +439,14 @@ static struct GNUNET_HashCode my_identity_hash;
439static struct GNUNET_CORE_Handle *core_api; 439static struct GNUNET_CORE_Handle *core_api;
440 440
441/** 441/**
442 * Handle to ATS. 442 * Handle to ATS performance monitoring.
443 */ 443 */
444static struct GNUNET_ATS_PerformanceHandle *atsAPI; 444static struct GNUNET_ATS_PerformanceHandle *ats_perf;
445
446/**
447 * Handle to ATS connectivity.
448 */
449static struct GNUNET_ATS_ConnectivityHandle *ats_ch;
445 450
446 451
447 452
@@ -513,9 +518,11 @@ update_core_preference (void *cls,
513 GNUNET_STATISTICS_update (GDS_stats, 518 GNUNET_STATISTICS_update (GDS_stats,
514 gettext_noop ("# Preference updates given to core"), 519 gettext_noop ("# Preference updates given to core"),
515 1, GNUNET_NO); 520 1, GNUNET_NO);
516 GNUNET_ATS_performance_change_preference (atsAPI, &peer->id, 521 GNUNET_ATS_performance_change_preference (ats_perf,
517 GNUNET_ATS_PREFERENCE_BANDWIDTH, 522 &peer->id,
518 (double) preference, GNUNET_ATS_PREFERENCE_END); 523 GNUNET_ATS_PREFERENCE_BANDWIDTH,
524 (double) preference,
525 GNUNET_ATS_PREFERENCE_END);
519 peer->preference_task = 526 peer->preference_task =
520 GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, 527 GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
521 &update_core_preference, peer); 528 &update_core_preference, peer);
@@ -824,7 +831,7 @@ core_transmit_notify (void *cls, size_t size, void *buf)
824 memcpy (&cbuf[off], pending->msg, msize); 831 memcpy (&cbuf[off], pending->msg, msize);
825 off += msize; 832 off += msize;
826 peer->pending_count--; 833 peer->pending_count--;
827 GNUNET_CONTAINER_DLL_remove (peer->head, 834 GNUNET_CONTAINER_DLL_remove (peer->head,
828 peer->tail, 835 peer->tail,
829 pending); 836 pending);
830 GNUNET_free (pending); 837 GNUNET_free (pending);
@@ -835,13 +842,13 @@ core_transmit_notify (void *cls, size_t size, void *buf)
835 avoids bogus gcc warning... */ 842 avoids bogus gcc warning... */
836 msize = ntohs (pending->msg->size); 843 msize = ntohs (pending->msg->size);
837 peer->th = 844 peer->th =
838 GNUNET_CORE_notify_transmit_ready (core_api, 845 GNUNET_CORE_notify_transmit_ready (core_api,
839 GNUNET_NO, 846 GNUNET_NO,
840 GNUNET_CORE_PRIO_BEST_EFFORT, 847 GNUNET_CORE_PRIO_BEST_EFFORT,
841 GNUNET_TIME_absolute_get_remaining (pending->timeout), 848 GNUNET_TIME_absolute_get_remaining (pending->timeout),
842 &peer->id, 849 &peer->id,
843 msize, 850 msize,
844 &core_transmit_notify, 851 &core_transmit_notify,
845 peer); 852 peer);
846 GNUNET_break (NULL != peer->th); 853 GNUNET_break (NULL != peer->th);
847 } 854 }
@@ -2057,7 +2064,8 @@ handle_dht_p2p_get (void *cls,
2057 * @return #GNUNET_YES (do not cut p2p connection) 2064 * @return #GNUNET_YES (do not cut p2p connection)
2058 */ 2065 */
2059static int 2066static int
2060handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, 2067handle_dht_p2p_result (void *cls,
2068 const struct GNUNET_PeerIdentity *peer,
2061 const struct GNUNET_MessageHeader *message) 2069 const struct GNUNET_MessageHeader *message)
2062{ 2070{
2063 const struct PeerResultMessage *prm; 2071 const struct PeerResultMessage *prm;
@@ -2116,7 +2124,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
2116 GNUNET_free (tmp); 2124 GNUNET_free (tmp);
2117 } 2125 }
2118 /* if we got a HELLO, consider it for our own routing table */ 2126 /* if we got a HELLO, consider it for our own routing table */
2119 if (type == GNUNET_BLOCK_TYPE_DHT_HELLO) 2127 if (GNUNET_BLOCK_TYPE_DHT_HELLO == type)
2120 { 2128 {
2121 const struct GNUNET_MessageHeader *h; 2129 const struct GNUNET_MessageHeader *h;
2122 struct GNUNET_PeerIdentity pid; 2130 struct GNUNET_PeerIdentity pid;
@@ -2135,24 +2143,35 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
2135 return GNUNET_YES; 2143 return GNUNET_YES;
2136 } 2144 }
2137 if (GNUNET_OK != 2145 if (GNUNET_OK !=
2138 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) h, &pid)) 2146 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) h,
2147 &pid))
2139 { 2148 {
2140 GNUNET_break_op (0); 2149 GNUNET_break_op (0);
2141 return GNUNET_YES; 2150 return GNUNET_YES;
2142 } 2151 }
2143 if ((GNUNET_YES != disable_try_connect) && 2152 if ( (GNUNET_YES != disable_try_connect) &&
2144 0 != memcmp (&my_identity, &pid, sizeof (struct GNUNET_PeerIdentity))) 2153 (0 != memcmp (&my_identity,
2154 &pid,
2155 sizeof (struct GNUNET_PeerIdentity))) )
2145 { 2156 {
2146 struct GNUNET_HashCode pid_hash; 2157 struct GNUNET_HashCode pid_hash;
2147 2158
2148 GNUNET_CRYPTO_hash (&pid, sizeof (struct GNUNET_PeerIdentity), &pid_hash); 2159 GNUNET_CRYPTO_hash (&pid,
2160 sizeof (struct GNUNET_PeerIdentity),
2161 &pid_hash);
2149 bucket = find_bucket (&pid_hash); 2162 bucket = find_bucket (&pid_hash);
2150 if ((bucket >= 0) && 2163 if ( (bucket >= 0) &&
2151 (k_buckets[bucket].peers_size < bucket_size) && 2164 (k_buckets[bucket].peers_size < bucket_size) &&
2152 (NULL != GDS_transport_handle)) 2165 (NULL != GDS_transport_handle) )
2153 { 2166 {
2154 GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, h, NULL, NULL); 2167 GNUNET_TRANSPORT_offer_hello (GDS_transport_handle,
2155 GNUNET_TRANSPORT_try_connect (GDS_transport_handle, &pid, NULL, NULL); /*FIXME TRY_CONNECT change */ 2168 h,
2169 NULL,
2170 NULL);
2171 GNUNET_TRANSPORT_try_connect (GDS_transport_handle,
2172 &pid,
2173 NULL,
2174 NULL); /*FIXME TRY_CONNECT change */
2156 } 2175 }
2157 } 2176 }
2158 } 2177 }
@@ -2229,7 +2248,10 @@ GDS_NEIGHBOURS_init ()
2229 2248
2230 log_route_details_stderr = 2249 log_route_details_stderr =
2231 (NULL != getenv("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO; 2250 (NULL != getenv("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO;
2232 atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); 2251 ats_perf = GNUNET_ATS_performance_init (GDS_cfg,
2252 NULL,
2253 NULL);
2254 ats_ch = GNUNET_ATS_connectivity_init (GDS_cfg);
2233 core_api = 2255 core_api =
2234 GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect, 2256 GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect,
2235 &handle_core_disconnect, NULL, GNUNET_NO, NULL, 2257 &handle_core_disconnect, NULL, GNUNET_NO, NULL,
@@ -2251,8 +2273,10 @@ GDS_NEIGHBOURS_done ()
2251 return; 2273 return;
2252 GNUNET_CORE_disconnect (core_api); 2274 GNUNET_CORE_disconnect (core_api);
2253 core_api = NULL; 2275 core_api = NULL;
2254 GNUNET_ATS_performance_done (atsAPI); 2276 GNUNET_ATS_performance_done (ats_perf);
2255 atsAPI = NULL; 2277 ats_perf = NULL;
2278 GNUNET_ATS_connectivity_done (ats_ch);
2279 ats_ch = NULL;
2256 GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (all_known_peers)); 2280 GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (all_known_peers));
2257 GNUNET_CONTAINER_multipeermap_destroy (all_known_peers); 2281 GNUNET_CONTAINER_multipeermap_destroy (all_known_peers);
2258 all_known_peers = NULL; 2282 all_known_peers = NULL;