currrent
authorvictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Mon, 9 Nov 2009 18:49:27 +0000 (18:49 +0000)
committervictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Mon, 9 Nov 2009 18:49:27 +0000 (18:49 +0000)
git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@519 e16421f0-f15b-0410-abcd-98678b794739

exec/leecher.cpp
hashtree.cpp
p2tp.cpp
p2tp.h
transfer.cpp

index 57d05a3..c18945c 100644 (file)
@@ -48,9 +48,10 @@ int main (int argn, char** args) {
        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 );
     }
index bdb8cce..55586ac 100644 (file)
@@ -64,7 +64,7 @@ std::string   Sha1Hash::hex() const {
 
 
 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)
 {
index 70a9b21..060d971 100644 (file)
--- a/p2tp.cpp
+++ b/p2tp.cpp
@@ -122,7 +122,7 @@ void    p2tp::AddPeer (Address address, const Sha1Hash& root) {
 }
 
 
-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
@@ -130,7 +130,7 @@ size_t  p2tp::Size (int fdes) {
 }
 
 
-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
@@ -138,7 +138,15 @@ size_t  p2tp::Complete (int fdes) {
 }
 
 
-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
diff --git a/p2tp.h b/p2tp.h
index 5e8b5c7..180d075 100644 (file)
--- a/p2tp.h
+++ b/p2tp.h
@@ -149,9 +149,10 @@ namespace p2tp {
         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) ;
        };
@@ -326,13 +327,14 @@ namespace p2tp {
     
     /** 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);
index 909b4e6..b1effc0 100644 (file)
@@ -35,7 +35,7 @@ FileTransfer::FileTransfer (const char* filename, const Sha1Hash& _root_hash) :
         files.resize(fd()+1);
     files[fd()] = this;
     picker_ = new SeqPiecePicker(this);
-    picker_->Randomize(rand());
+    picker_->Randomize(rand()&63);
 }