diff options
Diffstat (limited to '')
-rw-r--r-- | src/p2p/net_node.h | 8 | ||||
-rw-r--r-- | src/p2p/net_node.inl | 52 | ||||
-rw-r--r-- | src/p2p/net_node_common.h | 4 | ||||
-rw-r--r-- | src/p2p/p2p_protocol_defs.h | 23 |
4 files changed, 81 insertions, 6 deletions
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index 5943c248f..619bad40f 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -63,6 +63,7 @@ namespace nodetool struct p2p_connection_context_t: base_type //t_payload_net_handler::connection_context //public net_utils::connection_context_base { peerid_type peer_id; + uint32_t support_flags; }; template<class t_payload_net_handler> @@ -146,6 +147,7 @@ namespace nodetool HANDLE_INVOKE_T2(COMMAND_REQUEST_NETWORK_STATE, &node_server::handle_get_network_state) HANDLE_INVOKE_T2(COMMAND_REQUEST_PEER_ID, &node_server::handle_get_peer_id) #endif + HANDLE_INVOKE_T2(COMMAND_REQUEST_SUPPORT_FLAGS, &node_server::handle_get_support_flags) CHAIN_INVOKE_MAP_TO_OBJ_FORCE_CONTEXT(m_payload_handler, typename t_payload_net_handler::connection_context&) END_INVOKE_MAP2() @@ -158,6 +160,7 @@ namespace nodetool int handle_get_network_state(int command, COMMAND_REQUEST_NETWORK_STATE::request& arg, COMMAND_REQUEST_NETWORK_STATE::response& rsp, p2p_connection_context& context); int handle_get_peer_id(int command, COMMAND_REQUEST_PEER_ID::request& arg, COMMAND_REQUEST_PEER_ID::response& rsp, p2p_connection_context& context); #endif + int handle_get_support_flags(int command, COMMAND_REQUEST_SUPPORT_FLAGS::request& arg, COMMAND_REQUEST_SUPPORT_FLAGS::response& rsp, p2p_connection_context& context); bool init_config(); bool make_default_config(); bool store_config(); @@ -174,7 +177,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&, peerid_type)> f); + virtual void for_each_connection(std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type, uint32_t)> f); virtual bool add_ip_fail(uint32_t address); //----------------- i_connection_filter -------------------------------------------------------- virtual bool is_remote_ip_allowed(uint32_t adress); @@ -204,6 +207,7 @@ namespace nodetool bool is_addr_connected(const net_address& peer); template<class t_callback> bool try_ping(basic_node_data& node_data, p2p_connection_context& context, t_callback cb); + bool try_get_support_flags(const p2p_connection_context& context, std::function<void(p2p_connection_context&, const uint32_t&)> f); bool make_expected_connections_count(bool white_list, size_t expected_connections); void cache_connect_fail_info(const net_address& addr); bool is_addr_recently_failed(const net_address& addr); @@ -240,10 +244,12 @@ namespace nodetool { network_config m_net_config; uint64_t m_peer_id; + uint32_t m_support_flags; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(m_net_config) KV_SERIALIZE(m_peer_id) + KV_SERIALIZE(m_support_flags) END_KV_SERIALIZE_MAP() }; diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 04d73ba95..d8dadae1f 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -158,6 +158,7 @@ namespace nodetool m_config.m_net_config.connection_timeout = P2P_DEFAULT_CONNECTION_TIMEOUT; m_config.m_net_config.ping_connection_timeout = P2P_DEFAULT_PING_CONNECTION_TIMEOUT; m_config.m_net_config.send_peerlist_sz = P2P_DEFAULT_PEERS_IN_HANDSHAKE; + m_config.m_support_flags = P2P_SUPPORT_FLAGS; m_first_connection_maker_call = true; CATCH_ENTRY_L0("node_server::init_config", false); @@ -165,10 +166,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&, peerid_type)> f) + void node_server<t_payload_net_handler>::for_each_connection(std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type, uint32_t)> f) { m_net_server.get_config_object().foreach_connection([&](p2p_connection_context& cntx){ - return f(cntx, cntx.peer_id); + return f(cntx, cntx.peer_id, cntx.support_flags); }); } //----------------------------------------------------------------------------------- @@ -730,6 +731,13 @@ namespace nodetool LOG_PRINT_CC_L1(context_, "COMMAND_HANDSHAKE Failed"); m_net_server.get_config_object().close(context_.m_connection_id); } + else + { + try_get_support_flags(context_, [](p2p_connection_context& flags_context, const uint32_t& support_flags) + { + flags_context.support_flags = support_flags; + }); + } return hsh_result; } @@ -1221,6 +1229,13 @@ namespace nodetool #endif //----------------------------------------------------------------------------------- template<class t_payload_net_handler> + int node_server<t_payload_net_handler>::handle_get_support_flags(int command, COMMAND_REQUEST_SUPPORT_FLAGS::request& arg, COMMAND_REQUEST_SUPPORT_FLAGS::response& rsp, p2p_connection_context& context) + { + rsp.support_flags = m_config.m_support_flags; + return 1; + } + //----------------------------------------------------------------------------------- + template<class t_payload_net_handler> void node_server<t_payload_net_handler>::request_callback(const epee::net_utils::connection_context_base& context) { m_net_server.get_config_object().request_callback(context.m_connection_id); @@ -1338,6 +1353,32 @@ namespace nodetool } //----------------------------------------------------------------------------------- template<class t_payload_net_handler> + bool node_server<t_payload_net_handler>::try_get_support_flags(const p2p_connection_context& context, std::function<void(p2p_connection_context&, const uint32_t&)> f) + { + COMMAND_REQUEST_SUPPORT_FLAGS::request support_flags_request; + bool r = epee::net_utils::async_invoke_remote_command2<typename COMMAND_REQUEST_SUPPORT_FLAGS::response> + ( + context.m_connection_id, + COMMAND_REQUEST_SUPPORT_FLAGS::ID, + support_flags_request, + m_net_server.get_config_object(), + [=](int code, const typename COMMAND_REQUEST_SUPPORT_FLAGS::response& rsp, p2p_connection_context& context_) + { + if(code < 0) + { + LOG_PRINT_CC_RED(context_, "COMMAND_REQUEST_SUPPORT_FLAGS invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")", LOG_LEVEL_1); + return; + } + + f(context_, rsp.support_flags); + }, + P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT + ); + + return r; + } + //----------------------------------------------------------------------------------- + template<class t_payload_net_handler> int node_server<t_payload_net_handler>::handle_timed_sync(int command, typename COMMAND_TIMED_SYNC::request& arg, typename COMMAND_TIMED_SYNC::response& rsp, p2p_connection_context& context) { if(!m_payload_handler.process_payload_sync_data(arg.payload_data, context, false)) @@ -1394,7 +1435,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; - 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]() { @@ -1410,6 +1451,11 @@ namespace nodetool LOG_PRINT_CCONTEXT_L2("PING SUCCESS " << epee::string_tools::get_ip_string_from_int32(context.m_remote_ip) << ":" << port_l); }); } + + try_get_support_flags(context, [](p2p_connection_context& flags_context, const uint32_t& support_flags) + { + flags_context.support_flags = support_flags; + }); //fill response m_peerlist.get_peerlist_head(rsp.local_peerlist); diff --git a/src/p2p/net_node_common.h b/src/p2p/net_node_common.h index 5e7645365..846c07779 100644 --- a/src/p2p/net_node_common.h +++ b/src/p2p/net_node_common.h @@ -49,7 +49,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&, peerid_type)> f)=0; + virtual void for_each_connection(std::function<bool(t_connection_context&, peerid_type, uint32_t)> f)=0; virtual bool block_ip(uint32_t adress, time_t seconds = 0)=0; virtual bool unblock_ip(uint32_t adress)=0; virtual std::map<uint32_t, time_t> get_blocked_ips()=0; @@ -79,7 +79,7 @@ namespace nodetool { } - virtual void for_each_connection(std::function<bool(t_connection_context&,peerid_type)> f) + virtual void for_each_connection(std::function<bool(t_connection_context&,peerid_type,uint32_t)> f) { } diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h index bad4c89e3..ce1ee1449 100644 --- a/src/p2p/p2p_protocol_defs.h +++ b/src/p2p/p2p_protocol_defs.h @@ -332,6 +332,29 @@ namespace nodetool }; }; + /************************************************************************/ + /* */ + /************************************************************************/ + struct COMMAND_REQUEST_SUPPORT_FLAGS + { + const static int ID = P2P_COMMANDS_POOL_BASE + 7; + + struct request + { + BEGIN_KV_SERIALIZE_MAP() + END_KV_SERIALIZE_MAP() + }; + + struct response + { + uint32_t support_flags; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(support_flags) + END_KV_SERIALIZE_MAP() + }; + }; + #endif |