trial exec
authorvictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Thu, 12 Nov 2009 13:55:23 +0000 (13:55 +0000)
committervictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Thu, 12 Nov 2009 13:55:23 +0000 (13:55 +0000)
git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@540 e16421f0-f15b-0410-abcd-98678b794739

exec/trial.cpp [new file with mode: 0644]
p2tp.h
sendrecv.cpp
transfer.cpp

diff --git a/exec/trial.cpp b/exec/trial.cpp
new file mode 100644 (file)
index 0000000..90b4097
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ *  leecher.cpp
+ *  p2tp
+ *
+ *  Created by Victor Grishchenko on 11/3/09.
+ *  Copyright 2009 Delft University of Technology. All rights reserved.
+ *
+ */
+#include "p2tp.h"
+#include <time.h>
+
+
+using namespace p2tp;
+
+
+/** P2TP downloader. Params: root hash, filename, tracker ip/port, own ip/port */
+int main (int argn, char** args) {
+
+    srand(time(NULL));
+    Sha1Hash root_hash(true,"32e5d9d2d8c0f6073e2820cf47b15b58c2e42a23");
+    p2tp::LibraryInit();
+    const char* filename = "team.jpg";
+    Address tracker("130.161.211.198:10000"),
+            bindaddr(INADDR_ANY,10000);
+    if (0>p2tp::Listen(bindaddr)) {
+        print_error("cannot bind");
+        return 1;
+    }
+       p2tp::SetTracker(tracker);
+       int file = p2tp::Open(filename,root_hash);
+    printf("Downloading %s\n",root_hash.hex().c_str());
+    int count = 100;
+    while (!p2tp::IsComplete(file) && count-->0) {
+           p2tp::Loop(TINT_SEC/10);
+        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 );
+    }
+
+       p2tp::Close(file);
+       p2tp::Shutdown();
+
+}
diff --git a/p2tp.h b/p2tp.h
index 1aa6d44..d18b325 100644 (file)
--- a/p2tp.h
+++ b/p2tp.h
@@ -125,8 +125,6 @@ namespace p2tp {
         int             fd () const { return file_.file_descriptor(); }
         const Sha1Hash& root_hash () const { return file_.root_hash(); }
 
-        static int instance; // FIXME this smells
-
     private:
 
                static std::vector<FileTransfer*> files;
index 5a91e65..cb0e2d5 100644 (file)
@@ -291,7 +291,7 @@ void        Channel::Recv (Datagram& dgram) {
        }
     cc_->OnDataRecvd(data);
     last_recv_time_ = NOW;
-    if (data!=bin64_t::ALL)
+    if (data!=bin64_t::ALL && next_send_time_>NOW+TINT_MSEC)
         Send(); //RequeueSend(NOW);
 }
 
index 37c1a79..62bc51b 100644 (file)
@@ -21,7 +21,6 @@ using namespace p2tp;
 
 std::vector<FileTransfer*> FileTransfer::files(20);
 
-int FileTransfer::instance = 0;
 #define BINHASHSIZE (sizeof(bin64_t)+sizeof(Sha1Hash))
 
 #include "ext/seq_picker.cpp"