Semi-success with "fair" sharing without NACKs

There was a bug, causing empty queue on consumer nodes
diff --git a/model/fw/per-fib-limits.cc b/model/fw/per-fib-limits.cc
index 9703bd7..8190329 100644
--- a/model/fw/per-fib-limits.cc
+++ b/model/fw/per-fib-limits.cc
@@ -89,6 +89,11 @@
 {
   NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
   // totally override all (if any) parent processing
+
+  if (header->GetInterestLifetime () < Seconds (0.1))
+    {
+      NS_LOG_DEBUG( "What the fuck? Why interest lifetime is so short? [" << header->GetInterestLifetime ().ToDouble (Time::S) << "s]");
+    }
   
   pit::Entry::out_iterator outgoing =
     pitEntry->GetOutgoing ().find (outFace);
@@ -119,9 +124,18 @@
 
   // hack
   // offset lifetime, so we don't keep entries in queue for too long
-  pitEntry->OffsetLifetime (Seconds (- 0.9 * pitEntry->GetInterest ()->GetInterestLifetime ().ToDouble (Time::S)));
+  // pitEntry->OffsetLifetime (Seconds (0.010) + );
+  // std::cerr << (pitEntry->GetExpireTime () - Simulator::Now ()).ToDouble (Time::S) * 1000 << "ms" << std::endl;
+  pitEntry->OffsetLifetime (Seconds (-pitEntry->GetInterest ()->GetInterestLifetime ().ToDouble (Time::S)));
+  pitEntry->UpdateLifetime (Seconds (0.10));
   
   bool enqueued = m_pitQueues[outFace].Enqueue (inFace, pitEntry);
+
+  // if (Simulator::GetContext () == 6)
+  //   {
+  //     // std::cerr << "Attempt to enqueue packet for " << pitEntry->GetPrefix () << ": " << (enqueued?"succeeded":"failed") << std::endl;
+  //   }
+  
   if (enqueued)
     {
       NS_LOG_DEBUG ("PIT entry is enqueued for delayed processing. Telling that we forwarding possible");
@@ -137,17 +151,17 @@
   NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
   super::WillEraseTimedOutPendingInterest (pitEntry);
 
-  Ptr<Packet> pkt = Create<Packet> ();
-  Ptr<InterestHeader> nackHeader = Create<InterestHeader> (*pitEntry->GetInterest ());
-  nackHeader->SetNack (99);
-  pkt->AddHeader (*nackHeader);
+  // Ptr<Packet> pkt = Create<Packet> ();
+  // Ptr<InterestHeader> nackHeader = Create<InterestHeader> (*pitEntry->GetInterest ());
+  // nackHeader->SetNack (99);
+  // pkt->AddHeader (*nackHeader);
 
-  for (pit::Entry::in_container::iterator face = pitEntry->GetIncoming ().begin ();
-       face != pitEntry->GetIncoming ().end ();
-       face ++)
-    {
-      face->m_face->Send (pkt->Copy ());
-    }
+  // for (pit::Entry::in_container::iterator face = pitEntry->GetIncoming ().begin ();
+  //      face != pitEntry->GetIncoming ().end ();
+  //      face ++)
+  //   {
+  //     face->m_face->Send (pkt->Copy ());
+  //   }
   
   PitQueue::Remove (pitEntry);
   
@@ -199,17 +213,26 @@
         {
           // now we have enqueued packet and have slot available. Send out delayed packet
           Ptr<pit::Entry> pitEntry = queue->second.Pop ();
+          NS_ASSERT_MSG (pitEntry != 0, "There *have to* be an entry in queue");
 
           // hack
           // offset lifetime back, so PIT entry wouldn't prematurely expire
-          pitEntry->OffsetLifetime (Seconds (0.7 * pitEntry->GetInterest ()->GetInterestLifetime ().ToDouble (Time::S)));
           
-          NS_ASSERT_MSG (pitEntry != 0, "There *have to* be an entry in queue");
-          
+          // std::cerr << Simulator::GetContext () << ", Lifetime before " << (pitEntry->GetExpireTime () - Simulator::Now ()).ToDouble (Time::S) << "s" << std::endl;
+          pitEntry->OffsetLifetime (Seconds (-0.10) + Seconds (pitEntry->GetInterest ()->GetInterestLifetime ().ToDouble (Time::S)));
+          // std::cerr << Simulator::GetContext () << ", Lifetime after " << (pitEntry->GetExpireTime () - Simulator::Now ()).ToDouble (Time::S) << "s" << std::endl;
+                    
           pitEntry->AddOutgoing (outFace);
 
           Ptr<Packet> packetToSend = Create<Packet> ();
-          packetToSend->AddHeader (*pitEntry->GetInterest ());
+          Ptr<InterestHeader> header = Create<InterestHeader> (*pitEntry->GetInterest ());
+          NS_LOG_DEBUG ("Adjust interest lifetime to " << pitEntry->GetExpireTime () - Simulator::Now () << "s");
+          // header->SetInterestLifetime (
+          //                              // header->GetInterestLifetime () - ()
+          //                              pitEntry->GetExpireTime () - Simulator::Now ()
+          //                              );
+          // std::cerr << "New lifetime: " << (pitEntry->GetExpireTime () - Simulator::Now ()).ToDouble (Time::S) << "s" << std::endl;
+          packetToSend->AddHeader (*header);
 
           NS_LOG_DEBUG ("Delayed sending for " << pitEntry->GetPrefix ());
           outFace->Send (packetToSend);
@@ -226,30 +249,30 @@
   // super::DidReceiveValidNack (inFace, nackCode, pitEntry);
   // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
 
-  Ptr<Packet> pkt = Create<Packet> ();
-  Ptr<InterestHeader> nackHeader = Create<InterestHeader> (*pitEntry->GetInterest ());
-  nackHeader->SetNack (99);
-  pkt->AddHeader (*nackHeader);
+  // Ptr<Packet> pkt = Create<Packet> ();
+  // Ptr<InterestHeader> nackHeader = Create<InterestHeader> (*pitEntry->GetInterest ());
+  // nackHeader->SetNack (99);
+  // pkt->AddHeader (*nackHeader);
 
-  for (pit::Entry::in_container::iterator face = pitEntry->GetIncoming ().begin ();
-       face != pitEntry->GetIncoming ().end ();
-       face ++)
-    {
-      face->m_face->Send (pkt->Copy ());
-    }
+  // for (pit::Entry::in_container::iterator face = pitEntry->GetIncoming ().begin ();
+  //      face != pitEntry->GetIncoming ().end ();
+  //      face ++)
+  //   {
+  //     face->m_face->Send (pkt->Copy ());
+  //   }
   
-  PitQueue::Remove (pitEntry);
+  // PitQueue::Remove (pitEntry);
 
-  for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
-       face != pitEntry->GetOutgoing ().end ();
-       face ++)
-    {
-      face->m_face->GetLimits ().RemoveOutstanding ();
-    }
+  // for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
+  //      face != pitEntry->GetOutgoing ().end ();
+  //      face ++)
+  //   {
+  //     face->m_face->GetLimits ().RemoveOutstanding ();
+  //   }
 
-  m_pit->MarkErased (pitEntry);
+  // m_pit->MarkErased (pitEntry);
   
-  ProcessFromQueue ();
+  // ProcessFromQueue ();
 }
 
 
diff --git a/model/pit/ndn-pit-entry.cc b/model/pit/ndn-pit-entry.cc
index af66570..0a06ed2 100644
--- a/model/pit/ndn-pit-entry.cc
+++ b/model/pit/ndn-pit-entry.cc
@@ -248,6 +248,13 @@
 }
 
 uint32_t
