cleaned up public interface by removing some symbols from the exported set

This commit is contained in:
Arvid Norberg
2013-07-19 19:06:27 +00:00
parent 2f28ed78d4
commit a401aa0337
14 changed files with 240 additions and 182 deletions

View File

@@ -9,6 +9,7 @@ KADEMLIA_SOURCES = \
kademlia/refresh.cpp \
kademlia/routing_table.cpp \
kademlia/rpc_manager.cpp \
kademlia/logging.cpp \
kademlia/traversal_algorithm.cpp
endif

54
src/kademlia/logging.cpp Normal file
View File

@@ -0,0 +1,54 @@
/*
Copyright (c) 2006-2012, Arvid Norberg & Daniel Wallin
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.
*/
#include "libtorrent/kademlia/logging.hpp"
namespace libtorrent { namespace dht
{
log_event::log_event(log& log)
: log_(log)
{
if (log_.enabled())
log_ << time_now_string() << " [" << log.id() << "] ";
}
log_event::~log_event()
{
if (log_.enabled())
{
log_ << "\n";
log_.flush();
}
}
}}

View File

@@ -86,15 +86,6 @@ void stop_malloc_debug();
namespace libtorrent
{
#ifdef _MSC_VER
namespace aux
{
eh_initializer::eh_initializer()
{
::_set_se_translator(straight_to_debugger);
}
}
#endif
TORRENT_EXPORT void TORRENT_LINK_TEST_NAME() {}
@@ -401,9 +392,21 @@ namespace libtorrent
// configurations this will give a link error
void TORRENT_EXPORT TORRENT_CFG() {}
#if defined _MSC_VER && defined TORRENT_DEBUG
static void straight_to_debugger(unsigned int, _EXCEPTION_POINTERS*)
{ throw; }
#endif
void session::init(std::pair<int, int> listen_range, char const* listen_interface
, fingerprint const& id, boost::uint32_t alert_mask)
{
#if defined _MSC_VER && defined TORRENT_DEBUG
// workaround for microsofts
// hardware exceptions that makes
// it hard to debug stuff
::_set_se_translator(straight_to_debugger);
#endif
m_impl.reset(new session_impl(listen_range, id, listen_interface, alert_mask));
#ifdef TORRENT_MEMDEBUG
@@ -1118,16 +1121,14 @@ namespace libtorrent
TORRENT_ASYNC_CALL(start_lsd);
}
natpmp* session::start_natpmp()
void session::start_natpmp()
{
TORRENT_SYNC_CALL_RET(natpmp*, start_natpmp);
return r;
TORRENT_ASYNC_CALL(start_natpmp);
}
upnp* session::start_upnp()
void session::start_upnp()
{
TORRENT_SYNC_CALL_RET(upnp*, start_upnp);
return r;
TORRENT_ASYNC_CALL(start_upnp);
}
void session::stop_lsd()

View File

@@ -4793,13 +4793,23 @@ retry:
}
}
#if defined _MSC_VER && defined TORRENT_DEBUG
static void straight_to_debugger(unsigned int, _EXCEPTION_POINTERS*)
{ throw; }
#endif
void session_impl::main_thread()
{
#if defined _MSC_VER && defined TORRENT_DEBUG
// workaround for microsofts
// hardware exceptions that makes
// it hard to debug stuff
::_set_se_translator(straight_to_debugger);
#endif
#if (defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS) && defined BOOST_HAS_PTHREADS
m_network_thread = pthread_self();
#endif
TORRENT_ASSERT(is_network_thread());
eh_initializer();
// initialize async operations
init();
@@ -6381,5 +6391,74 @@ retry:
}
#endif
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
tracker_logger::tracker_logger(session_impl& ses): m_ses(ses) {}
void tracker_logger::tracker_warning(tracker_request const& req
, std::string const& str)
{
debug_log("*** tracker warning: %s", str.c_str());
}
void tracker_logger::tracker_response(tracker_request const&
, libtorrent::address const& tracker_ip
, std::list<address> const& ip_list
, std::vector<peer_entry>& peers
, int interval
, int min_interval
, int complete
, int incomplete
, int downloaded
, address const& external_ip
, std::string const& tracker_id)
{
std::string s;
s = "TRACKER RESPONSE:\n";
char tmp[200];
snprintf(tmp, 200, "interval: %d\nmin_interval: %d\npeers:\n", interval, min_interval);
s += tmp;
for (std::vector<peer_entry>::const_iterator i = peers.begin();
i != peers.end(); ++i)
{
char pid[41];
to_hex((const char*)&i->pid[0], 20, pid);
if (i->pid.is_all_zeros()) pid[0] = 0;
snprintf(tmp, 200, " %-16s %-5d %s\n", i->ip.c_str(), i->port, pid);
s += tmp;
}
snprintf(tmp, 200, "external ip: %s\n", print_address(external_ip).c_str());
s += tmp;
debug_log("%s", s.c_str());
}
void tracker_logger::tracker_request_timed_out(
tracker_request const&)
{
debug_log("*** tracker timed out");
}
void tracker_logger::tracker_request_error(tracker_request const& r
, int response_code, error_code const& ec, const std::string& str
, int retry_interval)
{
debug_log("*** tracker error: %d: %s %s"
, response_code, ec.message().c_str(), str.c_str());
}
void tracker_logger::debug_log(const char* fmt, ...) const
{
if (!m_ses.m_logger) return;
va_list v;
va_start(v, fmt);
char usr[1024];
vsnprintf(usr, sizeof(usr), fmt, v);
va_end(v);
char buf[1280];
snprintf(buf, sizeof(buf), "%s: %s\n", time_now_string(), usr);
(*m_ses.m_logger) << buf;
}
#endif
}}

