removed exceptions from metadata extensions
This commit is contained in:
parent
2fe729c9f5
commit
e2e4a34429
|
@ -281,18 +281,15 @@ namespace libtorrent { namespace
|
||||||
// called when the extension handshake from the other end is received
|
// called when the extension handshake from the other end is received
|
||||||
virtual bool on_extension_handshake(entry const& h)
|
virtual bool on_extension_handshake(entry const& h)
|
||||||
{
|
{
|
||||||
entry const& messages = h["m"];
|
m_message_index = 0;
|
||||||
if (entry const* index = messages.find_key("LT_metadata"))
|
entry const* messages = h.find_key("m");
|
||||||
{
|
if (!messages || messages->type() != entry::dictionary_t) return false;
|
||||||
|
|
||||||
|
entry const* index = messages->find_key("LT_metadata");
|
||||||
|
if (!index || index->type() != entry::int_t) return false;
|
||||||
m_message_index = int(index->integer());
|
m_message_index = int(index->integer());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
m_message_index = 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_metadata_request(std::pair<int, int> req)
|
void write_metadata_request(std::pair<int, int> req)
|
||||||
{
|
{
|
||||||
|
@ -376,7 +373,10 @@ namespace libtorrent { namespace
|
||||||
if (m_message_index == 0) return false;
|
if (m_message_index == 0) return false;
|
||||||
|
|
||||||
if (length > 500 * 1024)
|
if (length > 500 * 1024)
|
||||||
throw protocol_error("LT_metadata message larger than 500 kB");
|
{
|
||||||
|
m_pc.disconnect("LT_metadata message larger than 500 kB");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (body.left() < 1) return true;
|
if (body.left() < 1) return true;
|
||||||
int type = detail::read_uint8(body.begin);
|
int type = detail::read_uint8(body.begin);
|
||||||
|
@ -392,7 +392,8 @@ namespace libtorrent { namespace
|
||||||
if (length != 3)
|
if (length != 3)
|
||||||
{
|
{
|
||||||
// invalid metadata request
|
// invalid metadata request
|
||||||
throw protocol_error("invalid metadata request");
|
m_pc.disconnect("invalid metadata request");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_metadata(std::make_pair(start, size));
|
write_metadata(std::make_pair(start, size));
|
||||||
|
@ -407,13 +408,25 @@ namespace libtorrent { namespace
|
||||||
int data_size = length - 9;
|
int data_size = length - 9;
|
||||||
|
|
||||||
if (total_size > 500 * 1024)
|
if (total_size > 500 * 1024)
|
||||||
throw protocol_error("metadata size larger than 500 kB");
|
{
|
||||||
|
m_pc.disconnect("metadata size larger than 500 kB");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (total_size <= 0)
|
if (total_size <= 0)
|
||||||
throw protocol_error("invalid metadata size");
|
{
|
||||||
|
m_pc.disconnect("invalid metadata size");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (offset > total_size || offset < 0)
|
if (offset > total_size || offset < 0)
|
||||||
throw protocol_error("invalid metadata offset");
|
{
|
||||||
|
m_pc.disconnect("invalid metadata offset");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (offset + data_size > total_size)
|
if (offset + data_size > total_size)
|
||||||
throw protocol_error("invalid metadata message");
|
{
|
||||||
|
m_pc.disconnect("invalid metadata message");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
m_tp.metadata_progress(total_size
|
m_tp.metadata_progress(total_size
|
||||||
, body.left() - m_metadata_progress);
|
, body.left() - m_metadata_progress);
|
||||||
|
@ -434,8 +447,11 @@ namespace libtorrent { namespace
|
||||||
m_waiting_metadata_request = false;
|
m_waiting_metadata_request = false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw protocol_error("unknown metadata extension message: "
|
{
|
||||||
+ boost::lexical_cast<std::string>(type));
|
std::stringstream msg;
|
||||||
|
msg << "unknown metadata extension message: " << type;
|
||||||
|
m_pc.disconnect(msg.str().c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,18 +241,14 @@ namespace libtorrent { namespace
|
||||||
if (metadata_size && metadata_size->type() == entry::int_t)
|
if (metadata_size && metadata_size->type() == entry::int_t)
|
||||||
m_tp.metadata_size(metadata_size->integer());
|
m_tp.metadata_size(metadata_size->integer());
|
||||||
|
|
||||||
entry const& messages = h["m"];
|
entry const* messages = h.find_key("m");
|
||||||
if (entry const* index = messages.find_key("ut_metadata"))
|
if (!messages || messages->type() != entry::dictionary_t) return false;
|
||||||
{
|
|
||||||
m_message_index = index->integer();
|
entry const* index = messages->find_key("ut_metadata");
|
||||||
|
if (!index || index->type() != entry::int_t) return false;
|
||||||
|
m_message_index = int(index->integer());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
m_message_index = 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_metadata_packet(int type, int piece)
|
void write_metadata_packet(int type, int piece)
|
||||||
{
|
{
|
||||||
|
@ -309,7 +305,10 @@ namespace libtorrent { namespace
|
||||||
if (m_message_index == 0) return false;
|
if (m_message_index == 0) return false;
|
||||||
|
|
||||||
if (length > 17 * 1024)
|
if (length > 17 * 1024)
|
||||||
throw protocol_error("ut_metadata message larger than 17 kB");
|
{
|
||||||
|
m_pc.disconnect("ut_metadata message larger than 17 kB");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_pc.packet_finished()) return true;
|
if (!m_pc.packet_finished()) return true;
|
||||||
|
|
||||||
|
@ -362,8 +361,11 @@ namespace libtorrent { namespace
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw protocol_error("unknown metadata extension message: "
|
{
|
||||||
+ boost::lexical_cast<std::string>(type));
|
std::stringstream msg;
|
||||||
|
msg << "unknown ut_metadata extension message: " << type;
|
||||||
|
m_pc.disconnect(msg.str().c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue