summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fs/gnunet-service-fs_pe.c53
-rw-r--r--src/include/gnunet_container_lib.h125
-rw-r--r--src/include/platform.h2
3 files changed, 160 insertions, 20 deletions
diff --git a/src/fs/gnunet-service-fs_pe.c b/src/fs/gnunet-service-fs_pe.c
index 6041a61f6..226137d73 100644
--- a/src/fs/gnunet-service-fs_pe.c
+++ b/src/fs/gnunet-service-fs_pe.c
@@ -48,7 +48,13 @@ struct PeerPlan;
48 48
49/** 49/**
50 * DLL of request plans a particular pending request is 50 * DLL of request plans a particular pending request is
51 * involved with. 51 * involved with. The corresponding head and tail are
52 * stored in a 'struct GSF_PendingRequest'. (We need
53 * to be able to lookup all 'plan' entries for a given
54 * request easily).
55 *
56 * There is always one 'struct PendingRequestList'
57 * for each 'struct GSF_RequestPlanReference'.
52 */ 58 */
53struct GSF_RequestPlanReference 59struct GSF_RequestPlanReference
54{ 60{
@@ -56,12 +62,12 @@ struct GSF_RequestPlanReference
56 /** 62 /**
57 * This is a doubly-linked list. 63 * This is a doubly-linked list.
58 */ 64 */
59 struct GSF_RequestPlanReference *next; 65 struct GSF_RequestPlanReference *next_PR;
60 66
61 /** 67 /**
62 * This is a doubly-linked list. 68 * This is a doubly-linked list.
63 */ 69 */
64 struct GSF_RequestPlanReference *prev; 70 struct GSF_RequestPlanReference *prev_PR;
65 71
66 /** 72 /**
67 * Associated request plan. 73 * Associated request plan.
@@ -77,7 +83,13 @@ struct GSF_RequestPlanReference
77 83
78/** 84/**
79 * List of GSF_PendingRequests this request plan 85 * List of GSF_PendingRequests this request plan
80 * participates with. 86 * participates with. The corresponding head and tail
87 * are stored in a 'struct GSF_RequestPlan'. (We need
88 * to be able to lookup all pending requests corresponding
89 * to a given plan entry.)
90 *
91 * There is always one 'struct PendingRequestList'
92 * for each 'struct GSF_RequestPlanReference'.
81 */ 93 */
82struct PendingRequestList 94struct PendingRequestList
83{ 95{
@@ -85,12 +97,12 @@ struct PendingRequestList
85 /** 97 /**
86 * This is a doubly-linked list. 98 * This is a doubly-linked list.
87 */ 99 */
88 struct PendingRequestList *next; 100 struct PendingRequestList *next_PE;
89 101
90 /** 102 /**
91 * This is a doubly-linked list. 103 * This is a doubly-linked list.
92 */ 104 */
93 struct PendingRequestList *prev; 105 struct PendingRequestList *prev_PE;
94 106
95 /** 107 /**
96 * Associated pending request. 108 * Associated pending request.
@@ -364,13 +376,13 @@ get_latest (const struct GSF_RequestPlan *rp)
364 376
365 prl = rp->prl_head; 377 prl = rp->prl_head;
366 ret = prl->pr; 378 ret = prl->pr;
367 prl = prl->next; 379 prl = prl->next_PE;
368 while (NULL != prl) 380 while (NULL != prl)
369 { 381 {
370 if (GSF_pending_request_get_data_ (prl->pr)->ttl.abs_value > 382 if (GSF_pending_request_get_data_ (prl->pr)->ttl.abs_value >
371 GSF_pending_request_get_data_ (ret)->ttl.abs_value) 383 GSF_pending_request_get_data_ (ret)->ttl.abs_value)
372 ret = prl->pr; 384 ret = prl->pr;
373 prl = prl->next; 385 prl = prl->next_PE;
374 } 386 }
375 return ret; 387 return ret;
376} 388}
@@ -544,8 +556,8 @@ merge_pr (void *cls, const struct GNUNET_HashCode * query, void *element)
544 prl->rpr = rpr; 556 prl->rpr = rpr;
545 prl->pr = mpr->pr; 557 prl->pr = mpr->pr;
546 prd = GSF_pending_request_get_data_ (mpr->pr); 558 prd = GSF_pending_request_get_data_ (mpr->pr);
547 GNUNET_CONTAINER_DLL_insert (prd->rpr_head, prd->rpr_tail, rpr); 559 GNUNET_CONTAINER_MDLL_insert (PR, prd->rpr_head, prd->rpr_tail, rpr);
548 GNUNET_CONTAINER_DLL_insert (rp->prl_head, rp->prl_tail, prl); 560 GNUNET_CONTAINER_MDLL_insert (PE, rp->prl_head, rp->prl_tail, prl);
549 mpr->merged = GNUNET_YES; 561 mpr->merged = GNUNET_YES;
550#if INSANE_STATISTICS 562#if INSANE_STATISTICS
551 GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# requests merged"), 1, 563 GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# requests merged"), 1,
@@ -624,8 +636,8 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
624 rpr->prl = prl; 636 rpr->prl = prl;
625 prl->rpr = rpr; 637 prl->rpr = rpr;
626 prl->pr = pr; 638 prl->pr = pr;
627 GNUNET_CONTAINER_DLL_insert (prd->rpr_head, prd->rpr_tail, rpr); 639 GNUNET_CONTAINER_MDLL_insert (PR, prd->rpr_head, prd->rpr_tail, rpr);
628 GNUNET_CONTAINER_DLL_insert (rp->prl_head, rp->prl_tail, prl); 640 GNUNET_CONTAINER_MDLL_insert (PE, rp->prl_head, rp->prl_tail, prl);
629 rp->pp = pp; 641 rp->pp = pp;
630 GNUNET_assert (GNUNET_YES == 642 GNUNET_assert (GNUNET_YES ==
631 GNUNET_CONTAINER_multihashmap_put (pp->plan_map, 643 GNUNET_CONTAINER_multihashmap_put (pp->plan_map,
@@ -674,9 +686,9 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp)
674 get_rp_key (rp), rp)); 686 get_rp_key (rp), rp));
675 while (NULL != (prl = rp->prl_head)) 687 while (NULL != (prl = rp->prl_head))
676 { 688 {
677 GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl); 689 GNUNET_CONTAINER_MDLL_remove (PE, rp->prl_head, rp->prl_tail, prl);
678 prd = GSF_pending_request_get_data_ (prl->pr); 690 prd = GSF_pending_request_get_data_ (prl->pr);
679 GNUNET_CONTAINER_DLL_remove (prd->rpr_head, prd->rpr_tail, prl->rpr); 691 GNUNET_CONTAINER_MDLL_remove (PR, prd->rpr_head, prd->rpr_tail, prl->rpr);
680 GNUNET_free (prl->rpr); 692 GNUNET_free (prl->rpr);
681 GNUNET_free (prl); 693 GNUNET_free (prl);
682 } 694 }
@@ -691,9 +703,9 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp)
691 get_rp_key (rp), rp)); 703 get_rp_key (rp), rp));
692 while (NULL != (prl = rp->prl_head)) 704 while (NULL != (prl = rp->prl_head))
693 { 705 {
694 GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl); 706 GNUNET_CONTAINER_MDLL_remove (PE, rp->prl_head, rp->prl_tail, prl);
695 prd = GSF_pending_request_get_data_ (prl->pr); 707 prd = GSF_pending_request_get_data_ (prl->pr);
696 GNUNET_CONTAINER_DLL_remove (prd->rpr_head, prd->rpr_tail, prl->rpr); 708 GNUNET_CONTAINER_MDLL_remove (PR, prd->rpr_head, prd->rpr_tail, prl->rpr);
697 GNUNET_free (prl->rpr); 709 GNUNET_free (prl->rpr);
698 GNUNET_free (prl); 710 GNUNET_free (prl);
699 } 711 }
@@ -707,6 +719,7 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp)
707 GNUNET_free (pp); 719 GNUNET_free (pp);
708} 720}
709 721
722
710/** 723/**
711 * Get the last transmission attempt time for the request plan list 724 * Get the last transmission attempt time for the request plan list
712 * referenced by 'rpr_head', that was sent to 'sender' 725 * referenced by 'rpr_head', that was sent to 'sender'
@@ -722,7 +735,8 @@ GSF_request_plan_reference_get_last_transmission_ (
722 struct GNUNET_TIME_Absolute *result) 735 struct GNUNET_TIME_Absolute *result)
723{ 736{
724 struct GSF_RequestPlanReference *rpr; 737 struct GSF_RequestPlanReference *rpr;
725 for (rpr = rpr_head; rpr; rpr = rpr->next) 738
739 for (rpr = rpr_head; NULL != rpr; rpr = rpr->next_PR)
726 { 740 {
727 if (rpr->rp->pp->cp == sender) 741 if (rpr->rp->pp->cp == sender)
728 { 742 {
@@ -733,6 +747,7 @@ GSF_request_plan_reference_get_last_transmission_ (
733 return GNUNET_NO; 747 return GNUNET_NO;
734} 748}
735 749
750
736/** 751/**
737 * Notify the plan about a request being done; destroy all entries 752 * Notify the plan about a request being done; destroy all entries
738 * associated with this request. 753 * associated with this request.
@@ -749,9 +764,9 @@ GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr)
749 prd = GSF_pending_request_get_data_ (pr); 764 prd = GSF_pending_request_get_data_ (pr);
750 while (NULL != (rpr = prd->rpr_head)) 765 while (NULL != (rpr = prd->rpr_head))
751 { 766 {
752 GNUNET_CONTAINER_DLL_remove (prd->rpr_head, prd->rpr_tail, rpr); 767 GNUNET_CONTAINER_MDLL_remove (PR, prd->rpr_head, prd->rpr_tail, rpr);
753 rp = rpr->rp; 768 rp = rpr->rp;
754 GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, rpr->prl); 769 GNUNET_CONTAINER_MDLL_remove (PE, rp->prl_head, rp->prl_tail, rpr->prl);
755 if (NULL == rp->prl_head) 770 if (NULL == rp->prl_head)
756 { 771 {
757 GNUNET_CONTAINER_heap_remove_node (rp->hn); 772 GNUNET_CONTAINER_heap_remove_node (rp->hn);
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index a476b7f1b..2da177f16 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -832,6 +832,131 @@ GNUNET_CONTAINER_multihashmap_get_multiple (const struct
832 (element)->prev = NULL; } while (0) 832 (element)->prev = NULL; } while (0)
833 833
834 834
835/* ************ Multi-DLL interface, allows DLL elements to be
836 in multiple lists at the same time *********************** */
837
838/**
839 * Insert an element at the head of a MDLL. Assumes that head, tail and
840 * element are structs with prev and next fields.
841 *
842 * @param head pointer to the head of the MDLL
843 * @param tail pointer to the tail of the MDLL
844 * @param element element to insert
845 */
846#define GNUNET_CONTAINER_MDLL_insert(mdll,head,tail,element) do { \
847 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
848 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
849 (element)->next_##mdll = (head); \
850 (element)->prev_##mdll = NULL; \
851 if ((tail) == NULL) \
852 (tail) = element; \
853 else \
854 (head)->prev_##mdll = element; \
855 (head) = (element); } while (0)
856
857
858/**
859 * Insert an element at the tail of a MDLL. Assumes that head, tail and
860 * element are structs with prev and next fields.
861 *
862 * @param head pointer to the head of the MDLL
863 * @param tail pointer to the tail of the MDLL
864 * @param element element to insert
865 */
866#define GNUNET_CONTAINER_MDLL_insert_tail(mdll,head,tail,element) do { \
867 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
868 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
869 (element)->prev_##mdll = (tail); \
870 (element)->next_##mdll = NULL; \
871 if ((head) == NULL) \
872 (head) = element; \
873 else \
874 (tail)->next_##mdll = element; \
875 (tail) = (element); } while (0)
876
877
878/**
879 * Insert an element into a MDLL after the given other element. Insert
880 * at the head if the other element is NULL.
881 *
882 * @param head pointer to the head of the MDLL
883 * @param tail pointer to the tail of the MDLL
884 * @param other prior element, NULL for insertion at head of MDLL
885 * @param element element to insert
886 */
887#define GNUNET_CONTAINER_MDLL_insert_after(mdll,head,tail,other,element) do { \
888 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
889 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
890 (element)->prev_##mdll = (other); \
891 if (NULL == other) \
892 { \
893 (element)->next_##mdll = (head); \
894 (head) = (element); \
895 } \
896 else \
897 { \
898 (element)->next_##mdll = (other)->next_##mdll; \
899 (other)->next_##mdll = (element); \
900 } \
901 if (NULL == (element)->next_##mdll) \
902 (tail) = (element); \
903 else \
904 (element)->next->prev_##mdll = (element); } while (0)
905
906
907/**
908 * Insert an element into a MDLL before the given other element. Insert
909 * at the tail if the other element is NULL.
910 *
911 * @param head pointer to the head of the MDLL
912 * @param tail pointer to the tail of the MDLL
913 * @param other prior element, NULL for insertion at head of MDLL
914 * @param element element to insert
915 */
916#define GNUNET_CONTAINER_MDLL_insert_before(mdll,head,tail,other,element) do { \
917 GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
918 GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
919 (element)->next_##mdll = (other); \
920 if (NULL == other) \
921 { \
922 (element)->prev = (tail); \
923 (tail) = (element); \
924 } \
925 else \
926 { \
927 (element)->prev_##mdll = (other)->prev_##mdll; \
928 (other)->prev_##mdll = (element); \
929 } \
930 if (NULL == (element)->prev_##mdll) \
931 (head) = (element); \
932 else \
933 (element)->prev_##mdll->next_##mdll = (element); } while (0)
934
935
936/**
937 * Remove an element from a MDLL. Assumes
938 * that head, tail and element are structs
939 * with prev and next fields.
940 *
941 * @param head pointer to the head of the MDLL
942 * @param tail pointer to the tail of the MDLL
943 * @param element element to remove
944 */
945#define GNUNET_CONTAINER_MDLL_remove(mdll,head,tail,element) do { \
946 GNUNET_assert ( ( (element)->prev_##mdll != NULL) || ((head) == (element))); \
947 GNUNET_assert ( ( (element)->next_##mdll != NULL) || ((tail) == (element))); \
948 if ((element)->prev_##mdll == NULL) \
949 (head) = (element)->next_##mdll; \
950 else \
951 (element)->prev_##mdll->next_##mdll = (element)->next_##mdll; \
952 if ((element)->next_##mdll == NULL) \
953 (tail) = (element)->prev_##mdll; \
954 else \
955 (element)->next_##mdll->prev_##mdll = (element)->prev_##mdll; \
956 (element)->next_##mdll = NULL; \
957 (element)->prev_##mdll = NULL; } while (0)
958
959
835 960
836/* ******************** Heap *************** */ 961/* ******************** Heap *************** */
837 962
diff --git a/src/include/platform.h b/src/include/platform.h
index 8bd2e6706..912601dad 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -50,7 +50,7 @@
50#include <sys/types.h> 50#include <sys/types.h>
51#endif 51#endif
52 52
53#define ALLOW_EXTRA_CHECKS GNUNET_NO 53#define ALLOW_EXTRA_CHECKS GNUNET_YES
54 54
55/** 55/**
56 * For strptime (glibc2 needs this). 56 * For strptime (glibc2 needs this).