From 1313fb9fb8b8b7b95f19c934e8af455289db94ab Mon Sep 17 00:00:00 2001
From: Arvid Norberg
Client sends packet:
+optional part
-size | -name | -description | -
---|---|---|
int8_t | -flags | -1 = authentication | -
int8_t[8] | -username | -- |
int8_t[8] | -password_hash | -sha1-hash of the tracker password | -
what is the point of having a fixed size username field instead of -a null-terminated string?
-Why send the hash of the password instead of the password itself?
-Server replies with packet:
+Client sends packet:
+uint32_t | +key | +A unique key that is randomized by the +client. | +
int32_t | num_want | The maximum number of peers you want @@ -204,7 +183,39 @@ in the reply. Use -1 for default. |
Server replies with packet:
+If the server requires authorization, the following structure has to be +appended on the announce packet.
+size | +name | +description | +
---|---|---|
uint8_t[20] | +passwd_hash | +The sha1-hash of the announce packet +with the password appended. The +announce message here means the +mandatory part, not including this +authentication appendix. | +
int8_t[] | +username | +The rest of the packet is the +username. | +
the number of seconds you should wait until reannouncing yourself. | +||
int32_t | +leechers | +The number of peers in the swarm that +has not finished downloading. | +
int32_t | +seeders | +The number of peers in the swarm that +has finished downloading and are +seeding. | +
The rest of the server reply is a variable number of the following structure:
@@ -261,9 +283,11 @@ until reannouncing yourself.Client sends packet:
+transaction_id | Randomized by client. | + +
The rest of the packet contains a variable number of the following structure:
+size | +name | +description | +
---|---|---|
int8_t[20] | info_hash | The info hash that is to be scraped. |
Server replies with packet:
+int8_t[20] | -info_hash | -The info hash of this info. | -
int32_t | complete | The total number of completed @@ -358,9 +396,12 @@ leechers. |
In case of a tracker error, the server replies with this packet:
+In case of a tracker error,
+The action fields has the following encoding:
diff --git a/docs/udp_tracker_protocol.rst b/docs/udp_tracker_protocol.rst index 3f4e424d4..c6b184d67 100755 --- a/docs/udp_tracker_protocol.rst +++ b/docs/udp_tracker_protocol.rst @@ -26,9 +26,10 @@ retrying. connecting ----------- +++++++++++ Client sends packet: +-------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -40,25 +41,8 @@ Client sends packet: | int32_t | transaction_id | Randomized by client. | +-------------+---------------------+----------------------------------------+ -optional part - -+-------------+---------------------+----------------------------------------+ -| size | name | description | -+=============+=====================+========================================+ -| int8_t | flags | 1 = authentication | -+-------------+---------------------+----------------------------------------+ -| int8_t[8] | username | | -+-------------+---------------------+----------------------------------------+ -| int8_t[8] | password_hash | sha1-hash of the tracker password | -+-------------+---------------------+----------------------------------------+ - -what is the point of having a fixed size username field instead of -a null-terminated string? - -Why send the hash of the password instead of the password itself? - - Server replies with packet: +--------------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -81,9 +65,10 @@ Server replies with packet: announcing ----------- +++++++++++ Client sends packet: +-------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -120,13 +105,34 @@ Client sends packet: | | | the tracker to use the ``sender`` of | | | | this udp packet. | +-------------+---------------------+----------------------------------------+ +| uint32_t | key | A unique key that is randomized by the | +| | | client. | ++-------------+---------------------+----------------------------------------+ | int32_t | num_want | The maximum number of peers you want | | | | in the reply. Use -1 for default. | +-------------+---------------------+----------------------------------------+ | uint16_t | port | The port you're listening on. | +-------------+---------------------+----------------------------------------+ +If the server requires authorization, the following structure has to be +appended on the announce packet. + ++-------------+---------------------+----------------------------------------+ +| size | name | description | ++=============+=====================+========================================+ +| uint8_t[20] | passwd_hash | The sha1-hash of the announce packet | +| | | with the password appended. The | +| | | announce message here means the | +| | | mandatory part, not including this | +| | | authentication appendix. | ++-------------+---------------------+----------------------------------------+ +| int8_t[] | username | The rest of the packet is the | +| | | username. | ++-------------+---------------------+----------------------------------------+ + + Server replies with packet: +--------------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -141,6 +147,13 @@ Server replies with packet: | int32_t | interval | the number of seconds you should wait | | | | until reannouncing yourself. | +-------------+---------------------+----------------------------------------+ +| int32_t | leechers | The number of peers in the swarm that | +| | | has not finished downloading. | ++-------------+---------------------+----------------------------------------+ +| int32_t | seeders | The number of peers in the swarm that | +| | | has finished downloading and are | +| | | seeding. | ++-------------+---------------------+----------------------------------------+ The rest of the server reply is a variable number of the following structure: @@ -154,9 +167,11 @@ The rest of the server reply is a variable number of the following structure: scraping --------- +++++++++ + Client sends packet: +-------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -169,10 +184,18 @@ Client sends packet: +-------------+---------------------+----------------------------------------+ | int32_t | transaction_id | Randomized by client. | +-------------+---------------------+----------------------------------------+ + +The rest of the packet contains a variable number of the following structure: + ++-------------+---------------------+----------------------------------------+ +| size | name | description | ++=============+=====================+========================================+ | int8_t[20] | info_hash | The info hash that is to be scraped. | +-------------+---------------------+----------------------------------------+ + Server replies with packet: +--------------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -189,8 +212,6 @@ The rest of the packet contains a variable number of the following structures: +-------------+---------------------+----------------------------------------+ | size | name | description | +=============+=====================+========================================+ -| int8_t[20] | info_hash | The info hash of this info. | -+-------------+---------------------+----------------------------------------+ | int32_t | complete | The total number of completed | | | | downloads. | +-------------+---------------------+----------------------------------------+ @@ -201,9 +222,12 @@ The rest of the packet contains a variable number of the following structures: +-------------+---------------------+----------------------------------------+ errors ------- +++++++ -In case of a tracker error, the server replies with this packet: +In case of a tracker error, + +server replies packet: +---------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -219,7 +243,7 @@ In case of a tracker error, the server replies with this packet: actions -------- ++++++++ The action fields has the following encoding: @@ -230,7 +254,7 @@ The action fields has the following encoding: credits -------- ++++++++ Protocol designed by Olaf van der Spek diff --git a/src/file.cpp b/src/file.cpp index 2f500f0e5..845b89713 100755 --- a/src/file.cpp +++ b/src/file.cpp @@ -113,12 +113,19 @@ namespace libtorrent << strerror(errno); throw file_error(msg.str()); } +#ifdef WIN32 + assert(_lseeki64(m_fd, 0, SEEK_SET) == 0); +#endif m_open_mode = mode; } void close() { if (m_fd == -1) return; + + std::stringstream str; + str << "fd: " << m_fd << "\n"; + ::close(m_fd); m_fd = -1; m_open_mode = 0; @@ -165,14 +172,14 @@ namespace libtorrent #else size_type ret = lseek(m_fd, offset, seekdir); #endif - +/* if (ret == -1) { std::stringstream msg; msg << "seek failed: '" << strerror(errno) << "' fd: " << m_fd << " offset: " << offset << " seekdir: " << seekdir; throw file_error(msg.str()); } - +*/ } size_type tell() diff --git a/src/storage.cpp b/src/storage.cpp index e96ee97ac..9587a77cf 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -918,6 +918,7 @@ namespace libtorrent m_slot_to_piece.resize(m_info.num_pieces(), unallocated); m_free_slots.clear(); m_unallocated_slots.clear(); + pieces.clear(); pieces.resize(m_info.num_pieces(), false); @@ -1257,6 +1258,7 @@ namespace libtorrent if (iter == m_free_slots.end()) { assert(m_slot_to_piece[piece_index] != unassigned); + assert(!m_free_slots.empty()); iter = m_free_slots.end() - 1; // special case to make sure we don't use the last slot @@ -1388,6 +1390,8 @@ namespace libtorrent INVARIANT_CHECK; namespace fs = boost::filesystem; + + assert(!m_unallocated_slots.empty()); const int piece_size = static_cast