merged DHT change from RC_0_16
This commit is contained in:
@@ -48,6 +48,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/kademlia/rpc_manager.hpp"
|
||||
#include "libtorrent/kademlia/routing_table.hpp"
|
||||
#include "libtorrent/kademlia/node.hpp"
|
||||
#include <libtorrent/kademlia/dht_observer.hpp>
|
||||
|
||||
#include "libtorrent/kademlia/refresh.hpp"
|
||||
#include "libtorrent/kademlia/find_data.hpp"
|
||||
@@ -100,7 +101,8 @@ node_impl::node_impl(alert_dispatcher* alert_disp
|
||||
: m_settings(settings)
|
||||
, m_id(nid == (node_id::min)() || !verify_id(nid, external_address) ? generate_id(external_address) : nid)
|
||||
, m_table(m_id, 8, settings)
|
||||
, m_rpc(m_id, m_table, sock, observer)
|
||||
, m_rpc(m_id, m_table, sock)
|
||||
, m_observer(observer)
|
||||
, m_last_tracker_tick(time_now())
|
||||
, m_post_alert(alert_disp)
|
||||
, m_sock(sock)
|
||||
@@ -221,6 +223,28 @@ void node_impl::incoming(msg const& m)
|
||||
|
||||
char y = *(y_ent->string_ptr());
|
||||
|
||||
lazy_entry const* ext_ip = m.message.dict_find_string("ip");
|
||||
if (ext_ip && ext_ip->string_length() == 4)
|
||||
{
|
||||
// this node claims we use the wrong node-ID!
|
||||
address_v4::bytes_type b;
|
||||
memcpy(&b[0], ext_ip->string_ptr(), 4);
|
||||
if (m_observer)
|
||||
m_observer->set_external_address(address_v4(b)
|
||||
, m.addr.address());
|
||||
}
|
||||
#if TORRENT_USE_IPV6
|
||||
else if (ext_ip && ext_ip->string_length() == 16)
|
||||
{
|
||||
// this node claims we use the wrong node-ID!
|
||||
address_v6::bytes_type b;
|
||||
memcpy(&b[0], ext_ip->string_ptr(), 16);
|
||||
if (m_observer)
|
||||
m_observer->set_external_address(address_v6(b)
|
||||
, m.addr.address());
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (y)
|
||||
{
|
||||
case 'r':
|
||||
@@ -657,6 +681,17 @@ void node_impl::incoming_request(msg const& m, entry& e)
|
||||
return;
|
||||
}
|
||||
|
||||
e["ip"] = endpoint_to_bytes(m.addr);
|
||||
/*
|
||||
// if this nodes ID doesn't match its IP, tell it what
|
||||
// its IP is with an error
|
||||
// don't enforce this yet
|
||||
if (!verify_id(id, m.addr.address()))
|
||||
{
|
||||
incoming_error(e, "invalid node ID");
|
||||
return;
|
||||
}
|
||||
*/
|
||||
char const* query = top_level[0]->string_cstr();
|
||||
|
||||
lazy_entry const* arg_ent = top_level[1];
|
||||
@@ -668,11 +703,6 @@ void node_impl::incoming_request(msg const& m, entry& e)
|
||||
entry& reply = e["r"];
|
||||
m_rpc.add_our_id(reply);
|
||||
|
||||
// if this nodes ID doesn't match its IP, tell it what
|
||||
// its IP is
|
||||
if (!verify_id(id, m.addr.address()))
|
||||
reply["ip"] = address_to_bytes(m.addr.address());
|
||||
|
||||
// mirror back the other node's external port
|
||||
reply["p"] = m.addr.port();
|
||||
|
||||
|
@@ -46,7 +46,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <libtorrent/kademlia/refresh.hpp>
|
||||
#include <libtorrent/kademlia/node.hpp>
|
||||
#include <libtorrent/kademlia/observer.hpp>
|
||||
#include <libtorrent/kademlia/dht_observer.hpp>
|
||||
#include <libtorrent/hasher.hpp>
|
||||
#include <libtorrent/time.hpp>
|
||||
#include <time.h> // time()
|
||||
@@ -159,8 +158,7 @@ enum { observer_size = max3<
|
||||
};
|
||||
|
||||
rpc_manager::rpc_manager(node_id const& our_id
|
||||
, routing_table& table, udp_socket_interface* sock
|
||||
, dht_observer* observer)
|
||||
, routing_table& table, udp_socket_interface* sock)
|
||||
: m_pool_allocator(observer_size, 10)
|
||||
, m_sock(sock)
|
||||
, m_our_id(our_id)
|
||||
@@ -169,7 +167,6 @@ rpc_manager::rpc_manager(node_id const& our_id
|
||||
, m_random_number(generate_random_id())
|
||||
, m_allocated_observers(0)
|
||||
, m_destructing(false)
|
||||
, m_observer(observer)
|
||||
{
|
||||
std::srand(time(0));
|
||||
|
||||
@@ -340,28 +337,6 @@ bool rpc_manager::incoming(msg const& m, node_id* id)
|
||||
return false;
|
||||
}
|
||||
|
||||
lazy_entry const* ext_ip = ret_ent->dict_find_string("ip");
|
||||
if (ext_ip && ext_ip->string_length() == 4)
|
||||
{
|
||||
// this node claims we use the wrong node-ID!
|
||||
address_v4::bytes_type b;
|
||||
memcpy(&b[0], ext_ip->string_ptr(), 4);
|
||||
if (m_observer)
|
||||
m_observer->set_external_address(address_v4(b)
|
||||
, m.addr.address());
|
||||
}
|
||||
#if TORRENT_USE_IPV6
|
||||
else if (ext_ip && ext_ip->string_length() == 16)
|
||||
{
|
||||
// this node claims we use the wrong node-ID!
|
||||
address_v6::bytes_type b;
|
||||
memcpy(&b[0], ext_ip->string_ptr(), 16);
|
||||
if (m_observer)
|
||||
m_observer->set_external_address(address_v6(b)
|
||||
, m.addr.address());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||
TORRENT_LOG(rpc) << "[" << o->m_algorithm.get() << "] Reply with transaction id: "
|
||||
<< tid << " from " << m.addr;
|
||||
|
@@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/socket.hpp"
|
||||
#include "libtorrent/socket_io.hpp"
|
||||
#include "libtorrent/address.hpp"
|
||||
#include "libtorrent/io.hpp" // for write_uint16
|
||||
#include "libtorrent/hasher.hpp" // for hasher
|
||||
|
||||
namespace libtorrent
|
||||
@@ -50,18 +51,18 @@ namespace libtorrent
|
||||
|
||||
std::string address_to_bytes(address const& a)
|
||||
{
|
||||
#if TORRENT_USE_IPV6
|
||||
if (a.is_v6())
|
||||
{
|
||||
address_v6::bytes_type b = a.to_v6().to_bytes();
|
||||
return std::string((char*)&b[0], b.size());
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
address_v4::bytes_type b = a.to_v4().to_bytes();
|
||||
return std::string((char*)&b[0], b.size());
|
||||
}
|
||||
std::string ret;
|
||||
std::back_insert_iterator<std::string> out(ret);
|
||||
detail::write_address(a, out);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string endpoint_to_bytes(udp::endpoint const& ep)
|
||||
{
|
||||
std::string ret;
|
||||
std::back_insert_iterator<std::string> out(ret);
|
||||
detail::write_endpoint(ep, out);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string print_endpoint(tcp::endpoint const& ep)
|
||||
|
Reference in New Issue
Block a user