fix lt bug #126 and some duplicate data from torrent_info
This commit is contained in:
parent
a71a6b8e1a
commit
3608775441
|
@ -237,6 +237,7 @@ namespace libtorrent { namespace dht
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
if (!m_socket.is_open()) return;
|
||||||
time_duration d = m_dht.connection_timeout();
|
time_duration d = m_dht.connection_timeout();
|
||||||
m_connection_timer.expires_from_now(d);
|
m_connection_timer.expires_from_now(d);
|
||||||
m_connection_timer.async_wait(m_strand.wrap(bind(&dht_tracker::connection_timeout, self(), _1)));
|
m_connection_timer.async_wait(m_strand.wrap(bind(&dht_tracker::connection_timeout, self(), _1)));
|
||||||
|
@ -254,6 +255,7 @@ namespace libtorrent { namespace dht
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
if (!m_socket.is_open()) return;
|
||||||
time_duration d = m_dht.refresh_timeout();
|
time_duration d = m_dht.refresh_timeout();
|
||||||
m_refresh_timer.expires_from_now(d);
|
m_refresh_timer.expires_from_now(d);
|
||||||
m_refresh_timer.async_wait(m_strand.wrap(
|
m_refresh_timer.async_wait(m_strand.wrap(
|
||||||
|
@ -276,8 +278,9 @@ namespace libtorrent { namespace dht
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
if (!m_socket.is_open()) return;
|
||||||
m_timer.expires_from_now(minutes(tick_period));
|
m_timer.expires_from_now(minutes(tick_period));
|
||||||
m_timer.async_wait(m_strand.wrap(bind(&dht_tracker::tick, this, _1)));
|
m_timer.async_wait(m_strand.wrap(bind(&dht_tracker::tick, self(), _1)));
|
||||||
|
|
||||||
ptime now = time_now();
|
ptime now = time_now();
|
||||||
if (now - m_last_new_key > minutes(key_refresh))
|
if (now - m_last_new_key > minutes(key_refresh))
|
||||||
|
@ -388,6 +391,7 @@ namespace libtorrent { namespace dht
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (error == asio::error::operation_aborted) return;
|
if (error == asio::error::operation_aborted) return;
|
||||||
|
if (!m_socket.is_open()) return;
|
||||||
|
|
||||||
int current_buffer = m_buffer;
|
int current_buffer = m_buffer;
|
||||||
m_buffer = (m_buffer + 1) & 1;
|
m_buffer = (m_buffer + 1) & 1;
|
||||||
|
@ -716,6 +720,7 @@ namespace libtorrent { namespace dht
|
||||||
, udp::resolver::iterator host) try
|
, udp::resolver::iterator host) try
|
||||||
{
|
{
|
||||||
if (e || host == udp::resolver::iterator()) return;
|
if (e || host == udp::resolver::iterator()) return;
|
||||||
|
if (!m_socket.is_open()) return;
|
||||||
add_node(host->endpoint());
|
add_node(host->endpoint());
|
||||||
}
|
}
|
||||||
catch (std::exception&)
|
catch (std::exception&)
|
||||||
|
@ -734,6 +739,7 @@ namespace libtorrent { namespace dht
|
||||||
, udp::resolver::iterator host) try
|
, udp::resolver::iterator host) try
|
||||||
{
|
{
|
||||||
if (e || host == udp::resolver::iterator()) return;
|
if (e || host == udp::resolver::iterator()) return;
|
||||||
|
if (!m_socket.is_open()) return;
|
||||||
m_dht.add_router_node(host->endpoint());
|
m_dht.add_router_node(host->endpoint());
|
||||||
}
|
}
|
||||||
catch (std::exception&)
|
catch (std::exception&)
|
||||||
|
@ -972,3 +978,4 @@ namespace libtorrent { namespace dht
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -400,7 +400,9 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
if (i->first == "pieces"
|
if (i->first == "pieces"
|
||||||
|| i->first == "piece length"
|
|| i->first == "piece length"
|
||||||
|| i->first == "length")
|
|| i->first == "length"
|
||||||
|
|| i->first == "files"
|
||||||
|
|| i->first == "name")
|
||||||
continue;
|
continue;
|
||||||
m_extra_info[i->first] = i->second;
|
m_extra_info[i->first] = i->second;
|
||||||
}
|
}
|
||||||
|
@ -824,8 +826,33 @@ namespace libtorrent
|
||||||
m_nodes.push_back(node);
|
m_nodes.push_back(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool torrent_info::remap_files(std::vector<std::pair<std::string
|
||||||
|
, libtorrent::size_type> > const& map)
|
||||||
|
{
|
||||||
|
typedef std::vector<std::pair<std::string, size_type> > files_t;
|
||||||
|
|
||||||
|
size_type offset = 0;
|
||||||
|
m_remapped_files.resize(map.size());
|
||||||
|
|
||||||
|
for (int i = 0; i < int(map.size()); ++i)
|
||||||
|
{
|
||||||
|
file_entry& fe = m_remapped_files[i];
|
||||||
|
fe.path = map[i].first;
|
||||||
|
fe.offset = offset;
|
||||||
|
fe.size = map[i].second;
|
||||||
|
offset += fe.size;
|
||||||
|
}
|
||||||
|
if (offset != total_size())
|
||||||
|
{
|
||||||
|
m_remapped_files.clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<file_slice> torrent_info::map_block(int piece, size_type offset
|
std::vector<file_slice> torrent_info::map_block(int piece, size_type offset
|
||||||
, int size) const
|
, int size, bool storage) const
|
||||||
{
|
{
|
||||||
assert(num_files() > 0);
|
assert(num_files() > 0);
|
||||||
std::vector<file_slice> ret;
|
std::vector<file_slice> ret;
|
||||||
|
@ -839,9 +866,9 @@ namespace libtorrent
|
||||||
std::vector<file_entry>::const_iterator file_iter;
|
std::vector<file_entry>::const_iterator file_iter;
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (file_iter = begin_files();; ++counter, ++file_iter)
|
for (file_iter = begin_files(storage);; ++counter, ++file_iter)
|
||||||
{
|
{
|
||||||
assert(file_iter != end_files());
|
assert(file_iter != end_files(storage));
|
||||||
if (file_offset < file_iter->size)
|
if (file_offset < file_iter->size)
|
||||||
{
|
{
|
||||||
file_slice f;
|
file_slice f;
|
||||||
|
@ -862,11 +889,11 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
peer_request torrent_info::map_file(int file_index, size_type file_offset
|
peer_request torrent_info::map_file(int file_index, size_type file_offset
|
||||||
, int size) const
|
, int size, bool storage) const
|
||||||
{
|
{
|
||||||
assert(file_index < (int)m_files.size());
|
assert(file_index < num_files(storage));
|
||||||
assert(file_index >= 0);
|
assert(file_index >= 0);
|
||||||
size_type offset = file_offset + m_files[file_index].offset;
|
size_type offset = file_offset + file_at(file_index, storage).offset;
|
||||||
|
|
||||||
peer_request ret;
|
peer_request ret;
|
||||||
ret.piece = offset / piece_length();
|
ret.piece = offset / piece_length();
|
||||||
|
@ -876,3 +903,4 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue