From: victor Date: Tue, 24 Nov 2009 11:58:44 +0000 (+0000) Subject: routine X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=be4698c6579cc67dfa4f93b2545c7e25cd2b3319;p=swift-upb.git routine git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@626 e16421f0-f15b-0410-abcd-98678b794739 --- diff --git a/datagram.cpp b/datagram.cpp index ecb72df..4d6a4ef 100644 --- a/datagram.cpp +++ b/datagram.cpp @@ -102,7 +102,7 @@ int Datagram::Recv () { socklen_t addrlen = sizeof(struct sockaddr_in); offset = 0; length = recvfrom (sock, (char *)buf, MAXDGRAMSZ, 0, - (struct sockaddr*)&(addr), &addrlen); + (struct sockaddr*)&(addr.addr), &addrlen); if (length<0) { length = 0; print_error("error on recv"); diff --git a/ext/send_control.cpp b/ext/send_control.cpp index 490ecfa..c2c1cad 100644 --- a/ext/send_control.cpp +++ b/ext/send_control.cpp @@ -51,7 +51,8 @@ void PingPongController::OnAckRcvd(bin64_t ackd) { } -KeepAliveController::KeepAliveController (Channel* ch) : SendController(ch), delay_(ch->rtt_avg_) { +KeepAliveController::KeepAliveController (Channel* ch) : +SendController(ch), delay_(ch->rtt_avg_) { } @@ -108,7 +109,7 @@ bool CwndController::MaySendData() { void CwndController::OnDataSent(bin64_t b) { - if ( (b==bin64_t::ALL || b==bin64_t::NONE) && MaySendData() ) { // no more data (no hints?) + if ( (b==bin64_t::ALL || b==bin64_t::NONE) && MaySendData() ) {// no more data (no hints?) Schedule(NOW+ch_->rtt_avg_); // soft pause; nothing to send yet if (ch_->last_send_data_time_ < NOW-ch_->rtt_avg_) Swap(new KeepAliveController(this)); // really, nothing to send diff --git a/hashtree.cpp b/hashtree.cpp index fd3a713..4f08b11 100644 --- a/hashtree.cpp +++ b/hashtree.cpp @@ -85,6 +85,7 @@ complete_(0), completek_(0) { fd_ = open(filename,OPENFLAGS,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); if (fd_<0) { + fd_ = 0; print_error("cannot open the file"); return; } @@ -96,6 +97,7 @@ complete_(0), completek_(0) strcpy(hfn,hash_filename); hash_fd_ = open(hfn,OPENFLAGS,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); if (hash_fd_<0) { + hash_fd_ = 0; print_error("cannot open hash file"); return; } @@ -110,7 +112,7 @@ complete_(0), completek_(0) void HashTree::Submit () { size_ = file_size(fd_); - sizek_ = (size_>>10) + ((size_&1023) ? 1 : 0); + sizek_ = (size_ + 1023) >> 10; peak_count_ = bin64_t::peaks(sizek_,peaks_); int hashes_size = Sha1Hash::SIZE*sizek_*2; file_resize(hash_fd_,hashes_size); @@ -150,7 +152,7 @@ void HashTree::Submit () { for some optimizations. */ void HashTree::RecoverProgress () { size_t size = file_size(fd_); - size_t sizek = (size>>10) + ((size&1023) ? 1 : 0); + size_t sizek = (size + 1023) >> 10; bin64_t peaks[64]; int peak_count = bin64_t::peaks(sizek,peaks); for(int i=0; i>10) + ((size_&1023) ? 1 : 0); + sizek_ = (size_ + 1023) >> 10; size_t cur_size = file_size(fd_); if ( cur_size<=(sizek_-1)<<10 || cur_size>sizek_<<10 ) @@ -343,5 +345,7 @@ HashTree::~HashTree () { memory_unmap(hash_fd_, hashes_, sizek_*2*sizeof(Sha1Hash)); if (fd_) close(fd_); + if (hash_fd_) + close(hash_fd_); } diff --git a/sendrecv.cpp b/sendrecv.cpp index 6895739..7506751 100644 --- a/sendrecv.cpp +++ b/sendrecv.cpp @@ -54,6 +54,9 @@ bin64_t Channel::DequeueHint () { // TODO: resilience hint_in_.pop_front(); if (time < NOW-TINT_SEC*3/2 ) //NOW-8*rtt_avg_) continue; + // Totally flawed: + // a. May empty the queue when you least expect + // b. May lose parts of partially ACKd HINTs send = file().ack_out().find_filtered(ack_in_,hint,bins::FILLED); send = send.left_foot(); // single packet if (send!=bin64_t::NONE) @@ -275,7 +278,7 @@ void Channel::CleanHintOut (bin64_t pos) { while (hitransfer_==this) + delete Channel::channels[i]; }