InfoHash::InfoHash(const libtorrent::sha1_hash &nativeHash) : m_valid(true) , m_nativeHash(nativeHash) { const QByteArray raw = QByteArray::fromRawData(nativeHash.data(), libtorrent::sha1_hash::size); m_hashString = QString::fromLatin1(raw.toHex()); }
void write_handshake(boost::system::error_code const& ec, lt::sha1_hash ih) { asio::ip::tcp::endpoint ep = m_out_socket.remote_endpoint(); std::printf("fake_peer::connect (%s) -> (%d) %s\n" , lt::print_endpoint(ep).c_str(), ec.value() , ec.message().c_str()); static char const handshake[] = "\x13" "BitTorrent protocol\0\0\0\0\0\0\0\x04" " " // space for info-hash "aaaaaaaaaaaaaaaaaaaa" // peer-id "\0\0\0\x01\x02"; // interested int const len = sizeof(handshake) - 1; memcpy(m_out_buffer, handshake, len); memcpy(&m_out_buffer[28], ih.data(), 20); asio::async_write(m_out_socket, asio::const_buffers_1(&m_out_buffer[0] , len), [=](boost::system::error_code const& ec, size_t bytes_transferred) { std::printf("fake_peer::write_handshake(%s) -> (%d) %s\n" , lt::print_endpoint(ep).c_str(), ec.value() , ec.message().c_str()); this->m_out_socket.close(); }); }
void write_handshake(boost::system::error_code const& ec , lt::sha1_hash ih) { using namespace std::placeholders; asio::ip::tcp::endpoint const ep = m_socket.remote_endpoint(); std::printf("fake_peer::connect (%s) -> (%d) %s\n" , lt::print_endpoint(ep).c_str(), ec.value() , ec.message().c_str()); static char const handshake[] = "\x13" "BitTorrent protocol\0\0\0\0\0\0\0\x04" " " // space for info-hash "aaaaaaaaaaaaaaaaaaaa"; // peer-id int const len = sizeof(handshake) - 1; memcpy(m_out_buffer, handshake, len); memcpy(&m_out_buffer[28], ih.data(), 20); asio::async_write(m_socket, asio::const_buffers_1(&m_out_buffer[0] , len), [this, ep](boost::system::error_code const& ec, size_t bytes_transferred) { std::printf("fake_peer::write_handshake(%s) -> (%d) %s\n" , lt::print_endpoint(ep).c_str(), ec.value() , ec.message().c_str()); if (!m_send_buffer.empty()) { asio::async_write(m_socket, asio::const_buffers_1( m_send_buffer.data(), m_send_buffer.size()) , std::bind(&fake_peer::write_send_buffer, this, _1, _2)); } else { asio::async_read(m_socket, asio::mutable_buffers_1(&m_out_buffer[0], 68) , std::bind(&fake_peer::read_handshake, this, _1, _2)); } }); }