target = 'p2tp'
source = [ 'bin64.cpp','hashtree.cpp','datagram.cpp','bins.cpp',
'transfer.cpp', 'p2tp.cpp', 'sendrecv.cpp', 'ext/send_control.cpp',
- 'compat/hirestimeofday.cpp', 'compat/util.cpp']
+ 'compat/hirestimeofday.cpp', 'compat.cpp', 'compat/util.cpp']
env = Environment()
if sys.platform == "win32":
class SeqPiecePicker : public PiecePicker {
bins ack_hint_out_;
- FileTransfer* file_;
+ FileTransfer* transfer_;
uint64_t twist_;
public:
SeqPiecePicker (FileTransfer* file_to_pick_from) :
- file_(file_to_pick_from), ack_hint_out_(), twist_(0) {
- ack_hint_out_.copy_range(file_->ack_out(),bin64_t::ALL);
+ transfer_(file_to_pick_from), ack_hint_out_(), twist_() {
+ ack_hint_out_.copy_range(file().ack_out(),bin64_t::ALL);
+ }
+
+ HashTree& file() {
+ return transfer_->file();
}
virtual void Randomize (uint64_t twist) {
virtual bin64_t Pick (bins& offer, uint8_t layer) {
//dprintf("twist is %lli\n",twist_);
+ if (!file().size())
+ return bin64_t(0,0); // a hack to get peak hashes; FIXME
+ twist_ &= (file().peak(0)) & ((1<<16)-1);
if (twist_) {
offer.twist(twist_);
ack_hint_out_.twist(twist_);
}
virtual void Expired (bin64_t b) {
- ack_hint_out_.copy_range(file_->ack_out(),b);
+ ack_hint_out_.copy_range(file().ack_out(),b);
}
};
EXPECT_EQ(5,seed->size_kilo());
EXPECT_EQ(4100,seed->complete());
EXPECT_EQ(4100,seed->seq_complete());
+ EXPECT_EQ(bin64_t(2,0),seed->peak(0));
// retrieve it
unlink("copy");
ASSERT_EQ(5<<10,leech->size());
ASSERT_EQ(5,leech->size_kilo());
ASSERT_EQ(0,leech->complete());
+ EXPECT_EQ(bin64_t(2,0),leech->peak(0));
// transfer data and hashes
// ABCD E000
// AB CD E0 0
leech = & leech_transfer->file();
leech_transfer->picker().Randomize(0);
EXPECT_EQ(2,leech->complete_kilo());
+ EXPECT_EQ(bin64_t(2,0),leech->peak(0));
}
bin64_t next = leech_transfer->picker().Pick(seed->ack_out(),0);
ASSERT_NE(bin64_t::NONE,next);
files.resize(fd()+1);
files[fd()] = this;
picker_ = new SeqPiecePicker(this);
- if (file_.size())
- picker_->Randomize(rand()&31&(file_.peak(0).width()-1));
+ picker_->Randomize(rand());
}