From 9e6027efb2c7fb546e7233a0f3432f78d3c8029f Mon Sep 17 00:00:00 2001 From: "Victor Grishchenko (Vista)" Date: Thu, 25 Feb 2010 14:24:09 +0100 Subject: [PATCH] One swift to rule them all. --- exec/SConscript | 52 ---------------------------------- exec/bingrep.cpp | 20 ------------- exec/hasher.cpp | 26 ----------------- exec/leecher.cpp | 74 ------------------------------------------------ exec/seeder.cpp | 56 ------------------------------------ exec/trial.cpp | 64 ----------------------------------------- 6 files changed, 292 deletions(-) delete mode 100644 exec/SConscript delete mode 100644 exec/bingrep.cpp delete mode 100644 exec/hasher.cpp delete mode 100644 exec/leecher.cpp delete mode 100644 exec/seeder.cpp delete mode 100644 exec/trial.cpp diff --git a/exec/SConscript b/exec/SConscript deleted file mode 100644 index 8c1fa5d..0000000 --- a/exec/SConscript +++ /dev/null @@ -1,52 +0,0 @@ -import sys - -Import("DEBUG") -Import("env") -Import("libs") -Import("libpath") - -cpppath = env["CPPPATH"] -libs = ['swift'] + libs # order is important, crypto needs to be last - -if sys.platform == "win32": - cpppath = ".." - libpath += '..;' - if DEBUG: - env.Append(CXXFLAGS="/Zi /Yd /MTd") -else: - cpppath = cpppath + ':..' - libpath += ':..' - if DEBUG: - env.Append(CXXFLAGS="-g") - -print "tests: libpath is",libpath - - -#env.Program( -# target='trial', -# source=['trial.cpp'], -# CPPPATH=cpppath, -# LIBS=libs, -# LIBPATH=libpath ) - -env.Program( - target='seeder', - source=['seeder.cpp'], - CPPPATH=cpppath, - LIBS=libs, - LIBPATH=libpath ) - -env.Program( - target='leecher', - source=['leecher.cpp'], - CPPPATH=cpppath, - LIBS=libs, - LIBPATH=libpath ) - -env.Program( - target='hasher', - source=['hasher.cpp'], - CPPPATH=cpppath, - LIBS=libs, - LIBPATH=libpath ) - diff --git a/exec/bingrep.cpp b/exec/bingrep.cpp deleted file mode 100644 index 7ed2c1c..0000000 --- a/exec/bingrep.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include "bin64.h" - -int main (int argn, char** args) { - int lr; - unsigned long long of; - sscanf(args[1],"%i,%lli",&lr,&of); - bin64_t target(lr,of); - char line[1024]; - while (gets(line)) { - char* br = strchr(line,'('); - if (br && 2==sscanf(br,"(%i,%lli)",&lr,&of)) { - bin64_t found(lr,of); - if ( found.within(target) || target.within(found)) - printf("%s\n",line); - } - } - return 0; -} diff --git a/exec/hasher.cpp b/exec/hasher.cpp deleted file mode 100644 index 13c62e9..0000000 --- a/exec/hasher.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * hasher.cpp - * swift - * - * Created by Victor Grishchenko on 11/8/09. - * Copyright 2009 Delft University of Technology. All rights reserved. - * - */ -#include -#include "hashtree.h" -#include "swift.h" - - -int main (int argn, char** args) { - - if (argn<2) { - fprintf(stderr,"Usage: %s file_name\n",args[0]); - return 1; - } - - swift::HashTree* ht = new swift::HashTree(args[1]); - - printf("SHA1 Merkle tree root hash: %s\n",ht->root_hash().hex().c_str()); - -} - diff --git a/exec/leecher.cpp b/exec/leecher.cpp deleted file mode 100644 index 3a2b65f..0000000 --- a/exec/leecher.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * leecher.cpp - * swift - * - * Created by Victor Grishchenko on 11/3/09. - * Copyright 2009 Delft University of Technology. All rights reserved. - * - */ -#include "swift.h" -#include - - -using namespace swift; - - -/** swift downloader. Params: root hash, filename, tracker ip/port, own ip/port */ -int main (int argn, char** args) { - - srand(time(NULL)); - - if (argn<4) { - fprintf(stderr,"parameters: root_hash filename tracker_ip:port [own_ip:port]\n"); - return -1; - } - Sha1Hash root_hash(true,args[1]); - if (root_hash==Sha1Hash::ZERO) { - fprintf(stderr,"Sha1 hash format: hex, 40 symbols\n"); - return -2; - } - - swift::LibraryInit(); - - char* filename = args[2]; - - Address tracker(args[3]), bindaddr; - - if (tracker==Address()) { - fprintf(stderr,"Tracker address format: [1.2.3.4:]12345, not %s\n",args[3]); - return -2; - } - if (argn>=5) - bindaddr = Address(args[4]); - else - bindaddr = Address((uint32_t)INADDR_ANY,rand()%10000+7000); - - if (swift::Listen(bindaddr)<=0) { - fprintf(stderr,"Cannot listen on %s\n",bindaddr.str()); - return -3; - } - - swift::SetTracker(tracker); - - int file = swift::Open(filename,root_hash); - printf("Downloading %s\n",root_hash.hex().c_str()); - - tint start = NOW; - - while (true){ //!swift::IsComplete(file)){// && NOW-start=4) { - Address tracker(args[3]); - swift::SetTracker(tracker); - } - Address bindaddr(args[2]); - - if (bindaddr==Address()) { - fprintf(stderr,"Bind address format: [1.2.3.4:]12345\n"); - return -2; - } - - assert(0 -#include -#include "compat/util.h" -#ifndef _WIN32 -#include -#endif - - -using namespace swift; - - -/** swift downloader. Params: root hash, filename, tracker ip/port, own ip/port */ -int main (int argn, char** args) { - THIS IS NOT TRIAL BRANCH - srand(time(NULL)); - Sha1Hash root_hash(true,"32e5d9d2d8c0f6073e2820cf47b15b58c2e42a23"); - swift::LibraryInit(); - - // Arno: use tempdir - std::string tmpdir = gettmpdir(); - std::string sfn = tmpdir+"team.jpg"; - std::string hfn = tmpdir+"team.jpg.mhash"; - const char* filename = strdup(sfn.c_str()); - unlink(filename); - unlink(hfn.c_str()); - - Address tracker("victor.p2p-next.org:12345"), - bindaddr((uint32_t)INADDR_ANY,10000), - fallback("victor2.p2p-next.org:12345"); - - if (0>swift::Listen(bindaddr)) { - print_error("cannot bind"); - return 1; - } - swift::SetTracker(tracker); - int file = swift::Open(filename,root_hash); - printf("Downloading %s\n",root_hash.hex().c_str()); - int count = 400; - while (!swift::IsComplete(file) && count-->0) { - swift::Loop(TINT_SEC/10); - if (count==100) - FileTransfer::file(file)->OnPexIn(fallback); - printf("done %lli of %lli (seq %lli) %lli dgram %lli bytes up, %lli dgram %lli bytes down\n", - swift::Complete(file), swift::Size(file), swift::SeqComplete(file), - Datagram::dgrams_up, Datagram::bytes_up, - Datagram::dgrams_down, Datagram::bytes_down ); - } - int ret = !swift::IsComplete(file); - - swift::Close(file); - swift::Shutdown(); - - return ret; - -} -- 2.20.1