forked from premiere/premiere-libtorrent
header fix and refactor in udp_tracker_connection and typos in lazy_entry
This commit is contained in:
parent
139528aae4
commit
f715ebfd97
|
@ -116,7 +116,7 @@ namespace libtorrent
|
|||
// to know how many characters follow.
|
||||
char const* ptr;
|
||||
|
||||
// lexicographical comparison of strings. Order is consisten
|
||||
// lexicographical comparison of strings. Order is consistent
|
||||
// with memcmp.
|
||||
bool operator<(pascal_string const& rhs) const
|
||||
{
|
||||
|
@ -131,7 +131,7 @@ namespace libtorrent
|
|||
// type whose concrete type is one of:
|
||||
//
|
||||
// 1. dictionary (maps strings -> lazy_entry)
|
||||
// 2. list (sequence of lazy_entry, i.e. heterogenous)
|
||||
// 2. list (sequence of lazy_entry, i.e. heterogeneous)
|
||||
// 3. integer
|
||||
// 4. string
|
||||
//
|
||||
|
|
|
@ -39,10 +39,12 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <mutex>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
#include "libtorrent/udp_socket.hpp"
|
||||
#include "libtorrent/tracker_manager.hpp"
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/span.hpp"
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
|
|
@ -36,7 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "libtorrent/parse_url.hpp"
|
||||
#include "libtorrent/udp_tracker_connection.hpp"
|
||||
#include "libtorrent/io.hpp"
|
||||
#include "libtorrent/hex.hpp"
|
||||
#include "libtorrent/broadcast_socket.hpp" // for is_any
|
||||
#include "libtorrent/random.hpp"
|
||||
|
@ -45,15 +44,12 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/ip_filter.hpp"
|
||||
#include "libtorrent/aux_/time.hpp"
|
||||
#include "libtorrent/aux_/io.hpp"
|
||||
#include "libtorrent/span.hpp"
|
||||
#include "libtorrent/peer.hpp"
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
#include "libtorrent/socket_io.hpp"
|
||||
#endif
|
||||
|
||||
using namespace std::placeholders;
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
||||
|
@ -84,8 +80,7 @@ namespace libtorrent
|
|||
int port;
|
||||
error_code ec;
|
||||
|
||||
using std::ignore;
|
||||
std::tie(protocol, ignore, hostname, port, ignore)
|
||||
std::tie(protocol, std::ignore, hostname, port, std::ignore)
|
||||
= parse_url_components(tracker_req().url, ec);
|
||||
if (port == -1) port = protocol == "http" ? 80 : 443;
|
||||
|
||||
|
@ -107,6 +102,7 @@ namespace libtorrent
|
|||
}
|
||||
else
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
ADD_OUTSTANDING_ASYNC("udp_tracker_connection::name_lookup");
|
||||
// when stopping, pass in the prefer cache flag, because we
|
||||
// don't want to get stuck on DNS lookups when shutting down
|
||||
|
@ -135,7 +131,7 @@ namespace libtorrent
|
|||
, char const* msg, int interval, int min_interval)
|
||||
{
|
||||
// m_target failed. remove it from the endpoint list
|
||||
std::vector<tcp::endpoint>::iterator i = std::find(m_endpoints.begin()
|
||||
auto const i = std::find(m_endpoints.begin()
|
||||
, m_endpoints.end(), tcp::endpoint(m_target.address(), m_target.port()));
|
||||
|
||||
if (i != m_endpoints.end()) m_endpoints.erase(i);
|
||||
|
@ -204,15 +200,13 @@ namespace libtorrent
|
|||
// we're listening on. To make sure the tracker get our
|
||||
// correct listening address.
|
||||
|
||||
for (std::vector<address>::const_iterator i = addresses.begin()
|
||||
, end(addresses.end()); i != end; ++i)
|
||||
m_endpoints.push_back(tcp::endpoint(*i, std::uint16_t(port)));
|
||||
for (auto const& addr : addresses)
|
||||
m_endpoints.push_back(tcp::endpoint(addr, std::uint16_t(port)));
|
||||
|
||||
if (tracker_req().filter)
|
||||
{
|
||||
// remove endpoints that are filtered by the IP filter
|
||||
for (std::vector<tcp::endpoint>::iterator k = m_endpoints.begin();
|
||||
k != m_endpoints.end();)
|
||||
for (auto k = m_endpoints.begin(); k != m_endpoints.end();)
|
||||
{
|
||||
if (tracker_req().filter->access(k->address()) == ip_filter::blocked)
|
||||
{
|
||||
|
@ -283,8 +277,7 @@ namespace libtorrent
|
|||
void udp_tracker_connection::start_announce()
|
||||
{
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
std::map<address, connection_cache_entry>::iterator cc
|
||||
= m_connection_cache.find(m_target.address());
|
||||
auto const cc = m_connection_cache.find(m_target.address());
|
||||
if (cc != m_connection_cache.end())
|
||||
{
|
||||
// we found a cached entry! Now, we can only
|
||||
|
@ -467,7 +460,7 @@ namespace libtorrent
|
|||
|
||||
// reset transaction
|
||||
update_transaction_id();
|
||||
std::uint64_t const connection_id = aux::read_int64(buf);
|
||||
std::int64_t const connection_id = aux::read_int64(buf);
|
||||
|
||||
std::lock_guard<std::mutex> l(m_cache_mutex);
|
||||
connection_cache_entry& cce = m_connection_cache[m_target.address()];
|
||||
|
@ -554,8 +547,7 @@ namespace libtorrent
|
|||
{
|
||||
if (m_abort) return;
|
||||
|
||||
std::map<address, connection_cache_entry>::iterator i
|
||||
= m_connection_cache.find(m_target.address());
|
||||
auto const i = m_connection_cache.find(m_target.address());
|
||||
// this isn't really supposed to happen
|
||||
TORRENT_ASSERT(i != m_connection_cache.end());
|
||||
if (i == m_connection_cache.end()) return;
|
||||
|
@ -632,17 +624,16 @@ namespace libtorrent
|
|||
for (int i = 0; i < num_peers; ++i)
|
||||
{
|
||||
ipv4_peer_entry e;
|
||||
memcpy(&e.ip[0], buf.data(), 4);
|
||||
std::memcpy(e.ip.data(), buf.data(), 4);
|
||||
buf = buf.subspan(4);
|
||||
e.port = aux::read_uint16(buf);
|
||||
resp.peers4.push_back(e);
|
||||
}
|
||||
|
||||
std::list<address> ip_list;
|
||||
for (std::vector<tcp::endpoint>::const_iterator i = m_endpoints.begin()
|
||||
, end(m_endpoints.end()); i != end; ++i)
|
||||
for (auto const& endp : m_endpoints)
|
||||
{
|
||||
ip_list.push_back(i->address());
|
||||
ip_list.push_back(endp.address());
|
||||
}
|
||||
|
||||
cb->tracker_response(tracker_req(), m_target.address(), ip_list
|
||||
|
@ -711,8 +702,7 @@ namespace libtorrent
|
|||
tracker_request const& req = tracker_req();
|
||||
aux::session_settings const& settings = m_man.settings();
|
||||
|
||||
std::map<address, connection_cache_entry>::iterator i
|
||||
= m_connection_cache.find(m_target.address());
|
||||
auto const i = m_connection_cache.find(m_target.address());
|
||||
// this isn't really supposed to happen
|
||||
TORRENT_ASSERT(i != m_connection_cache.end());
|
||||
if (i == m_connection_cache.end()) return;
|
||||
|
@ -773,14 +763,12 @@ namespace libtorrent
|
|||
if (!m_hostname.empty())
|
||||
{
|
||||
m_man.send_hostname(m_hostname.c_str()
|
||||
, m_target.port(), span<char const>(buf
|
||||
, int(sizeof(buf) - out.size())), ec
|
||||
, m_target.port(), {buf, std::size_t(sizeof(buf) - out.size())}, ec
|
||||
, udp_socket::tracker_connection);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_man.send(m_target, span<char const>(buf
|
||||
, int(sizeof(buf) - out.size())), ec
|
||||
m_man.send(m_target, {buf, std::size_t(sizeof(buf) - out.size())}, ec
|
||||
, udp_socket::tracker_connection);
|
||||
}
|
||||
m_state = action_t::announce;
|
||||
|
|
Loading…
Reference in New Issue