From: Christian Grothoff Date: Fri, 11 Mar 2011 16:58:27 +0000 (+0000) Subject: changing heap remove node api to not pass heap; more fs hacking X-Git-Tag: initial-import-from-subversion-38251~18993 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=562b33143ee9fa431a68ea6741e4feb3ba388f83;p=oweals%2Fgnunet.git changing heap remove node api to not pass heap; more fs hacking --- diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c index 7a1606219..d12cc91df 100644 --- a/src/dht/gnunet-dht-driver.c +++ b/src/dht/gnunet-dht-driver.c @@ -1243,10 +1243,8 @@ do_get(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc); static int remove_peer_count(void *cls, const GNUNET_HashCode * key, void *value) { - struct FindPeerContext *find_peer_ctx = cls; struct PeerCount *peer_count = value; - GNUNET_CONTAINER_heap_remove_node (find_peer_ctx->peer_min_heap, - peer_count->heap_node); + GNUNET_CONTAINER_heap_remove_node (peer_count->heap_node); GNUNET_free(peer_count); return GNUNET_YES; diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index e455cbc30..08cc7dc88 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c @@ -2115,8 +2115,7 @@ remove_forward_entry (void *cls, struct DHTRouteSource *source_info = cls; struct DHTQueryRecord *record; source_info = - GNUNET_CONTAINER_heap_remove_node (forward_list.minHeap, - source_info->hnode); + GNUNET_CONTAINER_heap_remove_node (source_info->hnode); record = source_info->record; GNUNET_CONTAINER_DLL_remove (record->head, record->tail, source_info); @@ -3733,7 +3732,7 @@ remove_recent (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (recent.hashmap, &hash, req)); - GNUNET_CONTAINER_heap_remove_node (recent.minHeap, req->heap_node); + GNUNET_CONTAINER_heap_remove_node (req->heap_node); GNUNET_CONTAINER_bloomfilter_free (req->bloom); GNUNET_free (req); @@ -4241,7 +4240,7 @@ find_client_records (void *cls, const GNUNET_HashCode * key, void *value) if (pos != NULL) { GNUNET_CONTAINER_DLL_remove (record->head, record->tail, pos); - GNUNET_CONTAINER_heap_remove_node (forward_list.minHeap, pos->hnode); + GNUNET_CONTAINER_heap_remove_node (pos->hnode); if (pos->delete_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (pos->delete_task); diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index 900c8f5d7..a6fe9762b 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c @@ -2010,8 +2010,8 @@ distant_neighbor_free (struct DistantNeighbor *referee) GNUNET_CONTAINER_DLL_remove (referrer->referee_head, referrer->referee_tail, referee); } - GNUNET_CONTAINER_heap_remove_node (neighbor_max_heap, referee->max_loc); - GNUNET_CONTAINER_heap_remove_node (neighbor_min_heap, referee->min_loc); + GNUNET_CONTAINER_heap_remove_node (referee->max_loc); + GNUNET_CONTAINER_heap_remove_node (referee->min_loc); GNUNET_CONTAINER_multihashmap_remove_all (extended_neighbors, &referee->identity.hashPubKey); GNUNET_free_non_null (referee->pkey); diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 101698160..ab16bc834 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -1532,8 +1532,7 @@ destroy_pending_request (struct PendingRequest *pr) if (pr->hnode != NULL) { - GNUNET_CONTAINER_heap_remove_node (requests_by_expiration_heap, - pr->hnode); + GNUNET_CONTAINER_heap_remove_node (pr->hnode); pr->hnode = NULL; } if (NULL == pr->client_request_list) diff --git a/src/fs/gnunet-service-fs.h b/src/fs/gnunet-service-fs.h index a82206e9c..ee4cea8e2 100644 --- a/src/fs/gnunet-service-fs.h +++ b/src/fs/gnunet-service-fs.h @@ -70,6 +70,10 @@ struct GSF_PendingRequest; */ struct GSF_LocalClient; +/** + * Information kept per plan per request ('pe' module). + */ +struct GSF_RequestPlan; /** * Our connection to the datastore. diff --git a/src/fs/gnunet-service-fs_pe.c b/src/fs/gnunet-service-fs_pe.c index e7608653e..306bb948c 100644 --- a/src/fs/gnunet-service-fs_pe.c +++ b/src/fs/gnunet-service-fs_pe.c @@ -28,13 +28,51 @@ #include "gnunet-service-fs_pe.h" #include "gnunet-service-fs_pr.h" + +/** + * Information we keep per request per peer. This is a doubly-linked + * list (with head and tail in the 'struct GSF_PendingRequestData') + * with one entry in each heap of each 'struct PeerPlan'. Each + * entry tracks information relevant for this request and this peer. + */ +struct GSF_RequestPlan +{ + + /** + * This is a doubly-linked list. + */ + struct GSF_RequestPlan *next; + + /** + * This is a doubly-linked list. + */ + struct GSF_RequestPlan *prev; + + /** + * Heap node associated with this request and this peer. + */ + struct GNUNET_CONTAINER_HeapNode *hn; + + /** + * Associated pending request. + */ + struct GSF_PendingRequest *pr; + + /** + * Earliest time we'd be happy to transmit this request. + */ + struct GNUNET_TIME_Absolute earliest_transmission; + +}; + + /** * Transmission plan for a peer. */ struct PeerPlan { /** - * Heap with pending queries, smaller weights mean higher priority. + * Heap with pending queries (struct GSF_RequestPlan), smaller weights mean higher priority. */ struct GNUNET_CONTAINER_Heap *heap; @@ -61,6 +99,28 @@ struct PeerPlan static struct GNUNET_CONTAINER_MultiHashMap *plans; +/** + * Insert the given request plan into the heap with the appropriate weight. + * + * @param pp associated peer's plan + * @param rp request to plan + */ +static void +plan (struct PeerPlan *pp, + struct GSF_RequestPlan *rp) +{ + GNUNET_CONTAINER_HeapCostType weight; + struct GSF_PendingRequestData *prd; + + prd = GSF_pending_request_get_data_ (rp->pr); + weight = 0; // FIXME: calculate real weight! + // FIXME: calculate 'rp->earliest_transmission'! + rp->hn = GNUNET_CONTAINER_heap_insert (pp->heap, + rp, + weight); +} + + /** * Figure out when and how to transmit to the given peer. * @@ -86,7 +146,7 @@ transmit_message_callback (void *cls, void *buf) { struct PeerPlan *pp = cls; - struct GSF_PendingRequest *pr; + struct GSF_RequestPlan *rp; size_t msize; if (NULL == buf) @@ -95,8 +155,8 @@ transmit_message_callback (void *cls, pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp); return 0; } - pr = GNUNET_CONTAINER_heap_peek (pp->heap); - msize = GSF_pending_request_get_message_ (pr, buf_size, buf); + rp = GNUNET_CONTAINER_heap_peek (pp->heap); + msize = GSF_pending_request_get_message_ (rp->pr, buf_size, buf); if (msize > buf_size) { /* buffer to small (message changed), try again */ @@ -104,8 +164,9 @@ transmit_message_callback (void *cls, return 0; } /* remove from root, add again elsewhere... */ - GNUNET_assert (pr == GNUNET_CONTAINER_heap_remove_root (pp->heap)); - GSF_plan_add_ (pp->cp, pr); + GNUNET_assert (rp == GNUNET_CONTAINER_heap_remove_root (pp->heap)); + rp->hn = NULL; + plan (pp, rp); return msize; } @@ -121,7 +182,8 @@ schedule_peer_transmission (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct PeerPlan *pp = cls; - struct GSF_PendingRequest *pr; + struct GSF_RequestPlan *rp; + struct GSF_PendingRequestData *prd; size_t msize; struct GNUNET_TIME_Relative delay; @@ -131,17 +193,17 @@ schedule_peer_transmission (void *cls, if (0 == GNUNET_CONTAINER_heap_get_size (pp->heap)) return; GNUNET_assert (NULL == pp->pth); - pr = GNUNET_CONTAINER_heap_peek (pp->heap); - if (0) // FIXME: if (re)transmission should wait, wait... + rp = GNUNET_CONTAINER_heap_peek (pp->heap); + prd = GSF_pending_request_get_data_ (rp->pr); + delay = GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission); + if (delay.rel_value > 0) { - delay = GNUNET_TIME_UNIT_SECONDS; - // FIXME pp->task = GNUNET_SCHEDULER_add_delayed (delay, &schedule_peer_transmission, pp); return; } - msize = GSF_pending_request_get_message_ (pr, 0, NULL); + msize = GSF_pending_request_get_message_ (rp->pr, 0, NULL); pp->pth = GSF_peer_transmit_ (pp->cp, GNUNET_YES, 0 /* FIXME: pr->priority? */, @@ -165,7 +227,8 @@ GSF_plan_add_ (const struct GSF_ConnectedPeer *cp, { struct GNUNET_PeerIdentity id; struct PeerPlan *pp; - GNUNET_CONTAINER_HeapCostType weight; + struct GSF_PendingRequestData *prd; + struct GSF_RequestPlan *rp; GSF_connected_peer_get_identity_ (cp, &id); pp = GNUNET_CONTAINER_multihashmap_get (plans, @@ -179,13 +242,16 @@ GSF_plan_add_ (const struct GSF_ConnectedPeer *cp, pp, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); } - weight = 0; // FIXME: calculate real weight! - GNUNET_CONTAINER_heap_insert (pp->heap, - pr, - weight); + prd = GSF_pending_request_get_data_ (pr); + rp = GNUNET_malloc (sizeof (struct GSF_RequestPlan)); + rp->pr = pr; + GNUNET_CONTAINER_DLL_insert (prd->rp_head, + prd->rp_tail, + rp); + plan (pp, rp); if (pp->pth != NULL) { - if (pr != GNUNET_CONTAINER_heap_peek (pp->heap)) + if (rp != GNUNET_CONTAINER_heap_peek (pp->heap)) return; GSF_peer_transmit_cancel_ (pp->pth); pp->pth = NULL; @@ -208,6 +274,8 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp) { struct GNUNET_PeerIdentity id; struct PeerPlan *pp; + struct GSF_RequestPlan *rp; + struct GSF_PendingRequestData *prd; GSF_connected_peer_get_identity_ (cp, &id); pp = GNUNET_CONTAINER_multihashmap_get (plans, @@ -219,101 +287,40 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp) GSF_peer_transmit_cancel_ (pp->pth); if (GNUNET_SCHEDULER_NO_TASK != pp->task) GNUNET_SCHEDULER_cancel (pp->task); - GNUNET_CONTAINER_heap_destroy (pp->heap); - GNUNET_free (pp); -} - - -/** - * Closure for 'find_request'. - */ -struct FindRequestClosure -{ - /** - * Place to store the node that was found (NULL for none). - */ - struct GNUNET_CONTAINER_HeapNode *node; - - /** - * Value we're looking for - */ - const struct GSF_PendingRequest *pr; -}; - - -/** - * Find a heap node where the value matches the - * pending request given in the closure. - * - * @param cls the 'struct FindRequestClosure' - * @param node heap structure we're looking for on a match - * @param element the pending request stored in the heap - * @param cost weight of the request - * @return GNUNET_YES to continue looking - */ -static int -find_request (void *cls, - struct GNUNET_CONTAINER_HeapNode *node, - void *element, - GNUNET_CONTAINER_HeapCostType cost) -{ - struct FindRequestClosure *frc = cls; - struct GSF_PendingRequest *pr = element; - - if (pr == frc->pr) - { - frc->node = node; - return GNUNET_NO; - } - return GNUNET_YES; -} - - -/** - * Remove the given request from all heaps. * FIXME: O(n) -- inefficient! - * - * @param cls 'struct GSF_PendingRequest' to purge - * @param key identity of the peer we're currently looking at (unused) - * @param value PeerPlan for the given peer to search for the 'cls' - * @return GNUNET_OK (continue iteration) - */ -static int -remove_request (void *cls, - const GNUNET_HashCode *key, - void *value) -{ - const struct GSF_PendingRequest *pr = cls; - struct PeerPlan *pp = value; - struct GNUNET_CONTAINER_Heap *h = pp->heap; - struct FindRequestClosure frc; - - frc.pr = pr; - do + while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->heap))) { - frc.node = NULL; - GNUNET_CONTAINER_heap_iterate (h, &find_request, &frc); - if (frc.node != NULL) - GNUNET_CONTAINER_heap_remove_node (h, frc.node); + prd = GSF_pending_request_get_data_ (rp->pr); + GNUNET_CONTAINER_DLL_remove (prd->rp_head, + prd->rp_tail, + rp); + GNUNET_free (rp); } - while (NULL != frc.node); - return GNUNET_OK; + GNUNET_CONTAINER_heap_destroy (pp->heap); + GNUNET_free (pp); } /** * Notify the plan about a request being done; destroy all entries - * associated with this request. Note that this implementation is - * currently terribly inefficient (O(n)) and could instead be done in - * O(1). But for now, I first want to see it work correctly... + * associated with this request. * * @param pr request that is done */ void GSF_plan_notify_request_done_ (const struct GSF_PendingRequest *pr) { - GNUNET_CONTAINER_multihashmap_iterate (plans, - &remove_request, - (void*) pr); + struct GSF_RequestPlan *rp; + struct GSF_PendingRequestData *prd; + + while (NULL != (rp = prd->rp_head)) + { + prd = GSF_pending_request_get_data_ (rp->pr); + GNUNET_CONTAINER_heap_remove_node (rp->hn); + GNUNET_CONTAINER_DLL_remove (prd->rp_head, + prd->rp_tail, + rp); + GNUNET_free (rp); + } } diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index ff2f7a3a3..2c983eaed 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c @@ -526,8 +526,7 @@ clean_request (void *cls, GNUNET_CONTAINER_bloomfilter_free (pr->bf); GNUNET_PEER_change_rc (pr->sender_pid, -1); if (NULL != pr->hnode) - GNUNET_CONTAINER_heap_remove_node (requests_by_expiration_heap, - pr->hnode); + GNUNET_CONTAINER_heap_remove_node (pr->hnode); if (NULL != pr->qe) GNUNET_DATASTORE_cancel (pr->qe); if (NULL != pr->gh) diff --git a/src/fs/gnunet-service-fs_pr.h b/src/fs/gnunet-service-fs_pr.h index 9632df015..5759bee4a 100644 --- a/src/fs/gnunet-service-fs_pr.h +++ b/src/fs/gnunet-service-fs_pr.h @@ -91,6 +91,16 @@ struct GSF_PendingRequestData */ struct GNUNET_PeerIdentity target; + /** + * Fields for the plan module to track a DLL with the request. + */ + struct GSF_RequestPlan *rp_head; + + /** + * Fields for the plan module to track a DLL with the request. + */ + struct GSF_RequestPlan *rp_tail; + /** * Current TTL for the request. */ diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h index 41ed4bd3f..6b7016c74 100644 --- a/src/include/gnunet_container_lib.h +++ b/src/include/gnunet_container_lib.h @@ -1011,8 +1011,7 @@ GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap); * @return element data stored at the node, NULL if heap is empty */ void * -GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_Heap *heap, - struct GNUNET_CONTAINER_HeapNode *node); +GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node); /** diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h index 1677c714c..738811950 100644 --- a/src/include/gnunet_mesh_service.h +++ b/src/include/gnunet_mesh_service.h @@ -61,6 +61,7 @@ struct GNUNET_MESH_Tunnel; * @param cls closure (set from GNUNET_MESH_connect) * @param tunnel connection to the other end * @param tunnel_ctx place to store local state associated with the tunnel + * @param sender who sent the message * @param message the actual message * @param atsi performance data for the connection * @return GNUNET_OK to keep the connection open, @@ -69,7 +70,8 @@ struct GNUNET_MESH_Tunnel; typedef int (*GNUNET_MESH_MessageCallback) (void *cls, struct GNUNET_MESH_Tunnel *tunnel, - void **tunnel_ctx, + void **tunnel_ctx, + const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *message, const struct GNUNET_TRANSPORT_ATS_Information *atsi); @@ -248,6 +250,18 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel, const struct GNUNET_PeerIdentity *peer); +/** + * Request that a peer should be removed from the tunnel. The existing + * disconnect handler will be called ONCE if we were connected. + * + * @param tunnel handle to existing tunnel + * @param peer peer to remove + */ +void +GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel, + const struct GNUNET_PeerIdentity *peer); + + /** * Request that the mesh should try to connect to a peer supporting the given * message type. @@ -300,6 +314,7 @@ struct GNUNET_MESH_TransmitHandle; * @param cork is corking allowed for this transmission? * @param priority how important is the message? * @param maxdelay how long can the message wait? + * @param target destination for the message, NULL for multicast to all tunnel targets * @param notify_size how many bytes of buffer space does notify want? * @param notify function to call when buffer space is available; * will be called with NULL on timeout or if the overall queue @@ -319,6 +334,7 @@ GNUNET_MESH_notify_transmit_ready (struct struct GNUNET_TIME_Relative maxdelay, + // const struct GNUNET_PeerIdentity *target, size_t notify_size, GNUNET_CONNECTION_TransmitReadyNotify diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index 085f3ef4d..e51b0c890 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h @@ -21,6 +21,15 @@ /** * @author Bartlomiej Polot * @file mesh/mesh.h + * + * TODO: + * - soft stateing (keep-alive (CHANGE?) / timeout / disconnect) -- not a message issue + * - error reporting (CREATE/CHANGE/ADD/DEL?) -- new message! + * - partial disconnect reporting -- same as error reporting? + * - add vs create? change vs. keep-alive? same msg or different ones? -- thinking... + * - speed requirement specification (change?) in mesh API -- API call + * + * - API messages! */ @@ -35,67 +44,130 @@ struct GNUNET_MESH_ManipulatePath { /** - * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_[CREATE|CHANGE|ADD] + * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_[CREATE|CHANGE|ADD|DEL] + * + * Size: sizeof(struct GNUNET_MESH_ManipulatePath) + path_length * sizeof (struct GNUNET_PeerIdentity) */ struct GNUNET_MessageHeader header; /** - * Id of the tunnel this path belongs to + * Id of the tunnel this path belongs to, unique in conjunction with the origin. */ - uint32_t tid; + uint32_t tid GNUNET_PACKED; /** - * Information about speed requirements + * Information about speed requirements. If the tunnel cannot sustain the + * minimum bandwidth, packets are to be dropped. */ - uint32_t speed_min; - uint32_t speed_max; + uint32_t speed_min GNUNET_PACKED; /** - * Number of hops in the path given below + * path_length structs defining the *whole* path from the origin [0] to the + * final destination [path_length-1]. */ - uint16_t path_length; + // struct GNUNET_PeerIdentity peers[path_length]; +}; +/** + * Message for mesh data traffic to all tunnel targets. + */ +struct GNUNET_MESH_OriginMulticast +{ /** - * path_length structs defining the *whole* path + * Type: GNUNET_MESSAGE_TYPE_DATA_MULTICAST + */ + struct GNUNET_MessageHeader header; + + /** + * TID of the tunnel + */ + uint32_t tid GNUNET_PACKED; + + /** + * OID of the tunnel + */ + struct GNUNET_PeerIdentity oid; + + /** + * FIXME: Some form of authentication + */ + // uint32_t token; + + /** + * Payload follows */ - struct GNUNET_PeerIdentity peers[]; }; + /** - * Message for mesh data traffic + * Message for mesh data traffic to a particular destination from origin. */ -struct GNUNET_MESH_Data +struct GNUNET_MESH_DataMessageFromOrigin { /** - * Type: GNUNET_MESSAGE_TYPE_DATA_[GO|BACK] + * Type: GNUNET_MESSAGE_TYPE_DATA_MESSAGE_FROM_ORIGIN */ struct GNUNET_MessageHeader header; + /** + * TID of the tunnel + */ + uint32_t tid GNUNET_PACKED; + /** * OID of the tunnel */ struct GNUNET_PeerIdentity oid; + /** + * Destination. + */ + struct GNUNET_PeerIdentity destination; + + /** + * FIXME: Some form of authentication + */ + // uint32_t token; + + /** + * Payload follows + */ +}; + + +/** + * Message for mesh data traffic from a tunnel participant to origin. + */ +struct GNUNET_MESH_DataMessageToOrigin +{ + /** + * Type: GNUNET_MESSAGE_TYPE_DATA_MESSAGE_TO_ORIGIN + */ + struct GNUNET_MessageHeader header; + /** * TID of the tunnel */ - uint32_t tid; + uint32_t tid GNUNET_PACKED; /** - * FIXME Some form of authentication + * OID of the tunnel */ - uint32_t token; + struct GNUNET_PeerIdentity oid; /** - * Size of payload - * FIXME uint16 enough? + * Sender of the message. */ - uint16_t size; + struct GNUNET_PeerIdentity sender; /** - * Payload + * FIXME: Some form of authentication + */ + // uint32_t token; + + /** + * Payload follows */ - uint8_t data[]; }; /** @@ -109,24 +181,20 @@ struct GNUNET_MESH_SpeedNotify struct GNUNET_MessageHeader header; /** - * OID of the tunnel + * TID of the tunnel */ - struct GNUNET_PeerIdentity oid; + uint32_t tid GNUNET_PACKED; /** - * TID of the tunnel + * OID of the tunnel */ - uint32_t tid; + struct GNUNET_PeerIdentity oid; /** - * Slowest link down the path + * Slowest link down the path (above minimum speed requirement). */ uint32_t speed_min; - /** - * Fastest link down the path - */ - uint32_t speed_max; }; -#endif \ No newline at end of file +#endif diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index f539312cf..053449fbe 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -315,7 +315,7 @@ core_receive (void *cls, } return handler->callback (handle->cls, &tunnel->tunnel, - &tunnel->tunnel.ctx, rmessage, atsi); + &tunnel->tunnel.ctx, other, rmessage, atsi); } diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 9b43b5f05..b24b3ab7c 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -92,7 +92,7 @@ gnunet_service_resolver_LDADD = \ $(GN_LIBINTL) gnunet_service_resolver_DEPENDENCIES = \ libgnunetutil.la - + gnunet_resolver_SOURCES = \ gnunet-resolver.c @@ -229,7 +229,8 @@ test_crypto_aes_LDADD = \ test_crypto_aes_weak_SOURCES = \ test_crypto_aes_weak.c test_crypto_aes_weak_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la + $(top_builddir)/src/util/libgnunetutil.la \ + -lgcrypt test_crypto_crc_SOURCES = \ test_crypto_crc.c diff --git a/src/util/container_heap.c b/src/util/container_heap.c index 7cd30a0a7..c332cdd63 100644 --- a/src/util/container_heap.c +++ b/src/util/container_heap.c @@ -36,6 +36,11 @@ */ struct GNUNET_CONTAINER_HeapNode { + /** + * Heap this node belongs to. + */ + struct GNUNET_CONTAINER_Heap *heap; + /** * Parent node. */ @@ -340,6 +345,7 @@ GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, struct GNUNET_CONTAINER_HeapNode *node; node = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_HeapNode)); + node->heap = heap; node->element = element; node->cost = cost; heap->size++; @@ -405,10 +411,10 @@ GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap) * 'size' field of the tree. */ static void -remove_node (struct GNUNET_CONTAINER_Heap *heap, - struct GNUNET_CONTAINER_HeapNode *node) +remove_node (struct GNUNET_CONTAINER_HeapNode *node) { struct GNUNET_CONTAINER_HeapNode *ancestor; + struct GNUNET_CONTAINER_Heap *heap = node->heap; /* update 'size' of the ancestors */ ancestor = node; @@ -471,20 +477,20 @@ remove_node (struct GNUNET_CONTAINER_Heap *heap, /** * Removes a node from the heap. * - * @param heap heap to modify * @param node node to remove * @return element data stored at the node */ void * -GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_Heap *heap, - struct GNUNET_CONTAINER_HeapNode *node) +GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node) { void *ret; - + struct GNUNET_CONTAINER_Heap *heap; + + heap = node->heap; CHECK (heap->root); if (heap->walk_pos == node) (void) GNUNET_CONTAINER_heap_walk_get_next (heap); - remove_node (heap, node); + remove_node (node); heap->size--; ret = node->element; if (heap->walk_pos == node) @@ -518,7 +524,7 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap, (heap->size == heap->root->tree_size + 1) ); CHECK (heap->root); #endif - remove_node (heap, node); + remove_node (node); #if DEBUG CHECK (heap->root); GNUNET_assert ( ( (heap->size == 1) && diff --git a/src/util/test_container_heap.c b/src/util/test_container_heap.c index 87bc49129..6a0d5d68d 100644 --- a/src/util/test_container_heap.c +++ b/src/util/test_container_heap.c @@ -93,7 +93,7 @@ check () n2 = GNUNET_CONTAINER_heap_insert (myHeap, "78", 78); GNUNET_assert (2 == GNUNET_CONTAINER_heap_get_size (myHeap)); GNUNET_assert (0 == strcmp ("78", - GNUNET_CONTAINER_heap_remove_node (myHeap, n2))); + GNUNET_CONTAINER_heap_remove_node (n2))); GNUNET_assert (1 == GNUNET_CONTAINER_heap_get_size (myHeap)); GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); @@ -110,13 +110,13 @@ check () n5 = GNUNET_CONTAINER_heap_insert (myHeap, "100", 100); n6 = GNUNET_CONTAINER_heap_insert (myHeap, "30/200", 30); GNUNET_assert (5 == GNUNET_CONTAINER_heap_get_size (myHeap)); - GNUNET_CONTAINER_heap_remove_node (myHeap, n5); + GNUNET_CONTAINER_heap_remove_node (n5); r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n1 */ GNUNET_assert (NULL != r); GNUNET_assert (0 == strcmp ("11", r)); GNUNET_CONTAINER_heap_update_cost (myHeap, n6, 200); - GNUNET_CONTAINER_heap_remove_node (myHeap, n3); + GNUNET_CONTAINER_heap_remove_node (n3); r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n4 */ GNUNET_assert (NULL != r); GNUNET_assert (0 == strcmp ("50", @@ -137,7 +137,7 @@ check () n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); GNUNET_CONTAINER_heap_update_cost (myHeap, n1, 15); - r = GNUNET_CONTAINER_heap_remove_node (myHeap,n1); + r = GNUNET_CONTAINER_heap_remove_node (n1); GNUNET_assert (NULL != r); GNUNET_assert (0 == strcmp ("10", r)); @@ -145,10 +145,10 @@ check () n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); GNUNET_CONTAINER_heap_walk_get_next (myHeap); - r = GNUNET_CONTAINER_heap_remove_node (myHeap,n2); + r = GNUNET_CONTAINER_heap_remove_node (n2); GNUNET_assert (NULL != r); GNUNET_assert (0 == strcmp ("20", r)); - r = GNUNET_CONTAINER_heap_remove_node (myHeap,n1); + r = GNUNET_CONTAINER_heap_remove_node (n1); GNUNET_assert (NULL != r); GNUNET_assert (0 == strcmp ("10", r)); @@ -156,8 +156,8 @@ check () n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10); - GNUNET_CONTAINER_heap_remove_node (myHeap,n2); - GNUNET_CONTAINER_heap_remove_node (myHeap,n1); + GNUNET_CONTAINER_heap_remove_node (n2); + GNUNET_CONTAINER_heap_remove_node (n1); r = GNUNET_CONTAINER_heap_remove_root (myHeap); GNUNET_assert (NULL != r); GNUNET_assert (0 == strcmp ("30", r)); @@ -166,9 +166,9 @@ check () n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10); - GNUNET_CONTAINER_heap_remove_node (myHeap,n2); - GNUNET_CONTAINER_heap_remove_node (myHeap,n1); - r = GNUNET_CONTAINER_heap_remove_node (myHeap, n3); + GNUNET_CONTAINER_heap_remove_node (n2); + GNUNET_CONTAINER_heap_remove_node (n1); + r = GNUNET_CONTAINER_heap_remove_node ( n3); GNUNET_assert (NULL != r); GNUNET_assert (0 == strcmp ("30", r)); @@ -176,7 +176,7 @@ check () n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20); n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 30); - GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (myHeap,n2))); + GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_root (myHeap))); GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap))); @@ -191,11 +191,11 @@ check () n7 = GNUNET_CONTAINER_heap_insert (myHeap, "70", 10); n8 = GNUNET_CONTAINER_heap_insert (myHeap, "80", 10); - GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (myHeap,n3))); + GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (n3))); // Cleaning up... - GNUNET_assert (0 == nstrcmp ("60", GNUNET_CONTAINER_heap_remove_node (myHeap,n6))); - GNUNET_assert (0 == nstrcmp ("50", GNUNET_CONTAINER_heap_remove_node (myHeap,n5))); + GNUNET_assert (0 == nstrcmp ("60", GNUNET_CONTAINER_heap_remove_node (n6))); + GNUNET_assert (0 == nstrcmp ("50", GNUNET_CONTAINER_heap_remove_node (n5))); // Testing heap_walk_get_next GNUNET_CONTAINER_heap_walk_get_next (myHeap); @@ -204,11 +204,11 @@ check () GNUNET_CONTAINER_heap_walk_get_next (myHeap); GNUNET_CONTAINER_heap_walk_get_next (myHeap); - GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (myHeap,n1))); - GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (myHeap,n2))); - GNUNET_assert (0 == nstrcmp ("40", GNUNET_CONTAINER_heap_remove_node (myHeap,n4))); - GNUNET_assert (0 == nstrcmp ("70", GNUNET_CONTAINER_heap_remove_node (myHeap,n7))); - GNUNET_assert (0 == nstrcmp ("80", GNUNET_CONTAINER_heap_remove_node (myHeap,n8))); + GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1))); + GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); + GNUNET_assert (0 == nstrcmp ("40", GNUNET_CONTAINER_heap_remove_node (n4))); + GNUNET_assert (0 == nstrcmp ("70", GNUNET_CONTAINER_heap_remove_node (n7))); + GNUNET_assert (0 == nstrcmp ("80", GNUNET_CONTAINER_heap_remove_node (n8))); // End Testing remove_node @@ -220,30 +220,30 @@ check () n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); GNUNET_CONTAINER_heap_update_cost (myHeap, n1, 15); - GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (myHeap,n1))); + GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1))); n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); GNUNET_CONTAINER_heap_walk_get_next (myHeap); - GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (myHeap,n2))); - GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (myHeap,n1))); + GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); + GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1))); n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10); - GNUNET_CONTAINER_heap_remove_node (myHeap,n2); - GNUNET_CONTAINER_heap_remove_node (myHeap,n1); + GNUNET_CONTAINER_heap_remove_node (n2); + GNUNET_CONTAINER_heap_remove_node (n1); GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap))); n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10); - GNUNET_CONTAINER_heap_remove_node (myHeap,n2); - GNUNET_CONTAINER_heap_remove_node (myHeap,n1); - GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (myHeap,n3))); + GNUNET_CONTAINER_heap_remove_node (n2); + GNUNET_CONTAINER_heap_remove_node (n1); + GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (n3))); n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20); @@ -256,11 +256,11 @@ check () n7 = GNUNET_CONTAINER_heap_insert (myHeap, "70", 10); n8 = GNUNET_CONTAINER_heap_insert (myHeap, "80", 10); - GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (myHeap,n3))); + GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (n3))); // Cleaning up... - GNUNET_assert (0 == nstrcmp ("60", GNUNET_CONTAINER_heap_remove_node (myHeap,n6))); - GNUNET_assert (0 == nstrcmp ("50", GNUNET_CONTAINER_heap_remove_node (myHeap,n5))); + GNUNET_assert (0 == nstrcmp ("60", GNUNET_CONTAINER_heap_remove_node (n6))); + GNUNET_assert (0 == nstrcmp ("50", GNUNET_CONTAINER_heap_remove_node (n5))); // Testing heap_walk_get_next GNUNET_CONTAINER_heap_walk_get_next (myHeap); @@ -269,11 +269,11 @@ check () GNUNET_CONTAINER_heap_walk_get_next (myHeap); GNUNET_CONTAINER_heap_walk_get_next (myHeap); - GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (myHeap,n1))); - GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (myHeap,n2))); - GNUNET_assert (0 == nstrcmp ("40", GNUNET_CONTAINER_heap_remove_node (myHeap,n4))); - GNUNET_assert (0 == nstrcmp ("70", GNUNET_CONTAINER_heap_remove_node (myHeap,n7))); - GNUNET_assert (0 == nstrcmp ("80", GNUNET_CONTAINER_heap_remove_node (myHeap,n8))); + GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1))); + GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); + GNUNET_assert (0 == nstrcmp ("40", GNUNET_CONTAINER_heap_remove_node (n4))); + GNUNET_assert (0 == nstrcmp ("70", GNUNET_CONTAINER_heap_remove_node (n7))); + GNUNET_assert (0 == nstrcmp ("80", GNUNET_CONTAINER_heap_remove_node (n8))); // End Testing remove_node diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c index f6198894f..03e9831c8 100644 --- a/src/vpn/gnunet-daemon-exit.c +++ b/src/vpn/gnunet-daemon-exit.c @@ -447,6 +447,7 @@ static int receive_udp_service (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx, + const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *message, const struct GNUNET_TRANSPORT_ATS_Information *atsi) { diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 50c9d14b1..4d6a569f4 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -418,6 +418,7 @@ add_additional_port (struct map_entry *me, uint16_t port) static int receive_udp_back (void *cls, struct GNUNET_MESH_Tunnel* tunnel, void **tunnel_ctx, + const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *message, const struct GNUNET_TRANSPORT_ATS_Information *atsi) {