Hooks for Guillem
authorVictor Grishchenko <victor.grishchenko@gmail.com>
Fri, 21 May 2010 09:04:49 +0000 (11:04 +0200)
committerVictor Grishchenko <victor.grishchenko@gmail.com>
Fri, 21 May 2010 09:04:49 +0000 (11:04 +0200)
ext/seq_picker.cpp
hashtree.cpp
swift.h
tests/transfertest.cpp
transfer.cpp

index 05bde2f..48f1fe3 100644 (file)
@@ -20,10 +20,11 @@ class SeqPiecePicker : public PiecePicker {
     tbqueue         hint_out_;
     FileTransfer*   transfer_;
     uint64_t        twist_;
+    bin64_t         range_;
     
 public:
     
-    SeqPiecePicker (FileTransfer* file_to_pick_from) : 
+    SeqPiecePicker (FileTransfer* file_to_pick_from) : range_(bin64_t::ALL),
     transfer_(file_to_pick_from), ack_hint_out_(), twist_(0) {
         ack_hint_out_.range_copy(file().ack_out(),bin64_t::ALL);
     }
@@ -36,6 +37,10 @@ public:
     virtual void Randomize (uint64_t twist) {
         twist_ = twist;
     }
+
+    virtual void LimitRange (bin64_t range) {
+        range_ = range;
+    }
     
     virtual bin64_t Pick (binmap_t& offer, uint64_t max_width, tint expires) {
         while (hint_out_.size() && hint_out_.front().time<NOW-TINT_SEC*3/2) { // FIXME sec
@@ -51,7 +56,7 @@ public:
             offer.twist(twist_);
             ack_hint_out_.twist(twist_);
         }
-        bin64_t hint = offer.find_filtered (ack_hint_out_,bin64_t::ALL,binmap_t::FILLED);
+        bin64_t hint = offer.find_filtered (ack_hint_out_,range_,binmap_t::FILLED);
         if (twist_) {
             hint = hint.twisted(twist_);
             offer.twist(0);
index 825fe7c..783b900 100644 (file)
@@ -319,7 +319,7 @@ bool            HashTree::OfferData (bin64_t pos, const char* data, size_t lengt
 
     Sha1Hash data_hash(data,length);
     if (!OfferHash(pos, data_hash)) {
-        printf("invalid hash for %s: %s\n",pos.str(),data_hash.hex().c_str()); // FIXME
+        //printf("invalid hash for %s: %s\n",pos.str(),data_hash.hex().c_str()); // paranoid
         return false;
     }
 
diff --git a/swift.h b/swift.h
index 7ed26e5..8589a89 100644 (file)
--- a/swift.h
+++ b/swift.h
@@ -204,6 +204,7 @@ namespace swift {
         friend void    Close (int fd) ;
         friend void AddProgressCallback (int transfer,TransferProgressCallback cb);
         friend void RemoveProgressCallback (int transfer,TransferProgressCallback cb);
+        friend void ExternallyRetrieved (int transfer,bin64_t piece);
     };
 
 
@@ -220,6 +221,7 @@ namespace swift {
          *  @param  expires     (not used currently) when to consider request expired
          *  @return             the bin number to request */
         virtual bin64_t Pick (binmap_t& offered, uint64_t max_width, tint expires) = 0;
+        virtual void LimitRange (bin64_t range) = 0;
         virtual ~PiecePicker() {}
     };
 
@@ -456,6 +458,7 @@ namespace swift {
 
     void AddProgressCallback (int transfer,TransferProgressCallback cb);
     void RemoveProgressCallback (int transfer,TransferProgressCallback cb);
+    void ExternallyRetrieved (int transfer,bin64_t piece);
 
     //uint32_t Width (const tbinvec& v);
 
index 36a92a2..4f5bb12 100644 (file)
@@ -102,6 +102,7 @@ TEST(TransferTest,TransferFile) {
         uint8_t memo = *buf;
         *buf = 'z';
         EXPECT_FALSE(leech->OfferData(next, (char*)buf, len));
+        fprintf(stderr,"kidding\n");
         *buf = memo;
         EXPECT_TRUE(leech->OfferData(next, (char*)buf, len));
     }
index 296f743..2f1cb91 100644 (file)
@@ -48,6 +48,14 @@ void swift::AddProgressCallback (int transfer, TransferProgressCallback cb) {
 }
 
 
+void swift::ExternallyRetrieved (int transfer,bin64_t piece) {
+    FileTransfer* trans = FileTransfer::file(transfer);
+    if (!trans)
+        return;
+    trans->ack_out().set(piece); // that easy
+}
+
+
 void swift::RemoveProgressCallback (int transfer, TransferProgressCallback cb) {
     FileTransfer* trans = FileTransfer::file(transfer);
     if (!trans)