From 5d65eab1bd5b8a0175b42b9630b9325935e0ec33 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 1 Mar 2004 00:50:00 +0000 Subject: [PATCH] *** empty log message *** --- include/libtorrent/piece_picker.hpp | 3 +- include/libtorrent/torrent.hpp | 2 + include/libtorrent/tracker_manager.hpp | 2 + src/http_tracker_connection.cpp | 1 + src/identify_client.cpp | 18 ++++++++ src/policy.cpp | 58 ++++++++++++++++---------- src/torrent.cpp | 5 +++ src/udp_tracker_connection.cpp | 1 + 8 files changed, 65 insertions(+), 25 deletions(-) diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 61402a062..84364adc9 100755 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -100,8 +100,7 @@ namespace libtorrent // info about each block block_info info[max_blocks_per_piece]; - // TODO: store a crc and a peer_connection reference - // for each block. Then if the hash test fails on the + // TODO: If the hash test fails on the // piece, redownload one block from another peer // then the first time, and check the hash again. // also maintain a counter how many times a piece-hash diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 9eda49cd9..f98ab0163 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -270,6 +270,8 @@ namespace libtorrent m_password = pw; } + const address& current_tracker() const; + // DEBUG #ifndef NDEBUG logger* spawn_logger(const char* title); diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 7fa76fd89..88f367ff8 100755 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -105,6 +105,8 @@ namespace libtorrent int response_code , const std::string& description) = 0; + address m_tracker_address; + #ifndef NDEBUG virtual void debug_log(const std::string& line) = 0; #endif diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index e48680628..11b76e221 100755 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -109,6 +109,7 @@ namespace libtorrent // TODO: this is a problem. DNS-lookup is blocking! // (may block up to 5 seconds) address a(connect_to_host->c_str(), port); + if (c) c->m_tracker_address = a; boost::shared_ptr s(new socket(socket::tcp, false)); s->connect(a); diff --git a/src/identify_client.cpp b/src/identify_client.cpp index f4e1c9393..7c8268aa5 100755 --- a/src/identify_client.cpp +++ b/src/identify_client.cpp @@ -177,6 +177,9 @@ namespace libtorrent else if (std::equal(f->id, f->id+2, "MT")) identity << "Moonlight Torrent "; + else if (std::equal(f->id, f->id+2, "TS")) + identity << "TorrentStorm "; + // unknown client else identity << std::string(f->id, f->id+2) << " "; @@ -236,6 +239,21 @@ namespace libtorrent return "XanTorrent"; } + if (std::equal(PID, PID + 7, "Plus---")) + { + return "Bittorrent Plus"; + } + + if (std::equal(PID, PID + 16, "Deadman Walking-")) + { + return "Deadman"; + } + + if (std::equal(PID, PID + 7, "btuga")) + { + return "BTugaXP"; + } + if (std::equal(PID, PID + 7, "btfans")) { return "SimpleBT"; diff --git a/src/policy.cpp b/src/policy.cpp index e391e11bd..b267524a6 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -641,30 +641,30 @@ namespace libtorrent } } - // make sure we don't have too many - // unchoked peers - // TODO: this could result in two quick - // choke-unchoke messages. - while (m_num_unchoked > m_max_uploads) + if (m_max_uploads < m_torrent->num_peers()) { + // make sure we don't have too many + // unchoked peers + while (m_num_unchoked > m_max_uploads) + { + peer* p = find_choke_candidate(); + assert(p); + p->connection->send_choke(); + --m_num_unchoked; + } + + // optimistic unchoke. trade the 'worst' + // unchoked peer with one of the choked + assert(m_num_unchoked <= m_torrent->num_peers()); peer* p = find_choke_candidate(); - assert(p); - p->connection->send_choke(); - --m_num_unchoked; + if (p) + { + p->connection->send_choke(); + --m_num_unchoked; + unchoke_one_peer(); + } } - // optimistic unchoke. trade the 'worst' - // unchoked peer with one of the choked - assert(m_num_unchoked <= m_torrent->num_peers()); - peer* p = find_choke_candidate(); - if (p) - { - p->connection->send_choke(); - --m_num_unchoked; - unchoke_one_peer(); - } - - // make sure we have enough // unchoked peers while (m_num_unchoked < m_max_uploads && unchoke_one_peer()); @@ -691,10 +691,22 @@ namespace libtorrent { assert(!c.is_local()); - // TODO: have an exception if the incoming connection - // is from the tracker - if(m_torrent->num_peers() >= m_max_connections) + // if the connection comes from the tracker, + // it's probably just a NAT-check. Ignore the + // num connections constraint then. + // TODO: mske sure this works + if (m_torrent->num_peers() >= m_max_connections + && c.get_socket()->sender().ip() != m_torrent->current_tracker().ip()) + { throw protocol_error("too many connections, refusing incoming connection"); // cause a disconnect + } + +#ifndef NDEBUG + if (c.get_socket()->sender().ip() == m_torrent->current_tracker().ip()) + { + m_torrent->debug_log("overriding connection limit for tracker NAT-check"); + } +#endif std::vector::iterator i = std::find_if( m_peers.begin() diff --git a/src/torrent.cpp b/src/torrent.cpp index 5d46138c5..6e3889052 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -718,6 +718,11 @@ namespace libtorrent return true; } + const address& torrent::current_tracker() const + { + return m_tracker_address; + } + torrent_status torrent::status() const { assert(std::accumulate( diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index 16f87af3a..d87af5bfb 100755 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -74,6 +74,7 @@ namespace libtorrent // TODO: this is a problem. DNS-lookup is blocking! // (may block up to 5 seconds) address a(hostname.c_str(), port); + if (c) c->m_tracker_address = a; m_socket.reset(new socket(socket::udp, false)); m_socket->connect(a);