forked from premiere/premiere-libtorrent
use new bdecoder in ut_metadata class
This commit is contained in:
parent
eab1055938
commit
8d7af2344f
|
@ -126,7 +126,7 @@ namespace libtorrent {namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool received_metadata(ut_metadata_peer_plugin& source
|
bool received_metadata(ut_metadata_peer_plugin& source
|
||||||
, char const* buf, int size, int piece, int total_size);
|
, span<char const> buf, int piece, int total_size);
|
||||||
|
|
||||||
// returns a piece of the metadata that
|
// returns a piece of the metadata that
|
||||||
// we should request.
|
// we should request.
|
||||||
|
@ -309,9 +309,9 @@ namespace libtorrent {namespace {
|
||||||
|
|
||||||
if (!m_pc.packet_finished()) return true;
|
if (!m_pc.packet_finished()) return true;
|
||||||
|
|
||||||
std::ptrdiff_t len;
|
error_code ec;
|
||||||
entry msg = bdecode(body.begin(), body.end(), len);
|
bdecode_node msg = bdecode(body, ec);
|
||||||
if (msg.type() != entry::dictionary_t)
|
if (msg.type() != bdecode_node::dict_t)
|
||||||
{
|
{
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA"
|
m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA"
|
||||||
|
@ -321,10 +321,9 @@ namespace libtorrent {namespace {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry const* type_ent = msg.find_key("msg_type");
|
bdecode_node const& type_ent = msg.dict_find_int("msg_type");
|
||||||
entry const* piece_ent = msg.find_key("piece");
|
bdecode_node const& piece_ent = msg.dict_find_int("piece");
|
||||||
if (type_ent == nullptr || type_ent->type() != entry::int_t
|
if (!type_ent || !piece_ent)
|
||||||
|| piece_ent == nullptr || piece_ent->type() != entry::int_t)
|
|
||||||
{
|
{
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA"
|
m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA"
|
||||||
|
@ -334,8 +333,8 @@ namespace libtorrent {namespace {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// TODO: make this an enum class
|
// TODO: make this an enum class
|
||||||
auto const type = int(type_ent->integer());
|
auto const type = static_cast<int>(type_ent.int_value());
|
||||||
auto const piece = int(piece_ent->integer());
|
auto const piece = static_cast<int>(piece_ent.int_value());
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA"
|
m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA"
|
||||||
|
@ -386,9 +385,9 @@ namespace libtorrent {namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sent_requests.erase(i);
|
m_sent_requests.erase(i);
|
||||||
entry const* total_size = msg.find_key("total_size");
|
auto const len = msg.data_section().size();
|
||||||
m_tp.received_metadata(*this, body.begin() + len, int(body.size()) - int(len), piece
|
auto const total_size = msg.dict_find_int_value("total_size", 0);
|
||||||
, (total_size && total_size->type() == entry::int_t) ? int(total_size->integer()) : 0);
|
m_tp.received_metadata(*this, body.subspan(len), piece, static_cast<int>(total_size));
|
||||||
maybe_send_request();
|
maybe_send_request();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -523,9 +522,8 @@ namespace libtorrent {namespace {
|
||||||
return piece;
|
return piece;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ut_metadata_plugin::received_metadata(
|
bool ut_metadata_plugin::received_metadata(ut_metadata_peer_plugin& source
|
||||||
ut_metadata_peer_plugin& source
|
, span<char const> buf, int const piece, int const total_size)
|
||||||
, char const* buf, int const size, int const piece, int const total_size)
|
|
||||||
{
|
{
|
||||||
if (m_torrent.valid_metadata())
|
if (m_torrent.valid_metadata())
|
||||||
{
|
{
|
||||||
|
@ -533,7 +531,7 @@ namespace libtorrent {namespace {
|
||||||
source.m_pc.peer_log(peer_log_alert::info, "UT_METADATA"
|
source.m_pc.peer_log(peer_log_alert::info, "UT_METADATA"
|
||||||
, "already have metadata");
|
, "already have metadata");
|
||||||
#endif
|
#endif
|
||||||
m_torrent.add_redundant_bytes(size, waste_reason::piece_unknown);
|
m_torrent.add_redundant_bytes(static_cast<int>(buf.size()), waste_reason::piece_unknown);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,13 +573,13 @@ namespace libtorrent {namespace {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (piece * 16 * 1024 + size > m_metadata_size)
|
if (piece * 16 * 1024 + buf.size() > m_metadata_size)
|
||||||
{
|
{
|
||||||
// this piece is invalid
|
// this piece is invalid
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::memcpy(&m_metadata[piece * 16 * 1024], buf, aux::numeric_cast<std::size_t>(size));
|
std::memcpy(&m_metadata[piece * 16 * 1024], buf.data(), aux::numeric_cast<std::size_t>(buf.size()));
|
||||||
// mark this piece has 'have'
|
// mark this piece has 'have'
|
||||||
m_requested_metadata[piece].num_requests = std::numeric_limits<int>::max();
|
m_requested_metadata[piece].num_requests = std::numeric_limits<int>::max();
|
||||||
m_requested_metadata[piece].source = source.shared_from_this();
|
m_requested_metadata[piece].source = source.shared_from_this();
|
||||||
|
|
Loading…
Reference in New Issue