diff options
author | Antonio Juarez <antonio.maria.juarez@live.com> | 2014-03-20 11:46:11 +0000 |
---|---|---|
committer | Antonio Juarez <antonio.maria.juarez@live.com> | 2014-03-20 11:46:11 +0000 |
commit | 8efa1313f3614f34ac0bac947314bb53e9a2412b (patch) | |
tree | 2752f8e6dfbb75bc53d56ea422482a8ec5870ffa /src/p2p | |
parent | moved all stuff to github (diff) | |
download | monero-8efa1313f3614f34ac0bac947314bb53e9a2412b.tar.xz |
some fixes
Diffstat (limited to 'src/p2p')
-rw-r--r-- | src/p2p/net_node.h | 2 | ||||
-rw-r--r-- | src/p2p/net_node.inl | 57 | ||||
-rw-r--r-- | src/p2p/net_node_common.h | 6 | ||||
-rw-r--r-- | src/p2p/net_peerlist.h | 8 | ||||
-rw-r--r-- | src/p2p/p2p_protocol_defs.h | 18 |
5 files changed, 63 insertions, 28 deletions
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index 32249a6d1..794b97429 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -121,7 +121,7 @@ namespace nodetool virtual bool invoke_notify_to_peer(int command, const std::string& req_buff, const epee::net_utils::connection_context_base& context); virtual bool drop_connection(const epee::net_utils::connection_context_base& context); virtual void request_callback(const epee::net_utils::connection_context_base& context); - virtual void for_each_connection(std::function<bool(typename t_payload_net_handler::connection_context&)> f); + virtual void for_each_connection(std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type)> f); //----------------------------------------------------------------------------------------------- bool parse_peer_from_string(nodetool::net_address& pe, const std::string& node_addr); bool handle_command_line(const boost::program_options::variables_map& vm); diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index a5e534f8a..2b46470d9 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -76,10 +76,10 @@ namespace nodetool } //----------------------------------------------------------------------------------- template<class t_payload_net_handler> - void node_server<t_payload_net_handler>::for_each_connection(std::function<bool(typename t_payload_net_handler::connection_context&)> f) + void node_server<t_payload_net_handler>::for_each_connection(std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type)> f) { m_net_server.get_config_object().foreach_connection([&](p2p_connection_context& cntx){ - return f(cntx); + return f(cntx, cntx.peer_id); }); } //----------------------------------------------------------------------------------- @@ -143,20 +143,59 @@ namespace nodetool m_hide_my_port = true; return true; } //----------------------------------------------------------------------------------- -#define ADD_HARDCODED_SEED_NODE(addr_str) { nodetool::net_address na = AUTO_VAL_INIT(na);bool r = parse_peer_from_string(na, addr_str); \ - CHECK_AND_ASSERT_MES(r, false, "Failed to parse seed address from string: " << addr_str); m_seed_nodes.push_back(na); } + namespace + { + template<typename T> + bool append_net_address(T& nodes, const std::string& addr) + { + using namespace boost::asio; + + size_t pos = addr.find_last_of(':'); + CHECK_AND_ASSERT_MES(std::string::npos != pos && addr.length() - 1 != pos && 0 != pos, false, "Failed to parse seed address from string: '" << addr << '\''); + std::string host = addr.substr(0, pos); + std::string port = addr.substr(pos + 1); + + io_service io_srv; + ip::tcp::resolver resolver(io_srv); + ip::tcp::resolver::query query(host, port); + boost::system::error_code ec; + ip::tcp::resolver::iterator i = resolver.resolve(query, ec); + CHECK_AND_NO_ASSERT_MES(!ec, false, "Failed to resolve host name '" << host << "': " << ec.message() << ':' << ec.value()); + + ip::tcp::resolver::iterator iend; + for (; i != iend; ++i) + { + ip::tcp::endpoint endpoint = *i; + if (endpoint.address().is_v4()) + { + nodetool::net_address na; + na.ip = boost::asio::detail::socket_ops::host_to_network_long(endpoint.address().to_v4().to_ulong()); + na.port = endpoint.port(); + nodes.push_back(na); + LOG_PRINT_L4("Added seed node: " << endpoint.address().to_v4().to_string(ec) << ':' << na.port); + } + else + { + LOG_PRINT_L2("IPv6 doesn't supported, skip '" << host << "' -> " << endpoint.address().to_v6().to_string(ec)); + } + } + return true; + } + } + #define ADD_HARDCODED_SEED_NODE(addr) append_net_address(m_seed_nodes, addr); + //----------------------------------------------------------------------------------- template<class t_payload_net_handler> bool node_server<t_payload_net_handler>::init(const boost::program_options::variables_map& vm) { - + ADD_HARDCODED_SEED_NODE("seed.bytecoin.org:8080"); ADD_HARDCODED_SEED_NODE("85.25.201.95:8080"); ADD_HARDCODED_SEED_NODE("85.25.196.145:8080"); ADD_HARDCODED_SEED_NODE("85.25.196.146:8080"); ADD_HARDCODED_SEED_NODE("85.25.196.144:8080"); ADD_HARDCODED_SEED_NODE("5.199.168.138:8080"); - ADD_HARDCODED_SEED_NODE("62.75.236.152:8080"); + ADD_HARDCODED_SEED_NODE("62.75.236.152:8080"); ADD_HARDCODED_SEED_NODE("85.25.194.245:8080"); ADD_HARDCODED_SEED_NODE("95.211.224.160:8080"); ADD_HARDCODED_SEED_NODE("144.76.200.44:8080"); @@ -290,7 +329,7 @@ namespace nodetool bool r = net_utils::async_invoke_remote_command2<typename COMMAND_HANDSHAKE::response>(context_.m_connection_id, COMMAND_HANDSHAKE::ID, arg, m_net_server.get_config_object(), [this, &pi, &ev, &hsh_result, &just_take_peerlist](int code, const typename COMMAND_HANDSHAKE::response& rsp, p2p_connection_context& context) { - misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([&](){ev.rise();}); + misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([&](){ev.raise();}); if(code < 0) { @@ -542,7 +581,7 @@ namespace nodetool LOG_PRINT_RED_L0("Failed to connect to any of seed peers, continuing without seeds"); break; } - if(++current_index > m_seed_nodes.size()) + if(++current_index >= m_seed_nodes.size()) current_index = 0; } } @@ -939,7 +978,7 @@ namespace nodetool if(arg.node_data.peer_id != m_config.m_peer_id && arg.node_data.my_port) { peerid_type peer_id_l = arg.node_data.peer_id; - boost::uint32_t port_l = arg.node_data.my_port; + uint32_t port_l = arg.node_data.my_port; //try ping to be sure that we can add this peer to peer_list try_ping(arg.node_data, context, [peer_id_l, port_l, context, this]() { diff --git a/src/p2p/net_node_common.h b/src/p2p/net_node_common.h index db8b63095..17ae20cbe 100644 --- a/src/p2p/net_node_common.h +++ b/src/p2p/net_node_common.h @@ -6,7 +6,7 @@ #include <boost/uuid/uuid.hpp> #include "net/net_utils_base.h" - +#include "p2p_protocol_defs.h" namespace nodetool { @@ -23,7 +23,7 @@ namespace nodetool virtual bool drop_connection(const epee::net_utils::connection_context_base& context)=0; virtual void request_callback(const epee::net_utils::connection_context_base& context)=0; virtual uint64_t get_connections_count()=0; - virtual void for_each_connection(std::function<bool(t_connection_context&)> f)=0; + virtual void for_each_connection(std::function<bool(t_connection_context&, peerid_type)> f)=0; }; template<class t_connection_context> @@ -49,7 +49,7 @@ namespace nodetool { } - virtual void for_each_connection(std::function<bool(t_connection_context&)> f) + virtual void for_each_connection(std::function<bool(t_connection_context&,peerid_type)> f) { } diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h index 65dfd011a..ea541fcbc 100644 --- a/src/p2p/net_peerlist.h +++ b/src/p2p/net_peerlist.h @@ -49,7 +49,7 @@ namespace nodetool bool get_gray_peer_by_index(peerlist_entry& p, size_t i); bool append_with_peer_white(const peerlist_entry& pr); bool append_with_peer_gray(const peerlist_entry& pr); - bool set_peer_just_seen(peerid_type peer, boost::uint32_t ip, boost::uint32_t port); + bool set_peer_just_seen(peerid_type peer, uint32_t ip, uint32_t port); bool set_peer_just_seen(peerid_type peer, const net_address& addr); bool set_peer_unreachable(const peerlist_entry& pr); bool is_ip_allowed(uint32_t ip); @@ -284,7 +284,7 @@ namespace nodetool } //-------------------------------------------------------------------------------------------------- inline - bool peerlist_manager::set_peer_just_seen(peerid_type peer, boost::uint32_t ip, boost::uint32_t port) + bool peerlist_manager::set_peer_just_seen(peerid_type peer, uint32_t ip, uint32_t port) { net_address addr; addr.ip = ip; @@ -343,10 +343,6 @@ namespace nodetool if(!is_ip_allowed(ple.adr.ip)) return true; - if(ple.adr.port != 8080) - assert(false); - - CRITICAL_REGION_LOCAL(m_peerlist_lock); //find in white list auto by_addr_it_wt = m_peers_white.get<by_addr>().find(ple.adr); diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h index 7ae6d08f3..9994dca4c 100644 --- a/src/p2p/p2p_protocol_defs.h +++ b/src/p2p/p2p_protocol_defs.h @@ -19,8 +19,8 @@ namespace nodetool struct net_address { - boost::uint32_t ip; - boost::uint32_t port; + uint32_t ip; + uint32_t port; }; struct peerlist_entry @@ -74,13 +74,13 @@ namespace nodetool KV_SERIALIZE(config_id) END_KV_SERIALIZE_MAP() - boost::uint32_t connections_count; - boost::uint32_t connection_timeout; - boost::uint32_t ping_connection_timeout; - boost::uint32_t handshake_interval; - boost::uint32_t packet_max_size; - boost::uint32_t config_id; - boost::uint32_t send_peerlist_sz; + uint32_t connections_count; + uint32_t connection_timeout; + uint32_t ping_connection_timeout; + uint32_t handshake_interval; + uint32_t packet_max_size; + uint32_t config_id; + uint32_t send_peerlist_sz; }; struct basic_node_data |