+
Written by Arvid Norberg. Copyright (c) 2003
Contributions by Magnus Jonsson and Daniel Wallin
Thanks to Reimond Retz for bugfixes, suggestions and testing
diff --git a/docs/manual.rst b/docs/manual.rst
index 38d8b1f96..ffd989846 100755
--- a/docs/manual.rst
+++ b/docs/manual.rst
@@ -559,11 +559,13 @@ The ``torrent_info`` has the following synopsis::
{
public:
- torrent_info(entry const& torrent_file)
- torrent_info(int piece_size, const char* name);
+ torrent_info();
+ torrent_info(sha1_hash const& info_hash);
+ torrent_info(entry const& torrent_file);
entry create_torrent() const;
void set_comment(char const* str);
+ void set_piece_size(int size);
void set_creator(char const* str);
void set_hash(int index, const sha1_hash& h);
void add_tracker(std::string const& url, int tier = 0);
@@ -2318,7 +2320,7 @@ __ http://www.boost.org/libs/filesystem/doc/index.htm
acknowledgements
-===============
+================
Written by Arvid Norberg. Copyright (c) 2003
diff --git a/examples/Jamfile b/examples/Jamfile
index 92017cef2..d03ca0fa8 100755
--- a/examples/Jamfile
+++ b/examples/Jamfile
@@ -36,5 +36,5 @@ exe make_torrent
;
-stage bin : dump_torrent simple_client client_test make_torrent ;
+stage bin : dump_torrent make_torrent simple_client client_test ;
diff --git a/examples/simple_client.cpp b/examples/simple_client.cpp
index 0138a447e..7de544096 100755
--- a/examples/simple_client.cpp
+++ b/examples/simple_client.cpp
@@ -49,7 +49,7 @@ int main(int argc, char* argv[])
if (argc != 2)
{
- std::cerr << "usage: ./simple_cient torrent-file\n"
+ std::cerr << "usage: ./simple_client torrent-file\n"
"to stop the client, press return.\n";
return 1;
}
diff --git a/include/libtorrent/debug.hpp b/include/libtorrent/debug.hpp
index 344f828d5..65678e958 100755
--- a/include/libtorrent/debug.hpp
+++ b/include/libtorrent/debug.hpp
@@ -41,6 +41,8 @@ POSSIBILITY OF SUCH DAMAGE.
#endif
#include
+#include
+#include
#ifdef _MSC_VER
#pragma warning(pop)
@@ -102,11 +104,11 @@ namespace libtorrent
{
public:
file_logger(const char* filename)
- : m_file(filename)
+ : m_file(boost::filesystem::complete(filename))
{ assert(filename); }
virtual void log(const char* text) { assert(text); m_file << text; }
- std::ofstream m_file;
+ boost::filesystem::ofstream m_file;
};
}
diff --git a/include/libtorrent/policy.hpp b/include/libtorrent/policy.hpp
index e45839490..90d363f63 100755
--- a/include/libtorrent/policy.hpp
+++ b/include/libtorrent/policy.hpp
@@ -203,7 +203,7 @@ namespace libtorrent
return p.connection == 0
&& p.connected != not_tried_yet
- && second_clock::local_time() - p.connected > minutes(30);
+ && second_clock::universal_time() - p.connected > minutes(30);
}
};
diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp
index 99dce9372..22845cc6b 100755
--- a/include/libtorrent/torrent.hpp
+++ b/include/libtorrent/torrent.hpp
@@ -486,7 +486,7 @@ namespace libtorrent
inline void torrent::force_tracker_request()
{
namespace time = boost::posix_time;
- m_next_request = time::second_clock::local_time();
+ m_next_request = time::second_clock::universal_time();
}
inline void torrent::set_tracker_login(
diff --git a/src/alert.cpp b/src/alert.cpp
index 5c3596957..781265b92 100755
--- a/src/alert.cpp
+++ b/src/alert.cpp
@@ -37,7 +37,7 @@ namespace libtorrent {
alert::alert(severity_t severity, const std::string& msg)
: m_msg(msg)
, m_severity(severity)
- , m_timestamp(boost::posix_time::second_clock::local_time())
+ , m_timestamp(boost::posix_time::second_clock::universal_time())
{
}
diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp
index 47a9b1ddb..d3fddda06 100755
--- a/src/http_tracker_connection.cpp
+++ b/src/http_tracker_connection.cpp
@@ -72,6 +72,8 @@ namespace
}
+using namespace boost::posix_time;
+
namespace libtorrent
{
@@ -90,7 +92,7 @@ namespace libtorrent
, m_content_encoding(plain)
, m_content_length(0)
, m_recv_pos(0)
- , m_request_time(boost::posix_time::second_clock::local_time())
+ , m_request_time(second_clock::universal_time())
, m_settings(stn)
, m_req(req)
, m_password(password)
@@ -213,7 +215,7 @@ namespace libtorrent
using namespace boost::posix_time;
- time_duration d = second_clock::local_time() - m_request_time;
+ time_duration d = second_clock::universal_time() - m_request_time;
if (d > seconds(m_settings.tracker_timeout) ||
(!has_requester() && d > seconds(m_settings.stop_tracker_timeout)))
{
@@ -247,7 +249,7 @@ namespace libtorrent
}
if (sent != 0)
- m_request_time = boost::posix_time::second_clock::local_time();
+ m_request_time = second_clock::universal_time();
}
if (m_socket->has_error())
@@ -260,7 +262,7 @@ namespace libtorrent
// if the socket isn't ready for reading, there's no point in continuing
// trying to read from it
if (!m_socket->is_readable()) return false;
- m_request_time = boost::posix_time::second_clock::local_time();
+ m_request_time = second_clock::universal_time();
#ifndef NDEBUG
if (has_requester()) requester().debug_log("tracker connection socket readable");
diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp
index 30260ba96..db09d1ef9 100755
--- a/src/peer_connection.cpp
+++ b/src/peer_connection.cpp
@@ -56,6 +56,8 @@ namespace std
#define VERBOSE
+using namespace boost::posix_time;
+
namespace libtorrent
{
@@ -90,8 +92,8 @@ namespace libtorrent
, m_timeout(120)
, m_packet_size(1)
, m_recv_pos(0)
- , m_last_receive(boost::posix_time::second_clock::local_time())
- , m_last_sent(boost::posix_time::second_clock::local_time())
+ , m_last_receive(second_clock::universal_time())
+ , m_last_sent(second_clock::universal_time())
, m_selector(sel)
, m_socket(s)
, m_torrent(t)
@@ -110,10 +112,10 @@ namespace libtorrent
, m_free_upload(0)
, m_trust_points(0)
, m_num_invalid_requests(0)
- , m_last_piece(boost::posix_time::second_clock::local_time())
+ , m_last_piece(second_clock::universal_time())
, m_disconnecting(false)
- , m_became_uninterested(boost::posix_time::second_clock::local_time())
- , m_became_uninteresting(boost::posix_time::second_clock::local_time())
+ , m_became_uninterested(second_clock::universal_time())
+ , m_became_uninteresting(second_clock::universal_time())
, m_no_metadata(
boost::gregorian::date(1970, boost::date_time::Jan, 1)
, boost::posix_time::seconds(0))
@@ -167,8 +169,8 @@ namespace libtorrent
, m_timeout(120)
, m_packet_size(1)
, m_recv_pos(0)
- , m_last_receive(boost::posix_time::second_clock::local_time())
- , m_last_sent(boost::posix_time::second_clock::local_time())
+ , m_last_receive(second_clock::universal_time())
+ , m_last_sent(second_clock::universal_time())
, m_selector(sel)
, m_socket(s)
, m_torrent(0)
@@ -188,10 +190,10 @@ namespace libtorrent
, m_free_upload(0)
, m_trust_points(0)
, m_num_invalid_requests(0)
- , m_last_piece(boost::posix_time::second_clock::local_time())
+ , m_last_piece(second_clock::universal_time())
, m_disconnecting(false)
- , m_became_uninterested(boost::posix_time::second_clock::local_time())
- , m_became_uninteresting(boost::posix_time::second_clock::local_time())
+ , m_became_uninterested(second_clock::universal_time())
+ , m_became_uninteresting(second_clock::universal_time())
, m_no_metadata(
boost::gregorian::date(1970, boost::date_time::Jan, 1)
, boost::posix_time::seconds(0))
@@ -431,7 +433,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " ==> HANDSHAKE\n";
#endif
@@ -503,7 +505,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== CHOKE\n";
#endif
m_peer_choked = true;
@@ -539,7 +541,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== UNCHOKE\n";
#endif
m_peer_choked = false;
@@ -562,7 +564,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== INTERESTED\n";
#endif
m_peer_interested = true;
@@ -583,7 +585,7 @@ namespace libtorrent
m_statistics.received_bytes(0, received);
if (m_recv_pos < m_packet_size) return;
- m_became_uninterested = boost::posix_time::second_clock::local_time();
+ m_became_uninterested = second_clock::universal_time();
// clear the request queue if the client isn't interested
m_requests.clear();
@@ -591,7 +593,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== NOT_INTERESTED\n";
#endif
m_peer_interested = false;
@@ -620,7 +622,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== HAVE [ piece: " << index << "]\n";
#endif
@@ -673,7 +675,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== BITFIELD\n";
#endif
@@ -769,7 +771,7 @@ namespace libtorrent
// we shouldn't get a request
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== UNEXPECTED_REQUEST [ "
"piece: " << r.piece << " | "
"s: " << r.start << " | "
@@ -789,7 +791,7 @@ namespace libtorrent
// is making too many of them.
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== TOO MANY REQUESTS [ "
"piece: " << r.piece << " | "
"s: " << r.start << " | "
@@ -822,7 +824,7 @@ namespace libtorrent
send_buffer_updated();
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== REQUEST [ piece: " << r.piece << " | s: " << r.start << " | l: " << r.length << " ]\n";
#endif
}
@@ -830,7 +832,7 @@ namespace libtorrent
{
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== INVALID_REQUEST [ "
"piece: " << r.piece << " | "
"s: " << r.start << " | "
@@ -865,7 +867,7 @@ namespace libtorrent
assert(received > 0);
if (m_recv_pos - received <= 9)
{
- m_last_piece = boost::posix_time::second_clock::local_time();
+ m_last_piece = second_clock::universal_time();
}
// classify the received data as protocol chatter
// or data payload for the statistics
@@ -898,7 +900,7 @@ namespace libtorrent
{
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== INVALID_PIECE [ piece: " << p.piece << " | "
"start: " << p.start << " | "
"length: " << p.length << " ]\n";
@@ -916,11 +918,11 @@ namespace libtorrent
&& i->block_index == p.start / m_torrent->block_size())
break;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " *** SKIPPED_PIECE [ piece: " << i->piece_index << " | "
"b: " << i->block_index << " ] ***\n";
}
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== PIECE [ piece: " << p.piece << " | "
"b: " << p.start / m_torrent->block_size() << " | "
"s: " << p.start << " | "
@@ -1040,7 +1042,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== CANCEL [ piece: " << r.piece << " | s: " << r.start << " | l: " << r.length << " ]\n";
#endif
}
@@ -1223,7 +1225,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " <== METADATA [ tot: " << total_size << " offset: "
<< offset << " size: " << data_size << " ]\n";
#endif
@@ -1234,7 +1236,7 @@ namespace libtorrent
}
break;
case 2: // have no data
- m_no_metadata = boost::posix_time::second_clock::local_time();
+ m_no_metadata = second_clock::universal_time();
if (m_waiting_metadata_request)
m_torrent->cancel_metadata_request(m_last_metadata_request);
m_waiting_metadata_request = false;
@@ -1267,7 +1269,7 @@ namespace libtorrent
if (is_local())
{
#ifndef NDEBUG
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< "<== LISTEN_PORT [ UNEXPECTED ]\n";
#endif
return;
@@ -1277,7 +1279,7 @@ namespace libtorrent
unsigned short port = detail::read_uint16(ptr);
#ifndef NDEBUG
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< "<== LISTEN_PORT [ port: " << port << " ]\n";
#endif
@@ -1289,7 +1291,7 @@ namespace libtorrent
bool peer_connection::has_metadata() const
{
using namespace boost::posix_time;
- return second_clock::local_time() - m_no_metadata > minutes(5);
+ return second_clock::universal_time() - m_no_metadata > minutes(5);
}
@@ -1378,7 +1380,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " ==> CANCEL [ piece: " << block.piece_index << " | s: " << block_offset << " | l: " << block_size << " | " << block.block_index << " ]\n";
#endif
@@ -1426,7 +1428,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " ==> REQUEST [ "
"piece: " << block.piece_index << " | "
"b: " << block.block_index << " | "
@@ -1504,7 +1506,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " ==> METADATA_REQUEST [ start: " << req.first
<< " size: " << req.second << " ]\n";
#endif
@@ -1550,7 +1552,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " ==> BITFIELD\n";
#endif
const int packet_size = ((int)m_have_piece.size() + 7) / 8 + 5;
@@ -1576,7 +1578,7 @@ namespace libtorrent
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " ==> EXTENSIONS\n";
#endif
assert(m_supports_extensions);
@@ -1613,7 +1615,7 @@ namespace libtorrent
m_choked = true;
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " ==> CHOKE\n";
#endif
m_num_invalid_requests = 0;
@@ -1631,7 +1633,7 @@ namespace libtorrent
m_choked = false;
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " ==> UNCHOKE\n";
#endif
send_buffer_updated();
@@ -1647,7 +1649,7 @@ namespace libtorrent
m_interesting = true;
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " ==> INTERESTED\n";
#endif
send_buffer_updated();
@@ -1662,11 +1664,11 @@ namespace libtorrent
m_send_buffer.insert(m_send_buffer.end(), msg, msg+sizeof(msg));
m_interesting = false;
- m_became_uninteresting = boost::posix_time::second_clock::local_time();
+ m_became_uninteresting = second_clock::universal_time();
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " ==> NOT_INTERESTED\n";
#endif
send_buffer_updated();
@@ -1690,7 +1692,7 @@ namespace libtorrent
m_send_buffer.insert(m_send_buffer.end(), msg, msg + packet_size);
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " ==> HAVE [ piece: " << index << " ]\n";
#endif
send_buffer_updated();
@@ -1726,7 +1728,7 @@ namespace libtorrent
m_last_metadata_request = m_torrent->metadata_request();
send_metadata_request(m_last_metadata_request);
m_waiting_metadata_request = true;
- m_metadata_request = boost::posix_time::second_clock::local_time();
+ m_metadata_request = second_clock::universal_time();
}
m_statistics.second_tick();
@@ -1865,7 +1867,7 @@ namespace libtorrent
if (received > 0)
{
- m_last_receive = boost::posix_time::second_clock::local_time();
+ m_last_receive = second_clock::universal_time();
m_recv_pos += received;
m_dl_bandwidth_quota.used += received;
@@ -2180,7 +2182,7 @@ namespace libtorrent
, r.length);
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " ==> PIECE [ piece: " << r.piece << " | s: " << r.start << " | l: " << r.length << " ]\n";
#endif
@@ -2284,7 +2286,7 @@ namespace libtorrent
throw network_error(m_socket->last_error());
}
- m_last_sent = boost::posix_time::second_clock::local_time();
+ m_last_sent = second_clock::universal_time();
}
assert(m_writability_monitored);
@@ -2311,7 +2313,7 @@ namespace libtorrent
// if the peer hasn't said a thing for a certain
// time, it is considered to have timed out
time_duration d;
- d = second_clock::local_time() - m_last_receive;
+ d = second_clock::universal_time() - m_last_receive;
if (d > seconds(m_timeout)) return true;
// if the peer hasn't become interested and we haven't
@@ -2319,8 +2321,8 @@ namespace libtorrent
// has also timed out.
time_duration d1;
time_duration d2;
- d1 = second_clock::local_time() - m_became_uninterested;
- d2 = second_clock::local_time() - m_became_uninteresting;
+ d1 = second_clock::universal_time() - m_became_uninterested;
+ d2 = second_clock::universal_time() - m_became_uninteresting;
if (!m_interesting
&& !m_peer_interested
&& d1 > seconds(60 * 3)
@@ -2337,7 +2339,7 @@ namespace libtorrent
INVARIANT_CHECK;
boost::posix_time::time_duration d;
- d = boost::posix_time::second_clock::local_time() - m_last_sent;
+ d = second_clock::universal_time() - m_last_sent;
if (d.seconds() < m_timeout / 2) return;
// we must either send a keep-alive
@@ -2346,10 +2348,10 @@ namespace libtorrent
{
char noop[] = {0,0,0,0};
m_send_buffer.insert(m_send_buffer.end(), noop, noop+4);
- m_last_sent = boost::posix_time::second_clock::local_time();
+ m_last_sent = second_clock::universal_time();
#ifndef NDEBUG
using namespace boost::posix_time;
- (*m_logger) << to_simple_string(second_clock::local_time())
+ (*m_logger) << to_simple_string(second_clock::universal_time())
<< " ==> NOP\n";
#endif
}
diff --git a/src/policy.cpp b/src/policy.cpp
index 8105e625d..72591dab8 100755
--- a/src/policy.cpp
+++ b/src/policy.cpp
@@ -57,6 +57,8 @@ namespace libtorrent
class peer_connection;
}
+using namespace boost::posix_time;
+
namespace
{
enum
@@ -409,7 +411,7 @@ namespace libtorrent
double slowest_transfer_rate = std::numeric_limits::max();
boost::posix_time::ptime local_time
- = boost::posix_time::second_clock::local_time();
+ = second_clock::universal_time();
for (std::vector::iterator i = m_peers.begin();
i != m_peers.end();
@@ -446,7 +448,7 @@ namespace libtorrent
policy::peer *policy::find_connect_candidate()
{
- boost::posix_time::ptime local_time=boost::posix_time::second_clock::local_time();
+ boost::posix_time::ptime local_time=second_clock::universal_time();
boost::posix_time::ptime ptime(local_time);
policy::peer* candidate =0;
@@ -529,7 +531,7 @@ namespace libtorrent
{
peer* candidate = 0;
boost::posix_time::ptime last_unchoke
- = boost::posix_time::second_clock::local_time();
+ = second_clock::universal_time();
for (std::vector::iterator i = m_peers.begin();
i != m_peers.end();
@@ -554,7 +556,7 @@ namespace libtorrent
{
p->connection->send_unchoke();
p->last_optimistically_unchoked
- = boost::posix_time::second_clock::local_time();
+ = second_clock::universal_time();
++m_num_unchoked;
}
return p != 0;
@@ -600,7 +602,7 @@ namespace libtorrent
{
// every minute, disconnect the worst peer in hope of finding a better peer
- boost::posix_time::ptime local_time = boost::posix_time::second_clock::local_time();
+ boost::posix_time::ptime local_time = second_clock::universal_time();
if(m_last_optimistic_disconnect + boost::posix_time::seconds(120) <= local_time)
{
m_last_optimistic_disconnect = local_time;
@@ -610,7 +612,7 @@ namespace libtorrent
else
{
// don't do a disconnect earlier than 1 minute after some peer was connected
- m_last_optimistic_disconnect = boost::posix_time::second_clock::local_time();
+ m_last_optimistic_disconnect = second_clock::universal_time();
}
while (num_connected_peers > max_connections)
@@ -817,8 +819,8 @@ namespace libtorrent
i->prev_amount_download = 0;
i->prev_amount_upload = 0;
i->connection = &c;
- i->connected = boost::posix_time::second_clock::local_time();
- m_last_optimistic_disconnect = boost::posix_time::second_clock::local_time();
+ i->connected = second_clock::universal_time();
+ m_last_optimistic_disconnect = second_clock::universal_time();
}
void policy::peer_from_tracker(const address& remote, const peer_id& id)
@@ -992,7 +994,7 @@ namespace libtorrent
assert(!p->connection->is_disconnecting());
p->connection->send_unchoke();
- p->last_optimistically_unchoked = boost::posix_time::second_clock::local_time();
+ p->last_optimistically_unchoked = second_clock::universal_time();
++m_num_unchoked;
return true;
}
@@ -1020,7 +1022,7 @@ namespace libtorrent
p->prev_amount_upload = 0;
p->connected =
m_last_optimistic_disconnect =
- boost::posix_time::second_clock::local_time();
+ second_clock::universal_time();
return true;
}
catch (network_error&)
@@ -1052,7 +1054,7 @@ namespace libtorrent
if (i == m_peers.end()) return;
assert(i->connection == &c);
- i->connected = boost::posix_time::second_clock::local_time();
+ i->connected = second_clock::universal_time();
if (!i->connection->is_choked() && !m_torrent->is_aborted())
{
// if the peer that is diconnecting is unchoked
@@ -1139,7 +1141,7 @@ namespace libtorrent
, banned(false)
, connection(0)
{
- assert(connected < boost::posix_time::second_clock::local_time());
+ assert(connected < second_clock::universal_time());
}
size_type policy::peer::total_download() const
diff --git a/src/session.cpp b/src/session.cpp
index b9728e903..c3ebd139d 100755
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -77,6 +77,8 @@ namespace std
};
#endif
+using namespace boost::posix_time;
+
namespace libtorrent { namespace detail
{
@@ -320,7 +322,7 @@ namespace libtorrent { namespace detail
std::vector > readable_clients;
std::vector > writable_clients;
std::vector > error_clients;
- boost::posix_time::ptime timer = boost::posix_time::second_clock::local_time();
+ boost::posix_time::ptime timer = second_clock::universal_time();
#ifndef NDEBUG
int loops_per_second = 0;
@@ -597,9 +599,9 @@ namespace libtorrent { namespace detail
check_invariant("after ERROR SOCKETS");
#endif
- boost::posix_time::time_duration d = boost::posix_time::second_clock::local_time() - timer;
+ boost::posix_time::time_duration d = second_clock::universal_time() - timer;
if (d.seconds() < 1) continue;
- timer = boost::posix_time::second_clock::local_time();
+ timer = second_clock::universal_time();
// ************************
// THE SECTION BELOW IS EXECUTED ONCE EVERY SECOND
diff --git a/src/torrent.cpp b/src/torrent.cpp
index c6bdfe4bb..7a8a9789c 100755
--- a/src/torrent.cpp
+++ b/src/torrent.cpp
@@ -72,6 +72,7 @@ namespace std
#endif
using namespace libtorrent;
+using namespace boost::posix_time;
namespace
@@ -157,7 +158,7 @@ namespace libtorrent
, m_event(tracker_request::started)
, m_block_size(0)
, m_storage(0)
- , m_next_request(boost::posix_time::second_clock::local_time())
+ , m_next_request(second_clock::universal_time())
, m_duration(1800)
, m_policy()
, m_ses(ses)
@@ -195,7 +196,7 @@ namespace libtorrent
, m_event(tracker_request::started)
, m_block_size(0)
, m_storage(0)
- , m_next_request(boost::posix_time::second_clock::local_time())
+ , m_next_request(second_clock::universal_time())
, m_duration(1800)
, m_policy()
, m_ses(ses)
@@ -247,14 +248,13 @@ namespace libtorrent
// tracker request
bool torrent::should_request()
{
- namespace time = boost::posix_time;
if (m_just_paused)
{
m_just_paused = false;
return true;
}
return !m_paused &&
- m_next_request < time::second_clock::local_time();
+ m_next_request < second_clock::universal_time();
}
void torrent::tracker_response(
@@ -268,7 +268,7 @@ namespace libtorrent
m_last_working_tracker
= prioritize_tracker(m_currently_trying_tracker);
- m_next_request = boost::posix_time::second_clock::local_time()
+ m_next_request = second_clock::universal_time()
+ boost::posix_time::seconds(m_duration);
m_currently_trying_tracker = 0;
@@ -277,11 +277,11 @@ namespace libtorrent
{
// if the peer list is empty, we should contact the
// tracker soon again to see if there are any peers
- m_next_request = boost::posix_time::second_clock::local_time() + boost::posix_time::seconds(60);
+ m_next_request = second_clock::universal_time() + boost::posix_time::seconds(60);
}
else
{
- m_next_request = boost::posix_time::second_clock::local_time() + boost::posix_time::seconds(m_duration);
+ m_next_request = second_clock::universal_time() + boost::posix_time::seconds(m_duration);
}
// connect to random peers from the list
@@ -521,7 +521,7 @@ namespace libtorrent
{
m_duration = 1800;
m_next_request
- = boost::posix_time::second_clock::local_time()
+ = second_clock::universal_time()
+ boost::posix_time::seconds(tracker_retry_delay_max);
tracker_request req;
@@ -698,12 +698,12 @@ namespace libtorrent
++m_failed_trackers;
// if we've looped the tracker list, wait a bit before retrying
m_currently_trying_tracker = 0;
- m_next_request = second_clock::local_time() + seconds(delay);
+ m_next_request = second_clock::universal_time() + seconds(delay);
}
else
{
// don't delay before trying the next tracker
- m_next_request = boost::posix_time::second_clock::local_time();
+ m_next_request = second_clock::universal_time();
}
}
@@ -944,7 +944,7 @@ namespace libtorrent
st.upload_payload_rate = m_stat.upload_payload_rate();
st.next_announce = next_announce()
- - boost::posix_time::second_clock::local_time();
+ - second_clock::universal_time();
if (st.next_announce.is_negative()) st.next_announce
= boost::posix_time::seconds(0);
st.announce_interval = boost::posix_time::seconds(m_duration);
diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp
index 930d47742..d0a5c61cb 100755
--- a/src/torrent_info.cpp
+++ b/src/torrent_info.cpp
@@ -128,7 +128,7 @@ namespace libtorrent
, m_total_size(0)
, m_info_hash(info_hash)
, m_name()
- , m_creation_date(second_clock::local_time())
+ , m_creation_date(second_clock::universal_time())
{
}
@@ -137,7 +137,7 @@ namespace libtorrent
, m_total_size(0)
, m_info_hash(0)
, m_name()
- , m_creation_date(second_clock::local_time())
+ , m_creation_date(second_clock::universal_time())
{
}
@@ -363,13 +363,12 @@ namespace libtorrent
entry info(entry::dictionary_t);
- info["length"] = m_total_size;
-
assert(!m_files.empty());
if (m_files.size() == 1)
{
info["name"] = m_name;
+ info["length"] = m_files.front().size;
}
else
{
diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp
index 07b61acfc..d4ad54fe1 100755
--- a/src/udp_tracker_connection.cpp
+++ b/src/udp_tracker_connection.cpp
@@ -54,6 +54,8 @@ namespace
};
}
+using namespace boost::posix_time;
+
namespace libtorrent
{
@@ -64,7 +66,7 @@ namespace libtorrent
, boost::weak_ptr c
, const http_settings& stn)
: tracker_connection(c)
- , m_request_time(boost::posix_time::second_clock::local_time())
+ , m_request_time(second_clock::universal_time())
, m_request(req)
, m_transaction_id(0)
, m_connection_id(0)
@@ -85,7 +87,7 @@ namespace libtorrent
{
using namespace boost::posix_time;
- time_duration d = second_clock::local_time() - m_request_time;
+ time_duration d = second_clock::universal_time() - m_request_time;
return (m_transaction_id != 0
&& m_connection_id != 0)
|| d > seconds(m_settings.tracker_timeout);
@@ -95,7 +97,7 @@ namespace libtorrent
{
using namespace boost::posix_time;
- time_duration d = second_clock::local_time() - m_request_time;
+ time_duration d = second_clock::universal_time() - m_request_time;
if (m_connection_id == 0
&& d > seconds(udp_connect_timeout))
{
@@ -185,7 +187,7 @@ namespace libtorrent
detail::write_uint16(m_request.listen_port, ptr);
m_socket->send(buf, 94);
- m_request_time = boost::posix_time::second_clock::local_time();
+ m_request_time = second_clock::universal_time();
++m_attempts;
}
@@ -205,7 +207,7 @@ namespace libtorrent
detail::write_int32(m_transaction_id, ptr);
m_socket->send(send_buf, 16);
- m_request_time = boost::posix_time::second_clock::local_time();
+ m_request_time = second_clock::universal_time();
++m_attempts;
}