fix library ABI to not depend on logging being enabled

This commit is contained in:
Arvid Norberg 2013-03-10 09:19:58 +00:00
parent b943a9b057
commit a2a4b61b5d
7 changed files with 65 additions and 58 deletions

View File

@ -1,3 +1,4 @@
* fix library ABI to not depend on logging being enabled
* use hex encoding instead of base32 in create_magnet_uri
* include name, save_path and torrent_file in torrent_status, for improved performance
* separate anonymous mode and force-proxy mode, and tighten it up a bit

View File

@ -215,15 +215,14 @@ namespace libtorrent
std::pair<int, int> listen_port_range
, fingerprint const& cl_fprint
, char const* listen_interface
, boost::uint32_t alert_mask
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
, std::string const& logpath
#endif
);
, boost::uint32_t alert_mask);
virtual ~session_impl();
void update_dht_announce_interval();
void init();
void start_session();
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
void set_log_path(std::string const& p) { m_logpath = p; }
#endif
#ifndef TORRENT_DISABLE_EXTENSIONS
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(

View File

@ -75,14 +75,6 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_CFG_POOL pools_
#endif
#ifdef TORRENT_VERBOSE_LOGGING
#define TORRENT_CFG_LOG verboselog_
#elif defined TORRENT_LOGGING
#define TORRENT_CFG_LOG log_
#else
#define TORRENT_CFG_LOG nolog_
#endif
#ifdef _UNICODE
#define TORRENT_CFG_UNICODE unicode_
#else

View File

@ -463,11 +463,11 @@ inline int snprintf(char* buf, int len, char const* fmt, ...)
#endif
#if !defined(TORRENT_READ_HANDLER_MAX_SIZE)
# define TORRENT_READ_HANDLER_MAX_SIZE 300
# define TORRENT_READ_HANDLER_MAX_SIZE 330
#endif
#if !defined(TORRENT_WRITE_HANDLER_MAX_SIZE)
# define TORRENT_WRITE_HANDLER_MAX_SIZE 300
# define TORRENT_WRITE_HANDLER_MAX_SIZE 330
#endif
#if defined _MSC_VER && _MSC_VER <= 1200

View File

@ -124,12 +124,8 @@ namespace libtorrent
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
#define TORRENT_LOGPATH_ARG_DEFAULT , std::string logpath = "."
#define TORRENT_LOGPATH_ARG , std::string logpath
#define TORRENT_LOGPATH , logpath
#else
#define TORRENT_LOGPATH_ARG_DEFAULT
#define TORRENT_LOGPATH_ARG
#define TORRENT_LOGPATH
#endif
class TORRENT_EXPORT session: public boost::noncopyable, aux::eh_initializer
@ -143,7 +139,11 @@ namespace libtorrent
TORRENT_LOGPATH_ARG_DEFAULT)
{
TORRENT_CFG();
init(std::make_pair(0, 0), "0.0.0.0", print, flags, alert_mask TORRENT_LOGPATH);
init(std::make_pair(0, 0), "0.0.0.0", print, alert_mask);
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
set_log_path(logpath);
#endif
start(flags);
}
session(
@ -157,7 +157,11 @@ namespace libtorrent
TORRENT_CFG();
TORRENT_ASSERT(listen_port_range.first > 0);
TORRENT_ASSERT(listen_port_range.first < listen_port_range.second);
init(listen_port_range, listen_interface, print, flags, alert_mask TORRENT_LOGPATH);
init(listen_port_range, listen_interface, print, alert_mask);
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
set_log_path(logpath);
#endif
start(flags);
}
~session();
@ -492,7 +496,9 @@ namespace libtorrent
private:
void init(std::pair<int, int> listen_range, char const* listen_interface
, fingerprint const& id, int flags, boost::uint32_t alert_mask TORRENT_LOGPATH_ARG);
, fingerprint const& id, boost::uint32_t alert_mask);
void set_log_path(std::string const& p);
void start(int flags);
// data shared between the main thread
// and the working thread

View File