+Entry::GetOutgoingCount () const
+{
+  return m_outgoing.size ();
+}
+
+
+uint32_t
 Entry::GetMaxRetxCount () const
 {
   return m_maxRetxCount;
diff --git a/model/pit/ndn-pit-entry.h b/model/pit/ndn-pit-entry.h
index 7f4ef0e..259af75 100644
--- a/model/pit/ndn-pit-entry.h
+++ b/model/pit/ndn-pit-entry.h
@@ -262,6 +262,12 @@
   GetOutgoing () const;
 
   /**
+   * @brief Get number of outgoing faces (needed for python bindings)
+   */
+  uint32_t
+  GetOutgoingCount () const;
+  
+  /**
    * @brief Add new forwarding strategy tag
    */
   inline void
diff --git a/utils/ndn-pit-queue.cc b/utils/ndn-pit-queue.cc
index 75ce818..d8e810d 100644
--- a/utils/ndn-pit-queue.cc
+++ b/utils/ndn-pit-queue.cc
@@ -66,9 +66,12 @@
 
       queue = itemPair.first;
     }
-  
-  if (queue->second->size () >= inFace->GetLimits ().GetMaxLimit ())
+
+  if ((inFace->GetLimits ().GetMaxLimit () == 0 && queue->second->size () > 100) ||
+      (inFace->GetLimits ().GetMaxLimit () != 0 && queue->second->size () >= 0.5 * inFace->GetLimits ().GetMaxLimit ()))
+    {
       return false;
+    }
 
   Queue::iterator itemIterator = queue->second->insert (queue->second->end (), pitEntry);