From 294e1f6b760fbefd95602e1dd613523b0ba92cd3 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Mon, 7 Jan 2008 01:36:09 +0000 Subject: [PATCH] lt sync --- .../include/libtorrent/bandwidth_manager.hpp | 4 ++-- libtorrent/src/broadcast_socket.cpp | 2 +- libtorrent/src/peer_connection.cpp | 3 +++ libtorrent/src/torrent.cpp | 15 +++++++++++++ libtorrent/src/torrent_info.cpp | 21 +++++++++++++++---- libtorrent/src/udp_tracker_connection.cpp | 1 - 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/libtorrent/include/libtorrent/bandwidth_manager.hpp b/libtorrent/include/libtorrent/bandwidth_manager.hpp index cdb05f9d5..68cb7c73a 100644 --- a/libtorrent/include/libtorrent/bandwidth_manager.hpp +++ b/libtorrent/include/libtorrent/bandwidth_manager.hpp @@ -325,7 +325,7 @@ private: l.unlock(); t->expire_bandwidth(m_channel, qe.max_block_size); l.lock(); - TORRENT_ASSERT(amount == limit - m_current_quota); + amount = limit - m_current_quota; continue; } @@ -400,7 +400,7 @@ private: l.lock(); add_history_entry(history_entry( qe.peer, t, hand_out_amount, now + bw_window_size)); - TORRENT_ASSERT(amount == limit - m_current_quota); + amount = limit - m_current_quota; } if (!q.empty()) m_queue.insert(m_queue.begin(), q.begin(), q.end()); if (!tmp.empty()) m_queue.insert(m_queue.begin(), tmp.begin(), tmp.end()); diff --git a/libtorrent/src/broadcast_socket.cpp b/libtorrent/src/broadcast_socket.cpp index af4822fe6..3437648d9 100644 --- a/libtorrent/src/broadcast_socket.cpp +++ b/libtorrent/src/broadcast_socket.cpp @@ -201,7 +201,7 @@ namespace libtorrent for (std::list::iterator i = m_sockets.begin() , end(m_sockets.end()); i != end; ++i) { - if (!socket) continue; + if (!i->socket) continue; i->socket->close(); } } diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index a268f386b..b87553c5d 100755 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -2668,6 +2668,7 @@ namespace libtorrent #ifdef TORRENT_VERBOSE_LOGGING (*m_logger) << "**ERROR**: " << error.message() << "[in peer_connection::on_receive_data]\n"; #endif + set_failed(); on_receive(error, bytes_transferred); throw std::runtime_error(error.message()); } @@ -2828,6 +2829,7 @@ namespace libtorrent (*m_ses.m_logger) << "CONNECTION FAILED: " << m_remote.address().to_string() << ": " << e.message() << "\n"; #endif + set_failed(); m_ses.connection_failed(self(), m_remote, e.message().c_str()); return; } @@ -2888,6 +2890,7 @@ namespace libtorrent #ifdef TORRENT_VERBOSE_LOGGING (*m_logger) << "**ERROR**: " << error.message() << " [in peer_connection::on_send_data]\n"; #endif + set_failed(); throw std::runtime_error(error.message()); } if (m_disconnecting) return; diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index d5ce95551..12db1e59b 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -1589,6 +1589,18 @@ namespace libtorrent p->set_peer_info(0); TORRENT_ASSERT(i != m_connections.end()); m_connections.erase(i); + + // remove from bandwidth request-queue + for (int c = 0; c < 2; ++c) + { + for (queue_t::iterator i = m_bandwidth_queue[c].begin() + , end(m_bandwidth_queue[c].end()); i != end; ++i) + { + if (i->peer != p) continue; + m_bandwidth_queue[c].erase(i); + break; + } + } } catch (std::exception& e) { @@ -2605,6 +2617,9 @@ namespace libtorrent { session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); + TORRENT_ASSERT(m_bandwidth_queue[0].size() <= m_connections.size()); + TORRENT_ASSERT(m_bandwidth_queue[1].size() <= m_connections.size()); + int num_uploads = 0; std::map num_requests; for (const_peer_iterator i = begin(); i != end(); ++i) diff --git a/libtorrent/src/torrent_info.cpp b/libtorrent/src/torrent_info.cpp index b89510f9f..0aac5a7ba 100755 --- a/libtorrent/src/torrent_info.cpp +++ b/libtorrent/src/torrent_info.cpp @@ -350,10 +350,23 @@ namespace libtorrent { m_name = info["name"].string(); } fs::path tmp = m_name; - if (tmp.is_complete()) throw std::runtime_error("torrent contains " - "a file with an absolute path: '" + m_name + "'"); - if (tmp.has_branch_path()) throw std::runtime_error( - "torrent contains name with directories: '" + m_name + "'"); + if (tmp.is_complete()) + { + m_name = tmp.leaf(); + } + else if (tmp.has_branch_path()) + { + fs::path p; + for (fs::path::iterator i = tmp.begin() + , end(tmp.end()); i != end; ++i) + { + if (*i == "." || *i == "..") continue; + p /= *i; + } + m_name = p.string(); + } + if (m_name == ".." || m_name == ".") + throw std::runtime_error("invalid 'name' of torrent (possible exploit attempt)"); // extract file list entry const* i = info.find_key("files"); diff --git a/libtorrent/src/udp_tracker_connection.cpp b/libtorrent/src/udp_tracker_connection.cpp index eb138e67a..0ad38ef86 100755 --- a/libtorrent/src/udp_tracker_connection.cpp +++ b/libtorrent/src/udp_tracker_connection.cpp @@ -106,7 +106,6 @@ namespace libtorrent , udp::resolver::iterator i) try { if (error == asio::error::operation_aborted) return; - if (!m_socket.is_open()) return; // the operation was aborted if (error || i == udp::resolver::iterator()) { fail(-1, error.message().c_str());