int file = p2tp::Open(filename,root_hash);
printf("Downloading %s\n",root_hash.hex().c_str());
- while (!p2tp::Complete(file)) {
+ while (!p2tp::IsComplete(file)) {
p2tp::Loop(TINT_SEC);
- printf("%lli dgram %lli bytes up, %lli dgram %lli bytes down\n",
+ printf("done %lli of %lli (seq %lli) %lli dgram %lli bytes up, %lli dgram %lli bytes down\n",
+ p2tp::Complete(file), p2tp::Size(file), p2tp::SeqComplete(file),
Datagram::dgrams_up, Datagram::bytes_up,
Datagram::dgrams_down, Datagram::bytes_down );
}
HashTree::HashTree (const char* filename, const Sha1Hash& root_hash, const char* hash_filename) :
-root_hash_(root_hash), fd_(0), hash_fd_(0), data_recheck_(false),
+root_hash_(root_hash), fd_(0), hash_fd_(0), data_recheck_(true),
peak_count_(0), hashes_(NULL), size_(0), sizek_(0),
complete_(0), completek_(0)
{
}
-size_t p2tp::Size (int fdes) {
+uint64_t p2tp::Size (int fdes) {
if (FileTransfer::files.size()>fdes && FileTransfer::files[fdes])
return FileTransfer::files[fdes]->file().size();
else
}
-size_t p2tp::Complete (int fdes) {
+bool p2tp::IsComplete (int fdes) {
if (FileTransfer::files.size()>fdes && FileTransfer::files[fdes])
return FileTransfer::files[fdes]->file().is_complete();
else
}
-size_t p2tp::SeqComplete (int fdes) {
+uint64_t p2tp::Complete (int fdes) {
+ if (FileTransfer::files.size()>fdes && FileTransfer::files[fdes])
+ return FileTransfer::files[fdes]->file().complete();
+ else
+ return 0;
+}
+
+
+uint64_t p2tp::SeqComplete (int fdes) {
if (FileTransfer::files.size()>fdes && FileTransfer::files[fdes])
return FileTransfer::files[fdes]->file().seq_complete();
else
void OnPexIn (const Address& addr);
friend class Channel;
- friend size_t Size (int fdes);
- friend size_t Complete (int fdes);
- friend size_t SeqComplete (int fdes);
+ friend uint64_t Size (int fdes);
+ friend bool IsComplete (int fdes);
+ friend uint64_t Complete (int fdes);
+ friend uint64_t SeqComplete (int fdes);
friend int Open (const char* filename, const Sha1Hash& hash) ;
friend void Close (int fd) ;
};
/** Returns size of the file in bytes, 0 if unknown. Might be rounded up to a kilobyte
before the transmission is complete. */
- size_t Size (int fdes);
+ uint64_t Size (int fdes);
/** Returns the amount of retrieved and verified data, in bytes.
A 100% complete transmission has Size()==Complete(). */
- size_t Complete (int fdes);
+ uint64_t Complete (int fdes);
+ bool IsComplete (int fdes);
/** Returns the number of bytes that are complete sequentially, starting from the
beginning, till the first not-yet-retrieved packet. */
- size_t SeqComplete (int fdes);
+ uint64_t SeqComplete (int fdes);
//uint32_t Width (const tbinvec& v);
files.resize(fd()+1);
files[fd()] = this;
picker_ = new SeqPiecePicker(this);
- picker_->Randomize(rand());
+ picker_->Randomize(rand()&63);
}