Prechádzať zdrojové kódy

remove LinkedList2 and use LinkedList1 instead

ambrop7 13 rokov pred
rodič
commit
f9cb7b96a2

+ 5 - 5
client/DPReceive.c

@@ -41,7 +41,7 @@
 
 static DPReceivePeer * find_peer (DPReceiveDevice *o, peerid_t id)
 {
-    for (LinkedList2Node *node = LinkedList2_GetFirst(&o->peers_list); node; node = LinkedList2Node_Next(node)) {
+    for (LinkedList1Node *node = LinkedList1_GetFirst(&o->peers_list); node; node = LinkedList1Node_Next(node)) {
         DPReceivePeer *p = UPPER_OBJECT(node, DPReceivePeer, list_node);
         if (p->peer_id == id) {
             return p;
@@ -192,7 +192,7 @@ int DPReceiveDevice_Init (DPReceiveDevice *o, int device_mtu, DPReceiveDevice_ou
     o->have_peer_id = 0;
     
     // init peers list
-    LinkedList2_Init(&o->peers_list);
+    LinkedList1_Init(&o->peers_list);
     
     DebugObject_Init(&o->d_obj);
     return 1;
@@ -204,7 +204,7 @@ fail0:
 void DPReceiveDevice_Free (DPReceiveDevice *o)
 {
     DebugObject_Free(&o->d_obj);
-    ASSERT(LinkedList2_IsEmpty(&o->peers_list))
+    ASSERT(LinkedList1_IsEmpty(&o->peers_list))
     
     // free relay router
     DPRelayRouter_Free(&o->relay_router);
@@ -240,7 +240,7 @@ void DPReceivePeer_Init (DPReceivePeer *o, DPReceiveDevice *device, peerid_t pee
     o->dp_sink = NULL;
     
     // insert to peers list
-    LinkedList2_Append(&device->peers_list, &o->list_node);
+    LinkedList1_Append(&device->peers_list, &o->list_node);
     
     DebugCounter_Init(&o->d_receivers_ctr);
     DebugObject_Init(&o->d_obj);
@@ -253,7 +253,7 @@ void DPReceivePeer_Free (DPReceivePeer *o)
     ASSERT(!o->dp_sink)
     
     // remove from peers list
-    LinkedList2_Remove(&o->device->peers_list, &o->list_node);
+    LinkedList1_Remove(&o->device->peers_list, &o->list_node);
     
     // free relay sink
     DPRelaySink_Free(&o->relay_sink);

+ 3 - 3
client/DPReceive.h

@@ -37,7 +37,7 @@
 #include <protocol/scproto.h>
 #include <misc/debugcounter.h>
 #include <misc/debug.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <base/DebugObject.h>
 #include <client/DataProto.h>
 #include <client/DPRelay.h>
@@ -58,7 +58,7 @@ typedef struct {
     DPRelayRouter relay_router;
     int have_peer_id;
     peerid_t peer_id;
-    LinkedList2 peers_list;
+    LinkedList1 peers_list;
     DebugObject d_obj;
 } DPReceiveDevice;
 
@@ -70,7 +70,7 @@ typedef struct {
     DPRelaySource relay_source;
     DPRelaySink relay_sink;
     DataProtoSink *dp_sink;
-    LinkedList2Node list_node;
+    LinkedList1Node list_node;
     DebugObject d_obj;
     DebugCounter d_receivers_ctr;
 } DPReceivePeer;

+ 17 - 18
client/FragmentProtoAssembler.c

@@ -46,20 +46,20 @@
 static void free_frame (FragmentProtoAssembler *o, struct FragmentProtoAssembler_frame *frame)
 {
     // remove from used list
-    LinkedList2_Remove(&o->frames_used, &frame->list_node);
+    LinkedList1_Remove(&o->frames_used, &frame->list_node);
     // remove from used tree
     FPAFramesTree_Remove(&o->frames_used_tree, 0, frame);
     
     // append to free list
-    LinkedList2_Append(&o->frames_free, &frame->list_node);
+    LinkedList1_Append(&o->frames_free, &frame->list_node);
 }
 
 static void free_oldest_frame (FragmentProtoAssembler *o)
 {
-    ASSERT(!LinkedList2_IsEmpty(&o->frames_used))
+    ASSERT(!LinkedList1_IsEmpty(&o->frames_used))
     
     // obtain oldest frame (first on the list)
-    LinkedList2Node *list_node = LinkedList2_GetFirst(&o->frames_used);
+    LinkedList1Node *list_node = LinkedList1_GetFirst(&o->frames_used);
     ASSERT(list_node)
     struct FragmentProtoAssembler_frame *frame = UPPER_OBJECT(list_node, struct FragmentProtoAssembler_frame, list_node);
     
@@ -72,18 +72,18 @@ static struct FragmentProtoAssembler_frame * allocate_new_frame (FragmentProtoAs
     ASSERT(!FPAFramesTree_LookupExact(&o->frames_used_tree, 0, id))
     
     // if there are no free entries, free the oldest used one
-    if (LinkedList2_IsEmpty(&o->frames_free)) {
+    if (LinkedList1_IsEmpty(&o->frames_free)) {
         PeerLog(o, BLOG_INFO, "freeing used frame");
         free_oldest_frame(o);
     }
     
     // obtain frame entry
-    LinkedList2Node *list_node = LinkedList2_GetFirst(&o->frames_free);
+    LinkedList1Node *list_node = LinkedList1_GetFirst(&o->frames_free);
     ASSERT(list_node)
     struct FragmentProtoAssembler_frame *frame = UPPER_OBJECT(list_node, struct FragmentProtoAssembler_frame, list_node);
     
     // remove from free list
-    LinkedList2_Remove(&o->frames_free, &frame->list_node);
+    LinkedList1_Remove(&o->frames_free, &frame->list_node);
     
     // initialize values
     frame->id = id;
@@ -94,7 +94,7 @@ static struct FragmentProtoAssembler_frame * allocate_new_frame (FragmentProtoAs
     frame->length_so_far = 0;
     
     // append to used list
-    LinkedList2_Append(&o->frames_used, &frame->list_node);
+    LinkedList1_Append(&o->frames_used, &frame->list_node);
     // insert to used tree
     int res = FPAFramesTree_Insert(&o->frames_used_tree, 0, frame, NULL);
     ASSERT(res)
@@ -118,10 +118,9 @@ static void reduce_times (FragmentProtoAssembler *o)
 {
     // find the frame with minimal time, removing timed out frames
     struct FragmentProtoAssembler_frame *minframe = NULL;
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, &o->frames_used);
-    LinkedList2Node *list_node;
-    while (list_node = LinkedList2Iterator_Next(&it)) {
+    LinkedList1Node *list_node = LinkedList1_GetFirst(&o->frames_used);
+    while (list_node) {
+        LinkedList1Node *next = LinkedList1Node_Next(list_node);
         struct FragmentProtoAssembler_frame *frame = UPPER_OBJECT(list_node, struct FragmentProtoAssembler_frame, list_node);
         if (frame_is_timed_out(o, frame)) {
             PeerLog(o, BLOG_INFO, "freeing timed out frame (while reducing times)");
@@ -131,6 +130,7 @@ static void reduce_times (FragmentProtoAssembler *o)
                 minframe = frame;
             }
         }
+        list_node = next;
     }
     
     if (!minframe) {
@@ -142,8 +142,7 @@ static void reduce_times (FragmentProtoAssembler *o)
     uint32_t min_time = minframe->time;
     
     // subtract minimal time from all frames
-    LinkedList2Iterator_InitForward(&it, &o->frames_used);
-    while (list_node = LinkedList2Iterator_Next(&it)) {
+    for (list_node = LinkedList1_GetFirst(&o->frames_used); list_node; list_node = LinkedList1Node_Next(list_node)) {
         struct FragmentProtoAssembler_frame *frame = UPPER_OBJECT(list_node, struct FragmentProtoAssembler_frame, list_node);
         frame->time -= min_time;
     }
@@ -326,7 +325,7 @@ static void process_input (FragmentProtoAssembler *o)
     // increment packet time
     if (o->time == FPA_MAX_TIME) {
         reduce_times(o);
-        if (!LinkedList2_IsEmpty(&o->frames_used)) {
+        if (!LinkedList1_IsEmpty(&o->frames_used)) {
             ASSERT(o->time < FPA_MAX_TIME) // If there was a frame with zero time, it was removed because
                                            // time_tolerance < FPA_MAX_TIME. So something >0 was subtracted.
             o->time++;
@@ -411,8 +410,8 @@ int FragmentProtoAssembler_Init (FragmentProtoAssembler *o, int input_mtu, Packe
     }
     
     // init frame lists
-    LinkedList2_Init(&o->frames_free);
-    LinkedList2_Init(&o->frames_used);
+    LinkedList1_Init(&o->frames_free);
+    LinkedList1_Init(&o->frames_used);
     
     // initialize frame entries
     for (int i = 0; i < num_frames; i++) {
@@ -422,7 +421,7 @@ int FragmentProtoAssembler_Init (FragmentProtoAssembler *o, int input_mtu, Packe
         // set buffer pointer
         frame->buffer = o->frames_buffer + (size_t)i * o->output_mtu;
         // add to free list
-        LinkedList2_Append(&o->frames_free, &frame->list_node);
+        LinkedList1_Append(&o->frames_free, &frame->list_node);
     }
     
     // init tree

+ 4 - 4
client/FragmentProtoAssembler.h

@@ -41,7 +41,7 @@
 #include <misc/compare.h>
 #include <base/DebugObject.h>
 #include <base/BLog.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <structure/SAvl.h>
 #include <flow/PacketPassInterface.h>
 
@@ -58,7 +58,7 @@ struct FragmentProtoAssembler_chunk {
 };
 
 struct FragmentProtoAssembler_frame {
-    LinkedList2Node list_node; // node in free or used list
+    LinkedList1Node list_node; // node in free or used list
     struct FragmentProtoAssembler_chunk *chunks; // array of chunks, up to num_chunks
     uint8_t *buffer; // buffer with frame data, size output_mtu
     // everything below only defined when frame entry is used
@@ -89,8 +89,8 @@ typedef struct {
     struct FragmentProtoAssembler_frame *frames_entries;
     struct FragmentProtoAssembler_chunk *frames_chunks;
     uint8_t *frames_buffer;
-    LinkedList2 frames_free;
-    LinkedList2 frames_used;
+    LinkedList1 frames_free;
+    LinkedList1 frames_used;
     FPAFramesTree frames_used_tree;
     int in_len;
     uint8_t *in;

+ 47 - 41
client/FrameDecider.c

@@ -75,35 +75,35 @@ static void add_mac_to_peer (FrameDeciderPeer *o, uint8_t *mac)
     if (e_entry) {
         if (e_entry->peer == o) {
             // this is our MAC; only move it to the end of the used list
-            LinkedList2_Remove(&o->mac_entries_used, &e_entry->list_node);
-            LinkedList2_Append(&o->mac_entries_used, &e_entry->list_node);
+            LinkedList1_Remove(&o->mac_entries_used, &e_entry->list_node);
+            LinkedList1_Append(&o->mac_entries_used, &e_entry->list_node);
             return;
         }
         
         // some other peer has that MAC; disassociate it
         FDMacsTree_Remove(&d->macs_tree, 0, e_entry);
-        LinkedList2_Remove(&e_entry->peer->mac_entries_used, &e_entry->list_node);
-        LinkedList2_Append(&e_entry->peer->mac_entries_free, &e_entry->list_node);
+        LinkedList1_Remove(&e_entry->peer->mac_entries_used, &e_entry->list_node);
+        LinkedList1_Append(&e_entry->peer->mac_entries_free, &e_entry->list_node);
     }
     
     // aquire MAC address entry, if there are no free ones reuse the oldest used one
-    LinkedList2Node *list_node;
+    LinkedList1Node *list_node;
     struct _FrameDecider_mac_entry *entry;
-    if (list_node = LinkedList2_GetFirst(&o->mac_entries_free)) {
+    if (list_node = LinkedList1_GetFirst(&o->mac_entries_free)) {
         entry = UPPER_OBJECT(list_node, struct _FrameDecider_mac_entry, list_node);
         ASSERT(entry->peer == o)
         
         // remove from free
-        LinkedList2_Remove(&o->mac_entries_free, &entry->list_node);
+        LinkedList1_Remove(&o->mac_entries_free, &entry->list_node);
     } else {
-        list_node = LinkedList2_GetFirst(&o->mac_entries_used);
+        list_node = LinkedList1_GetFirst(&o->mac_entries_used);
         ASSERT(list_node)
         entry = UPPER_OBJECT(list_node, struct _FrameDecider_mac_entry, list_node);
         ASSERT(entry->peer == o)
         
         // remove from used
         FDMacsTree_Remove(&d->macs_tree, 0, entry);
-        LinkedList2_Remove(&o->mac_entries_used, &entry->list_node);
+        LinkedList1_Remove(&o->mac_entries_used, &entry->list_node);
     }
     
     PeerLog(o, BLOG_INFO, "adding MAC %02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8"", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
@@ -112,7 +112,7 @@ static void add_mac_to_peer (FrameDeciderPeer *o, uint8_t *mac)
     memcpy(entry->mac, mac, sizeof(entry->mac));
     
     // add to used
-    LinkedList2_Append(&o->mac_entries_used, &entry->list_node);
+    LinkedList1_Append(&o->mac_entries_used, &entry->list_node);
     int res = FDMacsTree_Insert(&d->macs_tree, 0, entry, NULL);
     ASSERT(res)
 }
@@ -203,22 +203,22 @@ static void add_group_to_peer (FrameDeciderPeer *o, uint32_t group)
     struct _FrameDecider_group_entry *group_entry = FDGroupsTree_LookupExact(&o->groups_tree, 0, group);
     if (group_entry) {
         // move to end of used list
-        LinkedList2_Remove(&o->group_entries_used, &group_entry->list_node);
-        LinkedList2_Append(&o->group_entries_used, &group_entry->list_node);
+        LinkedList1_Remove(&o->group_entries_used, &group_entry->list_node);
+        LinkedList1_Append(&o->group_entries_used, &group_entry->list_node);
     } else {
         PeerLog(o, BLOG_INFO, "joined group %"PRIu8".%"PRIu8".%"PRIu8".%"PRIu8"",
             ((uint8_t *)&group)[0], ((uint8_t *)&group)[1], ((uint8_t *)&group)[2], ((uint8_t *)&group)[3]
         );
         
         // aquire group entry, if there are no free ones reuse the earliest used one
-        LinkedList2Node *node;
-        if (node = LinkedList2_GetFirst(&o->group_entries_free)) {
+        LinkedList1Node *node;
+        if (node = LinkedList1_GetFirst(&o->group_entries_free)) {
             group_entry = UPPER_OBJECT(node, struct _FrameDecider_group_entry, list_node);
             
             // remove from free list
-            LinkedList2_Remove(&o->group_entries_free, &group_entry->list_node);
+            LinkedList1_Remove(&o->group_entries_free, &group_entry->list_node);
         } else {
-            node = LinkedList2_GetFirst(&o->group_entries_used);
+            node = LinkedList1_GetFirst(&o->group_entries_used);
             ASSERT(node)
             group_entry = UPPER_OBJECT(node, struct _FrameDecider_group_entry, list_node);
             
@@ -229,11 +229,11 @@ static void add_group_to_peer (FrameDeciderPeer *o, uint32_t group)
             FDGroupsTree_Remove(&o->groups_tree, 0, group_entry);
             
             // remove from used list
-            LinkedList2_Remove(&o->group_entries_used, &group_entry->list_node);
+            LinkedList1_Remove(&o->group_entries_used, &group_entry->list_node);
         }
         
         // add entry to used list
-        LinkedList2_Append(&o->group_entries_used, &group_entry->list_node);
+        LinkedList1_Append(&o->group_entries_used, &group_entry->list_node);
         
         // set group address
         group_entry->group = group;
@@ -269,10 +269,10 @@ static void remove_group_entry (struct _FrameDecider_group_entry *group_entry)
     FDGroupsTree_Remove(&peer->groups_tree, 0, group_entry);
     
     // remove from used list
-    LinkedList2_Remove(&peer->group_entries_used, &group_entry->list_node);
+    LinkedList1_Remove(&peer->group_entries_used, &group_entry->list_node);
     
     // add to free list
-    LinkedList2_Append(&peer->group_entries_free, &group_entry->list_node);
+    LinkedList1_Append(&peer->group_entries_free, &group_entry->list_node);
     
     // stop timer
     BReactor_RemoveTimer(d->reactor, &group_entry->timer);
@@ -333,7 +333,7 @@ void FrameDecider_Init (FrameDecider *o, int max_peer_macs, int max_peer_groups,
     o->reactor = reactor;
     
     // init peers list
-    LinkedList2_Init(&o->peers_list);
+    LinkedList1_Init(&o->peers_list);
     
     // init MAC tree
     FDMacsTree_Init(&o->macs_tree);
@@ -344,6 +344,9 @@ void FrameDecider_Init (FrameDecider *o, int max_peer_macs, int max_peer_groups,
     // init decide state
     o->decide_state = DECIDE_STATE_NONE;
     
+    // set no current flood peer
+    o->decide_flood_current = NULL;
+    
     DebugObject_Init(&o->d_obj);
 }
 
@@ -351,7 +354,7 @@ void FrameDecider_Free (FrameDecider *o)
 {
     ASSERT(FDMulticastTree_IsEmpty(&o->multicast_tree))
     ASSERT(FDMacsTree_IsEmpty(&o->macs_tree))
-    ASSERT(LinkedList2_IsEmpty(&o->peers_list))
+    ASSERT(LinkedList1_IsEmpty(&o->peers_list))
     DebugObject_Free(&o->d_obj);
 }
 
@@ -367,7 +370,6 @@ void FrameDecider_AnalyzeAndDecide (FrameDecider *o, const uint8_t *frame, int f
         case DECIDE_STATE_UNICAST:
             break;
         case DECIDE_STATE_FLOOD:
-            LinkedList2Iterator_Free(&o->decide_flood_it);
             break;
         case DECIDE_STATE_MULTICAST:
             LinkedList3Iterator_Free(&o->decide_multicast_it);
@@ -376,6 +378,7 @@ void FrameDecider_AnalyzeAndDecide (FrameDecider *o, const uint8_t *frame, int f
             ASSERT(0);
     }
     o->decide_state = DECIDE_STATE_NONE;
+    o->decide_flood_current = NULL;
     
     // analyze frame
     
@@ -467,7 +470,7 @@ out:;
     // if it's broadcast or IGMP, flood it
     if (is_igmp || !memcmp(eh->dest, broadcast_mac, sizeof(broadcast_mac))) {
         o->decide_state = DECIDE_STATE_FLOOD;
-        LinkedList2Iterator_InitForward(&o->decide_flood_it, &o->peers_list);
+        o->decide_flood_current = LinkedList1_GetFirst(&o->peers_list);
         return;
     }
     
@@ -498,7 +501,7 @@ out:;
     
     // unknown destination MAC, flood
     o->decide_state = DECIDE_STATE_FLOOD;
-    LinkedList2Iterator_InitForward(&o->decide_flood_it, &o->peers_list);
+    o->decide_flood_current = LinkedList1_GetFirst(&o->peers_list);
     return;
 }
 
@@ -518,11 +521,14 @@ FrameDeciderPeer * FrameDecider_NextDestination (FrameDecider *o)
         } break;
         
         case DECIDE_STATE_FLOOD: {
-            LinkedList2Node *list_node = LinkedList2Iterator_Next(&o->decide_flood_it);
-            if (!list_node) {
+            if (!o->decide_flood_current) {
                 o->decide_state = DECIDE_STATE_NONE;
                 return NULL;
             }
+            
+            LinkedList1Node *list_node = o->decide_flood_current;
+            o->decide_flood_current = LinkedList1Node_Next(o->decide_flood_current);
+            
             FrameDeciderPeer *peer = UPPER_OBJECT(list_node, FrameDeciderPeer, list_node);
             
             return peer;
@@ -565,11 +571,11 @@ int FrameDeciderPeer_Init (FrameDeciderPeer *o, FrameDecider *d, void *user, BLo
     }
     
     // insert to peers list
-    LinkedList2_Append(&d->peers_list, &o->list_node);
+    LinkedList1_Append(&d->peers_list, &o->list_node);
     
     // init MAC entry lists
-    LinkedList2_Init(&o->mac_entries_free);
-    LinkedList2_Init(&o->mac_entries_used);
+    LinkedList1_Init(&o->mac_entries_free);
+    LinkedList1_Init(&o->mac_entries_used);
     
     // initialize MAC entries
     for (int i = 0; i < d->max_peer_macs; i++) {
@@ -579,12 +585,12 @@ int FrameDeciderPeer_Init (FrameDeciderPeer *o, FrameDecider *d, void *user, BLo
         entry->peer = o;
         
         // insert to free list
-        LinkedList2_Append(&o->mac_entries_free, &entry->list_node);
+        LinkedList1_Append(&o->mac_entries_free, &entry->list_node);
     }
     
     // init group entry lists
-    LinkedList2_Init(&o->group_entries_free);
-    LinkedList2_Init(&o->group_entries_used);
+    LinkedList1_Init(&o->group_entries_free);
+    LinkedList1_Init(&o->group_entries_used);
     
     // initialize group entries
     for (int i = 0; i < d->max_peer_groups; i++) {
@@ -594,7 +600,7 @@ int FrameDeciderPeer_Init (FrameDeciderPeer *o, FrameDecider *d, void *user, BLo
         entry->peer = o;
         
         // insert to free list
-        LinkedList2_Append(&o->group_entries_free, &entry->list_node);
+        LinkedList1_Append(&o->group_entries_free, &entry->list_node);
         
         // init timer
         BTimer_Init(&entry->timer, 0, (BTimer_handler)group_entry_timer_handler, entry);
@@ -624,12 +630,10 @@ void FrameDeciderPeer_Free (FrameDeciderPeer *o)
         d->decide_state = DECIDE_STATE_NONE;
     }
     
-    LinkedList2Iterator it;
-    LinkedList2Node *node;
+    LinkedList1Node *node;
     
     // free group entries
-    LinkedList2Iterator_InitForward(&it, &o->group_entries_used);
-    while (node = LinkedList2Iterator_Next(&it)) {
+    for (node = LinkedList1_GetFirst(&o->group_entries_used); node; node = LinkedList1Node_Next(node)) {
         struct _FrameDecider_group_entry *entry = UPPER_OBJECT(node, struct _FrameDecider_group_entry, list_node);
         
         // remove from multicast
@@ -640,8 +644,7 @@ void FrameDeciderPeer_Free (FrameDeciderPeer *o)
     }
     
     // remove used MAC entries from tree
-    LinkedList2Iterator_InitForward(&it, &o->mac_entries_used);
-    while (node = LinkedList2Iterator_Next(&it)) {
+    for (node = LinkedList1_GetFirst(&o->mac_entries_used); node; node = LinkedList1Node_Next(node)) {
         struct _FrameDecider_mac_entry *entry = UPPER_OBJECT(node, struct _FrameDecider_mac_entry, list_node);
         
         // remove from tree
@@ -649,7 +652,10 @@ void FrameDeciderPeer_Free (FrameDeciderPeer *o)
     }
     
     // remove from peers list
-    LinkedList2_Remove(&d->peers_list, &o->list_node);
+    if (d->decide_flood_current == &o->list_node) {
+        d->decide_flood_current = LinkedList1Node_Next(d->decide_flood_current);
+    }
+    LinkedList1_Remove(&d->peers_list, &o->list_node);
     
     // free group entries
     BFree(o->group_entries);

+ 10 - 10
client/FrameDecider.h

@@ -37,7 +37,7 @@
 
 #include <stdint.h>
 
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <structure/LinkedList3.h>
 #include <structure/SAvl.h>
 #include <base/DebugObject.h>
@@ -61,7 +61,7 @@ typedef const uint8_t *FDMacsTree_key;
 
 struct _FrameDecider_mac_entry {
     struct _FrameDeciderPeer *peer;
-    LinkedList2Node list_node; // node in FrameDeciderPeer.mac_entries_free or FrameDeciderPeer.mac_entries_used
+    LinkedList1Node list_node; // node in FrameDeciderPeer.mac_entries_free or FrameDeciderPeer.mac_entries_used
     // defined when used:
     uint8_t mac[6];
     FDMacsTreeNode tree_node; // node in FrameDecider.macs_tree, indexed by mac
@@ -69,7 +69,7 @@ struct _FrameDecider_mac_entry {
 
 struct _FrameDecider_group_entry {
     struct _FrameDeciderPeer *peer;
-    LinkedList2Node list_node; // node in FrameDeciderPeer.group_entries_free or FrameDeciderPeer.group_entries_used
+    LinkedList1Node list_node; // node in FrameDeciderPeer.group_entries_free or FrameDeciderPeer.group_entries_used
     BTimer timer; // timer for removing the group entry, running when used
     // defined when used:
     // basic group data
@@ -95,11 +95,11 @@ typedef struct {
     btime_t igmp_group_membership_interval;
     btime_t igmp_last_member_query_time;
     BReactor *reactor;
-    LinkedList2 peers_list;
+    LinkedList1 peers_list;
     FDMacsTree macs_tree;
     FDMulticastTree multicast_tree;
     int decide_state;
-    LinkedList2Iterator decide_flood_it;
+    LinkedList1Node *decide_flood_current;
     struct _FrameDeciderPeer *decide_unicast_peer;
     LinkedList3Iterator decide_multicast_it;
     DebugObject d_obj;
@@ -114,11 +114,11 @@ typedef struct _FrameDeciderPeer {
     BLog_logfunc logfunc;
     struct _FrameDecider_mac_entry *mac_entries;
     struct _FrameDecider_group_entry *group_entries;
-    LinkedList2Node list_node; // node in FrameDecider.peers_list
-    LinkedList2 mac_entries_free;
-    LinkedList2 mac_entries_used;
-    LinkedList2 group_entries_free;
-    LinkedList2 group_entries_used;
+    LinkedList1Node list_node; // node in FrameDecider.peers_list
+    LinkedList1 mac_entries_free;
+    LinkedList1 mac_entries_used;
+    LinkedList1 group_entries_free;
+    LinkedList1 group_entries_used;
     FDGroupsTree groups_tree;
     DebugObject d_obj;
 } FrameDeciderPeer;

+ 16 - 16
client/PasswordListener.c

@@ -81,8 +81,8 @@ void remove_client (struct PasswordListenerClient *client)
     free(client->sock);
     
     // move to free list
-    LinkedList2_Remove(&l->clients_used, &client->list_node);
-    LinkedList2_Append(&l->clients_free, &client->list_node);
+    LinkedList1_Remove(&l->clients_used, &client->list_node);
+    LinkedList1_Append(&l->clients_free, &client->list_node);
 }
 
 void listener_handler (PasswordListener *l)
@@ -90,13 +90,13 @@ void listener_handler (PasswordListener *l)
     DebugObject_Access(&l->d_obj);
     
     // obtain client entry
-    if (LinkedList2_IsEmpty(&l->clients_free)) {
-        struct PasswordListenerClient *client = UPPER_OBJECT(LinkedList2_GetFirst(&l->clients_used), struct PasswordListenerClient, list_node);
+    if (LinkedList1_IsEmpty(&l->clients_free)) {
+        struct PasswordListenerClient *client = UPPER_OBJECT(LinkedList1_GetFirst(&l->clients_used), struct PasswordListenerClient, list_node);
         remove_client(client);
     }
-    struct PasswordListenerClient *client = UPPER_OBJECT(LinkedList2_GetLast(&l->clients_free), struct PasswordListenerClient, list_node);
-    LinkedList2_Remove(&l->clients_free, &client->list_node);
-    LinkedList2_Append(&l->clients_used, &client->list_node);
+    struct PasswordListenerClient *client = UPPER_OBJECT(LinkedList1_GetLast(&l->clients_free), struct PasswordListenerClient, list_node);
+    LinkedList1_Remove(&l->clients_free, &client->list_node);
+    LinkedList1_Append(&l->clients_used, &client->list_node);
     
     // allocate sslsocket structure
     if (!(client->sock = (sslsocket *)malloc(sizeof(*client->sock)))) {
@@ -172,8 +172,8 @@ fail2:
 fail1:
     free(client->sock);
 fail0:
-    LinkedList2_Remove(&l->clients_used, &client->list_node);
-    LinkedList2_Append(&l->clients_free, &client->list_node);
+    LinkedList1_Remove(&l->clients_used, &client->list_node);
+    LinkedList1_Append(&l->clients_free, &client->list_node);
 }
 
 void client_connection_handler (struct PasswordListenerClient *client, int event)
@@ -238,8 +238,8 @@ void client_receiver_handler (struct PasswordListenerClient *client)
     BConnection_SetHandlers(&client->sock->con, NULL, NULL);
     
     // move client entry to free list
-    LinkedList2_Remove(&l->clients_used, &client->list_node);
-    LinkedList2_Append(&l->clients_free, &client->list_node);
+    LinkedList1_Remove(&l->clients_used, &client->list_node);
+    LinkedList1_Append(&l->clients_free, &client->list_node);
     
     // give the socket to the handler
     pw_entry->handler_client(pw_entry->user, client->sock);
@@ -279,12 +279,12 @@ int PasswordListener_Init (PasswordListener *l, BReactor *bsys, BAddr listen_add
     }
     
     // initialize client entries
-    LinkedList2_Init(&l->clients_free);
-    LinkedList2_Init(&l->clients_used);
+    LinkedList1_Init(&l->clients_free);
+    LinkedList1_Init(&l->clients_used);
     for (int i = 0; i < max_clients; i++) {
         struct PasswordListenerClient *conn = &l->clients_data[i];
         conn->l = l;
-        LinkedList2_Append(&l->clients_free, &conn->list_node);
+        LinkedList1_Append(&l->clients_free, &conn->list_node);
     }
     
     // initialize passwords tree
@@ -315,8 +315,8 @@ void PasswordListener_Free (PasswordListener *l)
     DebugObject_Free(&l->d_obj);
 
     // free clients
-    LinkedList2Node *node;
-    while (node = LinkedList2_GetFirst(&l->clients_used)) {
+    LinkedList1Node *node;
+    while (node = LinkedList1_GetFirst(&l->clients_used)) {
         struct PasswordListenerClient *client = UPPER_OBJECT(node, struct PasswordListenerClient, list_node);
         remove_client(client);
     }

+ 4 - 4
client/PasswordListener.h

@@ -44,7 +44,7 @@
 
 #include <misc/debug.h>
 #include <misc/sslsocket.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <structure/BAVL.h>
 #include <base/DebugObject.h>
 #include <flow/SingleStreamReceiver.h>
@@ -77,8 +77,8 @@ typedef struct {
     PRFileDesc model_dprfd;
     PRFileDesc *model_prfd;
     struct PasswordListenerClient *clients_data;
-    LinkedList2 clients_free;
-    LinkedList2 clients_used;
+    LinkedList1 clients_free;
+    LinkedList1 clients_used;
     BAVL passwords;
     BListener listener;
     DebugObject d_obj;
@@ -93,7 +93,7 @@ typedef struct {
 
 struct PasswordListenerClient {
     PasswordListener *l;
-    LinkedList2Node list_node;
+    LinkedList1Node list_node;
     sslsocket *sock;
     BSSLConnection sslcon;
     SingleStreamReceiver receiver;

+ 1 - 1
client/StreamPeerIO.h

@@ -44,7 +44,7 @@
 #include <base/BLog.h>
 #include <system/BReactor.h>
 #include <system/BConnection.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <flow/PacketProtoDecoder.h>
 #include <flow/PacketStreamSender.h>
 #include <flow/SinglePacketBuffer.h>

+ 24 - 24
client/client.c

@@ -44,7 +44,7 @@
 #include <misc/loggers_string.h>
 #include <misc/string_begins_with.h>
 #include <misc/open_standard_streams.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <base/DebugObject.h>
 #include <base/BLog.h>
 #include <security/BSecurity.h>
@@ -174,17 +174,17 @@ DPReceiveDevice device_output_dprd;
 int data_mtu;
 
 // peers list
-LinkedList2 peers;
+LinkedList1 peers;
 int num_peers;
 
 // frame decider
 FrameDecider frame_decider;
 
 // peers that can be user as relays
-LinkedList2 relays;
+LinkedList1 relays;
 
 // peers than need a relay
-LinkedList2 waiting_relay_peers;
+LinkedList1 waiting_relay_peers;
 
 // server connection
 ServerConnection server;
@@ -539,17 +539,17 @@ int main (int argc, char *argv[])
     }
     
     // init peers list
-    LinkedList2_Init(&peers);
+    LinkedList1_Init(&peers);
     num_peers = 0;
     
     // init frame decider
     FrameDecider_Init(&frame_decider, options.max_macs, options.max_groups, options.igmp_group_membership_interval, options.igmp_last_member_query_time, &ss);
     
     // init relays list
-    LinkedList2_Init(&relays);
+    LinkedList1_Init(&relays);
     
     // init need relay list
-    LinkedList2_Init(&waiting_relay_peers);
+    LinkedList1_Init(&waiting_relay_peers);
     
     // start connecting to server
     if (!ServerConnection_Init(&server, &ss, server_addr, SC_KEEPALIVE_INTERVAL, SERVER_BUFFER_MIN_PACKETS, options.ssl, client_cert, client_key, server_name, NULL,
@@ -575,8 +575,8 @@ int main (int argc, char *argv[])
     }
     
     // free peers
-    LinkedList2Node *node;
-    while (node = LinkedList2_GetFirst(&peers)) {
+    LinkedList1Node *node;
+    while (node = LinkedList1_GetFirst(&peers)) {
         struct peer_data *peer = UPPER_OBJECT(node, struct peer_data, list_node);
         peer_remove(peer, 1);
     }
@@ -1426,7 +1426,7 @@ void peer_add (peerid_t id, int flags, const uint8_t *cert, int cert_len)
     peer->binding = 0;
     
     // add to peers list
-    LinkedList2_Append(&peers, &peer->list_node);
+    LinkedList1_Append(&peers, &peer->list_node);
     num_peers++;
     
     switch (chat_ssl_mode) {
@@ -1474,7 +1474,7 @@ void peer_remove (struct peer_data *peer, int exiting)
     ASSERT(!peer->is_relay)
     
     // remove from peers list
-    LinkedList2_Remove(&peers, &peer->list_node);
+    LinkedList1_Remove(&peers, &peer->list_node);
     num_peers--;
     
     // free reset timer
@@ -1711,10 +1711,10 @@ void peer_enable_relay_provider (struct peer_data *peer)
     ASSERT(!peer->waiting_relay)
     
     // add to relays list
-    LinkedList2_Append(&relays, &peer->relay_list_node);
+    LinkedList1_Append(&relays, &peer->relay_list_node);
     
     // init users list
-    LinkedList2_Init(&peer->relay_users);
+    LinkedList1_Init(&peer->relay_users);
     
     // set is relay
     peer->is_relay = 1;
@@ -1732,8 +1732,8 @@ void peer_disable_relay_provider (struct peer_data *peer)
     ASSERT(!peer->waiting_relay)
     
     // disconnect relay users
-    LinkedList2Node *list_node;
-    while (list_node = LinkedList2_GetFirst(&peer->relay_users)) {
+    LinkedList1Node *list_node;
+    while (list_node = LinkedList1_GetFirst(&peer->relay_users)) {
         struct peer_data *relay_user = UPPER_OBJECT(list_node, struct peer_data, relaying_list_node);
         ASSERT(relay_user->relaying_peer == peer)
         
@@ -1745,7 +1745,7 @@ void peer_disable_relay_provider (struct peer_data *peer)
     }
     
     // remove from relays list
-    LinkedList2_Remove(&relays, &peer->relay_list_node);
+    LinkedList1_Remove(&relays, &peer->relay_list_node);
     
     // set is not relay
     peer->is_relay = 0;
@@ -1767,7 +1767,7 @@ void peer_install_relaying (struct peer_data *peer, struct peer_data *relay)
     peer_log(peer, BLOG_INFO, "installing relaying through %d", (int)relay->id);
     
     // add to relay's users list
-    LinkedList2_Append(&relay->relay_users, &peer->relaying_list_node);
+    LinkedList1_Append(&relay->relay_users, &peer->relaying_list_node);
     
     // attach local flow to relay
     DataProtoFlow_Attach(&peer->local_dpflow, &relay->send_dp);
@@ -1793,7 +1793,7 @@ void peer_free_relaying (struct peer_data *peer)
     DataProtoFlow_Detach(&peer->local_dpflow);
     
     // remove from relay's users list
-    LinkedList2_Remove(&relay->relay_users, &peer->relaying_list_node);
+    LinkedList1_Remove(&relay->relay_users, &peer->relaying_list_node);
     
     // set not relaying
     peer->relaying_peer = NULL;
@@ -1831,7 +1831,7 @@ void peer_register_need_relay (struct peer_data *peer)
     ASSERT(!peer->is_relay)
     
     // add to need relay list
-    LinkedList2_Append(&waiting_relay_peers, &peer->waiting_relay_list_node);
+    LinkedList1_Append(&waiting_relay_peers, &peer->waiting_relay_list_node);
     
     // set waiting relay
     peer->waiting_relay = 1;
@@ -1846,7 +1846,7 @@ void peer_unregister_need_relay (struct peer_data *peer)
     ASSERT(!peer->is_relay)
     
     // remove from need relay list
-    LinkedList2_Remove(&waiting_relay_peers, &peer->waiting_relay_list_node);
+    LinkedList1_Remove(&waiting_relay_peers, &peer->waiting_relay_list_node);
     
     // set not waiting relay
     peer->waiting_relay = 0;
@@ -2598,7 +2598,7 @@ void peer_dataproto_handler (struct peer_data *peer, int up)
 
 struct peer_data * find_peer_by_id (peerid_t id)
 {
-    for (LinkedList2Node *node = LinkedList2_GetFirst(&peers); node; node = LinkedList2Node_Next(node)) {
+    for (LinkedList1Node *node = LinkedList1_GetFirst(&peers); node; node = LinkedList1Node_Next(node)) {
         struct peer_data *peer = UPPER_OBJECT(node, struct peer_data, list_node);
         if (peer->id == id) {
             return peer;
@@ -2635,8 +2635,8 @@ void device_dpsource_handler (void *unused, const uint8_t *frame, int frame_len)
 
 void assign_relays (void)
 {
-    LinkedList2Node *list_node;
-    while (list_node = LinkedList2_GetFirst(&waiting_relay_peers)) {
+    LinkedList1Node *list_node;
+    while (list_node = LinkedList1_GetFirst(&waiting_relay_peers)) {
         struct peer_data *peer = UPPER_OBJECT(list_node, struct peer_data, waiting_relay_list_node);
         ASSERT(peer->waiting_relay)
         
@@ -2644,7 +2644,7 @@ void assign_relays (void)
         ASSERT(!peer->have_link)
         
         // get a relay
-        LinkedList2Node *list_node2 = LinkedList2_GetFirst(&relays);
+        LinkedList1Node *list_node2 = LinkedList1_GetFirst(&relays);
         if (!list_node2) {
             BLog(BLOG_NOTICE, "no relays");
             return;

+ 6 - 6
client/client.h

@@ -31,7 +31,7 @@
 #include <stdint.h>
 
 #include <protocol/scproto.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <flow/PacketPassFairQueue.h>
 #include <flow/SinglePacketBuffer.h>
 #include <flow/PacketRecvConnector.h>
@@ -170,24 +170,24 @@ struct peer_data {
     
     // relaying objects
     struct peer_data *relaying_peer; // peer through which we are relaying, or NULL
-    LinkedList2Node relaying_list_node; // node in relay peer's relay_users
+    LinkedList1Node relaying_list_node; // node in relay peer's relay_users
     
     // waiting for relay data
     int waiting_relay;
-    LinkedList2Node waiting_relay_list_node;
+    LinkedList1Node waiting_relay_list_node;
     
     // retry timer
     BTimer reset_timer;
     
     // relay server specific
     int is_relay;
-    LinkedList2Node relay_list_node;
-    LinkedList2 relay_users;
+    LinkedList1Node relay_list_node;
+    LinkedList1 relay_users;
     
     // binding state
     int binding;
     int binding_addrpos;
     
     // peers linked list node
-    LinkedList2Node list_node;
+    LinkedList1Node list_node;
 };

+ 0 - 2
examples/CMakeLists.txt

@@ -1,5 +1,3 @@
-add_executable(linkedlist2_example linkedlist2_example.c)
-
 add_executable(btimer_example btimer_example.c)
 target_link_libraries(btimer_example system)
 

+ 0 - 168
examples/linkedlist2_example.c

@@ -1,168 +0,0 @@
-/**
- * @file linkedlist2_example.c
- * @author Ambroz Bizjak <ambrop7@gmail.com>
- * 
- * @section LICENSE
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the author nor the
- *    names of its contributors may be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stddef.h>
-
-#include <structure/LinkedList2.h>
-
-struct elem
-{
-    int i;
-    LinkedList2Node list_node;
-};
-
-void printnode (LinkedList2Node *node)
-{
-    if (!node) {
-        printf("(null) ");
-    } else {
-        struct elem *e = (struct elem *)((uint8_t *)node-offsetof(struct elem, list_node));
-        printf("%d ", e->i);
-    }
-}
-
-void printall (LinkedList2 *list)
-{
-    printf("List: ");
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, list);
-    LinkedList2Node *node;
-    while (node = LinkedList2Iterator_Next(&it)) {
-        printnode(node);
-    }
-    printf("\n");
-}
-
-void removeall (LinkedList2 *list)
-{
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, list);
-    LinkedList2Node *node;
-    while (node = LinkedList2Iterator_Next(&it)) {
-        LinkedList2_Remove(list, node);
-    }
-}
-
-int main ()
-{
-    struct elem elems[10];
-
-    LinkedList2 list;
-    LinkedList2_Init(&list);
-
-    int i;
-    for (i=0; i<10; i++) {
-        elems[i].i = i;
-        LinkedList2_Append(&list, &elems[i].list_node);
-    }
-
-    printall(&list);
-    
-    LinkedList2Iterator it1;
-    LinkedList2Iterator it2;
-    LinkedList2Iterator it3;
-    LinkedList2Iterator it4;
-    
-    LinkedList2Iterator_InitForward(&it1, &list);
-    LinkedList2Iterator_InitForward(&it2, &list);
-    LinkedList2Iterator_InitBackward(&it3, &list);
-    LinkedList2Iterator_InitBackward(&it4, &list);
-    
-    LinkedList2_Remove(&list, &elems[0].list_node);
-    LinkedList2_Remove(&list, &elems[1].list_node);
-    LinkedList2_Remove(&list, &elems[2].list_node);
-    LinkedList2_Remove(&list, &elems[3].list_node);
-    
-    LinkedList2_Remove(&list, &elems[9].list_node);
-    LinkedList2_Remove(&list, &elems[8].list_node);
-    LinkedList2_Remove(&list, &elems[7].list_node);
-    LinkedList2_Remove(&list, &elems[6].list_node);
-    
-    LinkedList2Node *node1;
-    LinkedList2Node *node2;
-    LinkedList2Node *node3;
-    LinkedList2Node *node4;
-    
-    node1 = LinkedList2Iterator_Next(&it1);
-    node2 = LinkedList2Iterator_Next(&it2);
-    printnode(node1);
-    printnode(node2);
-    printf("\n");
-    
-    node3 = LinkedList2Iterator_Next(&it3);
-    node4 = LinkedList2Iterator_Next(&it4);
-    printnode(node3);
-    printnode(node4);
-    printf("\n");
-    
-    printall(&list);
-    
-    node1 = LinkedList2Iterator_Next(&it1);
-    printnode(node1);
-    printf("\n");
-    
-    node3 = LinkedList2Iterator_Next(&it3);
-    printnode(node3);
-    printf("\n");
-    
-    printall(&list);
-    
-    LinkedList2_Prepend(&list, &elems[3].list_node);
-    LinkedList2_Append(&list, &elems[6].list_node);
-    
-    printall(&list);
-    
-    node1 = LinkedList2Iterator_Next(&it1);
-    node2 = LinkedList2Iterator_Next(&it2);
-    printnode(node1);
-    printnode(node2);
-    printf("\n");
-    
-    node3 = LinkedList2Iterator_Next(&it3);
-    node4 = LinkedList2Iterator_Next(&it4);
-    printnode(node3);
-    printnode(node4);
-    printf("\n");
-    
-    node1 = LinkedList2Iterator_Next(&it1);
-    node2 = LinkedList2Iterator_Next(&it2);
-    printnode(node1);
-    printnode(node2);
-    printf("\n");
-    
-    node3 = LinkedList2Iterator_Next(&it3);
-    node4 = LinkedList2Iterator_Next(&it4);
-    printnode(node3);
-    printnode(node4);
-    printf("\n");
-    
-    return 0;
-}

+ 5 - 8
flow/PacketPassFairQueue.c

@@ -97,10 +97,7 @@ static void increment_sent_flow (PacketPassFairQueueFlow *flow, uint64_t amount)
         }
         
         // subtract time from all flows
-        LinkedList2Iterator it;
-        LinkedList2Iterator_InitForward(&it, &m->flows_list);
-        LinkedList2Node *list_node;
-        while (list_node = LinkedList2Iterator_Next(&it)) {
+        for (LinkedList1Node *list_node = LinkedList1_GetFirst(&m->flows_list); list_node; list_node = LinkedList1Node_Next(list_node)) {
             PacketPassFairQueueFlow *someflow = UPPER_OBJECT(list_node, PacketPassFairQueueFlow, list_node);
             
             // don't subtract more time than there is, except for the just finished flow,
@@ -252,7 +249,7 @@ int PacketPassFairQueue_Init (PacketPassFairQueue *m, PacketPassInterface *outpu
     PacketPassFairQueue__Tree_Init(&m->queued_tree);
     
     // init flows list
-    LinkedList2_Init(&m->flows_list);
+    LinkedList1_Init(&m->flows_list);
     
     // not freeing
     m->freeing = 0;
@@ -270,7 +267,7 @@ fail0:
 
 void PacketPassFairQueue_Free (PacketPassFairQueue *m)
 {
-    ASSERT(LinkedList2_IsEmpty(&m->flows_list))
+    ASSERT(LinkedList1_IsEmpty(&m->flows_list))
     ASSERT(PacketPassFairQueue__Tree_IsEmpty(&m->queued_tree))
     ASSERT(!m->previous_flow)
     ASSERT(!m->sending_flow)
@@ -314,7 +311,7 @@ void PacketPassFairQueueFlow_Init (PacketPassFairQueueFlow *flow, PacketPassFair
     flow->time = 0;
     
     // add to flows list
-    LinkedList2_Append(&m->flows_list, &flow->list_node);
+    LinkedList1_Append(&m->flows_list, &flow->list_node);
     
     // is not queued
     flow->is_queued = 0;
@@ -347,7 +344,7 @@ void PacketPassFairQueueFlow_Free (PacketPassFairQueueFlow *flow)
     }
     
     // remove from flows list
-    LinkedList2_Remove(&m->flows_list, &flow->list_node);
+    LinkedList1_Remove(&m->flows_list, &flow->list_node);
     
     // free input
     PacketPassInterface_Free(&flow->input);

+ 3 - 3
flow/PacketPassFairQueue.h

@@ -39,7 +39,7 @@
 #include <misc/debug.h>
 #include <misc/debugcounter.h>
 #include <structure/SAvl.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <base/DebugObject.h>
 #include <base/BPending.h>
 #include <flow/PacketPassInterface.h>
@@ -60,7 +60,7 @@ typedef struct PacketPassFairQueueFlow_s {
     void *user;
     PacketPassInterface input;
     uint64_t time;
-    LinkedList2Node list_node;
+    LinkedList1Node list_node;
     int is_queued;
     struct {
         PacketPassFairQueue__TreeNode tree_node;
@@ -82,7 +82,7 @@ typedef struct PacketPassFairQueue_s {
     int sending_len;
     struct PacketPassFairQueueFlow_s *previous_flow;
     PacketPassFairQueue__Tree queued_tree;
-    LinkedList2 flows_list;
+    LinkedList1 flows_list;
     int freeing;
     BPending schedule_job;
     DebugObject d_obj;

+ 12 - 12
ncd/BEventLock.c

@@ -33,11 +33,11 @@
 
 static void exec_job_handler (BEventLock *o)
 {
-    ASSERT(!LinkedList2_IsEmpty(&o->jobs))
+    ASSERT(!LinkedList1_IsEmpty(&o->jobs))
     DebugObject_Access(&o->d_obj);
     
     // get job
-    BEventLockJob *j = UPPER_OBJECT(LinkedList2_GetFirst(&o->jobs), BEventLockJob, pending_node);
+    BEventLockJob *j = UPPER_OBJECT(LinkedList1_GetFirst(&o->jobs), BEventLockJob, pending_node);
     ASSERT(j->pending)
     
     // call handler
@@ -48,7 +48,7 @@ static void exec_job_handler (BEventLock *o)
 void BEventLock_Init (BEventLock *o, BPendingGroup *pg)
 {
     // init jobs list
-    LinkedList2_Init(&o->jobs);
+    LinkedList1_Init(&o->jobs);
     
     // init exec job
     BPending_Init(&o->exec_job, pg, (BPending_handler)exec_job_handler, o);
@@ -59,7 +59,7 @@ void BEventLock_Init (BEventLock *o, BPendingGroup *pg)
 
 void BEventLock_Free (BEventLock *o)
 {
-    ASSERT(LinkedList2_IsEmpty(&o->jobs))
+    ASSERT(LinkedList1_IsEmpty(&o->jobs))
     DebugCounter_Free(&o->pending_ctr);
     DebugObject_Free(&o->d_obj);
     
@@ -89,14 +89,14 @@ void BEventLockJob_Free (BEventLockJob *o)
     DebugObject_Free(&o->d_obj);
     
     if (o->pending) {
-        int was_first = (&o->pending_node == LinkedList2_GetFirst(&l->jobs));
+        int was_first = (&o->pending_node == LinkedList1_GetFirst(&l->jobs));
         
         // remove from jobs list
-        LinkedList2_Remove(&l->jobs, &o->pending_node);
+        LinkedList1_Remove(&l->jobs, &o->pending_node);
         
         // schedule/unschedule job
         if (was_first) {
-            if (LinkedList2_IsEmpty(&l->jobs)) {
+            if (LinkedList1_IsEmpty(&l->jobs)) {
                 BPending_Unset(&l->exec_job);
             } else {
                 BPending_Set(&l->exec_job);
@@ -111,13 +111,13 @@ void BEventLockJob_Wait (BEventLockJob *o)
     ASSERT(!o->pending)
     
     // append to jobs
-    LinkedList2_Append(&l->jobs, &o->pending_node);
+    LinkedList1_Append(&l->jobs, &o->pending_node);
     
     // set pending
     o->pending = 1;
     
     // schedule next job if needed
-    if (&o->pending_node == LinkedList2_GetFirst(&l->jobs)) {
+    if (&o->pending_node == LinkedList1_GetFirst(&l->jobs)) {
         BPending_Set(&l->exec_job);
     }
 }
@@ -127,17 +127,17 @@ void BEventLockJob_Release (BEventLockJob *o)
     BEventLock *l = o->l;
     ASSERT(o->pending)
     
-    int was_first = (&o->pending_node == LinkedList2_GetFirst(&l->jobs));
+    int was_first = (&o->pending_node == LinkedList1_GetFirst(&l->jobs));
     
     // remove from jobs list
-    LinkedList2_Remove(&l->jobs, &o->pending_node);
+    LinkedList1_Remove(&l->jobs, &o->pending_node);
     
     // set not pending
     o->pending = 0;
     
     // schedule/unschedule job
     if (was_first) {
-        if (LinkedList2_IsEmpty(&l->jobs)) {
+        if (LinkedList1_IsEmpty(&l->jobs)) {
             BPending_Unset(&l->exec_job);
         } else {
             BPending_Set(&l->exec_job);

+ 3 - 3
ncd/BEventLock.h

@@ -35,7 +35,7 @@
 #define BADVPN_BEVENTLOCK_H
 
 #include <misc/debugcounter.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <base/DebugObject.h>
 #include <base/BPending.h>
 
@@ -53,7 +53,7 @@ typedef void (*BEventLock_handler) (void *user);
  * A FIFO lock for events using the job queue ({@link BPending}).
  */
 typedef struct {
-    LinkedList2 jobs;
+    LinkedList1 jobs;
     BPending exec_job;
     DebugObject d_obj;
     DebugCounter pending_ctr;
@@ -67,7 +67,7 @@ typedef struct {
     BEventLock_handler handler;
     void *user;
     int pending;
-    LinkedList2Node pending_node;
+    LinkedList1Node pending_node;
     DebugObject d_obj;
 } BEventLockJob;
 

+ 11 - 14
ncd/modules/blocker.c

@@ -74,7 +74,7 @@
 
 #include <misc/offset.h>
 #include <misc/debug.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <structure/LinkedList0.h>
 #include <ncd/NCDModule.h>
 
@@ -84,7 +84,7 @@
 
 struct instance {
     NCDModuleInst *i;
-    LinkedList2 users;
+    LinkedList1 users;
     LinkedList0 rdownups_list;
     int up;
     int dying;
@@ -99,7 +99,7 @@ struct rdownup_instance {
 struct use_instance {
     NCDModuleInst *i;
     struct instance *blocker;
-    LinkedList2Node blocker_node;
+    LinkedList1Node blocker_node;
 };
 
 static void func_new (void *vo, NCDModuleInst *i)
@@ -114,7 +114,7 @@ static void func_new (void *vo, NCDModuleInst *i)
     }
     
     // init users list
-    LinkedList2_Init(&o->users);
+    LinkedList1_Init(&o->users);
     
     // init rdownups list
     LinkedList0_Init(&o->rdownups_list);
@@ -136,7 +136,7 @@ fail0:
 
 static void instance_free (struct instance *o)
 {
-    ASSERT(LinkedList2_IsEmpty(&o->users))
+    ASSERT(LinkedList1_IsEmpty(&o->users))
     
     // break any rdownups
     LinkedList0Node *ln;
@@ -156,7 +156,7 @@ static void func_die (void *vo)
     ASSERT(!o->dying)
     
     // if we have no users, die right away, else wait for users
-    if (LinkedList2_IsEmpty(&o->users)) {
+    if (LinkedList1_IsEmpty(&o->users)) {
         instance_free(o);
         return;
     }
@@ -183,10 +183,7 @@ static void updown_func_new_templ (NCDModuleInst *i, int up, int first_down)
     
     if (first_down || mo->up != up) {
         // signal users
-        LinkedList2Iterator it;
-        LinkedList2Iterator_InitForward(&it, &mo->users);
-        LinkedList2Node *node;
-        while (node = LinkedList2Iterator_Next(&it)) {
+        for (LinkedList1Node *node = LinkedList1_GetFirst(&mo->users); node; node = LinkedList1Node_Next(node)) {
             struct use_instance *user = UPPER_OBJECT(node, struct use_instance, blocker_node);
             ASSERT(user->blocker == mo)
             if (first_down && mo->up) {
@@ -265,7 +262,7 @@ static void rdownup_func_die (void *vo)
         LinkedList0_Remove(&blk->rdownups_list, &o->rdownups_list_node);
         
         // downup users
-        for (LinkedList2Node *ln = LinkedList2_GetFirst(&blk->users); ln; ln = LinkedList2Node_Next(ln)) {
+        for (LinkedList1Node *ln = LinkedList1_GetFirst(&blk->users); ln; ln = LinkedList1Node_Next(ln)) {
             struct use_instance *user = UPPER_OBJECT(ln, struct use_instance, blocker_node);
             ASSERT(user->blocker == blk)
             if (blk->up) {
@@ -296,7 +293,7 @@ static void use_func_new (void *vo, NCDModuleInst *i)
     o->blocker = NCDModuleInst_Backend_GetUser((NCDModuleInst *)i->method_user);
     
     // add to blocker's list
-    LinkedList2_Append(&o->blocker->users, &o->blocker_node);
+    LinkedList1_Append(&o->blocker->users, &o->blocker_node);
     
     // signal up if needed
     if (o->blocker->up) {
@@ -315,10 +312,10 @@ static void use_func_die (void *vo)
     struct use_instance *o = vo;
     
     // remove from blocker's list
-    LinkedList2_Remove(&o->blocker->users, &o->blocker_node);
+    LinkedList1_Remove(&o->blocker->users, &o->blocker_node);
     
     // make the blocker die if needed
-    if (o->blocker->dying && LinkedList2_IsEmpty(&o->blocker->users)) {
+    if (o->blocker->dying && LinkedList1_IsEmpty(&o->blocker->users)) {
         instance_free(o->blocker);
     }
     

+ 31 - 36
ncd/modules/depend.c

@@ -59,7 +59,7 @@
 
 #include <misc/offset.h>
 #include <misc/debug.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <structure/LinkedList3.h>
 #include <ncd/NCDModule.h>
 
@@ -76,8 +76,8 @@ struct provide {
             LinkedList3Node queued_node; // node in list which begins with provide.queued_provides_firstnode
         };
         struct {
-            LinkedList2Node provides_node; // node in provides
-            LinkedList2 depends;
+            LinkedList1Node provides_node; // node in provides
+            LinkedList1 depends;
             LinkedList3Node queued_provides_firstnode;
             int dying;
         };
@@ -88,23 +88,19 @@ struct depend {
     NCDModuleInst *i;
     const char *name;
     struct provide *p;
-    LinkedList2Node node;
+    LinkedList1Node node;
 };
 
-static LinkedList2 provides;
-static LinkedList2 free_depends;
+static LinkedList1 provides;
+static LinkedList1 free_depends;
 
 static struct provide * find_provide (const char *name)
 {
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, &provides);
-    LinkedList2Node *n;
-    while (n = LinkedList2Iterator_Next(&it)) {
+    for (LinkedList1Node *n = LinkedList1_GetFirst(&provides); n; n = LinkedList1Node_Next(n)) {
         struct provide *p = UPPER_OBJECT(n, struct provide, provides_node);
         ASSERT(!p->is_queued)
         
         if (!strcmp(p->name, name)) {
-            LinkedList2Iterator_Free(&it);
             return p;
         }
     }
@@ -120,47 +116,49 @@ static void provide_promote (struct provide *o)
     o->is_queued = 0;
     
     // insert to provides list
-    LinkedList2_Append(&provides, &o->provides_node);
+    LinkedList1_Append(&provides, &o->provides_node);
     
     // init depends list
-    LinkedList2_Init(&o->depends);
+    LinkedList1_Init(&o->depends);
     
     // set not dying
     o->dying = 0;
     
     // attach free depends with this name
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, &free_depends);
-    LinkedList2Node *n;
-    while (n = LinkedList2Iterator_Next(&it)) {
+    LinkedList1Node *n = LinkedList1_GetFirst(&free_depends);
+    while (n) {
+        LinkedList1Node *next = LinkedList1Node_Next(n);
         struct depend *d = UPPER_OBJECT(n, struct depend, node);
         ASSERT(!d->p)
         
         if (strcmp(d->name, o->name)) {
+            n = next;
             continue;
         }
         
         // remove from free depends list
-        LinkedList2_Remove(&free_depends, &d->node);
+        LinkedList1_Remove(&free_depends, &d->node);
         
         // insert to provide's list
-        LinkedList2_Append(&o->depends, &d->node);
+        LinkedList1_Append(&o->depends, &d->node);
         
         // set provide
         d->p = o;
         
         // signal up
         NCDModuleInst_Backend_Up(d->i);
+        
+        n = next;
     }
 }
 
 static int func_globalinit (struct NCDModuleInitParams params)
 {
     // init provides list
-    LinkedList2_Init(&provides);
+    LinkedList1_Init(&provides);
     
     // init free depends list
-    LinkedList2_Init(&free_depends);
+    LinkedList1_Init(&free_depends);
     
     return 1;
 }
@@ -229,14 +227,14 @@ static void provide_event_func_new (void *vo, NCDModuleInst *i)
 
 static void provide_free (struct provide *o)
 {
-    ASSERT(o->is_queued || LinkedList2_IsEmpty(&o->depends))
+    ASSERT(o->is_queued || LinkedList1_IsEmpty(&o->depends))
     
     if (o->is_queued) {
         // remove from existing provide's queued provides list
         LinkedList3Node_Free(&o->queued_node);
     } else {
         // remove from provides list
-        LinkedList2_Remove(&provides, &o->provides_node);
+        LinkedList1_Remove(&provides, &o->provides_node);
         
         // if we have provides queued, promote the first one
         if (LinkedList3Node_Next(&o->queued_provides_firstnode)) {
@@ -263,7 +261,7 @@ static void provide_func_die (void *vo)
     ASSERT(o->is_queued || !o->dying)
     
     // if we are queued or have no depends, die immediately
-    if (o->is_queued || LinkedList2_IsEmpty(&o->depends)) {
+    if (o->is_queued || LinkedList1_IsEmpty(&o->depends)) {
         provide_free(o);
         return;
     }
@@ -272,10 +270,7 @@ static void provide_func_die (void *vo)
     o->dying = 1;
     
     // signal our depends down
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, &o->depends);
-    LinkedList2Node *n;
-    while (n = LinkedList2Iterator_Next(&it)) {
+    for (LinkedList1Node *n = LinkedList1_GetFirst(&o->depends); n; n = LinkedList1Node_Next(n)) {
         struct depend *d = UPPER_OBJECT(n, struct depend, node);
         ASSERT(d->p == o)
         
@@ -307,7 +302,7 @@ static void depend_func_new (void *vo, NCDModuleInst *i)
     
     if (p && !p->dying) {
         // insert to provide's list
-        LinkedList2_Append(&p->depends, &o->node);
+        LinkedList1_Append(&p->depends, &o->node);
         
         // set provide
         o->p = p;
@@ -316,7 +311,7 @@ static void depend_func_new (void *vo, NCDModuleInst *i)
         NCDModuleInst_Backend_Up(o->i);
     } else {
         // insert to free depends list
-        LinkedList2_Append(&free_depends, &o->node);
+        LinkedList1_Append(&free_depends, &o->node);
         
         // set no provide
         o->p = NULL;
@@ -335,15 +330,15 @@ static void depend_free (struct depend *o)
     
     if (o->p) {
         // remove from provide's list
-        LinkedList2_Remove(&o->p->depends, &o->node);
+        LinkedList1_Remove(&o->p->depends, &o->node);
         
         // if provide is dying and is empty, let it die
-        if (o->p->dying && LinkedList2_IsEmpty(&o->p->depends)) {
+        if (o->p->dying && LinkedList1_IsEmpty(&o->p->depends)) {
             provide_free(o->p);
         }
     } else {
         // remove free depends list
-        LinkedList2_Remove(&free_depends, &o->node);
+        LinkedList1_Remove(&free_depends, &o->node);
     }
     
     NCDModuleInst_Backend_Dead(o->i);
@@ -368,16 +363,16 @@ static void depend_func_clean (void *vo)
     struct provide *p = o->p;
     
     // remove from provide's list
-    LinkedList2_Remove(&p->depends, &o->node);
+    LinkedList1_Remove(&p->depends, &o->node);
     
     // insert to free depends list
-    LinkedList2_Append(&free_depends, &o->node);
+    LinkedList1_Append(&free_depends, &o->node);
     
     // set no provide
     o->p = NULL;
     
     // if provide is empty, let it die
-    if (LinkedList2_IsEmpty(&p->depends)) {
+    if (LinkedList1_IsEmpty(&p->depends)) {
         provide_free(p);
     }
 }

+ 25 - 35
ncd/modules/multidepend.c

@@ -49,7 +49,7 @@
 
 #include <misc/offset.h>
 #include <misc/debug.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <ncd/NCDModule.h>
 
 #include <generated/blog_channel_ncd_multidepend.h>
@@ -59,32 +59,28 @@
 struct provide {
     NCDModuleInst *i;
     const char *name;
-    LinkedList2Node provides_node;
-    LinkedList2 depends;
+    LinkedList1Node provides_node;
+    LinkedList1 depends;
     int dying;
 };
 
 struct depend {
     NCDModuleInst *i;
     NCDValRef names;
-    LinkedList2Node depends_node;
+    LinkedList1Node depends_node;
     struct provide *provide;
-    LinkedList2Node provide_node;
+    LinkedList1Node provide_node;
     int provide_collapsing;
 };
 
-static LinkedList2 provides;
-static LinkedList2 depends;
+static LinkedList1 provides;
+static LinkedList1 depends;
 
 static struct provide * find_provide (const char *name)
 {
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, &provides);
-    LinkedList2Node *n;
-    while (n = LinkedList2Iterator_Next(&it)) {
+    for (LinkedList1Node *n = LinkedList1_GetFirst(&provides); n; n = LinkedList1Node_Next(n)) {
         struct provide *p = UPPER_OBJECT(n, struct provide, provides_node);
         if (!strcmp(p->name, name)) {
-            LinkedList2Iterator_Free(&it);
             return p;
         }
     }
@@ -131,7 +127,7 @@ static void depend_update (struct depend *o)
         NCDModuleInst_Backend_Down(o->i);
     } else {
         // insert to provide's list
-        LinkedList2_Append(&bp->depends, &o->provide_node);
+        LinkedList1_Append(&bp->depends, &o->provide_node);
         
         // set not collapsing
         o->provide_collapsing = 0;
@@ -147,10 +143,10 @@ static void depend_update (struct depend *o)
 static int func_globalinit (struct NCDModuleInitParams params)
 {
     // init provides list
-    LinkedList2_Init(&provides);
+    LinkedList1_Init(&provides);
     
     // init depends list
-    LinkedList2_Init(&depends);
+    LinkedList1_Init(&depends);
     
     return 1;
 }
@@ -179,10 +175,10 @@ static void provide_func_new (void *vo, NCDModuleInst *i)
     }
     
     // insert to provides list
-    LinkedList2_Append(&provides, &o->provides_node);
+    LinkedList1_Append(&provides, &o->provides_node);
     
     // init depends list
-    LinkedList2_Init(&o->depends);
+    LinkedList1_Init(&o->depends);
     
     // set not dying
     o->dying = 0;
@@ -193,10 +189,7 @@ static void provide_func_new (void *vo, NCDModuleInst *i)
     NCDModuleInst_Backend_Up(o->i);
     
     // update depends
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, &depends);
-    LinkedList2Node *n;
-    while (n = LinkedList2Iterator_Next(&it)) {
+    for (LinkedList1Node *n = LinkedList1_GetFirst(&depends); n; n = LinkedList1Node_Next(n)) {
         struct depend *d = UPPER_OBJECT(n, struct depend, depends_node);
         depend_update(d);
     }
@@ -210,10 +203,10 @@ fail0:
 
 static void provide_free (struct provide *o)
 {
-    ASSERT(LinkedList2_IsEmpty(&o->depends))
+    ASSERT(LinkedList1_IsEmpty(&o->depends))
     
     // remove from provides list
-    LinkedList2_Remove(&provides, &o->provides_node);
+    LinkedList1_Remove(&provides, &o->provides_node);
     
     NCDModuleInst_Backend_Dead(o->i);
 }
@@ -224,7 +217,7 @@ static void provide_func_die (void *vo)
     ASSERT(!o->dying)
     
     // if we have no depends, die immediately
-    if (LinkedList2_IsEmpty(&o->depends)) {
+    if (LinkedList1_IsEmpty(&o->depends)) {
         provide_free(o);
         return;
     }
@@ -233,11 +226,8 @@ static void provide_func_die (void *vo)
     o->dying = 1;
     
     // start collapsing our depends
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, &o->depends);
-    LinkedList2Node *n;
-    while (n = LinkedList2Iterator_Next(&it)) {
-        struct depend *d = UPPER_OBJECT(n, struct depend, provide_node);
+    for (LinkedList1Node *n = LinkedList1_GetFirst(&o->depends); n; n = LinkedList1Node_Next(n)) {
+        struct depend *d = UPPER_OBJECT(n, struct depend, depends_node);
         ASSERT(d->provide == o)
         
         // update depend to make sure it is collapsing
@@ -273,7 +263,7 @@ static void depend_func_new (void *vo, NCDModuleInst *i)
     }
     
     // insert to depends list
-    LinkedList2_Append(&depends, &o->depends_node);
+    LinkedList1_Append(&depends, &o->depends_node);
     
     // set no provide
     o->provide = NULL;
@@ -292,16 +282,16 @@ static void depend_free (struct depend *o)
 {
     if (o->provide) {
         // remove from provide's list
-        LinkedList2_Remove(&o->provide->depends, &o->provide_node);
+        LinkedList1_Remove(&o->provide->depends, &o->provide_node);
         
         // if provide is dying and is empty, let it die
-        if (o->provide->dying && LinkedList2_IsEmpty(&o->provide->depends)) {
+        if (o->provide->dying && LinkedList1_IsEmpty(&o->provide->depends)) {
             provide_free(o->provide);
         }
     }
     
     // remove from depends list
-    LinkedList2_Remove(&depends, &o->depends_node);
+    LinkedList1_Remove(&depends, &o->depends_node);
     
     NCDModuleInst_Backend_Dead(o->i);
 }
@@ -322,10 +312,10 @@ static void depend_func_clean (void *vo)
     }
     
     // remove from provide's list
-    LinkedList2_Remove(&o->provide->depends, &o->provide_node);
+    LinkedList1_Remove(&o->provide->depends, &o->provide_node);
     
     // if provide is dying and is empty, let it die
-    if (o->provide->dying && LinkedList2_IsEmpty(&o->provide->depends)) {
+    if (o->provide->dying && LinkedList1_IsEmpty(&o->provide->depends)) {
         provide_free(o->provide);
     }
     

+ 18 - 29
ncd/modules/net_dns.c

@@ -40,7 +40,7 @@
 #include <misc/bsort.h>
 #include <misc/balloc.h>
 #include <misc/compare.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <ncd/NCDModule.h>
 #include <ncd/NCDIfConfig.h>
 
@@ -50,17 +50,17 @@
 
 struct instance {
     NCDModuleInst *i;
-    LinkedList2 ipv4_dns_servers;
-    LinkedList2Node instances_node; // node in instances
+    LinkedList1 ipv4_dns_servers;
+    LinkedList1Node instances_node; // node in instances
 };
 
 struct ipv4_dns_entry {
-    LinkedList2Node list_node; // node in instance.ipv4_dns_servers
+    LinkedList1Node list_node; // node in instance.ipv4_dns_servers
     uint32_t addr;
     int priority;
 };
 
-static LinkedList2 instances;
+static LinkedList1 instances;
 
 static struct ipv4_dns_entry * add_ipv4_dns_entry (struct instance *o, uint32_t addr, int priority)
 {
@@ -75,7 +75,7 @@ static struct ipv4_dns_entry * add_ipv4_dns_entry (struct instance *o, uint32_t
     entry->priority = priority;
     
     // add to list
-    LinkedList2_Append(&o->ipv4_dns_servers, &entry->list_node);
+    LinkedList1_Append(&o->ipv4_dns_servers, &entry->list_node);
     
     return entry;
 }
@@ -83,7 +83,7 @@ static struct ipv4_dns_entry * add_ipv4_dns_entry (struct instance *o, uint32_t
 static void remove_ipv4_dns_entry (struct instance *o, struct ipv4_dns_entry *entry)
 {
     // remove from list
-    LinkedList2_Remove(&o->ipv4_dns_servers, &entry->list_node);
+    LinkedList1_Remove(&o->ipv4_dns_servers, &entry->list_node);
     
     // free entry
     free(entry);
@@ -91,8 +91,8 @@ static void remove_ipv4_dns_entry (struct instance *o, struct ipv4_dns_entry *en
 
 static void remove_ipv4_dns_entries (struct instance *o)
 {
-    LinkedList2Node *n;
-    while (n = LinkedList2_GetFirst(&o->ipv4_dns_servers)) {
+    LinkedList1Node *n;
+    while (n = LinkedList1_GetFirst(&o->ipv4_dns_servers)) {
         struct ipv4_dns_entry *e = UPPER_OBJECT(n, struct ipv4_dns_entry, list_node);
         remove_ipv4_dns_entry(o, e);
     }
@@ -102,14 +102,9 @@ static size_t num_servers (void)
 {
     size_t c = 0;
     
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, &instances);
-    LinkedList2Node *n;
-    while (n = LinkedList2Iterator_Next(&it)) {
+    for (LinkedList1Node *n = LinkedList1_GetFirst(&instances); n; n = LinkedList1Node_Next(n)) {
         struct instance *o = UPPER_OBJECT(n, struct instance, instances_node);
-        LinkedList2Iterator eit;
-        LinkedList2Iterator_InitForward(&eit, &o->ipv4_dns_servers);
-        while (LinkedList2Iterator_Next(&eit)) {
+        for (LinkedList1Node *en = LinkedList1_GetFirst(&o->ipv4_dns_servers); en; en = LinkedList1Node_Next(en)) {
             c++;
         }
     }
@@ -144,15 +139,9 @@ static int set_servers (void)
     size_t num_servers = 0;
     
     // fill sort array
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, &instances);
-    LinkedList2Node *n;
-    while (n = LinkedList2Iterator_Next(&it)) {
+    for (LinkedList1Node *n = LinkedList1_GetFirst(&instances); n; n = LinkedList1Node_Next(n)) {
         struct instance *o = UPPER_OBJECT(n, struct instance, instances_node);
-        LinkedList2Iterator eit;
-        LinkedList2Iterator_InitForward(&eit, &o->ipv4_dns_servers);
-        LinkedList2Node *en;
-        while (en = LinkedList2Iterator_Next(&eit)) {
+        for (LinkedList1Node *en = LinkedList1_GetFirst(&o->ipv4_dns_servers); en; en = LinkedList1Node_Next(en)) {
             struct ipv4_dns_entry *e = UPPER_OBJECT(en, struct ipv4_dns_entry, list_node);
             servers[num_servers].addr = e->addr;
             servers[num_servers].priority= e->priority;
@@ -192,7 +181,7 @@ fail0:
 
 static int func_globalinit (struct NCDModuleInitParams params)
 {
-    LinkedList2_Init(&instances);
+    LinkedList1_Init(&instances);
     
     return 1;
 }
@@ -203,7 +192,7 @@ static void func_new (void *vo, NCDModuleInst *i)
     o->i = i;
     
     // init servers list
-    LinkedList2_Init(&o->ipv4_dns_servers);
+    LinkedList1_Init(&o->ipv4_dns_servers);
     
     // get arguments
     NCDValRef servers_arg;
@@ -242,7 +231,7 @@ static void func_new (void *vo, NCDModuleInst *i)
     }
     
     // add to instances
-    LinkedList2_Append(&instances, &o->instances_node);
+    LinkedList1_Append(&instances, &o->instances_node);
     
     // set servers
     if (!set_servers()) {
@@ -255,7 +244,7 @@ static void func_new (void *vo, NCDModuleInst *i)
     return;
     
 fail2:
-    LinkedList2_Remove(&instances, &o->instances_node);
+    LinkedList1_Remove(&instances, &o->instances_node);
 fail1:
     remove_ipv4_dns_entries(o);
     NCDModuleInst_Backend_SetError(i);
@@ -267,7 +256,7 @@ static void func_die (void *vo)
     struct instance *o = vo;
     
     // remove from instances
-    LinkedList2_Remove(&instances, &o->instances_node);
+    LinkedList1_Remove(&instances, &o->instances_node);
     
     // set servers
     set_servers();

+ 16 - 16
ncd/modules/process_manager.c

@@ -50,7 +50,7 @@
 #include <string.h>
 
 #include <misc/offset.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <ncd/NCDModule.h>
 
 #include <generated/blog_channel_ncd_process_manager.h>
@@ -66,7 +66,7 @@
 
 struct instance {
     NCDModuleInst *i;
-    LinkedList2 processes_list;
+    LinkedList1 processes_list;
     int dying;
 };
 
@@ -74,7 +74,7 @@ struct process {
     struct instance *manager;
     char *name;
     BTimer retry_timer;
-    LinkedList2Node processes_list_node;
+    LinkedList1Node processes_list_node;
     int have_params;
     char *params_template_name;
     NCDValMem params_mem;
@@ -101,13 +101,13 @@ static void instance_free (struct instance *o);
 
 struct process * find_process (struct instance *o, const char *name)
 {
-    LinkedList2Node *n = LinkedList2_GetFirst(&o->processes_list);
+    LinkedList1Node *n = LinkedList1_GetFirst(&o->processes_list);
     while (n) {
         struct process *p = UPPER_OBJECT(n, struct process, processes_list_node);
         if (!strcmp(p->name, name)) {
             return p;
         }
-        n = LinkedList2Node_Next(n);
+        n = LinkedList1Node_Next(n);
     }
     
     return NULL;
@@ -139,7 +139,7 @@ int process_new (struct instance *o, const char *name, const char *template_name
     BTimer_Init(&p->retry_timer, RETRY_TIME, (BTimer_handler)process_retry_timer_handler, p);
     
     // insert to processes list
-    LinkedList2_Append(&o->processes_list, &p->processes_list_node);
+    LinkedList1_Append(&o->processes_list, &p->processes_list_node);
     
     // have no params
     p->have_params = 0;
@@ -168,7 +168,7 @@ int process_new (struct instance *o, const char *name, const char *template_name
     
 fail2:
     NCDValMem_Free(&mem);
-    LinkedList2_Remove(&o->processes_list, &p->processes_list_node);
+    LinkedList1_Remove(&o->processes_list, &p->processes_list_node);
     free(p->name);
 fail1:
     free(p);
@@ -188,7 +188,7 @@ void process_free (struct process *p)
     }
     
     // remove from processes list
-    LinkedList2_Remove(&o->processes_list, &p->processes_list_node);
+    LinkedList1_Remove(&o->processes_list, &p->processes_list_node);
     
     // free timer
     BReactor_RemoveTimer(o->i->iparams->reactor, &p->retry_timer);
@@ -241,7 +241,7 @@ void process_module_process_handler_event (struct process *p, int event)
             process_free(p);
         
             // if manager is dying and there are no more processes, let it die
-            if (o->dying && LinkedList2_IsEmpty(&o->processes_list)) {
+            if (o->dying && LinkedList1_IsEmpty(&o->processes_list)) {
                 instance_free(o);
             }
             
@@ -425,7 +425,7 @@ static void func_new (void *vo, NCDModuleInst *i)
     }
     
     // init processes list
-    LinkedList2_Init(&o->processes_list);
+    LinkedList1_Init(&o->processes_list);
     
     // set not dying
     o->dying = 0;
@@ -441,7 +441,7 @@ fail0:
 
 void instance_free (struct instance *o)
 {
-    ASSERT(LinkedList2_IsEmpty(&o->processes_list))
+    ASSERT(LinkedList1_IsEmpty(&o->processes_list))
     
     NCDModuleInst_Backend_Dead(o->i);
 }
@@ -452,16 +452,16 @@ static void func_die (void *vo)
     ASSERT(!o->dying)
     
     // request all processes to die
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, &o->processes_list);
-    LinkedList2Node *n;
-    while (n = LinkedList2Iterator_Next(&it)) {
+    LinkedList1Node *n = LinkedList1_GetFirst(&o->processes_list);
+    while (n) {
+        LinkedList1Node *next = LinkedList1Node_Next(n);
         struct process *p = UPPER_OBJECT(n, struct process, processes_list_node);
         process_stop(p);
+        n = next;
     }
     
     // if there are no processes, die immediately
-    if (LinkedList2_IsEmpty(&o->processes_list)) {
+    if (LinkedList1_IsEmpty(&o->processes_list)) {
         instance_free(o);
         return;
     }

+ 39 - 38
server/server.c

@@ -153,7 +153,7 @@ int clients_num;
 peerid_t clients_nextid;
 
 // clients list
-LinkedList2 clients;
+LinkedList1 clients;
 
 // clients tree (by ID)
 BAVL clients_tree;
@@ -489,7 +489,7 @@ int main (int argc, char *argv[])
     clients_nextid = 0;
     
     // initialize clients linked list
-    LinkedList2_Init(&clients);
+    LinkedList1_Init(&clients);
     
     // initialize clients tree
     BAVL_Init(&clients_tree, OFFSET_DIFF(struct client_data, id, tree_node), (BAVL_comparator)peerid_comparator, NULL);
@@ -509,27 +509,27 @@ int main (int argc, char *argv[])
     BReactor_Exec(&ss);
     
     // free clients
-    LinkedList2Node *node;
-    while (node = LinkedList2_GetFirst(&clients)) {
+    LinkedList1Node *node;
+    while (node = LinkedList1_GetFirst(&clients)) {
         struct client_data *client = UPPER_OBJECT(node, struct client_data, list_node);
         
         // remove outgoing knows
-        LinkedList2Node *node2;
-        while (node2 = LinkedList2_GetFirst(&client->know_out_list)) {
+        LinkedList1Node *node2;
+        while (node2 = LinkedList1_GetFirst(&client->know_out_list)) {
             struct peer_know *k = UPPER_OBJECT(node2, struct peer_know, from_node);
             remove_know(k);
         }
         
         // remove incoming knows
-        LinkedList2Node *node3;
-        while (node3 = LinkedList2_GetFirst(&client->know_in_list)) {
+        LinkedList1Node *node3;
+        while (node3 = LinkedList1_GetFirst(&client->know_in_list)) {
             struct peer_know *k = UPPER_OBJECT(node3, struct peer_know, to_node);
             remove_know(k);
         }
         
         // remove outgoing flows
-        LinkedList2Node *flow_node;
-        while (flow_node = LinkedList2_GetFirst(&client->peer_out_flows_list)) {
+        LinkedList1Node *flow_node;
+        while (flow_node = LinkedList1_GetFirst(&client->peer_out_flows_list)) {
             struct peer_flow *flow = UPPER_OBJECT(flow_node, struct peer_flow, src_list_node);
             ASSERT(flow->src_client == client)
             
@@ -908,15 +908,15 @@ void listener_handler (BListener *listener)
     
     // link in
     clients_num++;
-    LinkedList2_Append(&clients, &client->list_node);
+    LinkedList1_Append(&clients, &client->list_node);
     ASSERT_EXECUTE(BAVL_Insert(&clients_tree, &client->tree_node, NULL))
     
     // init knowledge lists
-    LinkedList2_Init(&client->know_out_list);
-    LinkedList2_Init(&client->know_in_list);
+    LinkedList1_Init(&client->know_out_list);
+    LinkedList1_Init(&client->know_in_list);
     
     // initialize peer flows from us list and tree (flows for sending messages to other clients)
-    LinkedList2_Init(&client->peer_out_flows_list);
+    LinkedList1_Init(&client->peer_out_flows_list);
     BAVL_Init(&client->peer_out_flows_tree, OFFSET_DIFF(struct peer_flow, dest_client_id, src_tree_node), (BAVL_comparator)peerid_comparator, NULL);
     
     // init dying
@@ -946,9 +946,9 @@ fail0:
 
 void client_dealloc (struct client_data *client)
 {
-    ASSERT(LinkedList2_IsEmpty(&client->know_out_list))
-    ASSERT(LinkedList2_IsEmpty(&client->know_in_list))
-    ASSERT(LinkedList2_IsEmpty(&client->peer_out_flows_list))
+    ASSERT(LinkedList1_IsEmpty(&client->know_out_list))
+    ASSERT(LinkedList1_IsEmpty(&client->know_in_list))
+    ASSERT(LinkedList1_IsEmpty(&client->peer_out_flows_list))
     
     // free I/O
     if (client->initstatus >= INITSTATUS_WAITHELLO && !client->dying) {
@@ -960,7 +960,7 @@ void client_dealloc (struct client_data *client)
     
     // link out
     BAVL_Remove(&clients_tree, &client->tree_node);
-    LinkedList2_Remove(&clients, &client->list_node);
+    LinkedList1_Remove(&clients, &client->list_node);
     clients_num--;
     
     // stop disconnect timer
@@ -1043,7 +1043,7 @@ int client_init_io (struct client_data *client)
     }
     
     // init list of flows
-    LinkedList2_Init(&client->output_peers_flows);
+    LinkedList1_Init(&client->output_peers_flows);
     
     return 1;
     
@@ -1068,8 +1068,8 @@ void client_dealloc_io (struct client_data *client)
     PacketPassFairQueue_PrepareFree(&client->output_peers_fairqueue);
     
     // remove flows to us
-    LinkedList2Node *node;
-    while (node = LinkedList2_GetFirst(&client->output_peers_flows)) {
+    LinkedList1Node *node;
+    while (node = LinkedList1_GetFirst(&client->output_peers_flows)) {
         struct peer_flow *flow = UPPER_OBJECT(node, struct peer_flow, dest_list_node);
         ASSERT(flow->dest_client == client)
         peer_flow_dealloc(flow);
@@ -1110,14 +1110,14 @@ void client_remove (struct client_data *client)
     }
     
     // remove outgoing knows
-    LinkedList2Node *node;
-    while (node = LinkedList2_GetFirst(&client->know_out_list)) {
+    LinkedList1Node *node;
+    while (node = LinkedList1_GetFirst(&client->know_out_list)) {
         struct peer_know *k = UPPER_OBJECT(node, struct peer_know, from_node);
         remove_know(k);
     }
     
     // remove outgoing flows
-    while (node = LinkedList2_GetFirst(&client->peer_out_flows_list)) {
+    while (node = LinkedList1_GetFirst(&client->peer_out_flows_list)) {
         struct peer_flow *flow = UPPER_OBJECT(node, struct peer_flow, src_list_node);
         ASSERT(flow->src_client == client)
         ASSERT(flow->dest_client->initstatus == INITSTATUS_COMPLETE)
@@ -1136,18 +1136,19 @@ void client_remove (struct client_data *client)
     BPending_Set(&client->dying_job);
     
     // inform other clients that 'client' is no more
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, &client->know_in_list);
-    while (node = LinkedList2Iterator_Next(&it)) {
+    node = LinkedList1_GetFirst(&client->know_in_list);
+    while (node) {
+        LinkedList1Node *next = LinkedList1Node_Next(node);
         struct peer_know *k = UPPER_OBJECT(node, struct peer_know, to_node);
         uninform_know(k);
+        node = next;
     }
 }
 
 void client_dying_job (struct client_data *client)
 {
     ASSERT(client->dying)
-    ASSERT(LinkedList2_IsEmpty(&client->know_in_list))
+    ASSERT(LinkedList1_IsEmpty(&client->know_in_list))
     
     client_dealloc(client);
     return;
@@ -1480,7 +1481,7 @@ void process_packet_hello (struct client_data *client, uint8_t *data, int data_l
     client->initstatus = INITSTATUS_COMPLETE;
     
     // publish client
-    for (LinkedList2Node *list_node = LinkedList2_GetFirst(&clients); list_node; list_node = LinkedList2Node_Next(list_node)) {
+    for (LinkedList1Node *list_node = LinkedList1_GetFirst(&clients); list_node; list_node = LinkedList1Node_Next(list_node)) {
         struct client_data *client2 = UPPER_OBJECT(list_node, struct client_data, list_node);
         if (client2 == client || client2->initstatus != INITSTATUS_COMPLETE || client2->dying || !clients_allowed(client, client2)) {
             continue;
@@ -1705,11 +1706,11 @@ struct peer_flow * peer_flow_create (struct client_data *src_client, struct clie
     flow->dest_client_id = dest_client->id;
     
     // add to source list and tree
-    LinkedList2_Append(&flow->src_client->peer_out_flows_list, &flow->src_list_node);
+    LinkedList1_Append(&flow->src_client->peer_out_flows_list, &flow->src_list_node);
     ASSERT_EXECUTE(BAVL_Insert(&flow->src_client->peer_out_flows_tree, &flow->src_tree_node, NULL))
     
     // add to destination client list
-    LinkedList2_Append(&flow->dest_client->output_peers_flows, &flow->dest_list_node);
+    LinkedList1_Append(&flow->dest_client->output_peers_flows, &flow->dest_list_node);
     
     // have no I/O
     flow->have_io = 0;
@@ -1736,12 +1737,12 @@ void peer_flow_dealloc (struct peer_flow *flow)
     }
     
     // remove from destination client list
-    LinkedList2_Remove(&flow->dest_client->output_peers_flows, &flow->dest_list_node);
+    LinkedList1_Remove(&flow->dest_client->output_peers_flows, &flow->dest_list_node);
     
     // remove from source list and hash table
     if (flow->src_client) {
         BAVL_Remove(&flow->src_client->peer_out_flows_tree, &flow->src_tree_node);
-        LinkedList2_Remove(&flow->src_client->peer_out_flows_list, &flow->src_list_node);
+        LinkedList1_Remove(&flow->src_client->peer_out_flows_list, &flow->src_list_node);
     }
     
     // free memory
@@ -1806,7 +1807,7 @@ void peer_flow_disconnect (struct peer_flow *flow)
     
     // remove from source list and hash table
     BAVL_Remove(&flow->src_client->peer_out_flows_tree, &flow->src_tree_node);
-    LinkedList2_Remove(&flow->src_client->peer_out_flows_list, &flow->src_list_node);
+    LinkedList1_Remove(&flow->src_client->peer_out_flows_list, &flow->src_list_node);
     
     // set no source
     flow->src_client = NULL;
@@ -2152,8 +2153,8 @@ struct peer_know * create_know (struct client_data *from, struct client_data *to
     k->relay_client = relay_client;
     
     // append to lists
-    LinkedList2_Append(&from->know_out_list, &k->from_node);
-    LinkedList2_Append(&to->know_in_list, &k->to_node);
+    LinkedList1_Append(&from->know_out_list, &k->from_node);
+    LinkedList1_Append(&to->know_in_list, &k->to_node);
     
     // init and set inform job to inform client 'from' about client 'to'
     BPending_Init(&k->inform_job, BReactor_PendingGroup(&ss), (BPending_handler)know_inform_job_handler, k);
@@ -2174,8 +2175,8 @@ void remove_know (struct peer_know *k)
     BPending_Free(&k->inform_job);
     
     // remove from lists
-    LinkedList2_Remove(&k->to->know_in_list, &k->to_node);
-    LinkedList2_Remove(&k->from->know_out_list, &k->from_node);
+    LinkedList1_Remove(&k->to->know_in_list, &k->to_node);
+    LinkedList1_Remove(&k->from->know_out_list, &k->from_node);
     
     // free structure
     free(k);

+ 10 - 10
server/server.h

@@ -30,7 +30,7 @@
 #include <stdint.h>
 
 #include <protocol/scproto.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <structure/BAVL.h>
 #include <flow/PacketProtoDecoder.h>
 #include <flow/PacketStreamSender.h>
@@ -87,9 +87,9 @@ struct peer_flow {
     // node in source client hash table (by destination), only when src_client != NULL
     BAVLNode src_tree_node;
     // node in source client list, only when src_client != NULL
-    LinkedList2Node src_list_node;
+    LinkedList1Node src_list_node;
     // node in destination client list
-    LinkedList2Node dest_list_node;
+    LinkedList1Node dest_list_node;
     // output chain
     int have_io;
     PacketPassFairQueueFlow qflow;
@@ -112,8 +112,8 @@ struct peer_know {
     struct client_data *to;
     int relay_server;
     int relay_client;
-    LinkedList2Node from_node;
-    LinkedList2Node to_node;
+    LinkedList1Node from_node;
+    LinkedList1Node to_node;
     BPending inform_job;
     BPending uninform_job;
 };
@@ -148,16 +148,16 @@ struct client_data {
     peerid_t id;
     
     // node in clients linked list
-    LinkedList2Node list_node;
+    LinkedList1Node list_node;
     // node in clients tree (by ID)
     BAVLNode tree_node;
     
     // knowledge lists
-    LinkedList2 know_out_list;
-    LinkedList2 know_in_list;
+    LinkedList1 know_out_list;
+    LinkedList1 know_in_list;
     
     // flows from us
-    LinkedList2 peer_out_flows_list;
+    LinkedList1 peer_out_flows_list;
     BAVL peer_out_flows_tree;
     
     // whether it's being removed
@@ -182,5 +182,5 @@ struct client_data {
     // output peers flow
     PacketPassPriorityQueueFlow output_peers_qflow;
     PacketPassFairQueue output_peers_fairqueue;
-    LinkedList2 output_peers_flows;
+    LinkedList1 output_peers_flows;
 };

+ 0 - 406
structure/LinkedList2.h

@@ -1,406 +0,0 @@
-/**
- * @file LinkedList2.h
- * @author Ambroz Bizjak <ambrop7@gmail.com>
- * 
- * @section LICENSE
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the author nor the
- *    names of its contributors may be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- * @section DESCRIPTION
- * 
- * Doubly linked list that support multiple iterations and removing
- * aritrary elements during iteration.
- */
-
-#ifndef BADVPN_STRUCTURE_LINKEDLIST2_H
-#define BADVPN_STRUCTURE_LINKEDLIST2_H
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <misc/debug.h>
-
-struct LinkedList2Iterator_t;
-
-/**
- * Linked list node.
- */
-typedef struct LinkedList2Node_t
-{
-    struct LinkedList2Node_t *p;
-    struct LinkedList2Node_t *n;
-    struct LinkedList2Iterator_t *it;
-} LinkedList2Node;
-
-/**
- * Doubly linked list that support multiple iterations and removing
- * aritrary elements during iteration.
- */
-typedef struct
-{
-    LinkedList2Node *first;
-    LinkedList2Node *last;
-} LinkedList2;
-
-/**
- * Linked list iterator.
- */
-typedef struct LinkedList2Iterator_t
-{
-    LinkedList2 *list;
-    int8_t dir;
-    struct LinkedList2Node_t *e;
-    struct LinkedList2Iterator_t *pi;
-    struct LinkedList2Iterator_t *ni;
-} LinkedList2Iterator;
-
-/**
- * Initializes the linked list.
- * 
- * @param list list to initialize
- */
-static void LinkedList2_Init (LinkedList2 *list);
-
-/**
- * Determines if the list is empty.
- * 
- * @param list the list
- * @return 1 if empty, 0 if not
- */
-static int LinkedList2_IsEmpty (LinkedList2 *list);
-
-/**
- * Returns the first node of the list.
- * 
- * @param list the list
- * @return first node of the list, or NULL if the list is empty
- */
-static LinkedList2Node * LinkedList2_GetFirst (LinkedList2 *list);
-
-/**
- * Returns the last node of the list.
- * 
- * @param list the list
- * @return last node of the list, or NULL if the list is empty
- */
-static LinkedList2Node * LinkedList2_GetLast (LinkedList2 *list);
-
-/**
- * Inserts a node to the beginning of the list.
- * 
- * @param list the list
- * @param node uninitialized node to insert
- */
-static void LinkedList2_Prepend (LinkedList2 *list, LinkedList2Node *node);
-
-/**
- * Inserts a node to the end of the list.
- * 
- * @param list the list
- * @param node uninitialized node to insert
- */
-static void LinkedList2_Append (LinkedList2 *list, LinkedList2Node *node);
-
-/**
- * Inserts a node before a given node.
- * 
- * @param list the list
- * @param node uninitialized node to insert
- * @param target node in the list to insert before
- */
-static void LinkedList2_InsertBefore (LinkedList2 *list, LinkedList2Node *node, LinkedList2Node *target);
-
-/**
- * Inserts a node after a given node.
- * 
- * @param list the list
- * @param node uninitialized node to insert
- * @param target node in the list to insert after
- */
-static void LinkedList2_InsertAfter (LinkedList2 *list, LinkedList2Node *node, LinkedList2Node *target);
-
-/**
- * Removes a node from the list.
- * 
- * @param list the list
- * @param node node to remove
- */
-static void LinkedList2_Remove (LinkedList2 *list, LinkedList2Node *node);
-
-/**
- * Returns the next node of a given node.
- * 
- * @param node reference node
- * @return next node, or NULL if none
- */
-static LinkedList2Node * LinkedList2Node_Next (LinkedList2Node *node);
-
-/**
- * Returns the previous node of a given node.
- * 
- * @param node reference node
- * @return previous node, or NULL if none
- */
-static LinkedList2Node * LinkedList2Node_Prev (LinkedList2Node *node);
-
-/**
- * Initializes a linked list iterator.
- * The iterator memory must remain available until either of these occurs:
- *   - the list is no longer needed, or
- *   - the iterator is freed with {@link LinkedList2Iterator_Free}, or
- *   - the iterator reaches the end of iteration.
- * 
- * @param it uninitialized iterator to initialize
- * @param list the list
- * @param dir direction of iteration. Must be 1 (forward) or -1 (backward).
- * @param node current position of the iterator. Can be a node in the list
- *             or NULL for end of iteration.
- */
-static void LinkedList2Iterator_Init (LinkedList2Iterator *it, LinkedList2 *list, int dir, LinkedList2Node *node);
-
-/**
- * Frees a linked list iterator.
- * 
- * @param it iterator to free
- */
-static void LinkedList2Iterator_Free (LinkedList2Iterator *it);
-
-/**
- * Initializes a linked list iterator with forward direction, with the current
- * position at the first node (or at the end of iteration if there are no nodes).
- * The iterator memory must remain available until either of these occurs:
- *   - the list is no longer needed, or
- *   - the iterator is freed with {@link LinkedList2Iterator_Free}, or
- *   - the iterator reaches the end of iteration.
- * 
- * @param it uninitialized iterator to initialize
- * @param list the list
- */
-static void LinkedList2Iterator_InitForward (LinkedList2Iterator *it, LinkedList2 *list);
-
-/**
- * Initializes a linked list iterator with backward direction, with the current
- * position at the last node (or at the end of iteration if there are no nodes).
- * The iterator memory must remain available until either of these occurs:
- *   - the list is no longer needed, or
- *   - the iterator is freed with {@link LinkedList2Iterator_Free}, or
- *   - the iterator reaches the end of iteration.
- * 
- * @param it uninitialized iterator to initialize
- * @param list the list
- */
-static void LinkedList2Iterator_InitBackward (LinkedList2Iterator *it, LinkedList2 *list);
-
-/**
- * Moves the iterator one node forward or backward (depending on its direction), or,
- * if it's at the last or first node (depending on the direction), it reaches
- * the end of iteration, or, if it's at the end of iteration, it remains there.
- * Returns the the previous position.
- * 
- * @param it the iterator
- * @return node on the position of iterator before it was (possibly) moved, or NULL
- *         if it was at the end of iteration
- */
-static LinkedList2Node * LinkedList2Iterator_Next (LinkedList2Iterator *it);
-
-void LinkedList2_Init (LinkedList2 *list)
-{
-    list->first = NULL;
-    list->last = NULL;
-}
-
-int LinkedList2_IsEmpty (LinkedList2 *list)
-{
-    return (!list->first);
-}
-
-LinkedList2Node * LinkedList2_GetFirst (LinkedList2 *list)
-{
-    return (list->first);
-}
-
-LinkedList2Node * LinkedList2_GetLast (LinkedList2 *list)
-{
-    return (list->last);
-}
-
-void LinkedList2_Prepend (LinkedList2 *list, LinkedList2Node *node)
-{
-    node->p = NULL;
-    node->n = list->first;
-    if (list->first) {
-        list->first->p = node;
-    } else {
-        list->last = node;
-    }
-    list->first = node;
-    
-    node->it = NULL;
-}
-
-void LinkedList2_Append (LinkedList2 *list, LinkedList2Node *node)
-{
-    node->p = list->last;
-    node->n = NULL;
-    if (list->last) {
-        list->last->n = node;
-    } else {
-        list->first = node;
-    }
-    list->last = node;
-    
-    node->it = NULL;
-}
-
-void LinkedList2_InsertBefore (LinkedList2 *list, LinkedList2Node *node, LinkedList2Node *target)
-{
-    node->p = target->p;
-    node->n = target;
-    if (target->p) {
-        target->p->n = node;
-    } else {
-        list->first = node;
-    }
-    target->p = node;
-    
-    node->it = NULL;
-}
-
-void LinkedList2_InsertAfter (LinkedList2 *list, LinkedList2Node *node, LinkedList2Node *target)
-{
-    node->p = target;
-    node->n = target->n;
-    if (target->n) {
-        target->n->p = node;
-    } else {
-        list->last = node;
-    }
-    target->n = node;
-    
-    node->it = NULL;
-}
-
-void LinkedList2_Remove (LinkedList2 *list, LinkedList2Node *node)
-{
-    // jump iterators
-    while (node->it) {
-        LinkedList2Iterator_Next(node->it);
-    }
-    
-    // remove from list
-    if (node->p) {
-        node->p->n = node->n;
-    } else {
-        list->first = node->n;
-    }
-    if (node->n) {
-        node->n->p = node->p;
-    } else {
-        list->last = node->p;
-    }
-}
-
-LinkedList2Node * LinkedList2Node_Next (LinkedList2Node *node)
-{
-    return node->n;
-}
-
-LinkedList2Node * LinkedList2Node_Prev (LinkedList2Node *node)
-{
-    return node->p;
-}
-
-void LinkedList2Iterator_Init (LinkedList2Iterator *it, LinkedList2 *list, int dir, LinkedList2Node *node)
-{
-    ASSERT(dir == 1 || dir == -1)
-    
-    it->list = list;
-    it->dir = dir;
-    it->e = node;
-    
-    if (it->e) {
-        // link into node's iterator list
-        it->pi = NULL;
-        it->ni = it->e->it;
-        if (it->e->it) {
-            it->e->it->pi = it;
-        }
-        it->e->it = it;
-    }
-}
-
-void LinkedList2Iterator_Free (LinkedList2Iterator *it)
-{
-    if (it->e) {
-        // remove from node's iterator list
-        if (it->ni) {
-            it->ni->pi = it->pi;
-        }
-        if (it->pi) {
-            it->pi->ni = it->ni;
-        } else {
-            it->e->it = it->ni;
-        }
-    }
-}
-
-void LinkedList2Iterator_InitForward (LinkedList2Iterator *it, LinkedList2 *list)
-{
-    LinkedList2Iterator_Init(it, list, 1, list->first);
-}
-
-void LinkedList2Iterator_InitBackward (LinkedList2Iterator *it, LinkedList2 *list)
-{
-    LinkedList2Iterator_Init(it, list, -1, list->last);
-}
-
-LinkedList2Node * LinkedList2Iterator_Next (LinkedList2Iterator *it)
-{
-    // remember original entry
-    LinkedList2Node *orig = it->e;
-    
-    // jump to next entry
-    if (it->e) {
-        // get next entry
-        LinkedList2Node *next;
-        switch (it->dir) {
-            case 1:
-                next = it->e->n;
-                break;
-            case -1:
-                next = it->e->p;
-                break;
-            default:
-                ASSERT(0);
-        }
-        // destroy interator
-        LinkedList2Iterator_Free(it);
-        // re-initialize at next entry
-        LinkedList2Iterator_Init(it, it->list, it->dir, next);
-    }
-    
-    // return original entry
-    return orig;
-}
-
-#endif

+ 5 - 9
system/BProcess.c

@@ -56,13 +56,9 @@ static void call_handler (BProcess *o, int normally, uint8_t normally_exit_statu
 
 static BProcess * find_process (BProcessManager *o, pid_t pid)
 {
-    LinkedList2Iterator it;
-    LinkedList2Iterator_InitForward(&it, &o->processes);
-    LinkedList2Node *node;
-    while (node = LinkedList2Iterator_Next(&it)) {
+    for (LinkedList1Node *node = LinkedList1_GetFirst(&o->processes); node; node = LinkedList1Node_Next(node)) {
         BProcess *p = UPPER_OBJECT(node, BProcess, list_node);
         if (p->pid == pid) {
-            LinkedList2Iterator_Free(&it);
             return p;
         }
     }
@@ -145,7 +141,7 @@ int BProcessManager_Init (BProcessManager *o, BReactor *reactor)
     }
     
     // init processes list
-    LinkedList2_Init(&o->processes);
+    LinkedList1_Init(&o->processes);
     
     // init wait job
     BPending_Init(&o->wait_job, BReactor_PendingGroup(o->reactor), (BPending_handler)wait_job_handler, o);
@@ -160,7 +156,7 @@ fail0:
 
 void BProcessManager_Free (BProcessManager *o)
 {
-    ASSERT(LinkedList2_IsEmpty(&o->processes))
+    ASSERT(LinkedList1_IsEmpty(&o->processes))
     DebugObject_Free(&o->d_obj);
     
     // free wait job
@@ -335,7 +331,7 @@ int BProcess_Init2 (BProcess *o, BProcessManager *m, BProcess_handler handler, v
     o->pid = pid;
     
     // add to processes list
-    LinkedList2_Append(&o->m->processes, &o->list_node);
+    LinkedList1_Append(&o->m->processes, &o->list_node);
     
     DebugObject_Init(&o->d_obj);
     DebugError_Init(&o->d_err, BReactor_PendingGroup(m->reactor));
@@ -370,7 +366,7 @@ void BProcess_Free (BProcess *o)
     DebugObject_Free(&o->d_obj);
     
     // remove from processes list
-    LinkedList2_Remove(&o->m->processes, &o->list_node);
+    LinkedList1_Remove(&o->m->processes, &o->list_node);
 }
 
 int BProcess_Terminate (BProcess *o)

+ 3 - 3
system/BProcess.h

@@ -35,7 +35,7 @@
 
 #include <misc/debug.h>
 #include <misc/debugerror.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <base/DebugObject.h>
 #include <system/BUnixSignal.h>
 #include <base/BPending.h>
@@ -48,7 +48,7 @@
 typedef struct {
     BReactor *reactor;
     BUnixSignal signal;
-    LinkedList2 processes;
+    LinkedList1 processes;
     BPending wait_job;
     DebugObject d_obj;
 } BProcessManager;
@@ -74,7 +74,7 @@ typedef struct {
     BProcess_handler handler;
     void *user;
     pid_t pid;
-    LinkedList2Node list_node; // node in BProcessManager.processes
+    LinkedList1Node list_node; // node in BProcessManager.processes
     DebugObject d_obj;
     DebugError d_err;
 } BProcess;

+ 16 - 16
threadwork/BThreadWork.c

@@ -57,16 +57,16 @@ static void * dispatcher_thread (struct BThreadWorkDispatcher_thread *t)
             break;
         }
         
-        if (LinkedList2_IsEmpty(&o->pending_list)) {
+        if (LinkedList1_IsEmpty(&o->pending_list)) {
             // wait for event
             ASSERT_FORCE(pthread_cond_wait(&t->new_cond, &o->mutex) == 0)
             continue;
         }
         
         // grab the work
-        BThreadWork *w = UPPER_OBJECT(LinkedList2_GetFirst(&o->pending_list), BThreadWork, list_node);
+        BThreadWork *w = UPPER_OBJECT(LinkedList1_GetFirst(&o->pending_list), BThreadWork, list_node);
         ASSERT(w->state == BTHREADWORK_STATE_PENDING)
-        LinkedList2_Remove(&o->pending_list, &w->list_node);
+        LinkedList1_Remove(&o->pending_list, &w->list_node);
         t->running_work = w;
         w->state = BTHREADWORK_STATE_RUNNING;
         
@@ -77,7 +77,7 @@ static void * dispatcher_thread (struct BThreadWorkDispatcher_thread *t)
         
         // release the work
         t->running_work = NULL;
-        LinkedList2_Append(&o->finished_list, &w->list_node);
+        LinkedList1_Append(&o->finished_list, &w->list_node);
         w->state = BTHREADWORK_STATE_FINISHED;
         ASSERT_FORCE(sem_post(&w->finished_sem) == 0)
         
@@ -103,18 +103,18 @@ static void dispatch_job (BThreadWorkDispatcher *o)
     ASSERT_FORCE(pthread_mutex_lock(&o->mutex) == 0)
     
     // check for finished job
-    if (LinkedList2_IsEmpty(&o->finished_list)) {
+    if (LinkedList1_IsEmpty(&o->finished_list)) {
         ASSERT_FORCE(pthread_mutex_unlock(&o->mutex) == 0)
         return;
     }
     
     // grab finished job
-    BThreadWork *w = UPPER_OBJECT(LinkedList2_GetFirst(&o->finished_list), BThreadWork, list_node);
+    BThreadWork *w = UPPER_OBJECT(LinkedList1_GetFirst(&o->finished_list), BThreadWork, list_node);
     ASSERT(w->state == BTHREADWORK_STATE_FINISHED)
-    LinkedList2_Remove(&o->finished_list, &w->list_node);
+    LinkedList1_Remove(&o->finished_list, &w->list_node);
     
     // schedule more
-    if (!LinkedList2_IsEmpty(&o->finished_list)) {
+    if (!LinkedList1_IsEmpty(&o->finished_list)) {
         BPending_Set(&o->more_job);
     }
     
@@ -213,10 +213,10 @@ int BThreadWorkDispatcher_Init (BThreadWorkDispatcher *o, BReactor *reactor, int
     
     if (num_threads_hint > 0) {
         // init pending list
-        LinkedList2_Init(&o->pending_list);
+        LinkedList1_Init(&o->pending_list);
         
         // init finished list
-        LinkedList2_Init(&o->finished_list);
+        LinkedList1_Init(&o->finished_list);
         
         // init mutex
         if (pthread_mutex_init(&o->mutex, NULL) != 0) {
@@ -309,9 +309,9 @@ void BThreadWorkDispatcher_Free (BThreadWorkDispatcher *o)
 {
     #ifdef BADVPN_THREADWORK_USE_PTHREAD
     if (o->num_threads > 0) {
-        ASSERT(LinkedList2_IsEmpty(&o->pending_list))
+        ASSERT(LinkedList1_IsEmpty(&o->pending_list))
         for (int i = 0; i < o->num_threads; i++) { ASSERT(!o->threads[i].running_work) }
-        ASSERT(LinkedList2_IsEmpty(&o->finished_list))
+        ASSERT(LinkedList1_IsEmpty(&o->finished_list))
     }
     #endif
     DebugObject_Free(&o->d_obj);
@@ -370,7 +370,7 @@ void BThreadWork_Init (BThreadWork *o, BThreadWorkDispatcher *d, BThreadWork_han
         
         // post work
         ASSERT_FORCE(pthread_mutex_lock(&d->mutex) == 0)
-        LinkedList2_Append(&d->pending_list, &o->list_node);
+        LinkedList1_Append(&d->pending_list, &o->list_node);
         for (int i = 0; i < d->num_threads; i++) {
             if (!d->threads[i].running_work) {
                 ASSERT_FORCE(pthread_cond_signal(&d->threads[i].new_cond) == 0)
@@ -406,7 +406,7 @@ void BThreadWork_Free (BThreadWork *o)
                 BLog(BLOG_DEBUG, "remove pending work");
                 
                 // remove from pending list
-                LinkedList2_Remove(&d->pending_list, &o->list_node);
+                LinkedList1_Remove(&d->pending_list, &o->list_node);
             } break;
             
             case BTHREADWORK_STATE_RUNNING: {
@@ -420,14 +420,14 @@ void BThreadWork_Free (BThreadWork *o)
                 ASSERT(o->state == BTHREADWORK_STATE_FINISHED)
                 
                 // remove from finished list
-                LinkedList2_Remove(&d->finished_list, &o->list_node);
+                LinkedList1_Remove(&d->finished_list, &o->list_node);
             } break;
             
             case BTHREADWORK_STATE_FINISHED: {
                 BLog(BLOG_DEBUG, "remove finished work");
                 
                 // remove from finished list
-                LinkedList2_Remove(&d->finished_list, &o->list_node);
+                LinkedList1_Remove(&d->finished_list, &o->list_node);
             } break;
             
             case BTHREADWORK_STATE_FORGOTTEN: {

+ 4 - 4
threadwork/BThreadWork.h

@@ -41,7 +41,7 @@
 #endif
 
 #include <misc/debug.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <base/DebugObject.h>
 #include <system/BReactor.h>
 
@@ -82,8 +82,8 @@ struct BThreadWorkDispatcher_thread {
 typedef struct BThreadWorkDispatcher_s {
     BReactor *reactor;
     #ifdef BADVPN_THREADWORK_USE_PTHREAD
-    LinkedList2 pending_list;
-    LinkedList2 finished_list;
+    LinkedList1 pending_list;
+    LinkedList1 finished_list;
     pthread_mutex_t mutex;
     int pipe[2];
     BFileDescriptor bfd;
@@ -105,7 +105,7 @@ typedef struct BThreadWork_s {
     union {
         #ifdef BADVPN_THREADWORK_USE_PTHREAD
         struct {
-            LinkedList2Node list_node;
+            LinkedList1Node list_node;
             int state;
             sem_t finished_sem;
         };

+ 8 - 8
tun2socks/tun2socks.c

@@ -43,7 +43,7 @@
 #include <misc/byteorder.h>
 #include <misc/balloc.h>
 #include <misc/open_standard_streams.h>
-#include <structure/LinkedList2.h>
+#include <structure/LinkedList1.h>
 #include <base/BLog.h>
 #include <system/BReactor.h>
 #include <system/BSignal.h>
@@ -107,7 +107,7 @@ struct {
 struct tcp_client {
     dead_t dead;
     dead_t dead_client;
-    LinkedList2Node list_node;
+    LinkedList1Node list_node;
     BAddr local_addr;
     BAddr remote_addr;
     struct tcp_pcb *pcb;
@@ -172,7 +172,7 @@ struct netif netif;
 struct tcp_pcb *listener;
 
 // TCP clients
-LinkedList2 tcp_clients;
+LinkedList1 tcp_clients;
 
 // number of clients
 int num_clients;
@@ -354,7 +354,7 @@ int main (int argc, char **argv)
     listener = NULL;
     
     // init clients list
-    LinkedList2_Init(&tcp_clients);
+    LinkedList1_Init(&tcp_clients);
     
     // init number of clients
     num_clients = 0;
@@ -364,8 +364,8 @@ int main (int argc, char **argv)
     BReactor_Exec(&ss);
     
     // free clients
-    LinkedList2Node *node;
-    while (node = LinkedList2_GetFirst(&tcp_clients)) {
+    LinkedList1Node *node;
+    while (node = LinkedList1_GetFirst(&tcp_clients)) {
         struct tcp_client *client = UPPER_OBJECT(node, struct tcp_client, list_node);
         client_murder(client);
     }
@@ -991,7 +991,7 @@ err_t listener_accept_func (void *arg, struct tcp_pcb *newpcb, err_t err)
     DEAD_INIT(client->dead_client);
     
     // add to linked list
-    LinkedList2_Append(&tcp_clients, &client->list_node);
+    LinkedList1_Append(&tcp_clients, &client->list_node);
     
     // increment counter
     ASSERT(num_clients >= 0)
@@ -1170,7 +1170,7 @@ void client_dealloc (struct tcp_client *client)
     num_clients--;
     
     // remove client entry
-    LinkedList2_Remove(&tcp_clients, &client->list_node);
+    LinkedList1_Remove(&tcp_clients, &client->list_node);
     
     // kill dead var
     DEAD_KILL(client->dead);