fix error_code vs. error_condition traits (#1169)
fix error_code vs. error_condition traits. deprecate get_*_category(), instead use *_category()
This commit is contained in:
parent
1974dca150
commit
cebd976cc2
@ -73,30 +73,30 @@ void bind_error_code()
|
|||||||
.def("assign", &error_code::assign)
|
.def("assign", &error_code::assign)
|
||||||
;
|
;
|
||||||
|
|
||||||
def("get_libtorrent_category", &get_libtorrent_category
|
using return_existing = return_value_policy<reference_existing_object>;
|
||||||
, return_value_policy<reference_existing_object>());
|
|
||||||
|
|
||||||
def("get_upnp_category", &get_upnp_category
|
|
||||||
, return_value_policy<reference_existing_object>());
|
|
||||||
|
|
||||||
def("get_http_category", &get_http_category
|
|
||||||
, return_value_policy<reference_existing_object>());
|
|
||||||
|
|
||||||
def("get_socks_category", &get_socks_category
|
|
||||||
, return_value_policy<reference_existing_object>());
|
|
||||||
|
|
||||||
|
def("libtorrent_category", &libtorrent_category, return_existing());
|
||||||
|
def("upnp_category", &upnp_category, return_existing());
|
||||||
|
def("http_category", &http_category, return_existing());
|
||||||
|
def("socks_category", &socks_category, return_existing());
|
||||||
|
def("bdecode_category", &bdecode_category, return_existing());
|
||||||
#if TORRENT_USE_I2P
|
#if TORRENT_USE_I2P
|
||||||
def("get_i2p_category", &get_i2p_category
|
def("i2p_category", &i2p_category, return_existing());
|
||||||
, return_value_policy<reference_existing_object>());
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
def("get_bdecode_category", &get_bdecode_category
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
, return_value_policy<reference_existing_object>());
|
def("get_libtorrent_category", &libtorrent_category, return_existing());
|
||||||
|
def("get_upnp_category", &upnp_category, return_existing());
|
||||||
|
def("get_http_category", &http_category, return_existing());
|
||||||
|
def("get_socks_category", &socks_category, return_existing());
|
||||||
|
def("get_bdecode_category", &bdecode_category, return_existing());
|
||||||
|
#if TORRENT_USE_I2P
|
||||||
|
def("get_i2p_category", &i2p_category, return_existing());
|
||||||
|
#endif
|
||||||
|
#endif // TORRENT_NO_DEPRECATE
|
||||||
|
|
||||||
def("generic_category", &boost::system::generic_category
|
def("generic_category", &boost::system::generic_category, return_existing());
|
||||||
, return_value_policy<reference_existing_object>());
|
|
||||||
|
|
||||||
def("system_category", &boost::system::system_category
|
def("system_category", &boost::system::system_category, return_existing());
|
||||||
, return_value_policy<reference_existing_object>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ for system errors. That is, errors that belong to the generic or system category
|
|||||||
|
|
||||||
Errors that belong to the libtorrent error category are not localized however, they
|
Errors that belong to the libtorrent error category are not localized however, they
|
||||||
are only available in english. In order to translate libtorrent errors, compare the
|
are only available in english. In order to translate libtorrent errors, compare the
|
||||||
error category of the ``error_code`` object against ``libtorrent::get_libtorrent_category()``,
|
error category of the ``error_code`` object against ``libtorrent::libtorrent_category()``,
|
||||||
and if matches, you know the error code refers to the list above. You can provide
|
and if matches, you know the error code refers to the list above. You can provide
|
||||||
your own mapping from error code to string, which is localized. In this case, you
|
your own mapping from error code to string, which is localized. In this case, you
|
||||||
cannot rely on ``error_code::message()`` to generate your strings.
|
cannot rely on ``error_code::message()`` to generate your strings.
|
||||||
@ -131,7 +131,7 @@ Here's a simple example of how to translate error codes:
|
|||||||
|
|
||||||
std::string error_code_to_string(boost::system::error_code const& ec)
|
std::string error_code_to_string(boost::system::error_code const& ec)
|
||||||
{
|
{
|
||||||
if (ec.category() != libtorrent::get_libtorrent_category())
|
if (ec.category() != libtorrent::libtorrent_category())
|
||||||
{
|
{
|
||||||
return ec.message();
|
return ec.message();
|
||||||
}
|
}
|
||||||
|
@ -934,8 +934,7 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a
|
|||||||
// handshake. The peers that we successfully connect to and then
|
// handshake. The peers that we successfully connect to and then
|
||||||
// disconnect is more interesting.
|
// disconnect is more interesting.
|
||||||
if (pd->operation == op_connect
|
if (pd->operation == op_connect
|
||||||
|| pd->error == error_code(errors::timed_out_no_handshake
|
|| pd->error == errors::timed_out_no_handshake)
|
||||||
, get_libtorrent_category()))
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,12 +99,18 @@ example layout:
|
|||||||
|
|
||||||
namespace libtorrent {
|
namespace libtorrent {
|
||||||
|
|
||||||
TORRENT_EXPORT boost::system::error_category& get_bdecode_category();
|
TORRENT_EXPORT boost::system::error_category& bdecode_category();
|
||||||
|
|
||||||
|
#ifndef TORRENT_NO_DEPRECATED
|
||||||
|
TORRENT_DEPRECATED
|
||||||
|
inline boost::system::error_category& get_bdecode_category()
|
||||||
|
{ return bdecode_category(); }
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace bdecode_errors
|
namespace bdecode_errors
|
||||||
{
|
{
|
||||||
// libtorrent uses boost.system's ``error_code`` class to represent
|
// libtorrent uses boost.system's ``error_code`` class to represent
|
||||||
// errors. libtorrent has its own error category get_bdecode_category()
|
// errors. libtorrent has its own error category bdecode_category()
|
||||||
// with the error codes defined by error_code_enum.
|
// with the error codes defined by error_code_enum.
|
||||||
enum error_code_enum
|
enum error_code_enum
|
||||||
{
|
{
|
||||||
@ -139,8 +145,6 @@ namespace boost { namespace system {
|
|||||||
template<> struct is_error_code_enum<libtorrent::bdecode_errors::error_code_enum>
|
template<> struct is_error_code_enum<libtorrent::bdecode_errors::error_code_enum>
|
||||||
{ static const bool value = true; };
|
{ static const bool value = true; };
|
||||||
|
|
||||||
template<> struct is_error_condition_enum<libtorrent::bdecode_errors::error_code_enum>
|
|
||||||
{ static const bool value = true; };
|
|
||||||
} }
|
} }
|
||||||
|
|
||||||
namespace libtorrent {
|
namespace libtorrent {
|
||||||
|
@ -540,13 +540,13 @@ namespace libtorrent
|
|||||||
disk_io_thread_pool& pool_for_job(disk_io_job* j);
|
disk_io_thread_pool& pool_for_job(disk_io_job* j);
|
||||||
|
|
||||||
// set to true once we start shutting down
|
// set to true once we start shutting down
|
||||||
std::atomic<bool> m_abort;
|
std::atomic<bool> m_abort{false};
|
||||||
|
|
||||||
// this is a counter of how many threads are currently running.
|
// this is a counter of how many threads are currently running.
|
||||||
// it's used to identify the last thread still running while
|
// it's used to identify the last thread still running while
|
||||||
// shutting down. This last thread is responsible for cleanup
|
// shutting down. This last thread is responsible for cleanup
|
||||||
// must hold the job mutex to access
|
// must hold the job mutex to access
|
||||||
int m_num_running_threads;
|
int m_num_running_threads = 0;
|
||||||
|
|
||||||
// std::mutex to protect the m_generic_io_jobs and m_hash_io_jobs lists
|
// std::mutex to protect the m_generic_io_jobs and m_hash_io_jobs lists
|
||||||
mutable std::mutex m_job_mutex;
|
mutable std::mutex m_job_mutex;
|
||||||
@ -566,12 +566,12 @@ namespace libtorrent
|
|||||||
void* m_userdata;
|
void* m_userdata;
|
||||||
|
|
||||||
// the last time we expired write blocks from the cache
|
// the last time we expired write blocks from the cache
|
||||||
time_point m_last_cache_expiry;
|
time_point m_last_cache_expiry = min_time();
|
||||||
|
|
||||||
time_point m_last_file_check;
|
time_point m_last_file_check;
|
||||||
|
|
||||||
// LRU cache of open files
|
// LRU cache of open files
|
||||||
file_pool m_file_pool;
|
file_pool m_file_pool{40};
|
||||||
|
|
||||||
// disk cache
|
// disk cache
|
||||||
mutable std::mutex m_cache_mutex;
|
mutable std::mutex m_cache_mutex;
|
||||||
@ -582,7 +582,7 @@ namespace libtorrent
|
|||||||
cache_check_active,
|
cache_check_active,
|
||||||
cache_check_reinvoke
|
cache_check_reinvoke
|
||||||
};
|
};
|
||||||
int m_cache_check_state;
|
int m_cache_check_state = cache_check_idle;
|
||||||
|
|
||||||
// total number of blocks in use by both the read
|
// total number of blocks in use by both the read
|
||||||
// and the write cache. This is not supposed to
|
// and the write cache. This is not supposed to
|
||||||
@ -608,7 +608,7 @@ namespace libtorrent
|
|||||||
io_service& m_ios;
|
io_service& m_ios;
|
||||||
|
|
||||||
// used to rate limit disk performance warnings
|
// used to rate limit disk performance warnings
|
||||||
time_point m_last_disk_aio_performance_warning;
|
time_point m_last_disk_aio_performance_warning = min_time();
|
||||||
|
|
||||||
// jobs that are completed are put on this queue
|
// jobs that are completed are put on this queue
|
||||||
// whenever the queue size grows from 0 to 1
|
// whenever the queue size grows from 0 to 1
|
||||||
@ -626,10 +626,10 @@ namespace libtorrent
|
|||||||
// when this is true, there is an outstanding message in the
|
// when this is true, there is an outstanding message in the
|
||||||
// message queue that will reclaim all blocks in
|
// message queue that will reclaim all blocks in
|
||||||
// m_blocks_to_reclaim, there's no need to send another one
|
// m_blocks_to_reclaim, there's no need to send another one
|
||||||
bool m_outstanding_reclaim_message;
|
bool m_outstanding_reclaim_message = false;
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
int m_magic;
|
int m_magic = 0x1337;
|
||||||
std::atomic<bool> m_jobs_aborted;
|
std::atomic<bool> m_jobs_aborted{false};
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
// libtorrent uses boost.system's ``error_code`` class to represent
|
// libtorrent uses boost.system's ``error_code`` class to represent
|
||||||
// errors. libtorrent has its own error category
|
// errors. libtorrent has its own error category
|
||||||
// get_libtorrent_category() with the error codes defined by
|
// libtorrent_category() with the error codes defined by
|
||||||
// error_code_enum.
|
// error_code_enum.
|
||||||
enum error_code_enum
|
enum error_code_enum
|
||||||
{
|
{
|
||||||
@ -466,10 +466,10 @@ namespace libtorrent
|
|||||||
|
|
||||||
// return the instance of the libtorrent_error_category which
|
// return the instance of the libtorrent_error_category which
|
||||||
// maps libtorrent error codes to human readable error messages.
|
// maps libtorrent error codes to human readable error messages.
|
||||||
TORRENT_EXPORT boost::system::error_category& get_libtorrent_category();
|
TORRENT_EXPORT boost::system::error_category& libtorrent_category();
|
||||||
|
|
||||||
// returns the error_category for HTTP errors
|
// returns the error_category for HTTP errors
|
||||||
TORRENT_EXPORT boost::system::error_category& get_http_category();
|
TORRENT_EXPORT boost::system::error_category& http_category();
|
||||||
|
|
||||||
using boost::system::error_code;
|
using boost::system::error_code;
|
||||||
using boost::system::error_condition;
|
using boost::system::error_condition;
|
||||||
@ -483,6 +483,14 @@ namespace libtorrent
|
|||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
using system_error = boost::system::system_error;
|
using system_error = boost::system::system_error;
|
||||||
|
|
||||||
|
TORRENT_DEPRECATED
|
||||||
|
inline boost::system::error_category& get_libtorrent_category()
|
||||||
|
{ return libtorrent_category(); }
|
||||||
|
|
||||||
|
TORRENT_DEPRECATED
|
||||||
|
inline boost::system::error_category& get_http_category()
|
||||||
|
{ return http_category(); }
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -548,14 +556,8 @@ namespace boost { namespace system {
|
|||||||
template<> struct is_error_code_enum<libtorrent::errors::error_code_enum>
|
template<> struct is_error_code_enum<libtorrent::errors::error_code_enum>
|
||||||
{ static const bool value = true; };
|
{ static const bool value = true; };
|
||||||
|
|
||||||
template<> struct is_error_condition_enum<libtorrent::errors::error_code_enum>
|
|
||||||
{ static const bool value = true; };
|
|
||||||
|
|
||||||
template<> struct is_error_code_enum<libtorrent::errors::http_errors>
|
template<> struct is_error_code_enum<libtorrent::errors::http_errors>
|
||||||
{ static const bool value = true; };
|
{ static const bool value = true; };
|
||||||
|
|
||||||
template<> struct is_error_condition_enum<libtorrent::errors::http_errors>
|
|
||||||
{ static const bool value = true; };
|
|
||||||
} }
|
} }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -48,7 +48,13 @@ namespace libtorrent
|
|||||||
, error_code& error);
|
, error_code& error);
|
||||||
|
|
||||||
// get the ``error_category`` for zip errors
|
// get the ``error_category`` for zip errors
|
||||||
TORRENT_EXPORT boost::system::error_category& get_gzip_category();
|
TORRENT_EXPORT boost::system::error_category& gzip_category();
|
||||||
|
|
||||||
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
|
TORRENT_DEPRECATED
|
||||||
|
inline boost::system::error_category& get_gzip_category()
|
||||||
|
{ return gzip_category(); }
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace gzip_errors
|
namespace gzip_errors
|
||||||
{
|
{
|
||||||
|
@ -70,7 +70,13 @@ namespace libtorrent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns the error category for I2P errors
|
// returns the error category for I2P errors
|
||||||
TORRENT_EXPORT boost::system::error_category& get_i2p_category();
|
TORRENT_EXPORT boost::system::error_category& i2p_category();
|
||||||
|
|
||||||
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
|
TORRENT_DEPRECATED
|
||||||
|
inline boost::system::error_category& get_i2p_category()
|
||||||
|
{ return i2p_category(); }
|
||||||
|
#endif
|
||||||
|
|
||||||
class i2p_stream : public proxy_base
|
class i2p_stream : public proxy_base
|
||||||
{
|
{
|
||||||
@ -227,10 +233,6 @@ template<>
|
|||||||
struct is_error_code_enum<libtorrent::i2p_error::i2p_error_code>
|
struct is_error_code_enum<libtorrent::i2p_error::i2p_error_code>
|
||||||
{ static const bool value = true; };
|
{ static const bool value = true; };
|
||||||
|
|
||||||
template<>
|
|
||||||
struct is_error_condition_enum<libtorrent::i2p_error::i2p_error_code>
|
|
||||||
{ static const bool value = true; };
|
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
|
||||||
#endif // TORRENT_USE_I2P
|
#endif // TORRENT_USE_I2P
|
||||||
|
@ -69,7 +69,13 @@ namespace socks_error {
|
|||||||
} // namespace socks_error
|
} // namespace socks_error
|
||||||
|
|
||||||
// returns the error_category for SOCKS5 errors
|
// returns the error_category for SOCKS5 errors
|
||||||
TORRENT_EXPORT boost::system::error_category& get_socks_category();
|
TORRENT_EXPORT boost::system::error_category& socks_category();
|
||||||
|
|
||||||
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
|
TORRENT_DEPRECATED
|
||||||
|
inline boost::system::error_category& get_socks_category()
|
||||||
|
{ return socks_category(); }
|
||||||
|
#endif
|
||||||
|
|
||||||
class socks5_stream : public proxy_base
|
class socks5_stream : public proxy_base
|
||||||
{
|
{
|
||||||
@ -254,8 +260,6 @@ namespace boost { namespace system {
|
|||||||
template<> struct is_error_code_enum<libtorrent::socks_error::socks_error_code>
|
template<> struct is_error_code_enum<libtorrent::socks_error::socks_error_code>
|
||||||
{ static const bool value = true; };
|
{ static const bool value = true; };
|
||||||
|
|
||||||
template<> struct is_error_condition_enum<libtorrent::socks_error::socks_error_code>
|
|
||||||
{ static const bool value = true; };
|
|
||||||
} }
|
} }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -91,7 +91,13 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the boost.system error category for UPnP errors
|
// the boost.system error category for UPnP errors
|
||||||
TORRENT_EXPORT boost::system::error_category& get_upnp_category();
|
TORRENT_EXPORT boost::system::error_category& upnp_category();
|
||||||
|
|
||||||
|
#ifndef TORRENT_NO_DEPRECATED
|
||||||
|
TORRENT_DEPRECATED
|
||||||
|
inline boost::system::error_category& get_upnp_category()
|
||||||
|
{ return upnp_category(); }
|
||||||
|
#endif
|
||||||
|
|
||||||
struct parse_state
|
struct parse_state
|
||||||
{
|
{
|
||||||
@ -193,7 +199,6 @@ private:
|
|||||||
void next(rootdevice& d, int i);
|
void next(rootdevice& d, int i);
|
||||||
void update_map(rootdevice& d, int i);
|
void update_map(rootdevice& d, int i);
|
||||||
|
|
||||||
|
|
||||||
void on_upnp_xml(error_code const& e
|
void on_upnp_xml(error_code const& e
|
||||||
, libtorrent::http_parser const& p, rootdevice& d
|
, libtorrent::http_parser const& p, rootdevice& d
|
||||||
, http_connection& c);
|
, http_connection& c);
|
||||||
@ -377,8 +382,6 @@ namespace boost { namespace system {
|
|||||||
template<> struct is_error_code_enum<libtorrent::upnp_errors::error_code_enum>
|
template<> struct is_error_code_enum<libtorrent::upnp_errors::error_code_enum>
|
||||||
{ static const bool value = true; };
|
{ static const bool value = true; };
|
||||||
|
|
||||||
template<> struct is_error_condition_enum<libtorrent::upnp_errors::error_code_enum>
|
|
||||||
{ static const bool value = true; };
|
|
||||||
} }
|
} }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -476,8 +476,7 @@ TORRENT_TEST(test_error)
|
|||||||
TEST_EQUAL(ae.is_working(), false);
|
TEST_EQUAL(ae.is_working(), false);
|
||||||
TEST_EQUAL(ae.message, "test");
|
TEST_EQUAL(ae.message, "test");
|
||||||
TEST_EQUAL(ae.url, "http://tracker.com:8080/announce");
|
TEST_EQUAL(ae.url, "http://tracker.com:8080/announce");
|
||||||
TEST_EQUAL(ae.last_error, error_code(errors::tracker_failure
|
TEST_EQUAL(ae.last_error, error_code(errors::tracker_failure));
|
||||||
, get_libtorrent_category()));
|
|
||||||
TEST_EQUAL(ae.fails, 1);
|
TEST_EQUAL(ae.fails, 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -574,7 +573,7 @@ TORRENT_TEST(test_http_status)
|
|||||||
TEST_EQUAL(ae.is_working(), false);
|
TEST_EQUAL(ae.is_working(), false);
|
||||||
TEST_EQUAL(ae.message, "Not A Tracker");
|
TEST_EQUAL(ae.message, "Not A Tracker");
|
||||||
TEST_EQUAL(ae.url, "http://tracker.com:8080/announce");
|
TEST_EQUAL(ae.url, "http://tracker.com:8080/announce");
|
||||||
TEST_EQUAL(ae.last_error, error_code(410, get_http_category()));
|
TEST_EQUAL(ae.last_error, error_code(410, http_category()));
|
||||||
TEST_EQUAL(ae.fails, 1);
|
TEST_EQUAL(ae.fails, 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -621,7 +620,7 @@ TORRENT_TEST(test_invalid_bencoding)
|
|||||||
TEST_EQUAL(ae.message, "");
|
TEST_EQUAL(ae.message, "");
|
||||||
TEST_EQUAL(ae.url, "http://tracker.com:8080/announce");
|
TEST_EQUAL(ae.url, "http://tracker.com:8080/announce");
|
||||||
TEST_EQUAL(ae.last_error, error_code(bdecode_errors::expected_value
|
TEST_EQUAL(ae.last_error, error_code(bdecode_errors::expected_value
|
||||||
, get_bdecode_category()));
|
, bdecode_category()));
|
||||||
TEST_EQUAL(ae.fails, 1);
|
TEST_EQUAL(ae.fails, 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ namespace libtorrent
|
|||||||
return msgs[ev];
|
return msgs[ev];
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::system::error_category& get_bdecode_category()
|
boost::system::error_category& bdecode_category()
|
||||||
{
|
{
|
||||||
static bdecode_error_category bdecode_category;
|
static bdecode_error_category bdecode_category;
|
||||||
return bdecode_category;
|
return bdecode_category;
|
||||||
@ -189,7 +189,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
boost::system::error_code make_error_code(error_code_enum e)
|
boost::system::error_code make_error_code(error_code_enum e)
|
||||||
{
|
{
|
||||||
return boost::system::error_code(e, get_bdecode_category());
|
return boost::system::error_code(e, bdecode_category());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -632,7 +632,7 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define TORRENT_FAIL_BDECODE(code) do { \
|
#define TORRENT_FAIL_BDECODE(code) do { \
|
||||||
ec = make_error_code(code); \
|
ec = code; \
|
||||||
if (error_pos) *error_pos = start - orig_start; \
|
if (error_pos) *error_pos = start - orig_start; \
|
||||||
goto done; \
|
goto done; \
|
||||||
} TORRENT_WHILE_0
|
} TORRENT_WHILE_0
|
||||||
@ -646,7 +646,7 @@ namespace libtorrent
|
|||||||
if (end - start > bdecode_token::max_offset)
|
if (end - start > bdecode_token::max_offset)
|
||||||
{
|
{
|
||||||
if (error_pos) *error_pos = 0;
|
if (error_pos) *error_pos = 0;
|
||||||
ec = make_error_code(bdecode_errors::limit_exceeded);
|
ec = bdecode_errors::limit_exceeded;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
close_reason_t error_to_close_reason(error_code const& ec)
|
close_reason_t error_to_close_reason(error_code const& ec)
|
||||||
{
|
{
|
||||||
if (ec.category() == get_libtorrent_category())
|
if (ec.category() == libtorrent_category())
|
||||||
{
|
{
|
||||||
#define TORRENT_MAP(error, close_reason) \
|
#define TORRENT_MAP(error, close_reason) \
|
||||||
case errors:: error : \
|
case errors:: error : \
|
||||||
@ -157,7 +157,7 @@ namespace libtorrent
|
|||||||
return close_no_memory;
|
return close_no_memory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ec.category() == get_http_category())
|
else if (ec.category() == http_category())
|
||||||
{
|
{
|
||||||
return close_no_memory;
|
return close_no_memory;
|
||||||
}
|
}
|
||||||
|
@ -252,13 +252,13 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (t.files().num_files() == 0)
|
if (t.files().num_files() == 0)
|
||||||
{
|
{
|
||||||
ec = error_code(errors::no_files_in_torrent, get_libtorrent_category());
|
ec = errors::no_files_in_torrent;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.files().total_size() == 0)
|
if (t.files().total_size() == 0)
|
||||||
{
|
{
|
||||||
ec = error_code(errors::torrent_invalid_length, get_libtorrent_category());
|
ec = errors::torrent_invalid_length;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,27 +137,16 @@ namespace libtorrent
|
|||||||
disk_io_thread::disk_io_thread(io_service& ios
|
disk_io_thread::disk_io_thread(io_service& ios
|
||||||
, counters& cnt
|
, counters& cnt
|
||||||
, void* userdata
|
, void* userdata
|
||||||
, int block_size)
|
, int const block_size)
|
||||||
: m_abort(false)
|
: m_generic_io_jobs(*this, generic_thread)
|
||||||
, m_num_running_threads(0)
|
|
||||||
, m_generic_io_jobs(*this, generic_thread)
|
|
||||||
, m_generic_threads(m_generic_io_jobs, ios)
|
, m_generic_threads(m_generic_io_jobs, ios)
|
||||||
, m_hash_io_jobs(*this, hasher_thread)
|
, m_hash_io_jobs(*this, hasher_thread)
|
||||||
, m_hash_threads(m_hash_io_jobs, ios)
|
, m_hash_threads(m_hash_io_jobs, ios)
|
||||||
, m_userdata(userdata)
|
, m_userdata(userdata)
|
||||||
, m_last_cache_expiry(min_time())
|
|
||||||
, m_last_file_check(clock_type::now())
|
, m_last_file_check(clock_type::now())
|
||||||
, m_file_pool(40)
|
|
||||||
, m_disk_cache(block_size, ios, std::bind(&disk_io_thread::trigger_cache_trim, this))
|
, m_disk_cache(block_size, ios, std::bind(&disk_io_thread::trigger_cache_trim, this))
|
||||||
, m_cache_check_state(cache_check_idle)
|
|
||||||
, m_stats_counters(cnt)
|
, m_stats_counters(cnt)
|
||||||
, m_ios(ios)
|
, m_ios(ios)
|
||||||
, m_last_disk_aio_performance_warning(min_time())
|
|
||||||
, m_outstanding_reclaim_message(false)
|
|
||||||
#if TORRENT_USE_ASSERTS
|
|
||||||
, m_magic(0x1337)
|
|
||||||
, m_jobs_aborted(false)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
ADD_OUTSTANDING_ASYNC("disk_io_thread::work");
|
ADD_OUTSTANDING_ASYNC("disk_io_thread::work");
|
||||||
error_code ec;
|
error_code ec;
|
||||||
@ -168,8 +157,8 @@ namespace libtorrent
|
|||||||
// futexes, shared objects etc.
|
// futexes, shared objects etc.
|
||||||
// 80% of the available file descriptors should go to connections
|
// 80% of the available file descriptors should go to connections
|
||||||
// 20% goes towards regular files
|
// 20% goes towards regular files
|
||||||
const int max_files = (std::min)((std::max)(5
|
const int max_files = std::min(std::max(5
|
||||||
, (max_open_files() - 20) * 2 / 10)
|
, (max_open_files() - 20) * 2 / 10)
|
||||||
, m_file_pool.size_limit());
|
, m_file_pool.size_limit());
|
||||||
m_file_pool.resize(max_files);
|
m_file_pool.resize(max_files);
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,7 @@ namespace libtorrent
|
|||||||
TORRENT_NO_RETURN inline void throw_error()
|
TORRENT_NO_RETURN inline void throw_error()
|
||||||
{
|
{
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
throw system_error(error_code(errors::invalid_entry_type
|
throw system_error(errors::invalid_entry_type);
|
||||||
, get_libtorrent_category()));
|
|
||||||
#else
|
#else
|
||||||
std::terminate();
|
std::terminate();
|
||||||
#endif
|
#endif
|
||||||
|
@ -270,7 +270,7 @@ namespace libtorrent
|
|||||||
return msgs[ev];
|
return msgs[ev];
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::system::error_category& get_libtorrent_category()
|
boost::system::error_category& libtorrent_category()
|
||||||
{
|
{
|
||||||
static libtorrent_error_category libtorrent_category;
|
static libtorrent_error_category libtorrent_category;
|
||||||
return libtorrent_category;
|
return libtorrent_category;
|
||||||
@ -313,7 +313,7 @@ namespace libtorrent
|
|||||||
{ return boost::system::error_condition(ev, *this); }
|
{ return boost::system::error_condition(ev, *this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
boost::system::error_category& get_http_category()
|
boost::system::error_category& http_category()
|
||||||
{
|
{
|
||||||
static http_error_category http_category;
|
static http_error_category http_category;
|
||||||
return http_category;
|
return http_category;
|
||||||
@ -324,7 +324,7 @@ namespace libtorrent
|
|||||||
// hidden
|
// hidden
|
||||||
boost::system::error_code make_error_code(error_code_enum e)
|
boost::system::error_code make_error_code(error_code_enum e)
|
||||||
{
|
{
|
||||||
return boost::system::error_code(e, get_libtorrent_category());
|
return boost::system::error_code(e, libtorrent_category());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,7 +532,7 @@ namespace libtorrent
|
|||||||
// something failed. Does the filesystem not support hard links?
|
// something failed. Does the filesystem not support hard links?
|
||||||
// TODO: 3 find out what error code is reported when the filesystem
|
// TODO: 3 find out what error code is reported when the filesystem
|
||||||
// does not support hard links.
|
// does not support hard links.
|
||||||
DWORD error = GetLastError();
|
DWORD const error = GetLastError();
|
||||||
if (error != ERROR_NOT_SUPPORTED && error != ERROR_ACCESS_DENIED)
|
if (error != ERROR_NOT_SUPPORTED && error != ERROR_ACCESS_DENIED)
|
||||||
{
|
{
|
||||||
// it's possible CreateHardLink will copy the file internally too,
|
// it's possible CreateHardLink will copy the file internally too,
|
||||||
|
@ -95,17 +95,17 @@ namespace libtorrent
|
|||||||
return msgs[ev];
|
return msgs[ev];
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::system::error_category& get_gzip_category()
|
boost::system::error_category& gzip_category()
|
||||||
{
|
{
|
||||||
static gzip_error_category gzip_category;
|
static gzip_error_category category;
|
||||||
return gzip_category;
|
return category;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace gzip_errors
|
namespace gzip_errors
|
||||||
{
|
{
|
||||||
boost::system::error_code make_error_code(error_code_enum e)
|
boost::system::error_code make_error_code(error_code_enum e)
|
||||||
{
|
{
|
||||||
return boost::system::error_code(e, get_gzip_category());
|
return boost::system::error_code(e, gzip_category());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ void http_connection::start(std::string const& hostname, int port
|
|||||||
if (is_i2p && i2p_conn->proxy().type != settings_pack::i2p_proxy)
|
if (is_i2p && i2p_conn->proxy().type != settings_pack::i2p_proxy)
|
||||||
{
|
{
|
||||||
m_timer.get_io_service().post(std::bind(&http_connection::callback
|
m_timer.get_io_service().post(std::bind(&http_connection::callback
|
||||||
, me, error_code(errors::no_i2p_router, get_libtorrent_category()), static_cast<char*>(nullptr), 0));
|
, me, error_code(errors::no_i2p_router), static_cast<char*>(nullptr), 0));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -279,7 +279,7 @@ namespace libtorrent
|
|||||||
, error_msg);
|
, error_msg);
|
||||||
}
|
}
|
||||||
received_bytes(0, int(bytes_transferred));
|
received_bytes(0, int(bytes_transferred));
|
||||||
disconnect(error_code(m_parser.status_code(), get_http_category()), op_bittorrent, 1);
|
disconnect(error_code(m_parser.status_code(), http_category()), op_bittorrent, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!m_parser.header_finished())
|
if (!m_parser.header_finished())
|
||||||
@ -414,7 +414,7 @@ namespace libtorrent
|
|||||||
received_bytes(0, int(bytes_transferred));
|
received_bytes(0, int(bytes_transferred));
|
||||||
// temporarily unavailable, retry later
|
// temporarily unavailable, retry later
|
||||||
t->retry_web_seed(this, retry_time);
|
t->retry_web_seed(this, retry_time);
|
||||||
disconnect(error_code(m_parser.status_code(), get_http_category()), op_bittorrent, 1);
|
disconnect(error_code(m_parser.status_code(), http_category()), op_bittorrent, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ namespace libtorrent
|
|||||||
std::size_t pos = url.find("announce");
|
std::size_t pos = url.find("announce");
|
||||||
if (pos == std::string::npos)
|
if (pos == std::string::npos)
|
||||||
{
|
{
|
||||||
tracker_connection::fail(error_code(errors::scrape_not_available));
|
tracker_connection::fail(errors::scrape_not_available);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
url.replace(pos, 8, "scrape");
|
url.replace(pos, 8, "scrape");
|
||||||
@ -162,7 +162,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
if (tracker_req().i2pconn->local_endpoint().empty())
|
if (tracker_req().i2pconn->local_endpoint().empty())
|
||||||
{
|
{
|
||||||
fail(error_code(errors::no_i2p_endpoint), -1, "Waiting for i2p acceptor from SAM bridge", 5);
|
fail(errors::no_i2p_endpoint, -1, "Waiting for i2p acceptor from SAM bridge", 5);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -281,7 +281,7 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (endpoints.empty())
|
if (endpoints.empty())
|
||||||
fail(error_code(errors::banned_by_ip_filter));
|
fail(errors::banned_by_ip_filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void http_tracker_connection::on_connect(http_connection& c)
|
void http_tracker_connection::on_connect(http_connection& c)
|
||||||
@ -312,7 +312,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (parser.status_code() != 200)
|
if (parser.status_code() != 200)
|
||||||
{
|
{
|
||||||
fail(error_code(parser.status_code(), get_http_category())
|
fail(error_code(parser.status_code(), http_category())
|
||||||
, parser.status_code(), parser.message().c_str());
|
, parser.status_code(), parser.message().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -378,7 +378,7 @@ namespace libtorrent
|
|||||||
// extract peer id (if any)
|
// extract peer id (if any)
|
||||||
if (info.type() != bdecode_node::dict_t)
|
if (info.type() != bdecode_node::dict_t)
|
||||||
{
|
{
|
||||||
ec.assign(errors::invalid_peer_dict, get_libtorrent_category());
|
ec = errors::invalid_peer_dict;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bdecode_node i = info.dict_find_string("peer id");
|
bdecode_node i = info.dict_find_string("peer id");
|
||||||
@ -396,7 +396,7 @@ namespace libtorrent
|
|||||||
i = info.dict_find_string("ip");
|
i = info.dict_find_string("ip");
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
ec.assign(errors::invalid_tracker_response, get_libtorrent_category());
|
ec = errors::invalid_tracker_response;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ret.hostname = i.string_value().to_string();
|
ret.hostname = i.string_value().to_string();
|
||||||
@ -405,7 +405,7 @@ namespace libtorrent
|
|||||||
i = info.dict_find_int("port");
|
i = info.dict_find_int("port");
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
ec.assign(errors::invalid_tracker_response, get_libtorrent_category());
|
ec = errors::invalid_tracker_response;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ret.port = std::uint16_t(i.int_value());
|
ret.port = std::uint16_t(i.int_value());
|
||||||
@ -425,7 +425,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (res != 0 || e.type() != bdecode_node::dict_t)
|
if (res != 0 || e.type() != bdecode_node::dict_t)
|
||||||
{
|
{
|
||||||
ec.assign(errors::invalid_tracker_response, get_libtorrent_category());
|
ec = errors::invalid_tracker_response;
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,7 +446,7 @@ namespace libtorrent
|
|||||||
if (failure)
|
if (failure)
|
||||||
{
|
{
|
||||||
resp.failure_reason = failure.string_value().to_string();
|
resp.failure_reason = failure.string_value().to_string();
|
||||||
ec.assign(errors::tracker_failure, get_libtorrent_category());
|
ec = errors::tracker_failure;
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,7 +459,7 @@ namespace libtorrent
|
|||||||
bdecode_node files = e.dict_find_dict("files");
|
bdecode_node files = e.dict_find_dict("files");
|
||||||
if (!files)
|
if (!files)
|
||||||
{
|
{
|
||||||
ec.assign(errors::invalid_files_entry, get_libtorrent_category());
|
ec = errors::invalid_files_entry;
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,7 +468,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (!scrape_data)
|
if (!scrape_data)
|
||||||
{
|
{
|
||||||
ec.assign(errors::invalid_hash_entry, get_libtorrent_category());
|
ec = errors::invalid_hash_entry;
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -573,7 +573,7 @@ namespace libtorrent
|
|||||||
if (peers_ent == 0 && ipv6_peers == 0
|
if (peers_ent == 0 && ipv6_peers == 0
|
||||||
&& tracker_req().event != tracker_request::stopped)
|
&& tracker_req().event != tracker_request::stopped)
|
||||||
{
|
{
|
||||||
ec.assign(errors::invalid_peers_entry, get_libtorrent_category());
|
ec = errors::invalid_peers_entry;
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -78,7 +78,7 @@ namespace libtorrent
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
boost::system::error_category& get_i2p_category()
|
boost::system::error_category& i2p_category()
|
||||||
{
|
{
|
||||||
static i2p_error_category i2p_category;
|
static i2p_error_category i2p_category;
|
||||||
return i2p_category;
|
return i2p_category;
|
||||||
@ -88,7 +88,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
boost::system::error_code make_error_code(i2p_error_code e)
|
boost::system::error_code make_error_code(i2p_error_code e)
|
||||||
{
|
{
|
||||||
return error_code(e, get_i2p_category());
|
return error_code(e, i2p_category());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,7 +307,7 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
|
|
||||||
error_code invalid_response(i2p_error::parse_failed
|
error_code invalid_response(i2p_error::parse_failed
|
||||||
, get_i2p_category());
|
, i2p_category());
|
||||||
|
|
||||||
// 0-terminate the string and parse it
|
// 0-terminate the string and parse it
|
||||||
m_buffer.push_back(0);
|
m_buffer.push_back(0);
|
||||||
@ -391,7 +391,7 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code ec(result, get_i2p_category());
|
error_code ec(result, i2p_category());
|
||||||
switch (result)
|
switch (result)
|
||||||
{
|
{
|
||||||
case i2p_error::no_error:
|
case i2p_error::no_error:
|
||||||
|
@ -563,7 +563,8 @@ void natpmp::on_reply(error_code const& e
|
|||||||
|
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
int errors[] =
|
// TODO: 3 it would be nice to have a separate NAT-PMP error category
|
||||||
|
errors::error_code_enum errors[] =
|
||||||
{
|
{
|
||||||
errors::unsupported_protocol_version,
|
errors::unsupported_protocol_version,
|
||||||
errors::natpmp_not_authorized,
|
errors::natpmp_not_authorized,
|
||||||
@ -571,21 +572,19 @@ void natpmp::on_reply(error_code const& e
|
|||||||
errors::no_resources,
|
errors::no_resources,
|
||||||
errors::unsupported_opcode,
|
errors::unsupported_opcode,
|
||||||
};
|
};
|
||||||
int ev = errors::no_error;
|
errors::error_code_enum ev = errors::no_error;
|
||||||
if (result >= 1 && result <= 5) ev = errors[result - 1];
|
if (result >= 1 && result <= 5) ev = errors[result - 1];
|
||||||
|
|
||||||
m->expires = aux::time_now() + hours(2);
|
m->expires = aux::time_now() + hours(2);
|
||||||
portmap_protocol const proto = m->protocol;
|
portmap_protocol const proto = m->protocol;
|
||||||
m_callback.on_port_mapping(index, address(), 0, proto
|
m_callback.on_port_mapping(index, address(), 0, proto
|
||||||
, error_code(ev, get_libtorrent_category())
|
, ev, aux::portmap_transport::natpmp);
|
||||||
, aux::portmap_transport::natpmp);
|
|
||||||
}
|
}
|
||||||
else if (m->act == mapping_t::action::add)
|
else if (m->act == mapping_t::action::add)
|
||||||
{
|
{
|
||||||
portmap_protocol const proto = m->protocol;
|
portmap_protocol const proto = m->protocol;
|
||||||
m_callback.on_port_mapping(index, m_external_ip, m->external_port, proto
|
m_callback.on_port_mapping(index, m_external_ip, m->external_port, proto
|
||||||
, error_code(errors::no_error, get_libtorrent_category())
|
, errors::no_error, aux::portmap_transport::natpmp);
|
||||||
, aux::portmap_transport::natpmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_abort) return;
|
if (m_abort) return;
|
||||||
|
@ -2124,7 +2124,7 @@ namespace libtorrent
|
|||||||
if (t->share_mode()) return false;
|
if (t->share_mode()) return false;
|
||||||
|
|
||||||
if (m_upload_only && t->is_upload_only()
|
if (m_upload_only && t->is_upload_only()
|
||||||
&& can_disconnect(error_code(errors::upload_upload_connection, get_libtorrent_category())))
|
&& can_disconnect(errors::upload_upload_connection))
|
||||||
{
|
{
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
peer_log(peer_log_alert::info, "UPLOAD_ONLY", "the peer is upload-only and our torrent is also upload-only");
|
peer_log(peer_log_alert::info, "UPLOAD_ONLY", "the peer is upload-only and our torrent is also upload-only");
|
||||||
@ -2137,7 +2137,7 @@ namespace libtorrent
|
|||||||
&& !m_interesting
|
&& !m_interesting
|
||||||
&& m_bitfield_received
|
&& m_bitfield_received
|
||||||
&& t->are_files_checked()
|
&& t->are_files_checked()
|
||||||
&& can_disconnect(error_code(errors::uninteresting_upload_peer, get_libtorrent_category())))
|
&& can_disconnect(errors::uninteresting_upload_peer))
|
||||||
{
|
{
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
peer_log(peer_log_alert::info, "UPLOAD_ONLY", "the peer is upload-only and we're not interested in it");
|
peer_log(peer_log_alert::info, "UPLOAD_ONLY", "the peer is upload-only and we're not interested in it");
|
||||||
@ -2352,8 +2352,7 @@ namespace libtorrent
|
|||||||
// may be a legitimate number of requests to have in flight when
|
// may be a legitimate number of requests to have in flight when
|
||||||
// getting choked
|
// getting choked
|
||||||
if (m_num_invalid_requests > 300 && !m_peer_choked
|
if (m_num_invalid_requests > 300 && !m_peer_choked
|
||||||
&& can_disconnect(error_code(errors::too_many_requests_when_choked
|
&& can_disconnect(errors::too_many_requests_when_choked))
|
||||||
, get_libtorrent_category())))
|
|
||||||
{
|
{
|
||||||
disconnect(errors::too_many_requests_when_choked, op_bittorrent, 2);
|
disconnect(errors::too_many_requests_when_choked, op_bittorrent, 2);
|
||||||
return;
|
return;
|
||||||
@ -2375,7 +2374,7 @@ namespace libtorrent
|
|||||||
// disconnect peers that downloads more than foo times an allowed
|
// disconnect peers that downloads more than foo times an allowed
|
||||||
// fast piece
|
// fast piece
|
||||||
if (m_choked && fast_idx != -1 && m_accept_fast_piece_cnt[fast_idx] >= 3 * blocks_per_piece
|
if (m_choked && fast_idx != -1 && m_accept_fast_piece_cnt[fast_idx] >= 3 * blocks_per_piece
|
||||||
&& can_disconnect(error_code(errors::too_many_requests_when_choked, get_libtorrent_category())))
|
&& can_disconnect(errors::too_many_requests_when_choked))
|
||||||
{
|
{
|
||||||
disconnect(errors::too_many_requests_when_choked, op_bittorrent, 2);
|
disconnect(errors::too_many_requests_when_choked, op_bittorrent, 2);
|
||||||
return;
|
return;
|
||||||
@ -2394,7 +2393,7 @@ namespace libtorrent
|
|||||||
// allow peers to send request up to 2 seconds after getting choked,
|
// allow peers to send request up to 2 seconds after getting choked,
|
||||||
// then disconnect them
|
// then disconnect them
|
||||||
if (aux::time_now() - seconds(2) > m_last_choke
|
if (aux::time_now() - seconds(2) > m_last_choke
|
||||||
&& can_disconnect(error_code(errors::too_many_requests_when_choked, get_libtorrent_category())))
|
&& can_disconnect(errors::too_many_requests_when_choked))
|
||||||
{
|
{
|
||||||
disconnect(errors::too_many_requests_when_choked, op_bittorrent, 2);
|
disconnect(errors::too_many_requests_when_choked, op_bittorrent, 2);
|
||||||
return;
|
return;
|
||||||
@ -4079,8 +4078,7 @@ namespace libtorrent
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ec == error_code(boost::asio::error::eof
|
if (ec == boost::asio::error::eof
|
||||||
, boost::asio::error::get_misc_category())
|
|
||||||
&& !in_handshake()
|
&& !in_handshake()
|
||||||
&& !is_connecting()
|
&& !is_connecting()
|
||||||
&& aux::time_now() - connected_time() < seconds(15))
|
&& aux::time_now() - connected_time() < seconds(15))
|
||||||
@ -4144,29 +4142,29 @@ namespace libtorrent
|
|||||||
m_counters.inc_stats_counter(counters::invalid_arg_peers);
|
m_counters.inc_stats_counter(counters::invalid_arg_peers);
|
||||||
else if (ec == error::operation_aborted)
|
else if (ec == error::operation_aborted)
|
||||||
m_counters.inc_stats_counter(counters::aborted_peers);
|
m_counters.inc_stats_counter(counters::aborted_peers);
|
||||||
else if (ec == error_code(errors::upload_upload_connection)
|
else if (ec == errors::upload_upload_connection
|
||||||
|| ec == error_code(errors::uninteresting_upload_peer)
|
|| ec == errors::uninteresting_upload_peer
|
||||||
|| ec == error_code(errors::torrent_aborted)
|
|| ec == errors::torrent_aborted
|
||||||
|| ec == error_code(errors::self_connection)
|
|| ec == errors::self_connection
|
||||||
|| ec == error_code(errors::torrent_paused))
|
|| ec == errors::torrent_paused)
|
||||||
m_counters.inc_stats_counter(counters::uninteresting_peers);
|
m_counters.inc_stats_counter(counters::uninteresting_peers);
|
||||||
|
|
||||||
if (ec == error_code(errors::timed_out)
|
if (ec == errors::timed_out
|
||||||
|| ec == error::timed_out)
|
|| ec == error::timed_out)
|
||||||
m_counters.inc_stats_counter(counters::transport_timeout_peers);
|
m_counters.inc_stats_counter(counters::transport_timeout_peers);
|
||||||
|
|
||||||
if (ec == error_code(errors::timed_out_inactivity)
|
if (ec == errors::timed_out_inactivity
|
||||||
|| ec == error_code(errors::timed_out_no_request)
|
|| ec == errors::timed_out_no_request
|
||||||
|| ec == error_code(errors::timed_out_no_interest))
|
|| ec == errors::timed_out_no_interest)
|
||||||
m_counters.inc_stats_counter(counters::timeout_peers);
|
m_counters.inc_stats_counter(counters::timeout_peers);
|
||||||
|
|
||||||
if (ec == error_code(errors::no_memory))
|
if (ec == errors::no_memory)
|
||||||
m_counters.inc_stats_counter(counters::no_memory_peers);
|
m_counters.inc_stats_counter(counters::no_memory_peers);
|
||||||
|
|
||||||
if (ec == error_code(errors::too_many_connections))
|
if (ec == errors::too_many_connections)
|
||||||
m_counters.inc_stats_counter(counters::too_many_peers);
|
m_counters.inc_stats_counter(counters::too_many_peers);
|
||||||
|
|
||||||
if (ec == error_code(errors::timed_out_no_handshake))
|
if (ec == errors::timed_out_no_handshake)
|
||||||
m_counters.inc_stats_counter(counters::connect_timeouts);
|
m_counters.inc_stats_counter(counters::connect_timeouts);
|
||||||
|
|
||||||
if (error > 0)
|
if (error > 0)
|
||||||
@ -4235,7 +4233,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
if ((error > 1 || ec.category() == get_socks_category())
|
if ((error > 1 || ec.category() == socks_category())
|
||||||
&& t->alerts().should_post<peer_error_alert>())
|
&& t->alerts().should_post<peer_error_alert>())
|
||||||
{
|
{
|
||||||
t->alerts().emplace_alert<peer_error_alert>(handle, remote()
|
t->alerts().emplace_alert<peer_error_alert>(handle, remote()
|
||||||
@ -4715,7 +4713,7 @@ namespace libtorrent
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (d > seconds(connect_timeout)
|
if (d > seconds(connect_timeout)
|
||||||
&& can_disconnect(error_code(errors::timed_out, get_libtorrent_category())))
|
&& can_disconnect(errors::timed_out))
|
||||||
{
|
{
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
peer_log(peer_log_alert::info, "CONNECT_FAILED", "waited %d seconds"
|
peer_log(peer_log_alert::info, "CONNECT_FAILED", "waited %d seconds"
|
||||||
@ -4736,7 +4734,7 @@ namespace libtorrent
|
|||||||
// because of less work in second_tick(), and might let use remove ticking
|
// because of less work in second_tick(), and might let use remove ticking
|
||||||
// entirely eventually
|
// entirely eventually
|
||||||
if (may_timeout && d > seconds(timeout()) && !m_connecting && m_reading_bytes == 0
|
if (may_timeout && d > seconds(timeout()) && !m_connecting && m_reading_bytes == 0
|
||||||
&& can_disconnect(error_code(errors::timed_out_inactivity, get_libtorrent_category())))
|
&& can_disconnect(errors::timed_out_inactivity))
|
||||||
{
|
{
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
peer_log(peer_log_alert::info, "LAST_ACTIVITY", "%d seconds ago"
|
peer_log(peer_log_alert::info, "LAST_ACTIVITY", "%d seconds ago"
|
||||||
@ -4779,7 +4777,7 @@ namespace libtorrent
|
|||||||
&& m_peer_interested
|
&& m_peer_interested
|
||||||
&& t && t->is_upload_only()
|
&& t && t->is_upload_only()
|
||||||
&& d > seconds(60)
|
&& d > seconds(60)
|
||||||
&& can_disconnect(error_code(errors::timed_out_no_request, get_libtorrent_category())))
|
&& can_disconnect(errors::timed_out_no_request))
|
||||||
{
|
{
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
peer_log(peer_log_alert::info, "NO_REQUEST", "waited %d seconds"
|
peer_log(peer_log_alert::info, "NO_REQUEST", "waited %d seconds"
|
||||||
@ -4809,7 +4807,7 @@ namespace libtorrent
|
|||||||
&& d2 > time_limit
|
&& d2 > time_limit
|
||||||
&& (m_ses.num_connections() >= m_settings.get_int(settings_pack::connections_limit)
|
&& (m_ses.num_connections() >= m_settings.get_int(settings_pack::connections_limit)
|
||||||
|| (t && t->num_peers() >= t->max_connections()))
|
|| (t && t->num_peers() >= t->max_connections()))
|
||||||
&& can_disconnect(error_code(errors::timed_out_no_interest)))
|
&& can_disconnect(errors::timed_out_no_interest))
|
||||||
{
|
{
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
if (should_log(peer_log_alert::info))
|
if (should_log(peer_log_alert::info))
|
||||||
@ -6402,12 +6400,12 @@ namespace libtorrent
|
|||||||
&& !t->share_mode())
|
&& !t->share_mode())
|
||||||
{
|
{
|
||||||
bool const ok_to_disconnect =
|
bool const ok_to_disconnect =
|
||||||
can_disconnect(error_code(errors::upload_upload_connection))
|
can_disconnect(errors::upload_upload_connection)
|
||||||
|| can_disconnect(error_code(errors::uninteresting_upload_peer))
|
|| can_disconnect(errors::uninteresting_upload_peer)
|
||||||
|| can_disconnect(error_code(errors::too_many_requests_when_choked))
|
|| can_disconnect(errors::too_many_requests_when_choked)
|
||||||
|| can_disconnect(error_code(errors::timed_out_no_interest))
|
|| can_disconnect(errors::timed_out_no_interest)
|
||||||
|| can_disconnect(error_code(errors::timed_out_no_request))
|
|| can_disconnect(errors::timed_out_no_request)
|
||||||
|| can_disconnect(error_code(errors::timed_out_inactivity));
|
|| can_disconnect(errors::timed_out_inactivity);
|
||||||
|
|
||||||
// make sure upload only peers are disconnected
|
// make sure upload only peers are disconnected
|
||||||
if (t->is_upload_only()
|
if (t->is_upload_only()
|
||||||
|
@ -72,14 +72,14 @@ namespace libtorrent
|
|||||||
if (rd.dict_find_string_value("file-format")
|
if (rd.dict_find_string_value("file-format")
|
||||||
!= "libtorrent resume file")
|
!= "libtorrent resume file")
|
||||||
{
|
{
|
||||||
ec = error_code(errors::invalid_file_tag, get_libtorrent_category());
|
ec = errors::invalid_file_tag;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto info_hash = rd.dict_find_string_value("info-hash");
|
auto info_hash = rd.dict_find_string_value("info-hash");
|
||||||
if (info_hash.size() != 20)
|
if (info_hash.size() != 20)
|
||||||
{
|
{
|
||||||
ec = error_code(errors::missing_info_hash, get_libtorrent_category());
|
ec = errors::missing_info_hash;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2821,7 +2821,7 @@ namespace aux {
|
|||||||
{
|
{
|
||||||
m_alerts.emplace_alert<peer_disconnected_alert>(torrent_handle(), endp, peer_id()
|
m_alerts.emplace_alert<peer_disconnected_alert>(torrent_handle(), endp, peer_id()
|
||||||
, op_bittorrent, s->type()
|
, op_bittorrent, s->type()
|
||||||
, error_code(errors::too_many_connections, get_libtorrent_category())
|
, error_code(errors::too_many_connections)
|
||||||
, close_no_reason);
|
, close_no_reason);
|
||||||
}
|
}
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
@ -3419,7 +3419,7 @@ namespace aux {
|
|||||||
int(i->second->num_peers() * m_settings.get_int(settings_pack::peer_turnover) / 100), 1)
|
int(i->second->num_peers() * m_settings.get_int(settings_pack::peer_turnover) / 100), 1)
|
||||||
, i->second->num_connect_candidates());
|
, i->second->num_connect_candidates());
|
||||||
i->second->disconnect_peers(peers_to_disconnect
|
i->second->disconnect_peers(peers_to_disconnect
|
||||||
, error_code(errors::optimistic_disconnect, get_libtorrent_category()));
|
, error_code(errors::optimistic_disconnect));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3441,7 +3441,7 @@ namespace aux {
|
|||||||
* m_settings.get_int(settings_pack::peer_turnover) / 100), 1)
|
* m_settings.get_int(settings_pack::peer_turnover) / 100), 1)
|
||||||
, t->num_connect_candidates());
|
, t->num_connect_candidates());
|
||||||
t->disconnect_peers(peers_to_disconnect
|
t->disconnect_peers(peers_to_disconnect
|
||||||
, error_code(errors::optimistic_disconnect, get_libtorrent_category()));
|
, error_code(errors::optimistic_disconnect));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6402,7 +6402,7 @@ namespace aux {
|
|||||||
int const disconnect = std::min(to_disconnect, num - my_average);
|
int const disconnect = std::min(to_disconnect, num - my_average);
|
||||||
to_disconnect -= disconnect;
|
to_disconnect -= disconnect;
|
||||||
t.second->disconnect_peers(disconnect
|
t.second->disconnect_peers(disconnect
|
||||||
, error_code(errors::too_many_connections, get_libtorrent_category()));
|
, error_code(errors::too_many_connections));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
boost::system::error_code make_error_code(socks_error_code e)
|
boost::system::error_code make_error_code(socks_error_code e)
|
||||||
{
|
{
|
||||||
return error_code(e, get_socks_category());
|
return error_code(e, socks_category());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,10 +74,10 @@ namespace libtorrent
|
|||||||
{ return boost::system::error_condition(ev, *this); }
|
{ return boost::system::error_condition(ev, *this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
TORRENT_EXPORT boost::system::error_category& get_socks_category()
|
TORRENT_EXPORT boost::system::error_category& socks_category()
|
||||||
{
|
{
|
||||||
static socks_error_category socks_category;
|
static socks_error_category cat;
|
||||||
return socks_category;
|
return cat;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -386,7 +386,7 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
if (response != 0)
|
if (response != 0)
|
||||||
{
|
{
|
||||||
error_code ec(socks_error::general_failure, get_socks_category());
|
error_code ec(socks_error::general_failure);
|
||||||
switch (response)
|
switch (response)
|
||||||
{
|
{
|
||||||
case 2: ec = boost::asio::error::no_permission; break;
|
case 2: ec = boost::asio::error::no_permission; break;
|
||||||
@ -483,7 +483,7 @@ namespace libtorrent
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code ec(socks_error::general_failure, get_socks_category());
|
error_code ec(socks_error::general_failure);
|
||||||
switch (response)
|
switch (response)
|
||||||
{
|
{
|
||||||
case 91: ec = boost::asio::error::connection_refused; break;
|
case 91: ec = boost::asio::error::connection_refused; break;
|
||||||
|
@ -421,7 +421,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (parser.status_code() != 200)
|
if (parser.status_code() != 200)
|
||||||
{
|
{
|
||||||
set_error(error_code(parser.status_code(), get_http_category()), torrent_status::error_file_url);
|
set_error(error_code(parser.status_code(), http_category()), torrent_status::error_file_url);
|
||||||
pause();
|
pause();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -468,7 +468,7 @@ namespace libtorrent
|
|||||||
// TODO: if the existing torrent doesn't have metadata, insert
|
// TODO: if the existing torrent doesn't have metadata, insert
|
||||||
// the metadata we just downloaded into it.
|
// the metadata we just downloaded into it.
|
||||||
|
|
||||||
set_error(error_code(errors::duplicate_torrent, get_libtorrent_category()), torrent_status::error_file_url);
|
set_error(errors::duplicate_torrent, torrent_status::error_file_url);
|
||||||
abort();
|
abort();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -5638,7 +5638,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
if (alerts().should_post<torrent_error_alert>())
|
if (alerts().should_post<torrent_error_alert>())
|
||||||
alerts().emplace_alert<torrent_error_alert>(get_handle()
|
alerts().emplace_alert<torrent_error_alert>(get_handle()
|
||||||
, error_code(errors::not_an_ssl_torrent), "");
|
, errors::not_an_ssl_torrent, "");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5884,7 +5884,7 @@ namespace libtorrent
|
|||||||
if (m_ses.alerts().should_post<url_seed_alert>())
|
if (m_ses.alerts().should_post<url_seed_alert>())
|
||||||
{
|
{
|
||||||
m_ses.alerts().emplace_alert<url_seed_alert>(get_handle(), web->url
|
m_ses.alerts().emplace_alert<url_seed_alert>(get_handle(), web->url
|
||||||
, error_code(libtorrent::errors::peer_banned, get_libtorrent_category()));
|
, libtorrent::errors::peer_banned);
|
||||||
}
|
}
|
||||||
// never try it again
|
// never try it again
|
||||||
remove_web_seed_iter(web);
|
remove_web_seed_iter(web);
|
||||||
@ -6836,8 +6836,7 @@ namespace libtorrent
|
|||||||
// we have an i2p torrent, but we're not connected to an i2p
|
// we have an i2p torrent, but we're not connected to an i2p
|
||||||
// SAM proxy.
|
// SAM proxy.
|
||||||
if (alerts().should_post<i2p_alert>())
|
if (alerts().should_post<i2p_alert>())
|
||||||
alerts().emplace_alert<i2p_alert>(error_code(errors::no_i2p_router
|
alerts().emplace_alert<i2p_alert>(errors::no_i2p_router);
|
||||||
, get_libtorrent_category()));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7003,7 +7002,7 @@ namespace libtorrent
|
|||||||
if (alerts().should_post<metadata_failed_alert>())
|
if (alerts().should_post<metadata_failed_alert>())
|
||||||
{
|
{
|
||||||
alerts().emplace_alert<metadata_failed_alert>(get_handle()
|
alerts().emplace_alert<metadata_failed_alert>(get_handle()
|
||||||
, error_code(errors::mismatching_info_hash, get_libtorrent_category()));
|
, errors::mismatching_info_hash);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -7989,8 +7988,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
if (alerts().should_post<file_rename_failed_alert>())
|
if (alerts().should_post<file_rename_failed_alert>())
|
||||||
alerts().emplace_alert<file_rename_failed_alert>(get_handle()
|
alerts().emplace_alert<file_rename_failed_alert>(get_handle()
|
||||||
, index, error_code(errors::session_is_closing
|
, index, errors::session_is_closing);
|
||||||
, get_libtorrent_category()));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8414,7 +8412,7 @@ namespace libtorrent
|
|||||||
if (num_peers() > int(m_max_connections))
|
if (num_peers() > int(m_max_connections))
|
||||||
{
|
{
|
||||||
disconnect_peers(num_peers() - m_max_connections
|
disconnect_peers(num_peers() - m_max_connections
|
||||||
, error_code(errors::too_many_connections, get_libtorrent_category()));
|
, errors::too_many_connections);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state_update)
|
if (state_update)
|
||||||
|
10
src/upnp.cpp
10
src/upnp.cpp
@ -62,7 +62,7 @@ namespace upnp_errors
|
|||||||
{
|
{
|
||||||
boost::system::error_code make_error_code(error_code_enum e)
|
boost::system::error_code make_error_code(error_code_enum e)
|
||||||
{
|
{
|
||||||
return error_code(e, get_upnp_category());
|
return error_code(e, upnp_category());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // upnp_errors namespace
|
} // upnp_errors namespace
|
||||||
@ -1221,7 +1221,7 @@ struct upnp_error_category : boost::system::error_category
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
boost::system::error_category& get_upnp_category()
|
boost::system::error_category& upnp_category()
|
||||||
{
|
{
|
||||||
static upnp_error_category cat;
|
static upnp_error_category cat;
|
||||||
return cat;
|
return cat;
|
||||||
@ -1493,7 +1493,7 @@ void upnp::return_error(int mapping, int code)
|
|||||||
error_string += e->msg;
|
error_string += e->msg;
|
||||||
}
|
}
|
||||||
portmap_protocol const proto = m_mappings[mapping].protocol;
|
portmap_protocol const proto = m_mappings[mapping].protocol;
|
||||||
m_callback.on_port_mapping(mapping, address(), 0, proto, error_code(code, get_upnp_category())
|
m_callback.on_port_mapping(mapping, address(), 0, proto, error_code(code, upnp_category())
|
||||||
, aux::portmap_transport::upnp);
|
, aux::portmap_transport::upnp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1558,8 +1558,8 @@ void upnp::on_upnp_unmap_response(error_code const& e
|
|||||||
portmap_protocol const proto = m_mappings[mapping].protocol;
|
portmap_protocol const proto = m_mappings[mapping].protocol;
|
||||||
|
|
||||||
m_callback.on_port_mapping(mapping, address(), 0, proto, p.status_code() != 200
|
m_callback.on_port_mapping(mapping, address(), 0, proto, p.status_code() != 200
|
||||||
? error_code(p.status_code(), get_http_category())
|
? error_code(p.status_code(), http_category())
|
||||||
: error_code(s.error_code, get_upnp_category())
|
: error_code(s.error_code, upnp_category())
|
||||||
, aux::portmap_transport::upnp);
|
, aux::portmap_transport::upnp);
|
||||||
|
|
||||||
d.mapping[mapping].protocol = portmap_protocol::none;
|
d.mapping[mapping].protocol = portmap_protocol::none;
|
||||||
|
@ -557,7 +557,7 @@ void web_peer_connection::handle_error(int bytes_left)
|
|||||||
, error_msg);
|
, error_msg);
|
||||||
}
|
}
|
||||||
received_bytes(0, bytes_left);
|
received_bytes(0, bytes_left);
|
||||||
disconnect(error_code(m_parser.status_code(), get_http_category()), op_bittorrent, 1);
|
disconnect(error_code(m_parser.status_code(), http_category()), op_bittorrent, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,8 +83,8 @@ TORRENT_TEST(primitives)
|
|||||||
TEST_CHECK(error_code(errors::http_parse_error).message() == "Invalid HTTP header");
|
TEST_CHECK(error_code(errors::http_parse_error).message() == "Invalid HTTP header");
|
||||||
TEST_CHECK(error_code(errors::error_code_max).message() == "Unknown error");
|
TEST_CHECK(error_code(errors::error_code_max).message() == "Unknown error");
|
||||||
|
|
||||||
TEST_CHECK(error_code(errors::unauthorized, get_http_category()).message() == "401 Unauthorized");
|
TEST_CHECK(error_code(errors::unauthorized, http_category()).message() == "401 Unauthorized");
|
||||||
TEST_CHECK(error_code(errors::service_unavailable, get_http_category()).message() == "503 Service Unavailable");
|
TEST_CHECK(error_code(errors::service_unavailable, http_category()).message() == "503 Service Unavailable");
|
||||||
|
|
||||||
// test snprintf
|
// test snprintf
|
||||||
|
|
||||||
@ -128,11 +128,11 @@ TORRENT_TEST(primitives)
|
|||||||
#if TORRENT_USE_IPV6
|
#if TORRENT_USE_IPV6
|
||||||
TEST_EQUAL(print_address(v6("2001:ff::1")), "2001:ff::1");
|
TEST_EQUAL(print_address(v6("2001:ff::1")), "2001:ff::1");
|
||||||
parse_endpoint("[ff::1]", ec);
|
parse_endpoint("[ff::1]", ec);
|
||||||
TEST_EQUAL(ec, error_code(errors::invalid_port, get_libtorrent_category()));
|
TEST_EQUAL(ec, error_code(errors::invalid_port));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
parse_endpoint("[ff::1:5", ec);
|
parse_endpoint("[ff::1:5", ec);
|
||||||
TEST_EQUAL(ec, error_code(errors::expected_close_bracket_in_address, get_libtorrent_category()));
|
TEST_EQUAL(ec, error_code(errors::expected_close_bracket_in_address));
|
||||||
|
|
||||||
// test address_to_bytes
|
// test address_to_bytes
|
||||||
TEST_EQUAL(address_to_bytes(address_v4::from_string("10.11.12.13")), "\x0a\x0b\x0c\x0d");
|
TEST_EQUAL(address_to_bytes(address_v4::from_string("10.11.12.13")), "\x0a\x0b\x0c\x0d");
|
||||||
@ -166,3 +166,14 @@ TORRENT_TEST(printf_trunc)
|
|||||||
std::snprintf(buffer, sizeof(buffer), "%d %s", val, "end");
|
std::snprintf(buffer, sizeof(buffer), "%d %s", val, "end");
|
||||||
TEST_EQUAL(buffer, std::string("184"))
|
TEST_EQUAL(buffer, std::string("184"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TORRENT_TEST(error_condition)
|
||||||
|
{
|
||||||
|
#ifdef TORRENT_WINDOWS
|
||||||
|
error_code ec(ERROR_FILE_NOT_FOUND, system_category());
|
||||||
|
#else
|
||||||
|
error_code ec(ENOENT, system_category());
|
||||||
|
#endif
|
||||||
|
TEST_CHECK(ec == boost::system::errc::no_such_file_or_directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ TORRENT_TEST(read_resume_missing_info_hash)
|
|||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
add_torrent_params atp = read_resume_data(&resume_data[0], int(resume_data.size()), ec);
|
add_torrent_params atp = read_resume_data(&resume_data[0], int(resume_data.size()), ec);
|
||||||
TEST_EQUAL(ec, error_code(errors::missing_info_hash, get_libtorrent_category()));
|
TEST_EQUAL(ec, error_code(errors::missing_info_hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_TEST(read_resume_missing_file_format)
|
TORRENT_TEST(read_resume_missing_file_format)
|
||||||
@ -140,7 +140,7 @@ TORRENT_TEST(read_resume_missing_file_format)
|
|||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
add_torrent_params atp = read_resume_data(&resume_data[0], int(resume_data.size()), ec);
|
add_torrent_params atp = read_resume_data(&resume_data[0], int(resume_data.size()), ec);
|
||||||
TEST_EQUAL(ec, error_code(errors::invalid_file_tag, get_libtorrent_category()));
|
TEST_EQUAL(ec, error_code(errors::invalid_file_tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_TEST(read_resume_mismatching_torrent)
|
TORRENT_TEST(read_resume_mismatching_torrent)
|
||||||
|
@ -201,7 +201,7 @@ TORRENT_TEST(parse_failure_reason)
|
|||||||
tracker_response resp = parse_tracker_response(response, sizeof(response) - 1
|
tracker_response resp = parse_tracker_response(response, sizeof(response) - 1
|
||||||
, ec, false, sha1_hash());
|
, ec, false, sha1_hash());
|
||||||
|
|
||||||
TEST_EQUAL(ec, error_code(errors::tracker_failure));
|
TEST_EQUAL(ec, errors::tracker_failure);
|
||||||
TEST_EQUAL(resp.peers.size(), 0);
|
TEST_EQUAL(resp.peers.size(), 0);
|
||||||
TEST_EQUAL(resp.failure_reason, "test message");
|
TEST_EQUAL(resp.failure_reason, "test message");
|
||||||
}
|
}
|
||||||
@ -296,21 +296,21 @@ TORRENT_TEST(extract_peer_not_a_dictionary)
|
|||||||
{
|
{
|
||||||
// not a dictionary
|
// not a dictionary
|
||||||
peer_entry result = extract_peer("2:ip11:example.com"
|
peer_entry result = extract_peer("2:ip11:example.com"
|
||||||
, error_code(errors::invalid_peer_dict, get_libtorrent_category()), false);
|
, errors::invalid_peer_dict, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_TEST(extract_peer_missing_ip)
|
TORRENT_TEST(extract_peer_missing_ip)
|
||||||
{
|
{
|
||||||
// missing IP
|
// missing IP
|
||||||
peer_entry result = extract_peer("d7:peer id20:abababababababababab4:porti1337ee"
|
peer_entry result = extract_peer("d7:peer id20:abababababababababab4:porti1337ee"
|
||||||
, error_code(errors::invalid_tracker_response, get_libtorrent_category()), false);
|
, errors::invalid_tracker_response, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_TEST(extract_peer_missing_port)
|
TORRENT_TEST(extract_peer_missing_port)
|
||||||
{
|
{
|
||||||
// missing port
|
// missing port
|
||||||
peer_entry result = extract_peer("d7:peer id20:abababababababababab2:ip4:abcde"
|
peer_entry result = extract_peer("d7:peer id20:abababababababababab2:ip4:abcde"
|
||||||
, error_code(errors::invalid_tracker_response, get_libtorrent_category()), false);
|
, errors::invalid_tracker_response, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_TEST(udp_tracker)
|
TORRENT_TEST(udp_tracker)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user