@@ -108,7 +108,7 @@ const std::string NET_MESSAGE_TYPE_OTHER = "*other*";
108108
109109static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL ; // SHA256("netgroup")[0:8]
110110static const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL ; // SHA256("localhostnonce")[0:8]
111- static const uint64_t RANDOMIZER_ID_ADDRCACHE = 0x1cf2e4ddd306dda9ULL ; // SHA256("addrcache ")[0:8]
111+ static const uint64_t RANDOMIZER_ID_NETWORKKEY = 0x0e8a2b136c592a7dULL ; // SHA256("networkkey ")[0:8]
112112//
113113// Global state variables
114114//
@@ -530,6 +530,13 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
530530 if (!addr_bind.IsValid ()) {
531531 addr_bind = GetBindAddress (*sock);
532532 }
533+ uint64_t network_id = GetDeterministicRandomizer (RANDOMIZER_ID_NETWORKKEY)
534+ .Write (target_addr.GetNetClass ())
535+ .Write (addr_bind.GetAddrBytes ())
536+ // For outbound connections, the port of the bound address is randomly
537+ // assigned by the OS and would therefore not be useful for seeding.
538+ .Write (0 )
539+ .Finalize ();
533540 CNode* pnode = new CNode (id,
534541 std::move (sock),
535542 target_addr,
@@ -539,6 +546,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
539546 pszDest ? pszDest : " " ,
540547 conn_type,
541548 /* inbound_onion=*/ false ,
549+ network_id,
542550 CNodeOptions{
543551 .permission_flags = permission_flags,
544552 .i2p_sam_session = std::move (i2p_transient_session),
@@ -1832,6 +1840,11 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
18321840 ServiceFlags local_services = GetLocalServices ();
18331841 const bool use_v2transport (local_services & NODE_P2P_V2);
18341842
1843+ uint64_t network_id = GetDeterministicRandomizer (RANDOMIZER_ID_NETWORKKEY)
1844+ .Write (inbound_onion ? NET_ONION : addr.GetNetClass ())
1845+ .Write (addr_bind.GetAddrBytes ())
1846+ .Write (addr_bind.GetPort ()) // inbound connections use bind port
1847+ .Finalize ();
18351848 CNode* pnode = new CNode (id,
18361849 std::move (sock),
18371850 CAddress{addr, NODE_NONE},
@@ -1841,6 +1854,7 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
18411854 /* addrNameIn=*/ " " ,
18421855 ConnectionType::INBOUND,
18431856 inbound_onion,
1857+ network_id,
18441858 CNodeOptions{
18451859 .permission_flags = permission_flags,
18461860 .prefer_evict = discouraged,
@@ -3519,15 +3533,9 @@ std::vector<CAddress> CConnman::GetAddressesUnsafe(size_t max_addresses, size_t
35193533std::vector<CAddress> CConnman::GetAddresses (CNode& requestor, size_t max_addresses, size_t max_pct)
35203534{
35213535 auto local_socket_bytes = requestor.addrBind .GetAddrBytes ();
3522- uint64_t cache_id = GetDeterministicRandomizer (RANDOMIZER_ID_ADDRCACHE)
3523- .Write (requestor.ConnectedThroughNetwork ())
3524- .Write (local_socket_bytes)
3525- // For outbound connections, the port of the bound address is randomly
3526- // assigned by the OS and would therefore not be useful for seeding.
3527- .Write (requestor.IsInboundConn () ? requestor.addrBind .GetPort () : 0 )
3528- .Finalize ();
3536+ uint64_t network_id = requestor.m_network_key ;
35293537 const auto current_time = GetTime<std::chrono::microseconds>();
3530- auto r = m_addr_response_caches.emplace (cache_id , CachedAddrResponse{});
3538+ auto r = m_addr_response_caches.emplace (network_id , CachedAddrResponse{});
35313539 CachedAddrResponse& cache_entry = r.first ->second ;
35323540 if (cache_entry.m_cache_entry_expiration < current_time) { // If emplace() added new one it has expiration 0.
35333541 cache_entry.m_addrs_response_cache = GetAddressesUnsafe (max_addresses, max_pct, /* network=*/ std::nullopt );
@@ -3804,6 +3812,7 @@ CNode::CNode(NodeId idIn,
38043812 const std::string& addrNameIn,
38053813 ConnectionType conn_type_in,
38063814 bool inbound_onion,
3815+ uint64_t network_key,
38073816 CNodeOptions&& node_opts)
38083817 : m_transport{MakeTransport (idIn, node_opts.use_v2transport , conn_type_in == ConnectionType::INBOUND)},
38093818 m_permission_flags{node_opts.permission_flags },
@@ -3816,6 +3825,7 @@ CNode::CNode(NodeId idIn,
38163825 m_inbound_onion{inbound_onion},
38173826 m_prefer_evict{node_opts.prefer_evict },
38183827 nKeyedNetGroup{nKeyedNetGroupIn},
3828+ m_network_key{network_key},
38193829 m_conn_type{conn_type_in},
38203830 id{idIn},
38213831 nLocalHostNonce{nLocalHostNonceIn},
0 commit comments