From d51e0884293d86e3847cde1dae4a5cd872b4623c Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 12 Nov 2009 13:55:23 +0000 Subject: [PATCH] trial exec git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@540 e16421f0-f15b-0410-abcd-98678b794739 --- exec/trial.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ p2tp.h | 2 -- sendrecv.cpp | 2 +- transfer.cpp | 1 - 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 exec/trial.cpp diff --git a/exec/trial.cpp b/exec/trial.cpp new file mode 100644 index 0000000..90b4097 --- /dev/null +++ b/exec/trial.cpp @@ -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 + + +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 --- 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 files; diff --git a/sendrecv.cpp b/sendrecv.cpp index 5a91e65..cb0e2d5 100644 --- a/sendrecv.cpp +++ b/sendrecv.cpp @@ -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); } diff --git a/transfer.cpp b/transfer.cpp index 37c1a79..62bc51b 100644 --- a/transfer.cpp +++ b/transfer.cpp @@ -21,7 +21,6 @@ using namespace p2tp; std::vector FileTransfer::files(20); -int FileTransfer::instance = 0; #define BINHASHSIZE (sizeof(bin64_t)+sizeof(Sha1Hash)) #include "ext/seq_picker.cpp" -- 2.20.1