* 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
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++;
--- /dev/null
+/*
+ * 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();
+
+}
}
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 {
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;
}
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_; }