aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet-new_peer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/gnunet-service-cadet-new_peer.c')
-rw-r--r--src/cadet/gnunet-service-cadet-new_peer.c64
1 files changed, 54 insertions, 10 deletions
diff --git a/src/cadet/gnunet-service-cadet-new_peer.c b/src/cadet/gnunet-service-cadet-new_peer.c
index 43e375c75..0ef65b7b6 100644
--- a/src/cadet/gnunet-service-cadet-new_peer.c
+++ b/src/cadet/gnunet-service-cadet-new_peer.c
@@ -37,6 +37,7 @@
37#include "gnunet-service-cadet-new.h" 37#include "gnunet-service-cadet-new.h"
38#include "gnunet-service-cadet-new_dht.h" 38#include "gnunet-service-cadet-new_dht.h"
39#include "gnunet-service-cadet-new_peer.h" 39#include "gnunet-service-cadet-new_peer.h"
40#include "gnunet-service-cadet-new_paths.h"
40#include "gnunet-service-cadet-new_tunnels.h" 41#include "gnunet-service-cadet-new_tunnels.h"
41 42
42/** 43/**
@@ -45,6 +46,12 @@
45#define IDLE_PEER_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) 46#define IDLE_PEER_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
46 47
47/** 48/**
49 * How long do we keep paths around if we no longer care about the peer?
50 */
51#define IDLE_PATH_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2)
52
53
54/**
48 * Struct containing all information regarding a given peer 55 * Struct containing all information regarding a given peer
49 */ 56 */
50struct CadetPeer 57struct CadetPeer
@@ -72,7 +79,8 @@ struct CadetPeer
72 struct CadetPeerPathEntry **path_tails; 79 struct CadetPeerPathEntry **path_tails;
73 80
74 /** 81 /**
75 * MIN-heap of paths ending at this peer. Ordered by desirability. 82 * MIN-heap of paths owned by this peer (they also end at this
83 * peer). Ordered by desirability.
76 */ 84 */
77 struct GNUNET_CONTAINER_Heap *path_heap; 85 struct GNUNET_CONTAINER_Heap *path_heap;
78 86
@@ -186,8 +194,6 @@ destroy_peer (void *cls)
186 } 194 }
187 /* FIXME: clean up search_delayedXXX! */ 195 /* FIXME: clean up search_delayedXXX! */
188 196
189 GNUNET_CONTAINER_multihashmap_destroy (cp->connections);
190 GNUNET_free_non_null (cp->hello);
191 if (NULL != cp->hello_offer) 197 if (NULL != cp->hello_offer)
192 { 198 {
193 GNUNET_TRANSPORT_offer_hello_cancel (cp->hello_offer); 199 GNUNET_TRANSPORT_offer_hello_cancel (cp->hello_offer);
@@ -198,6 +204,9 @@ destroy_peer (void *cls)
198 GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion); 204 GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion);
199 cp->connectivity_suggestion = NULL; 205 cp->connectivity_suggestion = NULL;
200 } 206 }
207 GNUNET_CONTAINER_multihashmap_destroy (cp->connections);
208 GNUNET_CONTAINER_heap_destroy (cp->path_heap);
209 GNUNET_free_non_null (cp->hello);
201 GNUNET_free (cp); 210 GNUNET_free (cp);
202} 211}
203 212
@@ -247,6 +256,34 @@ GCP_destroy_all_peers ()
247 * @param cp peer to clean up 256 * @param cp peer to clean up
248 */ 257 */
249static void 258static void
259consider_peer_destroy (struct CadetPeer *cp);
260
261
262/**
263 * We really no longere care about a peer, stop hogging memory with paths to it.
264 * Afterwards, see if there is more to be cleaned up about this peer.
265 *
266 * @param cls a `struct CadetPeer`.
267 */
268static void
269drop_paths (void *cls)
270{
271 struct CadetPeer *cp = cls;
272 struct CadetPeerPath *path;
273
274 cp->destroy_task = NULL;
275 while (NULL != (path = GNUNET_CONTAINER_heap_remove_root (cp->path_heap)))
276 GCPP_release (path);
277 consider_peer_destroy (cp);
278}
279
280
281/**
282 * This peer may no longer be needed, consider cleaning it up.
283 *
284 * @param cp peer to clean up
285 */
286static void
250consider_peer_destroy (struct CadetPeer *cp) 287consider_peer_destroy (struct CadetPeer *cp)
251{ 288{
252 struct GNUNET_TIME_Relative exp; 289 struct GNUNET_TIME_Relative exp;
@@ -260,17 +297,24 @@ consider_peer_destroy (struct CadetPeer *cp)
260 return; /* still relevant! */ 297 return; /* still relevant! */
261 if (NULL != cp->core_mq) 298 if (NULL != cp->core_mq)
262 return; /* still relevant! */ 299 return; /* still relevant! */
263 if (0 != cp->path_dll_length)
264 return; /* still relevant! */
265 if (0 != GNUNET_CONTAINER_multihashmap_size (cp->connections)) 300 if (0 != GNUNET_CONTAINER_multihashmap_size (cp->connections))
266 return; /* still relevant! */ 301 return; /* still relevant! */
302 if (0 < GNUNET_CONTAINER_heap_get_size (cp->path_heap))
303 {
304 cp->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_PATH_TIMEOUT,
305 &drop_paths,
306 cp);
307 return;
308 }
309 if (0 < cp->path_dll_length)
310 return; /* still relevant! */
267 if (NULL != cp->hello) 311 if (NULL != cp->hello)
268 { 312 {
269 /* relevant only until HELLO expires */ 313 /* relevant only until HELLO expires */
270 exp = GNUNET_TIME_absolute_get_remaining (GNUNET_HELLO_get_last_expiration (cp->hello)); 314 exp = GNUNET_TIME_absolute_get_remaining (GNUNET_HELLO_get_last_expiration (cp->hello));
271 cp->destroy_task = GNUNET_SCHEDULER_add_delayed (exp, 315 cp->destroy_task = GNUNET_SCHEDULER_add_delayed (exp,
272 &destroy_peer, 316 &destroy_peer,
273 cp); 317 cp);
274 return; 318 return;
275 } 319 }
276 cp->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_PEER_TIMEOUT, 320 cp->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_PEER_TIMEOUT,
@@ -337,7 +381,7 @@ GCP_path_entry_remove (struct CadetPeer *cp,
337 */ 381 */
338static void 382static void
339dht_result_cb (void *cls, 383dht_result_cb (void *cls,
340 const struct CadetPeerPath *path) 384 struct CadetPeerPath *path)
341{ 385{
342 struct CadetPeer *cp = cls; 386 struct CadetPeer *cp = cls;
343 GNUNET_CONTAINER_HeapCostType desirability; 387 GNUNET_CONTAINER_HeapCostType desirability;
@@ -368,8 +412,7 @@ dht_result_cb (void *cls,
368 { 412 {
369 /* Now we have way too many, drop least desirable */ 413 /* Now we have way too many, drop least desirable */
370 root = GNUNET_CONTAINER_heap_remove_root (cp->path_heap); 414 root = GNUNET_CONTAINER_heap_remove_root (cp->path_heap);
371 GCPP_release (path, 415 GCPP_release (path);
372 cp);
373 } 416 }
374} 417}
375 418
@@ -464,6 +507,7 @@ GCP_get (const struct GNUNET_PeerIdentity *peer_id,
464 cp->pid = *peer_id; 507 cp->pid = *peer_id;
465 cp->connections = GNUNET_CONTAINER_multihashmap_create (32, 508 cp->connections = GNUNET_CONTAINER_multihashmap_create (32,
466 GNUNET_YES); 509 GNUNET_YES);
510 cp->path_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
467 cp->search_h = NULL; // FIXME: start search immediately!? 511 cp->search_h = NULL; // FIXME: start search immediately!?
468 cp->connectivity_suggestion = NULL; // FIXME: request with ATS!? 512 cp->connectivity_suggestion = NULL; // FIXME: request with ATS!?
469 513