now with leecher
authorvictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Tue, 3 Nov 2009 14:57:21 +0000 (14:57 +0000)
committervictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Tue, 3 Nov 2009 14:57:21 +0000 (14:57 +0000)
git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@496 e16421f0-f15b-0410-abcd-98678b794739

BUGS
datagram.cpp
exec/leecher.cpp [new file with mode: 0644]
hashtree.cpp
p2tp.cpp
p2tp.h

diff --git a/BUGS b/BUGS
index 2dfe512..8fb861c 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -1,5 +1,9 @@
     * hints, data for non-existing ranges
     * opens multiple channels to the same address
+    * hints do not expire
+    * RTT calculations need improvement (test)
+    * google-log is unnecessary
+    * reduce template use (peer queue)
     v hints do not expire
     * survive 10% loss
     * unlimited ping pong
index 3c07bd4..86f1b6e 100644 (file)
@@ -46,6 +46,8 @@ char* Datagram::TimeStr (tint time) {
 int Datagram::Send () {
        int r = sendto(sock,(const char *)buf+offset,length-offset,0,
                                   (struct sockaddr*)&(addr.addr),sizeof(struct sockaddr_in));
+    if (r<0)
+        perror("can't send");
        //offset=0;
        //length=0;
     dgrams_up++;
diff --git a/exec/leecher.cpp b/exec/leecher.cpp
new file mode 100644 (file)
index 0000000..17d1aa7
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ *  leecher.cpp
+ *  p2tp
+ *
+ *  Created by Victor Grishchenko on 11/3/09.
+ *  Copyright 2009 Delft Technical University. All rights reserved.
+ *
+ */
+#include "p2tp.h"
+
+
+using namespace p2tp;
+
+
+int main (int argn, char** args) {
+    
+    assert(0<p2tp::Listen(Datagram::Address(INADDR_ANY,7002)));
+       p2tp::SetTracker(Datagram::Address("130.161.211.198",7001));
+    unlink("doc/sofi-copy.jpg");
+       int file = p2tp::Open("doc/sofi-copy.jpg",
+                          Sha1Hash(true,"282a863d5567695161721686a59f0c667250a35d"));
+    
+    while (!p2tp::Complete(file)) {
+           p2tp::Loop(TINT_SEC/10);
+        printf("%lli dgram %lli bytes up, %lli dgram %lli bytes down\n",
+               Datagram::dgrams_up, Datagram::bytes_up,
+               Datagram::dgrams_down, Datagram::bytes_down );
+    }
+    
+       p2tp::Close(file);
+    
+       p2tp::Shutdown();
+    
+}
index 096067a..b98cb9a 100644 (file)
@@ -39,8 +39,17 @@ Sha1Hash::Sha1Hash(const char* str) {
 }
 
 Sha1Hash::Sha1Hash(bool hex, const char* hash) {
-       assert(!hex);
-       memcpy(bits,hash,SIZE);
+       if (hex) {
+        char hx[3]; hx[2]=0;
+        int val;
+        for(int i=0; i<SIZE; i++) {
+            strncpy(hx,hash+i*2,2);
+            sscanf(hx, "%x", &val);
+            bits[i] = val;
+        }
+        assert(this->hex()==string(hash));
+    } else
+        memcpy(bits,hash,SIZE);
 }
 
 string Sha1Hash::hex() const {
index 75692d1..81fac8d 100644 (file)
--- a/p2tp.cpp
+++ b/p2tp.cpp
@@ -132,7 +132,7 @@ size_t  p2tp::Size (int fdes) {
 
 size_t  p2tp::Complete (int fdes) {
     if (FileTransfer::files.size()>fdes && FileTransfer::files[fdes])
-        return FileTransfer::files[fdes]->complete();
+        return FileTransfer::files[fdes]->is_complete();
     else
         return 0;
 }
diff --git a/p2tp.h b/p2tp.h
index 460a66a..e7cbf76 100644 (file)
--- a/p2tp.h
+++ b/p2tp.h
@@ -140,7 +140,7 @@ namespace p2tp {
         uint64_t        complete_kilo () const { return completek_; }
         uint64_t        seq_complete () const { return seq_complete_; }
         bool            is_complete () const
-            { return seq_complete_==size_; }
+            { return size_ && seq_complete_==size_; }
         bins&           ack_out ()  { return ack_out_; }
         int             file_descriptor () const { return fd_; }
         PiecePicker&    picker () { return *picker_; }