stress testing
authorvictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Thu, 29 Oct 2009 16:24:19 +0000 (16:24 +0000)
committervictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Thu, 29 Oct 2009 16:24:19 +0000 (16:24 +0000)
git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@491 e16421f0-f15b-0410-abcd-98678b794739

ext/seq_picker.cpp
p2tp.cpp
p2tp.h
sendrecv.cpp

index a880100..4070b55 100644 (file)
@@ -46,8 +46,8 @@ public:
         ack_hint_out_.set(b,bins::FILLED);
     }
     
-    virtual void    Expired (bins& b) {
-        ack_hint_out_.remove(b); // may invalidate
+    virtual void    Expired (bin64_t b) {
+        ack_hint_out_.copy_range(file_->ack_out(),b);
     }
     
 };
index fce9416..fd0e8b1 100644 (file)
--- a/p2tp.cpp
+++ b/p2tp.cpp
@@ -38,7 +38,7 @@ PeerSelector* Channel::peer_selector = new SimpleSelector();
 Channel::Channel       (FileTransfer* file, int socket, Address peer_addr) :
        file_(file), peer_(peer_addr), peer_channel_id_(0), pex_out_(0),
     socket_(socket==-1?sockets[0]:socket), // FIXME
-    own_id_mentioned_(false), next_send_time_(0), hint_out_rotate_(0)
+    own_id_mentioned_(false), next_send_time_(0)
 {
     if (peer_==Address())
         peer_ = tracker;
@@ -60,10 +60,10 @@ void     p2tp::SetTracker(const Address& tracker) {
 
 
 int Channel::DecodeID(int scrambled) {
-       return scrambled;
+       return scrambled ^ (int)Datagram::epoch;
 }
 int Channel::EncodeID(int unscrambled) {
-       return unscrambled;
+       return unscrambled ^ (int)Datagram::epoch;
 }
 
 
diff --git a/p2tp.h b/p2tp.h
index 2867c5c..39b8bee 100644 (file)
--- a/p2tp.h
+++ b/p2tp.h
@@ -139,6 +139,8 @@ namespace p2tp {
         uint64_t        complete () const { return complete_; }
         uint64_t        complete_kilo () const { return completek_; }
         uint64_t        seq_complete () const { return seq_complete_; }
+        bool            is_complete () const
+            { return seq_complete_==size_; }
         bins&           ack_out ()  { return ack_out_; }
         int             file_descriptor () const { return fd_; }
         PiecePicker&    picker () { return *picker_; }
@@ -228,7 +230,7 @@ namespace p2tp {
     class PiecePicker {
     public:
         virtual bin64_t Pick (bins& offered, uint8_t layer) = 0;
-        virtual void    Expired (bins& b) = 0;
+        virtual void    Expired (bin64_t b) = 0;
         virtual void    Received (bin64_t b) = 0;
     };
 
@@ -312,9 +314,7 @@ namespace p2tp {
                /**     Transmit schedule: in most cases filled with the peer's hints */
                binqueue    hint_in_;
                /** Hints sent (to detect and reschedule ignored hints). */
-               bins            hint_out_;
-        bins        hint_out_old_;
-        tint        hint_out_rotate_;
+               tbqueue         hint_out_;
                /** The congestion control strategy. */
                CongestionController    *cc_;
         /** Types of messages the peer accepts. */
index c31bf1c..e37a0c5 100644 (file)
@@ -121,15 +121,14 @@ void      Channel::Send () {
 
 void   Channel::AddHint (Datagram& dgram) {
 
-    if (hint_out_rotate_<Datagram::now-TINT_SEC) {
-        hint_out_rotate_ = Datagram::now;
-        if ( ! hint_out_old_.is_empty() )
-            file().picker().Expired(hint_out_old_);
-        swap(hint_out_,hint_out_old_);
-        hint_out_.clear();
+    while (!hint_out_.empty() &&
+            hint_out_.front().time<Datagram::now-TINT_SEC) {
+        file().picker().Expired(hint_out_.front().bin);
+        hint_out_.pop_front();
     }
-    
-    uint64_t hinted = hint_out_.mass();// + hint_out_old_.mass();
+    uint64_t hinted = 0;
+    for(tbqueue::iterator i=hint_out_.begin(); i!=hint_out_.end(); i++)
+        hinted += i->bin.width();
     int bps = cc_->PeerBPS();
     dprintf("%s #%i hinted %lli peer_bps %i\n",Datagram::TimeStr(),id,hinted,bps);
     //float peer_cwnd = cc_->PeerBPS() * cc_->RoundTripTime() / TINT_SEC;
@@ -143,7 +142,7 @@ void        Channel::AddHint (Datagram& dgram) {
             hint = file().picker().Pick(ack_in_,0);
         
         if (hint!=bin64_t::NONE) {
-            hint_out_.set(hint);
+            hint_out_.push_back(hint);
             dgram.Push8(P2TP_HINT);
             dgram.Push32(hint);
             dprintf("%s #%i +hint (%i,%lli)\n",Datagram::TimeStr(),id,hint.layer(),hint.offset());
@@ -240,10 +239,11 @@ bin64_t Channel::OnData (Datagram& dgram) {
     int length = dgram.Pull(&data,1024);
     bool ok = file().OfferData(pos, data, length) ;
     dprintf("%s #%i %cdata (%lli)\n",Datagram::TimeStr(),id,ok?'-':'!',pos.offset());
-    data_in_ = tintbin(Datagram::now,pos);
-    hint_out_.set(pos,bins::EMPTY);
-    hint_out_old_.set(pos,bins::EMPTY);
-    return ok ? pos : bin64_t::none();
+    if (ok) {
+        data_in_ = tintbin(Datagram::now,pos);
+        return pos;
+    } else
+        return bin64_t::NONE;
 }