diff --git a/src/net.cpp b/src/net.cpp index 6ae5c88943..83f89edace 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -273,7 +273,7 @@ std::optional GetLocalAddrForPeer(CNode *pnode) if (pnode->IsInboundConn()) { // For inbound connections, assume both the address and the port // as seen from the peer. - addrLocal = CAddress{pnode->GetAddrLocal(), addrLocal.nServices}; + addrLocal = CAddress{pnode->GetAddrLocal(), addrLocal.nServices, addrLocal.nTime}; } else { // For outbound connections, assume just the address as seen from // the peer and leave the port in `addrLocal` as returned by diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index 050cb3e4b4..f2ca1f2c67 100644 --- a/src/test/net_tests.cpp +++ b/src/test/net_tests.cpp @@ -676,10 +676,13 @@ BOOST_AUTO_TEST_CASE(get_local_addr_for_peer_port) const uint16_t bind_port = 20001; m_node.args->ForceSetArg("-bind", strprintf("3.4.5.6:%u", bind_port)); + const uint32_t current_time = static_cast(GetAdjustedTime()); + SetMockTime(current_time); + // Our address:port as seen from the peer, completely different from the above. in_addr peer_us_addr; peer_us_addr.s_addr = htonl(0x02030405); - const CAddress peer_us{CService{peer_us_addr, 20002}, NODE_NETWORK}; + const CAddress peer_us{CService{peer_us_addr, 20002}, NODE_NETWORK, current_time}; // Create a peer with a routable IPv4 address (outbound). in_addr peer_out_in_addr; @@ -700,7 +703,7 @@ BOOST_AUTO_TEST_CASE(get_local_addr_for_peer_port) // Without the fix peer_us:8333 is chosen instead of the proper peer_us:bind_port. auto chosen_local_addr = GetLocalAddrForPeer(&peer_out); BOOST_REQUIRE(chosen_local_addr); - const CService expected{peer_us_addr, bind_port}; + const CAddress expected{CService{peer_us_addr, bind_port}, NODE_NETWORK, current_time}; BOOST_CHECK(*chosen_local_addr == expected); // Create a peer with a routable IPv4 address (inbound).