int main (int argn, char** args) {
srand(time(NULL));
- FileTransfer::instance = rand();
if (argn<4) {
fprintf(stderr,"parameters: root_hash filename tracker_ip:port [own_ip:port]\n");
delay_ *= 2;
if (delay_>TINT_SEC*58)
delay_ = TINT_SEC*58;
- if (b!=bin64_t::ALL)
- Swap(new PingPongController(this));
+ if (b!=bin64_t::ALL && b!=bin64_t::NONE)
+ Swap(new SlowStartController(this));
}
void KeepAliveController::OnDataRecvd(bin64_t b) {
}
+CwndController::CwndController(SendController* orig, int cwnd) :
+SendController(orig), cwnd_(cwnd), last_change_(0) {
+ ch_->rtt_avg_ = TINT_SEC; // cannot trust the past value
+ ch_->dev_avg_ = 0;
+}
bool CwndController::MaySendData() {
dprintf("%s #%i sendctrl may send %i < %f & %s (rtt %lli)\n",tintstr(),
void CwndController::OnDataSent(bin64_t b) {
if (b==bin64_t::ALL || b==bin64_t::NONE) {
if (MaySendData())
- Swap(new PingPongController(this));
+ Swap(new KeepAliveController(this));
}
}
double cwnd_;
tint last_change_;
- CwndController(SendController* orig, int cwnd=1) :
- SendController(orig), cwnd_(cwnd), last_change_(0) { }
+ CwndController(SendController* orig, int cwnd=1) ;
bool MaySendData() ;
tint NextSendTime () ;
Channel::Channel (FileTransfer* transfer, int socket, Address peer_addr) :
transfer_(transfer), peer_(peer_addr), peer_channel_id_(0), pex_out_(0),
socket_(socket==-1?sockets[0]:socket), // FIXME
- data_out_cap_(bin64_t::ALL),
+ data_out_cap_(bin64_t::ALL), last_data_time_(0),
own_id_mentioned_(false), next_send_time_(0), last_send_time_(0),
last_recv_time_(0), rtt_avg_(TINT_SEC), dev_avg_(0), dip_avg_(TINT_SEC)
{
/** Smoothed averages for RTT, RTT deviation and data interarrival periods. */
tint rtt_avg_, dev_avg_, dip_avg_;
tint last_send_time_;
+ tint last_data_time_;
tint last_recv_time_;
tint next_send_time_;
tint peer_send_time_;
dprintf("%s #%i %cdata (%lli)\n",tintstr(),id,ok?'-':'!',pos.offset());
if (ok) {
data_in_ = tintbin(NOW,pos);
- if (last_recv_time_) {
- tint dip = NOW - last_recv_time_; // FIXME: was it an ACK?
+ if (last_data_time_) {
+ tint dip = NOW - last_data_time_;
dip_avg_ = ( dip_avg_*3 + dip ) >> 2;
}
+ last_data_time_ = NOW;
transfer().picker().Received(pos); // so dirty; FIXME FIXME FIXME
return pos;
} else
int file = p2tp::Open("doc/sofi.jpg");
FileTransfer* fileobj = FileTransfer::file(file);
- FileTransfer::instance++;
+ //FileTransfer::instance++;
p2tp::SetTracker(Address("127.0.0.1",7001));
// retrieve it
unlink("copy");
- FileTransfer::instance = 1;
FileTransfer* leech_transfer = new FileTransfer("copy",seed->root_hash());
HashTree* leech = & leech_transfer->file();
leech_transfer->picker().Randomize(0);
for (int i=0; i<5; i++) {
if (i==2) { // now: stop, save, start
delete leech_transfer;
- FileTransfer::instance = 1;
leech_transfer = new FileTransfer("copy",seed->root_hash());
leech = & leech_transfer->file();
leech_transfer->picker().Randomize(0);