View File

@@ -153,35 +153,32 @@ namespace libtorrent
namespace libtorrent
{
namespace aux
boost::int64_t performance_counter_to_microseconds(boost::int64_t pc)
{
boost::int64_t performance_counter_to_microseconds(boost::int64_t pc)
{
static LARGE_INTEGER performace_counter_frequency = {0,0};
if (performace_counter_frequency.QuadPart == 0)
QueryPerformanceFrequency(&performace_counter_frequency);
static LARGE_INTEGER performace_counter_frequency = {0,0};
if (performace_counter_frequency.QuadPart == 0)
QueryPerformanceFrequency(&performace_counter_frequency);
#ifdef TORRENT_DEBUG
// make sure we don't overflow
boost::int64_t ret = (pc * 1000 / performace_counter_frequency.QuadPart) * 1000;
TORRENT_ASSERT((pc >= 0 && pc >= ret) || (pc < 0 && pc < ret));
// make sure we don't overflow
boost::int64_t ret = (pc * 1000 / performace_counter_frequency.QuadPart) * 1000;
TORRENT_ASSERT((pc >= 0 && pc >= ret) || (pc < 0 && pc < ret));
#endif
return ((pc * 1000 + performace_counter_frequency.QuadPart / 2) / performace_counter_frequency.QuadPart) * 1000;
}
return ((pc * 1000 + performace_counter_frequency.QuadPart / 2) / performace_counter_frequency.QuadPart) * 1000;
}
boost::int64_t microseconds_to_performance_counter(boost::int64_t ms)
{
static LARGE_INTEGER performace_counter_frequency = {0,0};
if (performace_counter_frequency.QuadPart == 0)
QueryPerformanceFrequency(&performace_counter_frequency);
boost::int64_t microseconds_to_performance_counter(boost::int64_t ms)
{
static LARGE_INTEGER performace_counter_frequency = {0,0};
if (performace_counter_frequency.QuadPart == 0)
QueryPerformanceFrequency(&performace_counter_frequency);
#ifdef TORRENT_DEBUG
// make sure we don't overflow
boost::int64_t ret = (ms / 1000) * performace_counter_frequency.QuadPart / 1000;
TORRENT_ASSERT((ms >= 0 && ms <= ret)
|| (ms < 0 && ms > ret));
// make sure we don't overflow
boost::int64_t ret = (ms / 1000) * performace_counter_frequency.QuadPart / 1000;
TORRENT_ASSERT((ms >= 0 && ms <= ret)
|| (ms < 0 && ms > ret));
#endif
return (ms / 1000) * performace_counter_frequency.QuadPart / 1000;
}
return (ms / 1000) * performace_counter_frequency.QuadPart / 1000;
}
ptime time_now_hires()
@@ -190,6 +187,46 @@ namespace libtorrent
QueryPerformanceCounter(&now);
return ptime(now.QuadPart);
}
int total_seconds(time_duration td)
{
return int(performance_counter_to_microseconds(td.diff)
/ 1000000);
}
int total_milliseconds(time_duration td)
{
return int(performance_counter_to_microseconds(td.diff)
/ 1000);
}
boost::int64_t total_microseconds(time_duration td)
{
return performance_counter_to_microseconds(td.diff);
}
time_duration microsec(boost::int64_t s)
{
return time_duration(aux::microseconds_to_performance_counter(s));
}
time_duration milliseconds(boost::int64_t s)
{
return time_duration(aux::microseconds_to_performance_counter(
s * 1000));
}
time_duration seconds(boost::int64_t s)
{
return time_duration(aux::microseconds_to_performance_counter(
s * 1000000));
}
time_duration minutes(boost::int64_t s)
{
return time_duration(aux::microseconds_to_performance_counter(
s * 1000000 * 60));
}
time_duration hours(boost::int64_t s)
{
return time_duration(aux::microseconds_to_performance_counter(
s * 1000000 * 60 * 60));
}
}
#elif defined TORRENT_USE_CLOCK_GETTIME