diff --git a/include/libtorrent/bt_peer_connection.hpp b/include/libtorrent/bt_peer_connection.hpp index 478c10a04..d4cfe2dcb 100644 --- a/include/libtorrent/bt_peer_connection.hpp +++ b/include/libtorrent/bt_peer_connection.hpp @@ -90,6 +90,7 @@ namespace libtorrent , boost::shared_ptr s , tcp::endpoint const& remote , policy::peer* peerinfo + , peer_id const& pid , boost::weak_ptr t = boost::weak_ptr() , bool outgoing = false); @@ -387,6 +388,9 @@ private: static const message_handler m_message_handler[num_supported_messages]; + // the peer ID we advertise for ourself + peer_id m_our_peer_id; + // this is a queue of ranges that describes // where in the send buffer actual payload // data is located. This is currently diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 5d4490d1e..31f15653b 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -101,6 +101,7 @@ namespace libtorrent , shared_ptr s , tcp::endpoint const& remote , policy::peer* peerinfo + , peer_id const& pid , boost::weak_ptr tor , bool outgoing) : peer_connection(ses, tor, s, remote @@ -118,6 +119,7 @@ namespace libtorrent , m_encrypted(false) , m_rc4_encrypted(false) #endif + , m_our_peer_id(pid) #ifndef TORRENT_DISABLE_EXTENSIONS , m_upload_only_id(0) , m_holepunch_id(0) @@ -791,13 +793,11 @@ namespace libtorrent // in anonymous mode, every peer connection // has a unique peer-id for (int i = 0; i < 20; ++i) - ptr[i] = random() & 0xff; + m_our_peer_id[i] = random() & 0xff; } - else - { - memcpy(ptr, &m_ses.get_peer_id()[0], 20); - } -// ptr += 20; + + memcpy(ptr, &m_our_peer_id[0], 20); + ptr += 20; #ifdef TORRENT_VERBOSE_LOGGING peer_log("==> HANDSHAKE [ ih: %s ]", to_hex(ih.to_string()).c_str()); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 13de17942..b74c1a51a 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2857,7 +2857,7 @@ retry: setup_socket_buffers(*s); boost::intrusive_ptr c( - new bt_peer_connection(*this, s, endp, 0)); + new bt_peer_connection(*this, s, endp, 0, get_peer_id())); #if TORRENT_USE_ASSERTS c->m_in_constructor = false; #endif diff --git a/src/torrent.cpp b/src/torrent.cpp index 0e36181a2..0cb91b25b 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -5855,7 +5855,7 @@ namespace libtorrent m_ses.setup_socket_buffers(*s); boost::intrusive_ptr c(new bt_peer_connection( - m_ses, s, a, peerinfo, shared_from_this(), true)); + m_ses, s, a, peerinfo, m_ses.get_peer_id(), shared_from_this(), true)); #if TORRENT_USE_ASSERTS c->m_in_constructor = false;