cleanup and fixing of more warnings
This commit is contained in:
parent
4d15f1410f
commit
f5629eb403
|
@ -31,6 +31,7 @@ set(sources
|
|||
file
|
||||
gzip
|
||||
hasher
|
||||
hex
|
||||
http_connection
|
||||
http_stream
|
||||
http_parser
|
||||
|
|
1
Jamfile
1
Jamfile
|
@ -590,6 +590,7 @@ SOURCES =
|
|||
file
|
||||
gzip
|
||||
hasher
|
||||
hex
|
||||
http_connection
|
||||
http_stream
|
||||
http_parser
|
||||
|
|
|
@ -70,10 +70,8 @@ namespace libtorrent
|
|||
TORRENT_EXTRA_EXPORT void convert_path_to_windows(std::string& path);
|
||||
#endif
|
||||
|
||||
TORRENT_EXTRA_EXPORT std::string read_until(char const*& str, char delim, char const* end);
|
||||
TORRENT_EXTRA_EXPORT int hex_to_int(char in);
|
||||
|
||||
TORRENT_EXTRA_EXPORT bool is_hex(char const *in, int len);
|
||||
TORRENT_EXTRA_EXPORT std::string read_until(char const*& str, char delim
|
||||
, char const* end);
|
||||
|
||||
#if defined TORRENT_WINDOWS && TORRENT_USE_WSTRING
|
||||
TORRENT_EXTRA_EXPORT std::wstring convert_to_wstring(std::string const& s);
|
||||
|
|
|
@ -97,14 +97,15 @@ namespace libtorrent
|
|||
static char const* job_names[7];
|
||||
};
|
||||
|
||||
// TODO: 3 this is defined in disk_io_thread.cpp. The implementation should
|
||||
// be moved out to a separate file and declared in its header
|
||||
char const* job_name(int j);
|
||||
|
||||
void print_piece_log(std::vector<piece_log_t> const& piece_log);
|
||||
void assert_print_piece(cached_piece_entry const* pe);
|
||||
|
||||
#endif
|
||||
|
||||
extern const char* job_action_name[];
|
||||
|
||||
struct TORRENT_EXTRA_EXPORT partial_hash
|
||||
{
|
||||
partial_hash(): offset(0) {}
|
||||
|
|
|
@ -33,14 +33,26 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#ifndef TORRENT_HEX_HPP_INCLUDED
|
||||
#define TORRENT_HEX_HPP_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/array.hpp>
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/error_code.hpp"
|
||||
|
||||
#include "aux_/disable_warnings_push.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/array.hpp>
|
||||
|
||||
#include "aux_/disable_warnings_pop.hpp"
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
namespace detail {
|
||||
|
||||
TORRENT_EXTRA_EXPORT int hex_to_int(char in);
|
||||
TORRENT_EXTRA_EXPORT bool is_hex(char const *in, int len);
|
||||
|
||||
}
|
||||
|
||||
// The overload taking a ``std::string`` converts (binary) the string ``s``
|
||||
// to hexadecimal representation and returns it.
|
||||
// The overload taking a ``char const*`` and a length converts the binary
|
||||
|
|
|
@ -102,6 +102,8 @@ struct key_desc_t
|
|||
bool TORRENT_EXTRA_EXPORT verify_message(bdecode_node const& msg, key_desc_t const desc[]
|
||||
, bdecode_node ret[], int size , char* error, int error_size);
|
||||
|
||||
void TORRENT_EXTRA_EXPORT write_nodes_entry(entry& r, nodes_t const& nodes);
|
||||
|
||||
void incoming_error(entry& e, char const* msg, int error_code = 203);
|
||||
|
||||
// this is the entry for every peer
|
||||
|
|
|
@ -770,11 +770,7 @@ namespace libtorrent
|
|||
|
||||
bool allocate_disk_receive_buffer(int disk_buffer_size);
|
||||
|
||||
// if allow_encrypted is false, and the torrent 'ih' turns out
|
||||
// to be an encrypted torrent (AES-256 encrypted) the peer will
|
||||
// be disconnected. This is to prevent non-encrypted peers to
|
||||
// attach to an encrypted torrent
|
||||
void attach_to_torrent(sha1_hash const& ih, bool allow_encrypted);
|
||||
void attach_to_torrent(sha1_hash const& ih);
|
||||
|
||||
bool verify_piece(peer_request const& p) const;
|
||||
|
||||
|
|
|
@ -92,6 +92,12 @@ namespace libtorrent
|
|||
// make the following invocation return NULL, to indicate the end of the
|
||||
// string.
|
||||
TORRENT_EXTRA_EXPORT char* string_tokenize(char* last, char sep, char** next);
|
||||
|
||||
#if TORRENT_USE_I2P
|
||||
|
||||
bool is_i2p_url(std::string const& url);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -69,6 +69,7 @@ libtorrent_rasterbar_la_SOURCES = \
|
|||
file_storage.cpp \
|
||||
gzip.cpp \
|
||||
hasher.cpp \
|
||||
hex.cpp \
|
||||
http_connection.cpp \
|
||||
http_parser.cpp \
|
||||
http_seed_connection.cpp \
|
||||
|
|
|
@ -182,6 +182,30 @@ void log_refcounts(cached_piece_entry const* pe)
|
|||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
|
||||
const char* job_action_name[] =
|
||||
{
|
||||
"read",
|
||||
"write",
|
||||
"hash",
|
||||
"move_storage",
|
||||
"release_files",
|
||||
"delete_files",
|
||||
"check_fastresume",
|
||||
"save_resume_data",
|
||||
"rename_file",
|
||||
"stop_torrent",
|
||||
"cache_piece",
|
||||
"finalize_file",
|
||||
"flush_piece",
|
||||
"flush_hashed",
|
||||
"flush_storage",
|
||||
"trim_cache",
|
||||
"set_file_priority",
|
||||
"load_torrent",
|
||||
"clear_piece",
|
||||
"tick_storage",
|
||||
};
|
||||
|
||||
char const* piece_log_t::job_names[7] =
|
||||
{
|
||||
"flushing",
|
||||
|
@ -193,6 +217,16 @@ void log_refcounts(cached_piece_entry const* pe)
|
|||
"set_outstanding_jobs",
|
||||
};
|
||||
|
||||
char const* job_name(int j)
|
||||
{
|
||||
if (j < 0 || j >= piece_log_t::last_job)
|
||||
return "unknown";
|
||||
|
||||
if (j < piece_log_t::flushing)
|
||||
return job_action_name[j];
|
||||
return piece_log_t::job_names[j - piece_log_t::flushing];
|
||||
}
|
||||
|
||||
void print_piece_log(std::vector<piece_log_t> const& piece_log)
|
||||
{
|
||||
for (int i = 0; i < int(piece_log.size()); ++i)
|
||||
|
@ -208,8 +242,42 @@ void log_refcounts(cached_piece_entry const* pe)
|
|||
}
|
||||
}
|
||||
|
||||
// defined in disk_io_thread.cpp
|
||||
void assert_print_piece(cached_piece_entry const* pe);
|
||||
void assert_print_piece(cached_piece_entry const* pe)
|
||||
{
|
||||
static const char* const cache_state[] =
|
||||
{
|
||||
"write", "volatile-read", "read-lru", "read-lru-ghost", "read-lfu", "read-lfu-ghost"
|
||||
};
|
||||
|
||||
if (pe == NULL)
|
||||
{
|
||||
assert_print("piece: NULL\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_print("piece: %d\nrefcount: %d\npiece_refcount: %d\n"
|
||||
"num_blocks: %d\nhashing: %d\n\nhash: %p\nhash_offset: %d\n"
|
||||
"cache_state: (%d) %s\noutstanding_flush: %d\npiece: %d\n"
|
||||
"num_dirty: %d\nnum_blocks: %d\nblocks_in_piece: %d\n"
|
||||
"hashing_done: %d\nmarked_for_deletion: %d\nneed_readback: %d\n"
|
||||
"hash_passed: %d\nread_jobs: %d\njobs: %d\n"
|
||||
"piece_log:\n"
|
||||
, int(pe->piece), pe->refcount, pe->piece_refcount, pe->num_blocks
|
||||
, int(pe->hashing), pe->hash, pe->hash ? pe->hash->offset : -1
|
||||
, int(pe->cache_state), pe->cache_state >= 0 && pe->cache_state
|
||||
< cached_piece_entry::num_lrus ? cache_state[pe->cache_state] : ""
|
||||
, int(pe->outstanding_flush), int(pe->piece), int(pe->num_dirty)
|
||||
, int(pe->num_blocks), int(pe->blocks_in_piece), int(pe->hashing_done)
|
||||
, int(pe->marked_for_deletion), int(pe->need_readback), pe->hash_passes
|
||||
, int(pe->read_jobs.size()), int(pe->jobs.size()));
|
||||
for (int i = 0; i < pe->piece_log.size(); ++i)
|
||||
{
|
||||
assert_print(&", %s (%d)"[i==0], job_name(pe->piece_log[i].job), pe->piece_log[i].block);
|
||||
}
|
||||
}
|
||||
assert_print("\n");
|
||||
}
|
||||
|
||||
|
||||
#define TORRENT_PIECE_ASSERT(cond, piece) \
|
||||
do { if (!(cond)) { assert_print_piece(piece); assert_fail(#cond, __LINE__, __FILE__, TORRENT_FUNCTION, 0); } } while(false)
|
||||
|
|
|
@ -2757,7 +2757,7 @@ namespace libtorrent
|
|||
{
|
||||
if (!t)
|
||||
{
|
||||
attach_to_torrent(ti->info_hash(), false);
|
||||
attach_to_torrent(ti->info_hash());
|
||||
if (is_disconnecting()) return;
|
||||
TORRENT_ASSERT(!is_disconnecting());
|
||||
|
||||
|
@ -3260,14 +3260,7 @@ namespace libtorrent
|
|||
std::copy(recv_buffer.begin + 8, recv_buffer.begin + 28
|
||||
, (char*)info_hash.begin());
|
||||
|
||||
// TODO: 3 remove the allow_encrypted parameter
|
||||
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
|
||||
bool allow_encrypted = m_encrypted && m_rc4_encrypted;
|
||||
#else
|
||||
bool allow_encrypted = true;
|
||||
#endif
|
||||
|
||||
attach_to_torrent(info_hash, allow_encrypted);
|
||||
attach_to_torrent(info_hash);
|
||||
if (is_disconnecting()) return;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -72,45 +72,6 @@ namespace libtorrent
|
|||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
|
||||
char const* job_name(int j);
|
||||
|
||||
// TODO: 3 decleare this function in the header file, for block_cache.cpp
|
||||
void assert_print_piece(cached_piece_entry const* pe)
|
||||
{
|
||||
static const char* const cache_state[] =
|
||||
{
|
||||
"write", "volatile-read", "read-lru", "read-lru-ghost", "read-lfu", "read-lfu-ghost"
|
||||
};
|
||||
|
||||
if (pe == NULL)
|
||||
{
|
||||
assert_print("piece: NULL\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_print("piece: %d\nrefcount: %d\npiece_refcount: %d\n"
|
||||
"num_blocks: %d\nhashing: %d\n\nhash: %p\nhash_offset: %d\n"
|
||||
"cache_state: (%d) %s\noutstanding_flush: %d\npiece: %d\n"
|
||||
"num_dirty: %d\nnum_blocks: %d\nblocks_in_piece: %d\n"
|
||||
"hashing_done: %d\nmarked_for_deletion: %d\nneed_readback: %d\n"
|
||||
"hash_passed: %d\nread_jobs: %d\njobs: %d\n"
|
||||
"piece_log:\n"
|
||||
, int(pe->piece), pe->refcount, pe->piece_refcount, pe->num_blocks
|
||||
, int(pe->hashing), pe->hash, pe->hash ? pe->hash->offset : -1
|
||||
, int(pe->cache_state), pe->cache_state >= 0 && pe->cache_state
|
||||
< cached_piece_entry::num_lrus ? cache_state[pe->cache_state] : ""
|
||||
, int(pe->outstanding_flush), int(pe->piece), int(pe->num_dirty)
|
||||
, int(pe->num_blocks), int(pe->blocks_in_piece), int(pe->hashing_done)
|
||||
, int(pe->marked_for_deletion), int(pe->need_readback), pe->hash_passes
|
||||
, int(pe->read_jobs.size()), int(pe->jobs.size()));
|
||||
for (int i = 0; i < pe->piece_log.size(); ++i)
|
||||
{
|
||||
assert_print(&", %s (%d)"[i==0], job_name(pe->piece_log[i].job), pe->piece_log[i].block);
|
||||
}
|
||||
}
|
||||
assert_print("\n");
|
||||
}
|
||||
|
||||
#define TORRENT_PIECE_ASSERT(cond, piece) \
|
||||
do { if (!(cond)) { assert_print_piece(piece); assert_fail(#cond, __LINE__, __FILE__, TORRENT_FUNCTION, 0); } } while(false)
|
||||
|
||||
|
@ -118,6 +79,8 @@ namespace libtorrent
|
|||
#define TORRENT_PIECE_ASSERT(cond, piece) do {} while(false)
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
void debug_log(char const* fmt, ...)
|
||||
{
|
||||
#if DEBUG_DISK_THREAD
|
||||
|
@ -142,10 +105,12 @@ namespace libtorrent
|
|||
prepend_time = (usr[len-1] == '\n');
|
||||
mutex::scoped_lock l(log_mutex);
|
||||
fputs(buf, stderr);
|
||||
#else
|
||||
TORRENT_UNUSED(fmt);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int file_flags_for_job(disk_io_job* j)
|
||||
int file_flags_for_job(disk_io_job* j)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
@ -154,6 +119,8 @@ namespace libtorrent
|
|||
return ret;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// ------- disk_io_thread ------
|
||||
|
||||
disk_io_thread::disk_io_thread(io_service& ios
|
||||
|
@ -1058,45 +1025,8 @@ namespace libtorrent
|
|||
&disk_io_thread::do_tick,
|
||||
};
|
||||
|
||||
const char* job_action_name[] =
|
||||
{
|
||||
"read",
|
||||
"write",
|
||||
"hash",
|
||||
"move_storage",
|
||||
"release_files",
|
||||
"delete_files",
|
||||
"check_fastresume",
|
||||
"save_resume_data",
|
||||
"rename_file",
|
||||
"stop_torrent",
|
||||
"cache_piece",
|
||||
"finalize_file",
|
||||
"flush_piece",
|
||||
"flush_hashed",
|
||||
"flush_storage",
|
||||
"trim_cache",
|
||||
"set_file_priority",
|
||||
"load_torrent",
|
||||
"clear_piece",
|
||||
"tick_storage",
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
#if TORRENT_USE_ASSERTS || DEBUG_DISK_THREAD
|
||||
char const* job_name(int j)
|
||||
{
|
||||
if (j < 0 || j >= piece_log_t::last_job)
|
||||
return "unknown";
|
||||
|
||||
if (j < piece_log_t::flushing)
|
||||
return job_action_name[j];
|
||||
return piece_log_t::job_names[j - piece_log_t::flushing];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// evict and/or flush blocks if we're exceeding the cache size
|
||||
// or used to exceed it and haven't dropped below the low watermark yet
|
||||
// the low watermark is dynamic, based on the number of peers waiting
|
||||
|
@ -2785,7 +2715,10 @@ namespace libtorrent
|
|||
}
|
||||
#endif
|
||||
|
||||
void get_cache_info_impl(cached_piece_info& info, cached_piece_entry const* i, int block_size)
|
||||
namespace {
|
||||
|
||||
void get_cache_info_impl(cached_piece_info& info, cached_piece_entry const* i
|
||||
, int block_size)
|
||||
{
|
||||
info.piece = i->piece;
|
||||
info.storage = i->storage.get();
|
||||
|
@ -2803,6 +2736,8 @@ namespace libtorrent
|
|||
info.blocks[b] = i->blocks[b].buf != 0;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
void disk_io_thread::update_stats_counters(counters& c) const
|
||||
{
|
||||
// These are atomic_counts, so it's safe to access them from
|
||||
|
|
|
@ -70,6 +70,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
namespace libtorrent
|
||||
{
|
||||
// defined in hex.cpp
|
||||
extern const char hex_chars[];
|
||||
|
||||
std::string unescape_string(std::string const& s, error_code& ec)
|
||||
{
|
||||
|
@ -141,8 +143,6 @@ namespace libtorrent
|
|||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789";
|
||||
|
||||
static const char hex_chars[] = "0123456789abcdef";
|
||||
|
||||
// the offset is used to ignore the first characters in the unreserved_chars table.
|
||||
static std::string escape_string_impl(const char* str, int len, int offset)
|
||||
{
|
||||
|
@ -454,62 +454,6 @@ namespace libtorrent
|
|||
return url.substr(pos, url.find('&', pos) - pos);
|
||||
}
|
||||
|
||||
TORRENT_EXPORT std::string to_hex(std::string const& s)
|
||||
{
|
||||
std::string ret;
|
||||
for (std::string::const_iterator i = s.begin(); i != s.end(); ++i)
|
||||
{
|
||||
ret += hex_chars[((unsigned char)*i) >> 4];
|
||||
ret += hex_chars[((unsigned char)*i) & 0xf];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
TORRENT_EXPORT void to_hex(char const *in, int len, char* out)
|
||||
{
|
||||
for (char const* end = in + len; in < end; ++in)
|
||||
{
|
||||
*out++ = hex_chars[((unsigned char)*in) >> 4];
|
||||
*out++ = hex_chars[((unsigned char)*in) & 0xf];
|
||||
}
|
||||
*out = '\0';
|
||||
}
|
||||
|
||||
// TODO: 3 move the hex coding to its own .cpp file corresponding
|
||||
// to the functions exported by hex.hpp
|
||||
TORRENT_EXTRA_EXPORT int hex_to_int(char in)
|
||||
{
|
||||
if (in >= '0' && in <= '9') return int(in) - '0';
|
||||
if (in >= 'A' && in <= 'F') return int(in) - 'A' + 10;
|
||||
if (in >= 'a' && in <= 'f') return int(in) - 'a' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
TORRENT_EXTRA_EXPORT bool is_hex(char const *in, int len)
|
||||
{
|
||||
for (char const* end = in + len; in < end; ++in)
|
||||
{
|
||||
int t = hex_to_int(*in);
|
||||
if (t == -1) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
TORRENT_EXPORT bool from_hex(char const *in, int len, char* out)
|
||||
{
|
||||
for (char const* end = in + len; in < end; ++in, ++out)
|
||||
{
|
||||
int t = hex_to_int(*in);
|
||||
if (t == -1) return false;
|
||||
*out = t << 4;
|
||||
++in;
|
||||
t = hex_to_int(*in);
|
||||
if (t == -1) return false;
|
||||
*out |= t & 15;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined TORRENT_WINDOWS && TORRENT_USE_WSTRING
|
||||
std::wstring convert_to_wstring(std::string const& s)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
|
||||
Copyright (c) 2003-2015, Arvid Norberg
|
||||
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/hex.hpp"
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
||||
namespace detail {
|
||||
|
||||
TORRENT_EXTRA_EXPORT int hex_to_int(char in)
|
||||
{
|
||||
if (in >= '0' && in <= '9') return int(in) - '0';
|
||||
if (in >= 'A' && in <= 'F') return int(in) - 'A' + 10;
|
||||
if (in >= 'a' && in <= 'f') return int(in) - 'a' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
TORRENT_EXTRA_EXPORT bool is_hex(char const *in, int len)
|
||||
{
|
||||
for (char const* end = in + len; in < end; ++in)
|
||||
{
|
||||
int t = hex_to_int(*in);
|
||||
if (t == -1) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // detail namespace
|
||||
|
||||
TORRENT_EXPORT bool from_hex(char const *in, int len, char* out)
|
||||
{
|
||||
for (char const* end = in + len; in < end; ++in, ++out)
|
||||
{
|
||||
int t = detail::hex_to_int(*in);
|
||||
if (t == -1) return false;
|
||||
*out = t << 4;
|
||||
++in;
|
||||
t = detail::hex_to_int(*in);
|
||||
if (t == -1) return false;
|
||||
*out |= t & 15;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
extern const char hex_chars[];
|
||||
|
||||
const char hex_chars[] = "0123456789abcdef";
|
||||
|
||||
TORRENT_EXPORT std::string to_hex(std::string const& s)
|
||||
{
|
||||
std::string ret;
|
||||
for (std::string::const_iterator i = s.begin(); i != s.end(); ++i)
|
||||
{
|
||||
ret += hex_chars[((unsigned char)*i) >> 4];
|
||||
ret += hex_chars[((unsigned char)*i) & 0xf];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
TORRENT_EXPORT void to_hex(char const *in, int len, char* out)
|
||||
{
|
||||
for (char const* end = in + len; in < end; ++in)
|
||||
{
|
||||
*out++ = hex_chars[((unsigned char)*in) >> 4];
|
||||
*out++ = hex_chars[((unsigned char)*in) & 0xf];
|
||||
}
|
||||
*out = '\0';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/aux_/session_impl.hpp"
|
||||
#include "libtorrent/parse_url.hpp"
|
||||
#include "libtorrent/peer_info.hpp"
|
||||
#include "libtorrent/aux_/escape_string.hpp" // for is_hex
|
||||
#include "libtorrent/hex.hpp" // for is_hex
|
||||
|
||||
using boost::shared_ptr;
|
||||
using libtorrent::aux::session_impl;
|
||||
|
@ -362,7 +362,8 @@ namespace libtorrent
|
|||
boost::int64_t chunk_size = 0;
|
||||
buffer::const_interval chunk_start = recv_buffer;
|
||||
chunk_start.begin += m_chunk_pos;
|
||||
TORRENT_ASSERT(chunk_start.begin[0] == '\r' || is_hex(chunk_start.begin, 1));
|
||||
TORRENT_ASSERT(chunk_start.begin[0] == '\r'
|
||||
|| detail::is_hex(chunk_start.begin, 1));
|
||||
bool ret = m_parser.parse_chunk_header(chunk_start, &chunk_size, &header_size);
|
||||
if (!ret)
|
||||
{
|
||||
|
|
|
@ -58,6 +58,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/io.hpp"
|
||||
#include "libtorrent/socket.hpp"
|
||||
#include "libtorrent/broadcast_socket.hpp" // for is_local
|
||||
#include "libtorrent/string_util.hpp" // for is_i2p_url
|
||||
#include "libtorrent/aux_/session_settings.hpp"
|
||||
#include "libtorrent/resolver_interface.hpp"
|
||||
#include "libtorrent/ip_filter.hpp"
|
||||
|
@ -66,11 +67,6 @@ using namespace libtorrent;
|
|||
|
||||
namespace libtorrent
|
||||
{
|
||||
#if TORRENT_USE_I2P
|
||||
// defined in torrent_info.cpp
|
||||
bool is_i2p_url(std::string const& url);
|
||||
#endif
|
||||
|
||||
http_tracker_connection::http_tracker_connection(
|
||||
io_service& ios
|
||||
, tracker_manager& man
|
||||
|
|
|
@ -647,19 +647,16 @@ void node_impl::lookup_peers(sha1_hash const& info_hash, entry& reply
|
|||
return;
|
||||
}
|
||||
|
||||
namespace
|
||||
void TORRENT_EXTRA_EXPORT write_nodes_entry(entry& r, nodes_t const& nodes)
|
||||
{
|
||||
void TORRENT_EXTRA_EXPORT write_nodes_entry(entry& r, nodes_t const& nodes)
|
||||
entry& n = r["nodes"];
|
||||
std::back_insert_iterator<std::string> out(n.string());
|
||||
for (nodes_t::const_iterator i = nodes.begin()
|
||||
, end(nodes.end()); i != end; ++i)
|
||||
{
|
||||
entry& n = r["nodes"];
|
||||
std::back_insert_iterator<std::string> out(n.string());
|
||||
for (nodes_t::const_iterator i = nodes.begin()
|
||||
, end(nodes.end()); i != end; ++i)
|
||||
{
|
||||
if (!i->addr().is_v4()) continue;
|
||||
std::copy(i->id.begin(), i->id.end(), out);
|
||||
write_endpoint(udp::endpoint(i->addr(), i->port()), out);
|
||||
}
|
||||
if (!i->addr().is_v4()) continue;
|
||||
std::copy(i->id.begin(), i->id.end(), out);
|
||||
write_endpoint(udp::endpoint(i->addr(), i->port()), out);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1172,7 +1172,7 @@ namespace libtorrent
|
|||
&& t->to_req(piece_block(p.piece, p.start / t->block_size())) == p;
|
||||
}
|
||||
|
||||
void peer_connection::attach_to_torrent(sha1_hash const& ih, bool allow_encrypted)
|
||||
void peer_connection::attach_to_torrent(sha1_hash const& ih)
|
||||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
INVARIANT_CHECK;
|
||||
|
|
|
@ -33,10 +33,18 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/string_util.hpp"
|
||||
#include "libtorrent/random.hpp"
|
||||
#include "libtorrent/error_code.hpp"
|
||||
#include "libtorrent/parse_url.hpp"
|
||||
|
||||
#include "aux_/disable_warnings_push.hpp"
|
||||
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
#include <cstdlib> // for malloc
|
||||
#include <cstring> // for memmov/strcpy/strlen
|
||||
|
||||
#include "aux_/disable_warnings_pop.hpp"
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
||||
|
@ -49,7 +57,9 @@ namespace libtorrent
|
|||
char *p = &ret.back();
|
||||
*p = '\0';
|
||||
boost::uint64_t un = n;
|
||||
if (n < 0) un = -un; // TODO: warning C4146: unary minus operator applied to unsigned type, result still unsigned
|
||||
// TODO: warning C4146: unary minus operator applied to unsigned type,
|
||||
// result still unsigned
|
||||
if (n < 0) un = -un;
|
||||
do {
|
||||
*--p = '0' + un % 10;
|
||||
un /= 10;
|
||||
|
@ -252,5 +262,20 @@ namespace libtorrent
|
|||
return last;
|
||||
}
|
||||
|
||||
#if TORRENT_USE_I2P
|
||||
|
||||
bool is_i2p_url(std::string const& url)
|
||||
{
|
||||
using boost::tuples::ignore;
|
||||
std::string hostname;
|
||||
error_code ec;
|
||||
boost::tie(ignore, ignore, hostname, ignore, ignore)
|
||||
= parse_url_components(url, ec);
|
||||
char const* top_domain = strrchr(hostname.c_str(), '.');
|
||||
return top_domain && strcmp(top_domain, ".i2p") == 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -30,19 +30,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
*/
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#if !defined TORRENT_NO_DEPRECATE && TORRENT_USE_IOSTREAM
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#endif
|
||||
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/ConvertUTF.h"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/string_util.hpp" // is_space
|
||||
#include "libtorrent/string_util.hpp" // is_space, is_i2p_url
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/entry.hpp"
|
||||
|
@ -59,20 +50,24 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/lazy_entry.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
#endif
|
||||
#include "aux_/disable_warnings_push.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/unordered_set.hpp>
|
||||
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <ctime>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#if !defined TORRENT_NO_DEPRECATE && TORRENT_USE_IOSTREAM
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#endif
|
||||
|
||||
#include "aux_/disable_warnings_pop.hpp"
|
||||
|
||||
#if TORRENT_USE_I2P
|
||||
#include "libtorrent/parse_url.hpp"
|
||||
#endif
|
||||
|
@ -1480,23 +1475,6 @@ namespace libtorrent
|
|||
return ret;
|
||||
}
|
||||
|
||||
#if TORRENT_USE_I2P
|
||||
|
||||
// TODO: 3 this function is used in other translation units. Make sure
|
||||
// it's declared in an appropriate header.
|
||||
bool is_i2p_url(std::string const& url)
|
||||
{
|
||||
using boost::tuples::ignore;
|
||||
std::string hostname;
|
||||
error_code ec;
|
||||
boost::tie(ignore, ignore, hostname, ignore, ignore)
|
||||
= parse_url_components(url, ec);
|
||||
char const* top_domain = strrchr(hostname.c_str(), '.');
|
||||
return top_domain && strcmp(top_domain, ".i2p") == 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool torrent_info::parse_torrent_file(bdecode_node const& torrent_file
|
||||
, error_code& ec, int flags)
|
||||
{
|
||||
|
|
|
@ -48,7 +48,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/peer_info.hpp"
|
||||
#include "libtorrent/aux_/session_interface.hpp"
|
||||
#include "libtorrent/alert_manager.hpp" // for alert_manageralert_manager
|
||||
#include "libtorrent/aux_/escape_string.hpp" // for is_hex
|
||||
#include "libtorrent/aux_/escape_string.hpp" // for escape_path
|
||||
#include "libtorrent/hex.hpp" // for is_hex
|
||||
|
||||
using boost::shared_ptr;
|
||||
|
||||
|
@ -807,7 +808,8 @@ void web_peer_connection::on_receive(error_code const& error
|
|||
boost::int64_t chunk_size = 0;
|
||||
buffer::const_interval chunk_start = recv_buffer;
|
||||
chunk_start.begin += m_chunk_pos;
|
||||
TORRENT_ASSERT(chunk_start.begin[0] == '\r' || is_hex(chunk_start.begin, 1));
|
||||
TORRENT_ASSERT(chunk_start.begin[0] == '\r'
|
||||
|| detail::is_hex(chunk_start.begin, 1));
|
||||
bool ret = m_parser.parse_chunk_header(chunk_start, &chunk_size, &header_size);
|
||||
if (!ret)
|
||||
{
|
||||
|
|
|
@ -201,12 +201,6 @@ void send_dht_request(node_impl& node, char const* msg, udp::endpoint const& ep
|
|||
g_sent_packets.erase(i);
|
||||
}
|
||||
|
||||
namespace libtorrent { namespace dht { namespace detail
|
||||
{
|
||||
// defined in node.cpp
|
||||
void write_nodes_entry(entry& r, nodes_t const& nodes);
|
||||
} } }
|
||||
|
||||
void write_peers(entry::dictionary_type& r, std::set<tcp::endpoint> const& peers)
|
||||
{
|
||||
entry::list_type& pe = r["values"].list();
|
||||
|
@ -238,7 +232,7 @@ void send_dht_response(node_impl& node, bdecode_node const& request, udp::endpoi
|
|||
else r["id"] = nid->to_string();
|
||||
if (!token.empty()) r["token"] = token;
|
||||
if (port) r["p"] = port;
|
||||
if (!nodes.empty()) dht::detail::write_nodes_entry(e["r"], nodes);
|
||||
if (!nodes.empty()) dht::write_nodes_entry(e["r"], nodes);
|
||||
if (!peers.empty()) write_peers(r, peers);
|
||||
if (value) r["v"] = *value;
|
||||
if (!sig.empty()) r["sig"] = sig;
|
||||
|
|
|
@ -201,16 +201,16 @@ int test_main()
|
|||
{
|
||||
bool hex = strchr(hex_chars, i) != NULL;
|
||||
char c = i;
|
||||
TEST_EQUAL(is_hex(&c, 1), hex);
|
||||
TEST_EQUAL(detail::is_hex(&c, 1), hex);
|
||||
}
|
||||
|
||||
TEST_EQUAL(hex_to_int('0'), 0);
|
||||
TEST_EQUAL(hex_to_int('7'), 7);
|
||||
TEST_EQUAL(hex_to_int('a'), 10);
|
||||
TEST_EQUAL(hex_to_int('f'), 15);
|
||||
TEST_EQUAL(hex_to_int('b'), 11);
|
||||
TEST_EQUAL(hex_to_int('t'), -1);
|
||||
TEST_EQUAL(hex_to_int('g'), -1);
|
||||
TEST_EQUAL(detail::hex_to_int('0'), 0);
|
||||
TEST_EQUAL(detail::hex_to_int('7'), 7);
|
||||
TEST_EQUAL(detail::hex_to_int('a'), 10);
|
||||
TEST_EQUAL(detail::hex_to_int('f'), 15);
|
||||
TEST_EQUAL(detail::hex_to_int('b'), 11);
|
||||
TEST_EQUAL(detail::hex_to_int('t'), -1);
|
||||
TEST_EQUAL(detail::hex_to_int('g'), -1);
|
||||
|
||||
std::string path = "a\\b\\c";
|
||||
convert_path_to_posix(path);
|
||||
|
|
Loading…
Reference in New Issue