made ut_pex not rely on exceptions
This commit is contained in:
parent
ce506c63ca
commit
e45e6af107
|
@ -198,19 +198,16 @@ namespace libtorrent { namespace
|
|||
|
||||
virtual bool on_extension_handshake(entry const& h)
|
||||
{
|
||||
entry const& messages = h["m"];
|
||||
m_message_index = 0;
|
||||
entry const* messages = h.find_key("m");
|
||||
if (!messages || messages->type() != entry::dictionary_t) return false;
|
||||
|
||||
entry const* index = messages->find_key(extension_name);
|
||||
if (!index || index->type() != entry::int_t) return false;
|
||||
|
||||
if (entry const* index = messages.find_key(extension_name))
|
||||
{
|
||||
m_message_index = index->integer();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_message_index = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool on_extended(int length, int msg, buffer::const_interval body)
|
||||
{
|
||||
|
@ -222,11 +219,15 @@ namespace libtorrent { namespace
|
|||
|
||||
if (body.left() < length) return true;
|
||||
|
||||
try
|
||||
{
|
||||
entry pex_msg = bdecode(body.begin, body.end);
|
||||
std::string const& peers = pex_msg["added"].string();
|
||||
std::string const& peer_flags = pex_msg["added.f"].string();
|
||||
|
||||
entry const* p = pex_msg.find_key("added");
|
||||
entry const* pf = pex_msg.find_key("added.f");
|
||||
|
||||
if (p != 0 && pf != 0 && p->type() == entry::string_t && pf->type() == entry::string_t)
|
||||
{
|
||||
std::string const& peers = p->string();
|
||||
std::string const& peer_flags = pf->string();
|
||||
|
||||
int num_peers = peers.length() / 6;
|
||||
char const* in = peers.c_str();
|
||||
|
@ -243,11 +244,14 @@ namespace libtorrent { namespace
|
|||
char flags = detail::read_uint8(fin);
|
||||
p.peer_from_tracker(adr, pid, peer_info::pex, flags);
|
||||
}
|
||||
}
|
||||
|
||||
if (entry const* p6 = pex_msg.find_key("added6"))
|
||||
entry const* p6 = pex_msg.find_key("added6");
|
||||
entry const* p6f = pex_msg.find_key("added6.f");
|
||||
if (p6 && p6f && p6->type() == entry::string_t && p6f->type() == entry::string_t)
|
||||
{
|
||||
std::string const& peers6 = p6->string();
|
||||
std::string const& peer6_flags = pex_msg["added6.f"].string();
|
||||
std::string const& peer6_flags = p6f->string();
|
||||
|
||||
int num_peers = peers6.length() / 18;
|
||||
char const* in = peers6.c_str();
|
||||
|
@ -265,11 +269,6 @@ namespace libtorrent { namespace
|
|||
p.peer_from_tracker(adr, pid, peer_info::pex, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
throw protocol_error("invalid uT peer exchange message");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue