2008-07-18 16:41:08 +02:00
|
|
|
/*
|
|
|
|
|
2018-04-09 09:04:33 +02:00
|
|
|
Copyright (c) 2008-2018, Arvid Norberg
|
2008-07-18 16:41:08 +02:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2009-07-26 04:27:52 +02:00
|
|
|
#include "libtorrent/config.hpp"
|
2008-07-18 16:41:08 +02:00
|
|
|
#include "libtorrent/error_code.hpp"
|
2015-03-15 00:10:20 +01:00
|
|
|
#include "libtorrent/string_util.hpp" // for to_string()
|
2008-07-18 16:41:08 +02:00
|
|
|
|
2018-11-24 14:24:04 +01:00
|
|
|
#include <sstream>
|
|
|
|
|
2017-04-12 19:00:57 +02:00
|
|
|
namespace libtorrent {
|
|
|
|
|
2019-01-19 22:47:48 +01:00
|
|
|
struct libtorrent_error_category final : boost::system::error_category
|
2013-10-23 01:57:12 +02:00
|
|
|
{
|
2016-07-10 02:10:38 +02:00
|
|
|
const char* name() const BOOST_SYSTEM_NOEXCEPT override;
|
2017-11-10 00:46:03 +01:00
|
|
|
std::string message(int ev) const override;
|
2016-07-10 02:10:38 +02:00
|
|
|
boost::system::error_condition default_error_condition(int ev) const BOOST_SYSTEM_NOEXCEPT override
|
2013-10-23 01:57:12 +02:00
|
|
|
{ return boost::system::error_condition(ev, *this); }
|
|
|
|
};
|
|
|
|
|
2013-09-25 21:44:29 +02:00
|
|
|
const char* libtorrent_error_category::name() const BOOST_SYSTEM_NOEXCEPT
|
2008-07-18 16:41:08 +02:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
return "libtorrent";
|
2008-07-18 16:41:08 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 00:46:03 +01:00
|
|
|
std::string libtorrent_error_category::message(int ev) const
|
2008-07-18 16:41:08 +02:00
|
|
|
{
|
|
|
|
static char const* msgs[] =
|
2009-02-03 08:46:24 +01:00
|
|
|
{
|
|
|
|
"no error",
|
|
|
|
"torrent file collides with file from another torrent",
|
2009-02-13 20:01:02 +01:00
|
|
|
"hash check failed",
|
|
|
|
"torrent file is not a dictionary",
|
|
|
|
"missing or invalid 'info' section in torrent file",
|
|
|
|
"'info' entry is not a dictionary",
|
|
|
|
"invalid or missing 'piece length' entry in torrent file",
|
|
|
|
"missing name in torrent file",
|
|
|
|
"invalid 'name' of torrent (possible exploit attempt)",
|
|
|
|
"invalid length of torrent",
|
|
|
|
"failed to parse files from torrent file",
|
|
|
|
"invalid or missing 'pieces' entry in torrent file",
|
|
|
|
"incorrect number of piece hashes in torrent file",
|
2009-02-23 02:21:19 +01:00
|
|
|
"too many pieces in torrent",
|
|
|
|
"invalid metadata received from swarm",
|
|
|
|
"invalid bencoding",
|
|
|
|
"no files in torrent",
|
|
|
|
"invalid escaped string",
|
|
|
|
"session is closing",
|
|
|
|
"torrent already exists in session",
|
|
|
|
"invalid torrent handle used",
|
|
|
|
"invalid type requested from entry",
|
2009-02-26 08:09:56 +01:00
|
|
|
"missing info-hash from URI",
|
2009-05-21 18:15:05 +02:00
|
|
|
"file too short",
|
2009-05-30 20:50:38 +02:00
|
|
|
"unsupported URL protocol",
|
|
|
|
"failed to parse URL",
|
2009-06-12 18:40:38 +02:00
|
|
|
"peer sent 0 length piece",
|
|
|
|
"parse failed",
|
|
|
|
"invalid file format tag",
|
|
|
|
"missing info-hash",
|
|
|
|
"mismatching info-hash",
|
|
|
|
"invalid hostname",
|
|
|
|
"invalid port",
|
|
|
|
"port blocked by port-filter",
|
|
|
|
"expected closing ] for address",
|
|
|
|
"destructing torrent",
|
|
|
|
"timed out",
|
2009-06-24 03:49:06 +02:00
|
|
|
"upload to upload connection",
|
2009-06-12 18:40:38 +02:00
|
|
|
"uninteresting upload-only peer",
|
|
|
|
"invalid info-hash",
|
|
|
|
"torrent paused",
|
|
|
|
"'have'-message with higher index than the number of pieces",
|
|
|
|
"bitfield of invalid size",
|
|
|
|
"too many piece requests while choked",
|
|
|
|
"invalid piece packet",
|
|
|
|
"out of memory",
|
|
|
|
"torrent aborted",
|
|
|
|
"connected to ourselves",
|
|
|
|
"invalid piece size",
|
|
|
|
"timed out: no interest",
|
|
|
|
"timed out: inactivity",
|
|
|
|
"timed out: no handshake",
|
|
|
|
"timed out: no request",
|
|
|
|
"invalid choke message",
|
|
|
|
"invalid unchoke message",
|
|
|
|
"invalid interested message",
|
|
|
|
"invalid not-interested message",
|
|
|
|
"invalid request message",
|
|
|
|
"invalid hash list",
|
|
|
|
"invalid hash piece message",
|
|
|
|
"invalid cancel message",
|
|
|
|
"invalid dht-port message",
|
|
|
|
"invalid suggest piece message",
|
|
|
|
"invalid have-all message",
|
|
|
|
"invalid have-none message",
|
|
|
|
"invalid reject message",
|
|
|
|
"invalid allow-fast message",
|
|
|
|
"invalid extended message",
|
|
|
|
"invalid message",
|
|
|
|
"sync hash not found",
|
|
|
|
"unable to verify encryption constant",
|
|
|
|
"plaintext mode not provided",
|
|
|
|
"rc4 mode not provided",
|
|
|
|
"unsupported encryption mode",
|
|
|
|
"peer selected unsupported encryption mode",
|
|
|
|
"invalid encryption pad size",
|
|
|
|
"invalid encryption handshake",
|
|
|
|
"incoming encrypted connections disabled",
|
|
|
|
"incoming regular connections disabled",
|
|
|
|
"duplicate peer-id",
|
|
|
|
"torrent removed",
|
|
|
|
"packet too large",
|
2010-02-23 17:26:24 +01:00
|
|
|
"",
|
2009-06-12 18:40:38 +02:00
|
|
|
"HTTP error",
|
|
|
|
"missing location header",
|
|
|
|
"invalid redirection",
|
|
|
|
"redirecting",
|
|
|
|
"invalid HTTP range",
|
|
|
|
"missing content-length",
|
|
|
|
"banned by IP filter",
|
|
|
|
"too many connections",
|
|
|
|
"peer banned",
|
|
|
|
"stopping torrent",
|
|
|
|
"too many corrupt pieces",
|
|
|
|
"torrent is not ready to accept peers",
|
|
|
|
"peer is not properly constructed",
|
|
|
|
"session is closing",
|
|
|
|
"optimistic disconnect",
|
|
|
|
"torrent finished",
|
|
|
|
"no router found",
|
|
|
|
"metadata too large",
|
|
|
|
"invalid metadata request",
|
|
|
|
"invalid metadata size",
|
|
|
|
"invalid metadata offset",
|
|
|
|
"invalid metadata message",
|
|
|
|
"pex message too large",
|
|
|
|
"invalid pex message",
|
|
|
|
"invalid lt_tracker message",
|
2010-11-29 02:33:05 +01:00
|
|
|
"pex messages sent too frequent (possible attack)",
|
2011-03-04 07:17:55 +01:00
|
|
|
"torrent has no metadata",
|
2011-08-07 02:41:13 +02:00
|
|
|
"invalid dont-have message",
|
2012-01-14 17:04:25 +01:00
|
|
|
"SSL connection required",
|
|
|
|
"invalid SSL certificate",
|
2014-01-20 02:01:03 +01:00
|
|
|
"not an SSL torrent",
|
2014-07-06 21:18:00 +02:00
|
|
|
"banned by port filter",
|
2017-05-28 12:41:50 +02:00
|
|
|
"invalid session handle used",
|
2017-07-22 04:18:16 +02:00
|
|
|
"listen socket has been closed",
|
2009-12-06 00:03:48 +01:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2011-11-13 04:35:03 +01:00
|
|
|
|
2009-06-28 02:36:41 +02:00
|
|
|
// natpmp errors
|
2009-06-12 18:40:38 +02:00
|
|
|
"unsupported protocol version",
|
|
|
|
"not authorized to create port map (enable NAT-PMP on your router)",
|
|
|
|
"network failure",
|
|
|
|
"out of resources",
|
|
|
|
"unsupported opcode",
|
2009-12-06 00:03:48 +01:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2011-11-13 04:35:03 +01:00
|
|
|
|
2009-06-28 02:36:41 +02:00
|
|
|
// fastresume errors
|
|
|
|
"missing or invalid 'file sizes' entry",
|
|
|
|
"no files in resume data",
|
|
|
|
"missing 'slots' and 'pieces' entry",
|
|
|
|
"mismatching number of files",
|
|
|
|
"mismatching file size",
|
|
|
|
"mismatching file timestamp",
|
|
|
|
"not a dictionary",
|
|
|
|
"invalid 'blocks per piece' entry",
|
|
|
|
"missing slots list",
|
|
|
|
"file has more slots than torrent",
|
|
|
|
"invalid entry type in slot list",
|
|
|
|
"invalid piece index in slot list",
|
|
|
|
"pieces needs to be reordered",
|
2014-07-06 21:18:00 +02:00
|
|
|
"fastresume not modified since last save",
|
2009-06-28 02:36:41 +02:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2011-11-13 04:35:03 +01:00
|
|
|
|
2009-12-06 00:03:48 +01:00
|
|
|
// HTTP errors
|
|
|
|
"Invalid HTTP header",
|
|
|
|
"missing Location header in HTTP redirect",
|
|
|
|
"failed to decompress HTTP response",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2009-06-28 02:36:41 +02:00
|
|
|
"",
|
2011-11-13 04:35:03 +01:00
|
|
|
|
2009-12-06 00:03:48 +01:00
|
|
|
// i2p errors
|
2009-08-20 05:19:12 +02:00
|
|
|
"no i2p router is set up",
|
2010-02-23 22:53:45 +01:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2011-11-13 04:35:03 +01:00
|
|
|
|
2010-02-23 22:53:45 +01:00
|
|
|
// tracker errors
|
|
|
|
"scrape not available on tracker",
|
|
|
|
"invalid tracker response",
|
|
|
|
"invalid peer dictionary entry",
|
|
|
|
"tracker sent a failure message",
|
|
|
|
"missing or invalid 'files' entry",
|
|
|
|
"missing or invalid 'hash' entry",
|
|
|
|
"missing or invalid 'peers' and 'peers6' entry",
|
|
|
|
"udp tracker response packet has invalid size",
|
|
|
|
"invalid transaction id in udp tracker response",
|
|
|
|
"invalid action field in udp tracker response",
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2010-10-28 06:01:59 +02:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2010-11-25 03:49:50 +01:00
|
|
|
"",
|
2010-10-28 06:01:59 +02:00
|
|
|
|
|
|
|
// bdecode errors
|
2010-11-25 03:49:50 +01:00
|
|
|
"expected string in bencoded string",
|
|
|
|
"expected colon in bencoded string",
|
|
|
|
"unexpected end of file in bencoded string",
|
2010-10-28 06:01:59 +02:00
|
|
|
"expected value (list, dict, int or string) in bencoded string",
|
|
|
|
"bencoded nesting depth exceeded",
|
2010-11-25 03:49:50 +01:00
|
|
|
"bencoded item count limit exceeded",
|
2014-04-04 05:21:15 +02:00
|
|
|
"integer overflow",
|
2017-01-16 15:50:56 +01:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2019-07-21 01:36:05 +02:00
|
|
|
#else
|
|
|
|
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
|
2013-10-23 01:57:12 +02:00
|
|
|
#endif
|
2017-01-16 15:50:56 +01:00
|
|
|
"random number generator failed",
|
2009-02-03 08:46:24 +01:00
|
|
|
};
|
2011-02-14 02:59:01 +01:00
|
|
|
if (ev < 0 || ev >= int(sizeof(msgs)/sizeof(msgs[0])))
|
2008-07-18 16:41:08 +02:00
|
|
|
return "Unknown error";
|
|
|
|
return msgs[ev];
|
|
|
|
}
|
|
|
|
|
2016-10-02 21:27:50 +02:00
|
|
|
boost::system::error_category& libtorrent_category()
|
2013-06-24 02:14:17 +02:00
|
|
|
{
|
|
|
|
static libtorrent_error_category libtorrent_category;
|
|
|
|
return libtorrent_category;
|
|
|
|
}
|
|
|
|
|
2019-01-19 22:47:48 +01:00
|
|
|
struct http_error_category final : boost::system::error_category
|
2014-02-02 05:07:36 +01:00
|
|
|
{
|
2016-07-10 02:10:38 +02:00
|
|
|
const char* name() const BOOST_SYSTEM_NOEXCEPT override
|
2018-10-27 15:24:05 +02:00
|
|
|
{ return "http"; }
|
2017-11-10 00:46:03 +01:00
|
|
|
std::string message(int ev) const override
|
2014-02-02 05:07:36 +01:00
|
|
|
{
|
|
|
|
std::string ret;
|
2016-05-01 05:10:47 +02:00
|
|
|
ret += to_string(ev).data();
|
2017-06-01 10:17:01 +02:00
|
|
|
ret += ' ';
|
2014-02-02 05:07:36 +01:00
|
|
|
switch (ev)
|
|
|
|
{
|
|
|
|
case errors::cont: ret += "Continue"; break;
|
|
|
|
case errors::ok: ret += "OK"; break;
|
|
|
|
case errors::created: ret += "Created"; break;
|
|
|
|
case errors::accepted: ret += "Accepted"; break;
|
|
|
|
case errors::no_content: ret += "No Content"; break;
|
|
|
|
case errors::multiple_choices: ret += "Multiple Choices"; break;
|
|
|
|
case errors::moved_permanently: ret += "Moved Permanently"; break;
|
|
|
|
case errors::moved_temporarily: ret += "Moved Temporarily"; break;
|
|
|
|
case errors::not_modified: ret += "Not Modified"; break;
|
|
|
|
case errors::bad_request: ret += "Bad Request"; break;
|
|
|
|
case errors::unauthorized: ret += "Unauthorized"; break;
|
|
|
|
case errors::forbidden: ret += "Forbidden"; break;
|
|
|
|
case errors::not_found: ret += "Not Found"; break;
|
|
|
|
case errors::internal_server_error: ret += "Internal Server Error"; break;
|
|
|
|
case errors::not_implemented: ret += "Not Implemented"; break;
|
|
|
|
case errors::bad_gateway: ret += "Bad Gateway"; break;
|
|
|
|
case errors::service_unavailable: ret += "Service Unavailable"; break;
|
|
|
|
default: ret += "(unknown HTTP error)"; break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2016-07-10 02:10:38 +02:00
|
|
|
boost::system::error_condition default_error_condition(
|
|
|
|
int ev) const BOOST_SYSTEM_NOEXCEPT override
|
2014-02-02 05:07:36 +01:00
|
|
|
{ return boost::system::error_condition(ev, *this); }
|
|
|
|
};
|
|
|
|
|
2016-10-02 21:27:50 +02:00
|
|
|
boost::system::error_category& http_category()
|
2013-06-24 02:14:17 +02:00
|
|
|
{
|
|
|
|
static http_error_category http_category;
|
|
|
|
return http_category;
|
|
|
|
}
|
2008-07-18 16:41:08 +02:00
|
|
|
|
2014-07-21 05:19:58 +02:00
|
|
|
namespace errors
|
|
|
|
{
|
|
|
|
// hidden
|
|
|
|
boost::system::error_code make_error_code(error_code_enum e)
|
|
|
|
{
|
2016-10-02 21:27:50 +02:00
|
|
|
return boost::system::error_code(e, libtorrent_category());
|
2014-07-21 05:19:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-24 14:24:04 +01:00
|
|
|
std::string print_error(error_code const& ec)
|
|
|
|
{
|
|
|
|
if (!ec) return {};
|
|
|
|
std::stringstream ret;
|
|
|
|
ret << "ERROR: (" << ec.category().name() << ":" << ec.value() << ") "
|
|
|
|
<< ec.message();
|
|
|
|
return ret.str();
|
|
|
|
}
|
|
|
|
|
2009-03-06 09:57:00 +01:00
|
|
|
}
|