/* * datasendrecv.cpp * serp++ * * Created by Victor Grishchenko on 3/6/09. * Copyright 2009 Delft Technical University. All rights reserved. * */ #include #include #include "p2tp.h" using namespace std; using namespace p2tp; void Channel::AddPeakHashes (Datagram& dgram) { const std::vector& peaks = file().hashes.peak_hashes(); for(int i=0; idata_out.size()) { Datagram dgram(socket_,peer); dgram.Push32(peer_channel_id); AddAck(dgram); AddHint(dgram); AddData(dgram); // always the last: might be tail block if (dgram.size()==4 && now-last_send_time2) //std::max(1,cc.peer_cwnd()*2)) need = need.left(); return need; } void Channel::AddHint (Datagram& dgram) { LOG(INFO)<<"peer cwnd "<=file().packet_size()) RETLOG("DATA pos out of bounds"); Sha1Hash hash(data,length); if (file().OfferHash(pos, hash)) { //memcpy(file->data+offset*KILO, //channel->datagram->data+channel->datagram->offset,KILO); pwrite(fd,data,length,pos.offset()*1024); // TODO; if (last) ftruncate if (pos==file().hashes.data_mass()) { int lendiff = 1024-length; ftruncate(fd, file().size()-lendiff); } data_in = pos; file().ack_out |= pos; file().history.push_back(file().ack_out.get(pos)); if (file().history.size()==file().packet_size()+1) // FIXME: encapsulate file().status_ = File::DONE; cc.OnCongestionEvent(CongestionControl::DATA_EV); DLOG(INFO)<<*this<<" DATA< "<file().hashes.data_mass()) { LOG(WARNING) << "out-of-bounds ACK"; return; } ack_in |= pos; for(int i=0; i