Datagram::bytes_up=0, Datagram::bytes_down=0;
char* Datagram::TimeStr (tint time) {
- static char ret_str[32][4]; // wow
+ assert(!time || time>=epoch);
+ static char ret_str[4][32]; // wow
static int i;
i = (i+1) & 3;
if (time==0)
time = now;
time -= epoch;
+ assert(time>=0);
int hours = time/TINT_HOUR;
time %= TINT_HOUR;
int mins = time/TINT_MIN;
}
void PingPongController::OnAckRcvd(bin64_t ackd) {
- if (ch_->data_out_.empty())
- Swap(new SlowStartController(this));
+ //if (ch_->data_out_.empty())
+ Swap(new SlowStartController(this));
}
bool CwndController::MaySendData() {
+ dprintf("%s #%i maysend %i < %f & %s (rtt %lli)\n",Datagram::TimeStr(),
+ ch_->id,(int)ch_->data_out_.size(),cwnd_,Datagram::TimeStr(NextSendTime()),
+ ch_->rtt_avg_);
return ch_->data_out_.size() < cwnd_ && Datagram::now >= NextSendTime();
}
tint CwndController::NextSendTime () {
+ tint sendtime;
if (ch_->data_out_.size() < cwnd_)
- return ch_->last_send_time_ + ch_->rtt_avg_ / cwnd_;
+ sendtime = ch_->last_send_time_ + (ch_->rtt_avg_ / cwnd_);
else
- return ch_->last_send_time_ + ch_->rtt_avg_ + ch_->dev_avg_ * 4 ;
+ sendtime = ch_->last_send_time_ + ch_->rtt_avg_ + ch_->dev_avg_ * 4 ;
+ return sendtime;
}
void CwndController::OnDataSent(bin64_t b) {
struct CwndController : public SendController {
- float cwnd_;
+ double cwnd_;
CwndController(SendController* orig, int cwnd=1) :
SendController(orig), cwnd_(cwnd) { }
void Channel::Recv (Datagram& dgram) {
+ if (last_send_time_ && rtt_avg_==TINT_SEC && dev_avg_==0) {
+ rtt_avg_ = Datagram::now - last_send_time_;
+ dev_avg_ = rtt_avg_;
+ dprintf("%s #%i rtt init %lli\n",Datagram::TimeStr(),id,rtt_avg_);
+ }
bin64_t data = dgram.size() ? bin64_t::NONE : bin64_t::ALL;
while (dgram.size()) {
uint8_t type = dgram.Pull8();
dprintf("%s #%i -ack (%i,%lli)\n",Datagram::TimeStr(),id,ackd_pos.layer(),ackd_pos.offset());
for (int i=0; i<8 && i<data_out_.size(); i++)
if (data_out_[i].bin.within(ackd_pos)) {
- tintbin x = data_out_[i];
- data_out_[i].bin = bin64_t::ALL;
- tint rtt = Datagram::now-x.time;
+ tint rtt = Datagram::now-data_out_[i].time;
rtt_avg_ = (rtt_avg_*3 + rtt) >> 2;
dev_avg_ = ( dev_avg_*3 + abs(rtt-rtt_avg_) ) >> 2;
dprintf("%s #%i rtt %lli dev %lli\n",
Datagram::TimeStr(),id,rtt_avg_,dev_avg_);
- cc_->OnAckRcvd(x.bin);
+ cc_->OnAckRcvd(data_out_[i].bin);
}
- while (data_out_.size() && data_out_.front().bin==bin64_t::ALL)
- data_out_.pop_front();
ack_in_.set(ackd_pos);
+ while (data_out_.size() && ack_in_.get(data_out_.front().bin)==bins::FILLED)
+ data_out_.pop_front();
}