forked from premiere/premiere-libtorrent
improved port reading in lsd, minor code refactor
This commit is contained in:
parent
e73435a77b
commit
6b70ac1f77
|
@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#define TORRENT_LSD_HPP
|
||||
|
||||
#include "libtorrent/socket.hpp"
|
||||
#include "libtorrent/peer_id.hpp"
|
||||
#include "libtorrent/sha1_hash.hpp"
|
||||
#include "libtorrent/broadcast_socket.hpp"
|
||||
#include "libtorrent/deadline_timer.hpp"
|
||||
#include "libtorrent/aux_/lsd.hpp"
|
||||
|
@ -74,7 +74,7 @@ private:
|
|||
#endif
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
bool should_log() const;
|
||||
void debug_log(char const* fmt, ...) const TORRENT_FORMAT(2,3);
|
||||
void debug_log(char const* fmt, ...) const TORRENT_FORMAT(2, 3);
|
||||
#endif
|
||||
|
||||
// used to resend udp packets in case
|
||||
|
|
20
src/lsd.cpp
20
src/lsd.cpp
|
@ -36,7 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <cstdio> // for vsnprintf
|
||||
|
||||
#include "libtorrent/lsd.hpp"
|
||||
#include "libtorrent/io.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
#include "libtorrent/random.hpp"
|
||||
#include "libtorrent/http_parser.hpp"
|
||||
|
@ -87,7 +86,7 @@ bool lsd::should_log() const
|
|||
return m_callback.should_log_lsd();
|
||||
}
|
||||
|
||||
TORRENT_FORMAT(2,3)
|
||||
TORRENT_FORMAT(2, 3)
|
||||
void lsd::debug_log(char const* fmt, ...) const
|
||||
{
|
||||
if (!should_log()) return;
|
||||
|
@ -206,7 +205,7 @@ void lsd::on_announce(udp::endpoint const& from, char const* buf
|
|||
http_parser p;
|
||||
|
||||
bool error = false;
|
||||
p.incoming(span<char const>(buf, bytes_transferred), error);
|
||||
p.incoming({buf, bytes_transferred}, error);
|
||||
|
||||
if (!p.header_finished() || error)
|
||||
{
|
||||
|
@ -233,7 +232,14 @@ void lsd::on_announce(udp::endpoint const& from, char const* buf
|
|||
return;
|
||||
}
|
||||
|
||||
int const port = std::atoi(port_str.c_str());
|
||||
long const port = std::strtol(port_str.c_str(), nullptr, 10);
|
||||
if (port <= 0 || port >= int(std::numeric_limits<std::uint16_t>::max()))
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
debug_log("<== LSD: invalid BT-SEARCH port value: %s", port_str.c_str());
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
auto const& headers = p.headers();
|
||||
|
||||
|
@ -242,7 +248,7 @@ void lsd::on_announce(udp::endpoint const& from, char const* buf
|
|||
{
|
||||
// we expect it to be hexadecimal
|
||||
// if it isn't, it's not our cookie anyway
|
||||
long const cookie = strtol(cookie_iter->second.c_str(), nullptr, 16);
|
||||
long const cookie = std::strtol(cookie_iter->second.c_str(), nullptr, 16);
|
||||
if (cookie == m_cookie)
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
|
@ -266,7 +272,7 @@ void lsd::on_announce(udp::endpoint const& from, char const* buf
|
|||
continue;
|
||||
}
|
||||
|
||||
sha1_hash ih(nullptr);
|
||||
sha1_hash ih;
|
||||
aux::from_hex(ih_str, ih.data());
|
||||
|
||||
if (!ih.is_all_zeros() && port != 0)
|
||||
|
@ -276,7 +282,7 @@ void lsd::on_announce(udp::endpoint const& from, char const* buf
|
|||
{
|
||||
debug_log("<== LSD: %s:%d ih: %s"
|
||||
, print_address(from.address()).c_str()
|
||||
, port, ih_str.c_str());
|
||||
, int(port), ih_str.c_str());
|
||||
}
|
||||
#endif
|
||||
// we got an announce, pass it on through the callback
|
||||
|
|
Loading…
Reference in New Issue