@ -393,13 +393,24 @@ namespace libtorrent
void TORRENT_EXPORT TORRENT_CFG() {}
void session::init(std::pair<int, int> listen_range, char const* listen_interface
, fingerprint const& id, int flags, boost::uint32_t alert_mask TORRENT_LOGPATH_ARG)
, fingerprint const& id, boost::uint32_t alert_mask)
{
m_impl.reset(new session_impl(listen_range, id, listen_interface, alert_mask TORRENT_LOGPATH));
m_impl.reset(new session_impl(listen_range, id, listen_interface, alert_mask));
#ifdef TORRENT_MEMDEBUG
start_malloc_debug();
#endif
}
void session::set_log_path(std::string const& p)
{
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
m_impl->set_log_path(p);
#endif
}
void session::start(int flags)
{
#ifndef TORRENT_DISABLE_EXTENSIONS
if (flags & add_default_plugins)
{

View File

@ -597,9 +597,6 @@ namespace aux {
, fingerprint const& cl_fprint
, char const* listen_interface
, boost::uint32_t alert_mask
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
, std::string const& logpath
#endif
)
: m_ipv4_peer_pool(500)
#if TORRENT_USE_IPV6
@ -666,7 +663,7 @@ namespace aux {
, m_tick_residual(0)
, m_non_filtered_torrents(0)
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
, m_logpath(logpath)
, m_logpath(".")
#endif
#ifndef TORRENT_DISABLE_GEO_IP
, m_asnum_db(0)
@ -704,6 +701,33 @@ namespace aux {
}
#endif
error_code ec;
if (!listen_interface) listen_interface = "0.0.0.0";
m_listen_interface = tcp::endpoint(address::from_string(listen_interface, ec), listen_port_range.first);
TORRENT_ASSERT_VAL(!ec, ec);
// ---- generate a peer id ----
static seed_random_generator seeder;
m_key = random() + (random() << 15) + (random() << 30);
std::string print = cl_fprint.to_string();
TORRENT_ASSERT_VAL(print.length() <= 20, print.length());
// the client's fingerprint
std::copy(
print.begin()
, print.begin() + print.length()
, m_peer_id.begin());
url_random((char*)&m_peer_id[print.length()], (char*)&m_peer_id[0] + 20);
update_rate_settings();
update_connections_limit();
update_unchoke_limit();
}
void session_impl::start_session()
{
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
m_logger = create_log("main_session", listen_port(), false);
session_log("log created");
@ -727,10 +751,6 @@ namespace aux {
m_next_connect_torrent = m_torrents.begin();
m_next_disk_peer = m_connections.begin();
if (!listen_interface) listen_interface = "0.0.0.0";
m_listen_interface = tcp::endpoint(address::from_string(listen_interface, ec), listen_port_range.first);
TORRENT_ASSERT_VAL(!ec, ec);
m_tcp_mapping[0] = -1;
m_tcp_mapping[1] = -1;
m_udp_mapping[0] = -1;
@ -1063,28 +1083,14 @@ namespace aux {
#endif // TORRENT_BSD || TORRENT_LINUX
// ---- generate a peer id ----
static seed_random_generator seeder;
m_key = random() + (random() << 15) + (random() << 30);
std::string print = cl_fprint.to_string();
TORRENT_ASSERT_VAL(print.length() <= 20, print.length());
// the client's fingerprint
std::copy(
print.begin()
, print.begin() + print.length()
, m_peer_id.begin());
url_random((char*)&m_peer_id[print.length()], (char*)&m_peer_id[0] + 20);
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
session_log(" generated peer ID: %s", m_peer_id.to_string().c_str());
#endif
update_rate_settings();
update_connections_limit();
update_unchoke_limit();
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
session_log(" spawning network thread");
#endif
m_thread.reset(new thread(boost::bind(&session_impl::main_thread, this)));
}
#ifdef TORRENT_STATS
@ -1305,14 +1311,6 @@ namespace aux {
}
#endif
void session_impl::start_session()
{
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
session_log(" spawning network thread");
#endif
m_thread.reset(new thread(boost::bind(&session_impl::main_thread, this)));
}
void session_impl::trigger_auto_manage()
{
if (m_pending_auto_manage || m_abort) return;