diff --git a/include/libtorrent/peer_id.hpp b/include/libtorrent/peer_id.hpp index b1deb1027..b06534536 100755 --- a/include/libtorrent/peer_id.hpp +++ b/include/libtorrent/peer_id.hpp @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include namespace libtorrent { diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index 1a16db550..9632e5623 100755 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -185,7 +185,7 @@ namespace libtorrent private: - socket(int sock, const address& sender); + socket(int sock, const address& sender, bool blocking); int m_socket; address m_sender; diff --git a/src/session.cpp b/src/session.cpp index e6daad526..313aa5c76 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -291,12 +291,15 @@ namespace libtorrent { namespace detail , print.begin() + print.length() , m_peer_id.begin()); + // http-accepted characters: + static char const printable[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'()"; + // the random number for (unsigned char* i = m_peer_id.begin() + print.length(); i != m_peer_id.end(); ++i) { - *i = rand(); + *i = printable[rand() % (sizeof(printable)-1)]; } } diff --git a/src/storage.cpp b/src/storage.cpp index 84359c580..f344f8e88 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1178,10 +1178,26 @@ namespace libtorrent } catch (file_error&) { - // TODO: skip the whole file here! - // this means the slot wasn't allocated - assert(m_slot_to_piece[current_slot] == unallocated); - m_unallocated_slots.push_back(current_slot); + // find the file that failed, and skip all the blocks in that file + size_type file_offset = 0; + size_type current_offset = current_slot * m_info.piece_length(); + for (torrent_info::file_iterator i = m_info.begin_files(); + i != m_info.end_files(); ++i) + { + file_offset += i->size; + if (file_offset > current_offset) break; + } + + assert(file_offset > current_offset); + int skip_blocks = (file_offset - current_offset + m_info.piece_length() - 1) + / m_info.piece_length(); + + for (int i = current_slot; i < current_slot + skip_blocks; ++i) + { + assert(m_slot_to_piece[i] == unallocated); + m_unallocated_slots.push_back(i); + } + current_slot += skip_blocks; } // Update progress meter and check if we've been requested to abort