For the purpose of consistency.
/*
* bin64.cpp
- * p2tp
+ * swift
*
* Created by Victor Grishchenko on 10/10/09.
* Copyright 2009 Delft University of Technology. All rights reserved.
/*
* compat.cpp
- * p2tp
+ * swift
*
* Created by Arno Bakker, Victor Grishchenko
* Copyright 2009 Delft University of Technology. All rights reserved.
#include <sys/time.h>
#endif
-namespace p2tp {
+namespace swift {
#ifdef _WIN32
static HANDLE map_handles[1024];
#define S_IROTH _S_IREAD
#endif
-namespace p2tp {
+namespace swift {
/** tint is the time integer type; microsecond-precise. */
typedef int64_t tint;
#include <sys/time.h>\r
#endif\r
\r
-namespace p2tp {\r
+namespace swift {\r
\r
HiResTimeOfDay* HiResTimeOfDay::_instance = 0;\r
\r
\r
\r
\r
-// ARNOTODO: move to p2tp.cpp\r
+// ARNOTODO: move to swift.cpp\r
\r
#ifdef _WIN32\r
static WSADATA _WSAData;\r
#ifdef TEST\r
#include <iostream>\r
\r
-using namespace p2tp;\r
+using namespace swift;\r
\r
int main()\r
{\r
#include <windows.h>\r
#endif\r
\r
-namespace p2tp {\r
+namespace swift {\r
\r
typedef int64_t tint;\r
#define TINT_SEC ((tint)1000000)\r
#include <Tchar.h>\r
#endif\r
\r
-namespace p2tp\r
+namespace swift\r
{\r
\r
std::string gettmpdir(void)\r
\r
#include <string>\r
\r
-namespace p2tp\r
+namespace swift\r
{\r
/**\r
* Return path of temporary directory.\r
#include "datagram.h"
#include "compat.h"
-namespace p2tp {
+namespace swift {
tint Datagram::now = Datagram::Time();
tint Datagram::start = now;
#include "compat.h"
-namespace p2tp {
+namespace swift {
#define MAXDGRAMSZ 2800
#ifndef _WIN32
/*
* hasher.cpp
- * p2tp
+ * swift
*
* Created by Victor Grishchenko on 11/8/09.
* Copyright 2009 Delft University of Technology. All rights reserved.
return 1;
}
- p2tp::HashTree* ht = new p2tp::HashTree(args[1]);
+ swift::HashTree* ht = new swift::HashTree(args[1]);
printf("SHA1 Merkle tree root hash: %s\n",ht->root_hash().hex().c_str());
/*
* leecher.cpp
- * p2tp
+ * swift
*
* Created by Victor Grishchenko on 11/3/09.
* Copyright 2009 Delft University of Technology. All rights reserved.
*
*/
-#include "p2tp.h"
+#include "swift.h"
#include <time.h>
-using namespace p2tp;
+using namespace swift;
/** P2TP downloader. Params: root hash, filename, tracker ip/port, own ip/port */
return -2;
}
- p2tp::LibraryInit();
+ swift::LibraryInit();
char* filename = args[2];
else
bindaddr = Address((uint32_t)INADDR_ANY,rand()%10000+7000);
- assert(0<p2tp::Listen(bindaddr));
+ assert(0<swift::Listen(bindaddr));
- p2tp::SetTracker(tracker);
+ swift::SetTracker(tracker);
- int file = p2tp::Open(filename,root_hash);
+ int file = swift::Open(filename,root_hash);
printf("Downloading %s\n",root_hash.hex().c_str());
tint start = NOW;
- while (!p2tp::IsComplete(file)){// && NOW-start<TINT_SEC*60) {
- p2tp::Loop(TINT_SEC);
+ while (!swift::IsComplete(file)){// && NOW-start<TINT_SEC*60) {
+ swift::Loop(TINT_SEC);
eprintf("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),
+ swift::Complete(file), swift::Size(file), swift::SeqComplete(file),
Datagram::dgrams_up, Datagram::bytes_up,
Datagram::dgrams_down, Datagram::bytes_down );
}
- bool complete = p2tp::IsComplete(file);
+ bool complete = swift::IsComplete(file);
- p2tp::Close(file);
+ swift::Close(file);
- p2tp::Shutdown();
+ swift::Shutdown();
return !complete;
}
* Copyright 2009 Delft University of Technology. All rights reserved.
*
*/
-#include "p2tp.h"
+#include "swift.h"
-using namespace p2tp;
+using namespace swift;
/** P2TP seeder. Params: filename, own ip/port, tracker ip/port */
return -1;
}
- p2tp::LibraryInit();
+ swift::LibraryInit();
char* filename = args[1];
if (argn>=4) {
Address tracker(args[3]);
- p2tp::SetTracker(tracker);
+ swift::SetTracker(tracker);
}
Address bindaddr(args[2]);
return -2;
}
- assert(0<p2tp::Listen(bindaddr));
+ assert(0<swift::Listen(bindaddr));
printf("seeder bound to %s\n",bindaddr.str());
- int file = p2tp::Open(filename);
+ int file = swift::Open(filename);
printf("seeding %s %s\n",filename,RootMerkleHash(file).hex().c_str());
while (true) {
- p2tp::Loop(TINT_SEC*60);
+ swift::Loop(TINT_SEC*60);
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);
+ swift::Close(file);
- p2tp::Shutdown();
+ swift::Shutdown();
}
/*
* leecher.cpp
- * p2tp
+ * swift
*
* Created by Victor Grishchenko on 11/3/09.
* Copyright 2009 Delft University of Technology. All rights reserved.
*
*/
-#include "p2tp.h"
+#include "swift.h"
#include <time.h>
#include <string>
#include "compat/util.h"
#endif
-using namespace p2tp;
+using namespace swift;
/** P2TP downloader. Params: root hash, filename, tracker ip/port, own ip/port */
THIS IS NOT TRIAL BRANCH
srand(time(NULL));
Sha1Hash root_hash(true,"32e5d9d2d8c0f6073e2820cf47b15b58c2e42a23");
- p2tp::LibraryInit();
+ swift::LibraryInit();
// Arno: use tempdir
std::string tmpdir = gettmpdir();
bindaddr((uint32_t)INADDR_ANY,10000),
fallback("victor2.p2p-next.org:12345");
- if (0>p2tp::Listen(bindaddr)) {
+ if (0>swift::Listen(bindaddr)) {
print_error("cannot bind");
return 1;
}
- p2tp::SetTracker(tracker);
- int file = p2tp::Open(filename,root_hash);
+ swift::SetTracker(tracker);
+ int file = swift::Open(filename,root_hash);
printf("Downloading %s\n",root_hash.hex().c_str());
int count = 400;
- while (!p2tp::IsComplete(file) && count-->0) {
- p2tp::Loop(TINT_SEC/10);
+ 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",
- p2tp::Complete(file), p2tp::Size(file), p2tp::SeqComplete(file),
+ swift::Complete(file), swift::Size(file), swift::SeqComplete(file),
Datagram::dgrams_up, Datagram::bytes_up,
Datagram::dgrams_down, Datagram::bytes_down );
}
- int ret = !p2tp::IsComplete(file);
+ int ret = !swift::IsComplete(file);
- p2tp::Close(file);
- p2tp::Shutdown();
+ swift::Close(file);
+ swift::Shutdown();
return ret;
/*
* ledbat_controller.cpp
- * p2tp
+ * swift
*
* Created by Victor Grishchenko on 10/6/09.
* Copyright 2009 Delft University of Technology. All rights reserved.
*
*/
-#include "p2tp.h"
+#include "swift.h"
-using namespace p2tp;
+using namespace swift;
class LedbatController : public CongestionController {
public:
/*
* mmap_storer.cpp
- * p2tp
+ * swift
*
* Created by Victor Grishchenko on 10/7/09.
* Copyright 2009 Delft University of Technology. All rights reserved.
*
*/
-#include "p2tp.h"
+#include "swift.h"
class MMappedStorer : public DataStorer {
public:
/*
* seq_picker.cpp
- * p2tp
+ * swift
*
* Created by Victor Grishchenko on 10/6/09.
* Copyright 2009 Delft University of Technology. All rights reserved.
*
*/
-#include "p2tp.h"
+#include "swift.h"
-using namespace p2tp;
+using namespace swift;
+
+/** Picks pieces nearly sequentialy; some local randomization (twisting)
+ is introduced to prevent synchronization among multiple channels. */
class SeqPiecePicker : public PiecePicker {
binmap_t ack_hint_out_;
if (!file().size()) {
return bin64_t(0,0); // whoever sends it first
}
- retry:
+ retry: // bite me
twist_ &= (file().peak(0)) & ((1<<6)-1);
if (twist_) {
offer.twist(twist_);
/*
* simple_selector.cpp
- * p2tp
+ * swift
*
* Created by Victor Grishchenko on 10/6/09.
* Copyright 2009 Delft University of Technology. All rights reserved.
*/
#include <queue>
-#include "p2tp.h"
+#include "swift.h"
-using namespace p2tp;
+using namespace swift;
class SimpleSelector : public PeerSelector {
typedef std::pair<Address,Sha1Hash> memo_t;
#endif
-using namespace p2tp;
+using namespace swift;
#define HASHSZ 20
const size_t Sha1Hash::SIZE = HASHSZ;
#include <string.h>
#include <string>
-namespace p2tp {
+namespace swift {
/** SHA-1 hash, 20 bytes of data */
# docmd.sh); all failed executions are
# put to the FAILURES file
rm -f FAILURES
-for srv in `cat servers.txt`; do
+
+if [ -z "$SERVERS" ]; then
+ SERVERS="das2.txt"
+fi
+HOSTS=`cat $SERVERS | awk '{print $2}'`
+
+for srv in $HOSTS; do
( for cmd in $@; do
if ! ./docmd.sh $srv $cmd; then
echo $srv >> FAILURES
*
*/
-#include "p2tp.h"
+#include "swift.h"
-using namespace p2tp;
+using namespace swift;
using namespace std;
tint Channel::MIN_DEV = 50*TINT_MSEC;
* Copyright 2009 Delft University of Technology. All rights reserved.
*
*/
-#include "p2tp.h"
+#include "swift.h"
#include "compat/util.h"
-using namespace p2tp;
+using namespace swift;
using namespace std;
/*
/*
- * p2tp.cpp
+ * swift.cpp
* serp++
*
* Created by Victor Grishchenko on 3/6/09.
#include <string.h>
//#include <glog/logging.h>
-#include "p2tp.h"
+#include "swift.h"
#include "datagram.h"
using namespace std;
-using namespace p2tp;
+using namespace swift;
-p2tp::tint Channel::last_tick = 0;
+swift::tint Channel::last_tick = 0;
int Channel::MAX_REORDERING = 4;
bool Channel::SELF_CONN_OK = false;
-p2tp::tint Channel::TIMEOUT = TINT_SEC*60;
+swift::tint Channel::TIMEOUT = TINT_SEC*60;
std::vector<Channel*> Channel::channels(1);
SOCKET Channel::sockets[8] = {0,0,0,0,0,0,0,0};
int Channel::socket_count = 0;
}
-void p2tp::SetTracker(const Address& tracker) {
+void swift::SetTracker(const Address& tracker) {
Channel::tracker = tracker;
}
}
-int p2tp::Listen (Address addr) {
+int swift::Listen (Address addr) {
int sock = Datagram::Bind(addr);
if (sock!=INVALID_SOCKET)
Channel::sockets[Channel::socket_count++] = sock;
}
-void p2tp::Shutdown (int sock_des) {
+void swift::Shutdown (int sock_des) {
for(int i=0; i<Channel::socket_count; i++)
if (sock_des==-1 || Channel::sockets[i]==sock_des) {
Datagram::Close(Channel::sockets[i]);
}
-void p2tp::Loop (tint till) {
+void swift::Loop (tint till) {
Channel::Loop(till);
}
-int p2tp::Open (const char* filename, const Sha1Hash& hash) {
+int swift::Open (const char* filename, const Sha1Hash& hash) {
FileTransfer* ft = new FileTransfer(filename, hash);
int fdes = ft->file().file_descriptor();
if (fdes>0) {
}
-void p2tp::Close (int fd) {
+void swift::Close (int fd) {
// FIXME delete all channels
if (fd>FileTransfer::files.size() && FileTransfer::files[fd])
delete FileTransfer::files[fd];
}
-void p2tp::AddPeer (Address address, const Sha1Hash& root) {
+void swift::AddPeer (Address address, const Sha1Hash& root) {
Channel::peer_selector->AddPeer(address,root);
}
-uint64_t p2tp::Size (int fdes) {
+uint64_t swift::Size (int fdes) {
if (FileTransfer::files.size()>fdes && FileTransfer::files[fdes])
return FileTransfer::files[fdes]->file().size();
else
}
-bool p2tp::IsComplete (int fdes) {
+bool swift::IsComplete (int fdes) {
if (FileTransfer::files.size()>fdes && FileTransfer::files[fdes])
return FileTransfer::files[fdes]->file().is_complete();
else
}
-uint64_t p2tp::Complete (int fdes) {
+uint64_t swift::Complete (int fdes) {
if (FileTransfer::files.size()>fdes && FileTransfer::files[fdes])
return FileTransfer::files[fdes]->file().complete();
else
}
-uint64_t p2tp::SeqComplete (int fdes) {
+uint64_t swift::SeqComplete (int fdes) {
if (FileTransfer::files.size()>fdes && FileTransfer::files[fdes])
return FileTransfer::files[fdes]->file().seq_complete();
else
}
-const Sha1Hash& p2tp::RootMerkleHash (int file) {
+const Sha1Hash& swift::RootMerkleHash (int file) {
FileTransfer* trans = FileTransfer::file(file);
if (!trans)
return Sha1Hash::ZERO;
/*
- * p2tp.h
+ * swift.h
* the main header file for libswift, normally you should only read this one
*
* Created by Victor Grishchenko on 3/6/09.
#include "datagram.h"
#include "hashtree.h"
-namespace p2tp {
+namespace swift {
#define NOW Datagram::now
#include <gtest/gtest.h>
//#include <glog/logging.h>
-#include "p2tp.h"
+#include "swift.h"
#include <time.h>
-using namespace p2tp;
+using namespace swift;
TEST(P2TP,CwndTest) {
int size = st.st_size;//, sizek = (st.st_size>>10) + (st.st_size%1024?1:0) ;
Channel::SELF_CONN_OK = true;
- int sock1 = p2tp::Listen(7001);
+ int sock1 = swift::Listen(7001);
ASSERT_TRUE(sock1>=0);
- int file = p2tp::Open("doc/sofi.jpg");
+ int file = swift::Open("doc/sofi.jpg");
FileTransfer* fileobj = FileTransfer::file(file);
//FileTransfer::instance++;
- p2tp::SetTracker(Address("127.0.0.1",7001));
+ swift::SetTracker(Address("127.0.0.1",7001));
- int copy = p2tp::Open("doc/sofi-copy.jpg",fileobj->root_hash());
+ int copy = swift::Open("doc/sofi-copy.jpg",fileobj->root_hash());
- p2tp::Loop(TINT_SEC);
+ swift::Loop(TINT_SEC);
int count = 0;
- while (p2tp::SeqComplete(copy)!=size && count++<600)
- p2tp::Loop(TINT_SEC);
- ASSERT_EQ(size,p2tp::SeqComplete(copy));
+ while (swift::SeqComplete(copy)!=size && count++<600)
+ swift::Loop(TINT_SEC);
+ ASSERT_EQ(size,swift::SeqComplete(copy));
- p2tp::Close(file);
- p2tp::Close(copy);
+ swift::Close(file);
+ swift::Close(copy);
- p2tp::Shutdown(sock1);
+ swift::Shutdown(sock1);
}
int main (int argc, char** argv) {
- p2tp::LibraryInit();
+ swift::LibraryInit();
testing::InitGoogleTest(&argc, argv);
int ret = RUN_ALL_TESTS();
return ret;
#include <gtest/gtest.h>
//#include <glog/logging.h>
#include "datagram.h"
-#include "p2tp.h" // Arno: for LibraryInit
+#include "swift.h" // Arno: for LibraryInit
-using namespace p2tp;
+using namespace swift;
TEST(Datagram, AddressTest) {
Address addr("127.0.0.1:1000");
int main (int argc, char** argv) {
- p2tp::LibraryInit();
+ swift::LibraryInit();
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
#include <gtest/gtest.h>
#include "hashtree.h"
-using namespace p2tp;
+using namespace swift;
char hash123[] = "a8fdc205a9f19cc1c7507a60c4f01b13d11d7fd0";
char rooth123[] = "d0bdb8ba28076d84d2b3a0e62521b998e42349a1";
#include <vector>
#include <deque>
#include "datagram.h"
-#include "p2tp.h"
+#include "swift.h"
#include <gtest/gtest.h>
-using namespace p2tp;
+using namespace swift;
using namespace std;
/**
int main (int argc, char** argv) {
printf("Warning: use the script to set up dummynet!\n");
- p2tp::LibraryInit();
+ swift::LibraryInit();
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
/*
* transfertest.cpp
- * p2tp
+ * swift
*
* Created by Victor Grishchenko on 10/7/09.
* Copyright 2009 Delft University of Technology. All rights reserved.
*/
//#include <gtest/gtest.h>
//#include <glog/logging.h>
-#include "p2tp.h"
+#include "swift.h"
#include "compat.h"
#include <gtest/gtest.h>
-using namespace p2tp;
+using namespace swift;
const char* BTF = "test_file";
#include <errno.h>
#include <string>
#include <sstream>
-#include "p2tp.h"
+#include "swift.h"
#include "compat/util.h"
#include "ext/seq_picker.cpp" // FIXME FIXME FIXME FIXME
-using namespace p2tp;
+using namespace swift;
std::vector<FileTransfer*> FileTransfer::files(20);