aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-16 11:24:30 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-16 11:24:30 +0100
commitd473582634ea55c2a412da1360b05a2898ed568d (patch)
tree39ca0098ac657e5dbc0960469ae05195e2506f60 /src
parent301693904d07a063711bfc1ff4c5505c61eaf821 (diff)
downloadgnunet-d473582634ea55c2a412da1360b05a2898ed568d.tar.gz
gnunet-d473582634ea55c2a412da1360b05a2898ed568d.zip
simplify GNUNET_CONTAINER_heap_update_cost API
Diffstat (limited to 'src')
-rw-r--r--src/datacache/plugin_datacache_heap.c3
-rw-r--r--src/datastore/plugin_datastore_heap.c8
-rw-r--r--src/exit/gnunet-daemon-exit.c5
-rw-r--r--src/include/gnunet_container_lib.h8
-rw-r--r--src/transport/plugin_transport_udp.c9
-rw-r--r--src/util/container_heap.c27
-rw-r--r--src/util/test_container_heap.c13
-rw-r--r--src/vpn/gnunet-service-vpn.c12
8 files changed, 31 insertions, 54 deletions
diff --git a/src/datacache/plugin_datacache_heap.c b/src/datacache/plugin_datacache_heap.c
index 185d54f2f..49e60bca1 100644
--- a/src/datacache/plugin_datacache_heap.c
+++ b/src/datacache/plugin_datacache_heap.c
@@ -180,8 +180,7 @@ put_cb (void *cls,
180 GNUNET_memcpy (val->path_info, 180 GNUNET_memcpy (val->path_info,
181 put_ctx->path_info, 181 put_ctx->path_info,
182 put_ctx->path_info_len * sizeof (struct GNUNET_PeerIdentity)); 182 put_ctx->path_info_len * sizeof (struct GNUNET_PeerIdentity));
183 GNUNET_CONTAINER_heap_update_cost (put_ctx->heap, 183 GNUNET_CONTAINER_heap_update_cost (val->hn,
184 val->hn,
185 val->discard_time.abs_value_us); 184 val->discard_time.abs_value_us);
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "Got same value for key %s and type %d (size %u vs %u)\n", 186 "Got same value for key %s and type %d (size %u vs %u)\n",
diff --git a/src/datastore/plugin_datastore_heap.c b/src/datastore/plugin_datastore_heap.c
index 51f61764c..977d599d2 100644
--- a/src/datastore/plugin_datastore_heap.c
+++ b/src/datastore/plugin_datastore_heap.c
@@ -331,7 +331,7 @@ struct GetContext
331 * The plugin. 331 * The plugin.
332 */ 332 */
333 struct Plugin *plugin; 333 struct Plugin *plugin;
334 334
335 /** 335 /**
336 * Requested value hash. 336 * Requested value hash.
337 */ 337 */
@@ -608,7 +608,7 @@ heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
608 * priority should be added to the existing priority, ignoring the 608 * priority should be added to the existing priority, ignoring the
609 * priority in value. 609 * priority in value.
610 * 610 *
611 * @param cls our "struct Plugin*" 611 * @param cls our `struct Plugin *`
612 * @param uid unique identifier of the datum 612 * @param uid unique identifier of the datum
613 * @param delta by how much should the priority 613 * @param delta by how much should the priority
614 * change? If priority + delta < 0 the 614 * change? If priority + delta < 0 the
@@ -628,7 +628,6 @@ heap_plugin_update (void *cls,
628 PluginUpdateCont cont, 628 PluginUpdateCont cont,
629 void *cont_cls) 629 void *cont_cls)
630{ 630{
631 struct Plugin *plugin = cls;
632 struct Value *value; 631 struct Value *value;
633 632
634 value = (struct Value*) (long) uid; 633 value = (struct Value*) (long) uid;
@@ -636,8 +635,7 @@ heap_plugin_update (void *cls,
636 if (value->expiration.abs_value_us != expire.abs_value_us) 635 if (value->expiration.abs_value_us != expire.abs_value_us)
637 { 636 {
638 value->expiration = expire; 637 value->expiration = expire;
639 GNUNET_CONTAINER_heap_update_cost (plugin->by_expiration, 638 GNUNET_CONTAINER_heap_update_cost (value->expire_heap,
640 value->expire_heap,
641 expire.abs_value_us); 639 expire.abs_value_us);
642 } 640 }
643 if ( (delta < 0) && (value->priority < - delta) ) 641 if ( (delta < 0) && (value->priority < - delta) )
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c
index 790780aa6..92acc61cd 100644
--- a/src/exit/gnunet-daemon-exit.c
+++ b/src/exit/gnunet-daemon-exit.c
@@ -747,9 +747,8 @@ get_redirect_state (int af,
747 return NULL; 747 return NULL;
748 /* Mark this connection as freshly used */ 748 /* Mark this connection as freshly used */
749 if (NULL == state_key) 749 if (NULL == state_key)
750 GNUNET_CONTAINER_heap_update_cost (connections_heap, 750 GNUNET_CONTAINER_heap_update_cost (state->specifics.tcp_udp.heap_node,
751 state->specifics.tcp_udp.heap_node, 751 GNUNET_TIME_absolute_get ().abs_value_us);
752 GNUNET_TIME_absolute_get ().abs_value_us);
753 return state; 752 return state;
754} 753}
755 754
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index 03c47c201..075c0822a 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -1915,8 +1915,8 @@ GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap);
1915 * @return cost of the node 1915 * @return cost of the node
1916 */ 1916 */
1917GNUNET_CONTAINER_HeapCostType 1917GNUNET_CONTAINER_HeapCostType
1918GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode 1918GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode *node);
1919 *node); 1919
1920 1920
1921/** 1921/**
1922 * @ingroup heap 1922 * @ingroup heap
@@ -2006,13 +2006,11 @@ GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node);
2006 * @ingroup heap 2006 * @ingroup heap
2007 * Updates the cost of any node in the tree 2007 * Updates the cost of any node in the tree
2008 * 2008 *
2009 * @param heap heap to modify
2010 * @param node node for which the cost is to be changed 2009 * @param node node for which the cost is to be changed
2011 * @param new_cost new cost for the node 2010 * @param new_cost new cost for the node
2012 */ 2011 */
2013void 2012void
2014GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap, 2013GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_HeapNode *node,
2015 struct GNUNET_CONTAINER_HeapNode *node,
2016 GNUNET_CONTAINER_HeapCostType new_cost); 2014 GNUNET_CONTAINER_HeapCostType new_cost);
2017 2015
2018 2016
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 8281e48c5..fd8493e5f 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -1246,7 +1246,7 @@ udp_plugin_check_address (void *cls,
1246 if (sizeof(struct IPv4UdpAddress) == addrlen) 1246 if (sizeof(struct IPv4UdpAddress) == addrlen)
1247 { 1247 {
1248 struct sockaddr_in s4; 1248 struct sockaddr_in s4;
1249 1249
1250 v4 = (const struct IPv4UdpAddress *) addr; 1250 v4 = (const struct IPv4UdpAddress *) addr;
1251 if (GNUNET_OK != check_port (plugin, 1251 if (GNUNET_OK != check_port (plugin,
1252 ntohs (v4->u4_port))) 1252 ntohs (v4->u4_port)))
@@ -1258,7 +1258,7 @@ udp_plugin_check_address (void *cls,
1258#endif 1258#endif
1259 s4.sin_port = v4->u4_port; 1259 s4.sin_port = v4->u4_port;
1260 s4.sin_addr.s_addr = v4->ipv4_addr; 1260 s4.sin_addr.s_addr = v4->ipv4_addr;
1261 1261
1262 if (GNUNET_OK != 1262 if (GNUNET_OK !=
1263 GNUNET_NAT_test_address (plugin->nat, 1263 GNUNET_NAT_test_address (plugin->nat,
1264 &s4, 1264 &s4,
@@ -3052,8 +3052,7 @@ read_process_fragment (struct Plugin *plugin,
3052 msg)) 3052 msg))
3053 { 3053 {
3054 /* keep this 'rc' from expiring */ 3054 /* keep this 'rc' from expiring */
3055 GNUNET_CONTAINER_heap_update_cost (plugin->defrag_ctxs, 3055 GNUNET_CONTAINER_heap_update_cost (d_ctx->hnode,
3056 d_ctx->hnode,
3057 (GNUNET_CONTAINER_HeapCostType) now.abs_value_us); 3056 (GNUNET_CONTAINER_HeapCostType) now.abs_value_us);
3058 } 3057 }
3059 if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > 3058 if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) >
@@ -3539,7 +3538,7 @@ udp_plugin_select_v4 (void *cls)
3539{ 3538{
3540 struct Plugin *plugin = cls; 3539 struct Plugin *plugin = cls;
3541 const struct GNUNET_SCHEDULER_TaskContext *tc; 3540 const struct GNUNET_SCHEDULER_TaskContext *tc;
3542 3541
3543 plugin->select_task_v4 = NULL; 3542 plugin->select_task_v4 = NULL;
3544 if (NULL == plugin->sockv4) 3543 if (NULL == plugin->sockv4)
3545 return; 3544 return;
diff --git a/src/util/container_heap.c b/src/util/container_heap.c
index 4f82fb076..1ead5ec6d 100644
--- a/src/util/container_heap.c
+++ b/src/util/container_heap.c
@@ -541,36 +541,23 @@ GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node)
541/** 541/**
542 * Updates the cost of any node in the tree 542 * Updates the cost of any node in the tree
543 * 543 *
544 * @param heap heap to modify
545 * @param node node for which the cost is to be changed 544 * @param node node for which the cost is to be changed
546 * @param new_cost new cost for the node 545 * @param new_cost new cost for the node
547 */ 546 */
548void 547void
549GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap, 548GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_HeapNode *node,
550 struct GNUNET_CONTAINER_HeapNode *node,
551 GNUNET_CONTAINER_HeapCostType new_cost) 549 GNUNET_CONTAINER_HeapCostType new_cost)
552{ 550{
553#if EXTRA_CHECKS 551 struct GNUNET_CONTAINER_Heap *heap = node->heap;
554 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) || 552
555 (heap->size == heap->root->tree_size + 1));
556 CHECK (heap->root);
557#endif
558 remove_node (node); 553 remove_node (node);
559#if EXTRA_CHECKS
560 CHECK (heap->root);
561 GNUNET_assert (((heap->size == 1) && (heap->root == NULL)) ||
562 (heap->size == heap->root->tree_size + 2));
563#endif
564 node->cost = new_cost; 554 node->cost = new_cost;
565 if (heap->root == NULL) 555 if (NULL == heap->root)
566 heap->root = node; 556 heap->root = node;
567 else 557 else
568 insert_node (heap, heap->root, node); 558 insert_node (heap,
569#if EXTRA_CHECKS 559 heap->root,
570 CHECK (heap->root); 560 node);
571 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
572 (heap->size == heap->root->tree_size + 1));
573#endif
574} 561}
575 562
576 563
diff --git a/src/util/test_container_heap.c b/src/util/test_container_heap.c
index f115159bf..82b0e9523 100644
--- a/src/util/test_container_heap.c
+++ b/src/util/test_container_heap.c
@@ -28,7 +28,8 @@
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29 29
30static int 30static int
31iterator_callback (void *cls, struct GNUNET_CONTAINER_HeapNode *node, 31iterator_callback (void *cls,
32 struct GNUNET_CONTAINER_HeapNode *node,
32 void *element, GNUNET_CONTAINER_HeapCostType cost) 33 void *element, GNUNET_CONTAINER_HeapCostType cost)
33{ 34{
34 return GNUNET_OK; 35 return GNUNET_OK;
@@ -93,12 +94,12 @@ check ()
93 GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); 94 GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL);
94 95
95 n3 = GNUNET_CONTAINER_heap_insert (myHeap, "15", 5); 96 n3 = GNUNET_CONTAINER_heap_insert (myHeap, "15", 5);
96 GNUNET_CONTAINER_heap_update_cost (myHeap, n3, 15); 97 GNUNET_CONTAINER_heap_update_cost (n3, 15);
97 GNUNET_assert (2 == GNUNET_CONTAINER_heap_get_size (myHeap)); 98 GNUNET_assert (2 == GNUNET_CONTAINER_heap_get_size (myHeap));
98 GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); 99 GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL);
99 100
100 n4 = GNUNET_CONTAINER_heap_insert (myHeap, "50", 50); 101 n4 = GNUNET_CONTAINER_heap_insert (myHeap, "50", 50);
101 GNUNET_CONTAINER_heap_update_cost (myHeap, n4, 50); 102 GNUNET_CONTAINER_heap_update_cost (n4, 50);
102 GNUNET_assert (3 == GNUNET_CONTAINER_heap_get_size (myHeap)); 103 GNUNET_assert (3 == GNUNET_CONTAINER_heap_get_size (myHeap));
103 GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); 104 GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL);
104 105
@@ -109,7 +110,7 @@ check ()
109 r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n1 */ 110 r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n1 */
110 GNUNET_assert (NULL != r); 111 GNUNET_assert (NULL != r);
111 GNUNET_assert (0 == strcmp ("11", r)); 112 GNUNET_assert (0 == strcmp ("11", r));
112 GNUNET_CONTAINER_heap_update_cost (myHeap, n6, 200); 113 GNUNET_CONTAINER_heap_update_cost (n6, 200);
113 GNUNET_CONTAINER_heap_remove_node (n3); 114 GNUNET_CONTAINER_heap_remove_node (n3);
114 r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n4 */ 115 r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n4 */
115 GNUNET_assert (NULL != r); 116 GNUNET_assert (NULL != r);
@@ -128,7 +129,7 @@ check ()
128 myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 129 myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
129 130
130 n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); 131 n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
131 GNUNET_CONTAINER_heap_update_cost (myHeap, n1, 15); 132 GNUNET_CONTAINER_heap_update_cost (n1, 15);
132 133
133 r = GNUNET_CONTAINER_heap_remove_node (n1); 134 r = GNUNET_CONTAINER_heap_remove_node (n1);
134 GNUNET_assert (NULL != r); 135 GNUNET_assert (NULL != r);
@@ -213,7 +214,7 @@ check ()
213 myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX); 214 myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
214 215
215 n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); 216 n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
216 GNUNET_CONTAINER_heap_update_cost (myHeap, n1, 15); 217 GNUNET_CONTAINER_heap_update_cost (n1, 15);
217 218
218 GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1))); 219 GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1)));
219 220
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index 4c0978d5c..c66023c85 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.c
@@ -1129,8 +1129,7 @@ route_packet (struct DestinationEntry *destination,
1129 } 1129 }
1130 else 1130 else
1131 { 1131 {
1132 GNUNET_CONTAINER_heap_update_cost (channel_heap, 1132 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
1133 ts->heap_node,
1134 GNUNET_TIME_absolute_get ().abs_value_us); 1133 GNUNET_TIME_absolute_get ().abs_value_us);
1135 } 1134 }
1136 if (NULL == ts->channel) 1135 if (NULL == ts->channel)
@@ -2062,8 +2061,7 @@ receive_icmp_back (void *cls,
2062 default: 2061 default:
2063 GNUNET_assert (0); 2062 GNUNET_assert (0);
2064 } 2063 }
2065 GNUNET_CONTAINER_heap_update_cost (channel_heap, 2064 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
2066 ts->heap_node,
2067 GNUNET_TIME_absolute_get ().abs_value_us); 2065 GNUNET_TIME_absolute_get ().abs_value_us);
2068 GNUNET_CADET_receive_done (channel); 2066 GNUNET_CADET_receive_done (channel);
2069 return GNUNET_OK; 2067 return GNUNET_OK;
@@ -2218,8 +2216,7 @@ receive_udp_back (void *cls,
2218 default: 2216 default:
2219 GNUNET_assert (0); 2217 GNUNET_assert (0);
2220 } 2218 }
2221 GNUNET_CONTAINER_heap_update_cost (channel_heap, 2219 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
2222 ts->heap_node,
2223 GNUNET_TIME_absolute_get ().abs_value_us); 2220 GNUNET_TIME_absolute_get ().abs_value_us);
2224 GNUNET_CADET_receive_done (channel); 2221 GNUNET_CADET_receive_done (channel);
2225 return GNUNET_OK; 2222 return GNUNET_OK;
@@ -2361,8 +2358,7 @@ receive_tcp_back (void *cls,
2361 } 2358 }
2362 break; 2359 break;
2363 } 2360 }
2364 GNUNET_CONTAINER_heap_update_cost (channel_heap, 2361 GNUNET_CONTAINER_heap_update_cost (ts->heap_node,
2365 ts->heap_node,
2366 GNUNET_TIME_absolute_get ().abs_value_us); 2362 GNUNET_TIME_absolute_get ().abs_value_us);
2367 GNUNET_CADET_receive_done (channel); 2363 GNUNET_CADET_receive_done (channel);
2368 return GNUNET_OK; 2364 return GNUNET_OK;