mirror of https://github.com/oxen-io/oxen-core.git
Merge commit '092a57df996be75e3a45e9dc69d15138093f503b' into MergeUpstream3
This commit is contained in:
commit
7345e62532
|
@ -88,17 +88,13 @@ namespace net_utils
|
|||
BEGIN_KV_SERIALIZE_MAP()
|
||||
if (is_store)
|
||||
{
|
||||
KV_SERIALIZE_VAL_POD_AS_BLOB_N(m_ip, "ip")
|
||||
uint32_t ip = SWAP32LE(this_ref.m_ip);
|
||||
epee::serialization::selector<is_store>::serialize(ip, stg, hparent_section, "m_ip");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!epee::serialization::selector<is_store>::serialize_t_val_as_blob(this_ref.m_ip, stg, hparent_section, "ip"))
|
||||
{
|
||||
KV_SERIALIZE(m_ip)
|
||||
const_cast<ipv4_network_address&>(this_ref).m_ip = SWAP32LE(this_ref.m_ip);
|
||||
}
|
||||
KV_SERIALIZE(m_ip)
|
||||
const_cast<ipv4_network_address&>(this_ref).m_ip = SWAP32LE(this_ref.m_ip);
|
||||
}
|
||||
KV_SERIALIZE(m_port)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
|
|
|
@ -118,6 +118,8 @@ public: \
|
|||
|
||||
#define KV_SERIALIZE_OPT_N(variable, val_name, default_value) \
|
||||
do { \
|
||||
if (is_store && this_ref.variable == default_value) \
|
||||
break; \
|
||||
if (!epee::serialization::selector<is_store>::serialize(this_ref.variable, stg, hparent_section, val_name)) \
|
||||
epee::serialize_default(this_ref.variable, default_value); \
|
||||
} while (0);
|
||||
|
|
|
@ -114,6 +114,7 @@ namespace nodetool
|
|||
peerid_type peer_id;
|
||||
uint32_t support_flags;
|
||||
bool m_in_timedsync;
|
||||
std::set<epee::net_utils::network_address> sent_addresses;
|
||||
};
|
||||
|
||||
template<class t_payload_net_handler>
|
||||
|
@ -339,7 +340,7 @@ namespace nodetool
|
|||
const boost::program_options::variables_map& vm
|
||||
);
|
||||
bool idle_worker();
|
||||
bool handle_remote_peerlist(const std::vector<peerlist_entry>& peerlist, time_t local_time, const epee::net_utils::connection_context_base& context);
|
||||
bool handle_remote_peerlist(const std::vector<peerlist_entry>& peerlist, const epee::net_utils::connection_context_base& context);
|
||||
bool get_local_node_data(basic_node_data& node_data, const network_zone& zone);
|
||||
//bool get_local_handshake_data(handshake_data& hshd);
|
||||
|
||||
|
|
|
@ -1037,7 +1037,7 @@ namespace nodetool
|
|||
return;
|
||||
}
|
||||
|
||||
if(!handle_remote_peerlist(rsp.local_peerlist_new, rsp.node_data.local_time, context))
|
||||
if(!handle_remote_peerlist(rsp.local_peerlist_new, context))
|
||||
{
|
||||
LOG_WARNING_CC(context, "COMMAND_HANDSHAKE: failed to handle_remote_peerlist(...), closing connection.");
|
||||
add_host_fail(context.m_remote_address);
|
||||
|
@ -1114,7 +1114,7 @@ namespace nodetool
|
|||
return;
|
||||
}
|
||||
|
||||
if(!handle_remote_peerlist(rsp.local_peerlist_new, rsp.local_time, context))
|
||||
if(!handle_remote_peerlist(rsp.local_peerlist_new, context))
|
||||
{
|
||||
LOG_WARNING_CC(context, "COMMAND_TIMED_SYNC: failed to handle_remote_peerlist(...), closing connection.");
|
||||
m_network_zones.at(context.m_remote_address.get_zone()).m_net_server.get_config_object().close(context.m_connection_id );
|
||||
|
@ -1893,7 +1893,7 @@ namespace nodetool
|
|||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
bool node_server<t_payload_net_handler>::handle_remote_peerlist(const std::vector<peerlist_entry>& peerlist, time_t local_time, const epee::net_utils::connection_context_base& context)
|
||||
bool node_server<t_payload_net_handler>::handle_remote_peerlist(const std::vector<peerlist_entry>& peerlist, const epee::net_utils::connection_context_base& context)
|
||||
{
|
||||
std::vector<peerlist_entry> peerlist_ = peerlist;
|
||||
if(!sanitize_peerlist(peerlist_))
|
||||
|
@ -1910,16 +1910,13 @@ namespace nodetool
|
|||
}
|
||||
|
||||
LOG_DEBUG_CC(context, "REMOTE PEERLIST: remote peerlist size=" << peerlist_.size());
|
||||
LOG_TRACE_CC(context, "REMOTE PEERLIST: \n" << ENDL << print_peerlist_to_string(peerlist_));
|
||||
LOG_TRACE_CC(context, "REMOTE PEERLIST: \n" << print_peerlist_to_string(peerlist_));
|
||||
return m_network_zones.at(context.m_remote_address.get_zone()).m_peerlist.merge_peerlist(peerlist_);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
bool node_server<t_payload_net_handler>::get_local_node_data(basic_node_data& node_data, const network_zone& zone)
|
||||
{
|
||||
time_t local_time;
|
||||
time(&local_time);
|
||||
node_data.local_time = local_time; // \TODO This can be an identifying value across zones (public internet to tor/i2p) ...
|
||||
node_data.peer_id = zone.m_config.m_peer_id;
|
||||
if(!m_hide_my_port && zone.m_can_pingback)
|
||||
node_data.my_port = m_external_port ? m_external_port : m_listening_port;
|
||||
|
@ -2281,12 +2278,20 @@ namespace nodetool
|
|||
}
|
||||
|
||||
//fill response
|
||||
rsp.local_time = time(NULL);
|
||||
|
||||
const epee::net_utils::zone zone_type = context.m_remote_address.get_zone();
|
||||
network_zone& zone = m_network_zones.at(zone_type);
|
||||
|
||||
zone.m_peerlist.get_peerlist_head(rsp.local_peerlist_new, true);
|
||||
std::vector<peerlist_entry> local_peerlist_new;
|
||||
zone.m_peerlist.get_peerlist_head(local_peerlist_new, true, P2P_DEFAULT_PEERS_IN_HANDSHAKE);
|
||||
|
||||
//only include out peers we did not already send
|
||||
rsp.local_peerlist_new.reserve(local_peerlist_new.size());
|
||||
for (auto &pe: local_peerlist_new)
|
||||
{
|
||||
if (!context.sent_addresses.insert(pe.adr).second)
|
||||
continue;
|
||||
rsp.local_peerlist_new.push_back(std::move(pe));
|
||||
}
|
||||
m_payload_handler.get_payload_sync_data(rsp.payload_data);
|
||||
|
||||
/* Tor/I2P nodes receiving connections via forwarding (from tor/i2p daemon)
|
||||
|
@ -2408,6 +2413,8 @@ namespace nodetool
|
|||
|
||||
//fill response
|
||||
zone.m_peerlist.get_peerlist_head(rsp.local_peerlist_new, true);
|
||||
for (const auto &e: rsp.local_peerlist_new)
|
||||
context.sent_addresses.insert(e.adr);
|
||||
get_local_node_data(rsp.node_data, zone);
|
||||
m_payload_handler.get_payload_sync_data(rsp.payload_data);
|
||||
LOG_DEBUG_CC(context, "COMMAND_HANDSHAKE");
|
||||
|
|
|
@ -270,19 +270,19 @@ namespace nodetool
|
|||
peers_indexed::index<by_time>::type& by_time_index=m_peers_white.get<by_time>();
|
||||
uint32_t cnt = 0;
|
||||
|
||||
// picks a random set of peers within the first 120%, rather than a set of the first 100%.
|
||||
// picks a random set of peers within the whole set, rather pick the first depth elements.
|
||||
// The intent is that if someone asks twice, they can't easily tell:
|
||||
// - this address was not in the first list, but is in the second, so the only way this can be
|
||||
// is if its last_seen was recently reset, so this means the target node recently had a new
|
||||
// connection to that address
|
||||
// - this address was in the first list, and not in the second, which means either the address
|
||||
// was moved to the gray list (if it's not accessibe, which the attacker can check if
|
||||
// was moved to the gray list (if it's not accessible, which the attacker can check if
|
||||
// the address accepts incoming connections) or it was the oldest to still fit in the 250 items,
|
||||
// so its last_seen is old.
|
||||
//
|
||||
// See Cao, Tong et al. "Exploring the Monero Peer-to-Peer Network". https://eprint.iacr.org/2019/411
|
||||
//
|
||||
const uint32_t pick_depth = anonymize ? depth + depth / 5 : depth;
|
||||
const uint32_t pick_depth = anonymize ? m_peers_white.size() : depth;
|
||||
bs_head.reserve(pick_depth);
|
||||
for(const peers_indexed::value_type& vl: boost::adaptors::reverse(by_time_index))
|
||||
{
|
||||
|
|
|
@ -79,8 +79,7 @@ namespace nodetool
|
|||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(adr)
|
||||
KV_SERIALIZE(id)
|
||||
if (!is_store || this_ref.last_seen != 0)
|
||||
KV_SERIALIZE_OPT(last_seen, (int64_t)0)
|
||||
KV_SERIALIZE_OPT(last_seen, (int64_t)0)
|
||||
KV_SERIALIZE_OPT(pruning_seed, (uint32_t)0)
|
||||
KV_SERIALIZE_OPT(rpc_port, (uint16_t)0)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
|
@ -161,7 +160,6 @@ namespace nodetool
|
|||
struct basic_node_data
|
||||
{
|
||||
uuid network_id;
|
||||
uint64_t local_time;
|
||||
uint32_t my_port;
|
||||
uint16_t rpc_port;
|
||||
peerid_type peer_id;
|
||||
|
@ -169,7 +167,6 @@ namespace nodetool
|
|||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE_VAL_POD_AS_BLOB(network_id)
|
||||
KV_SERIALIZE(peer_id)
|
||||
KV_SERIALIZE(local_time)
|
||||
KV_SERIALIZE(my_port)
|
||||
KV_SERIALIZE_OPT(rpc_port, (uint16_t)(0))
|
||||
END_KV_SERIALIZE_MAP()
|
||||
|
@ -206,35 +203,7 @@ namespace nodetool
|
|||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(node_data)
|
||||
KV_SERIALIZE(payload_data)
|
||||
if (is_store)
|
||||
{
|
||||
// saving: save both, so old and new peers can understand it
|
||||
KV_SERIALIZE(local_peerlist_new)
|
||||
std::vector<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
for (const auto &p: this_ref.local_peerlist_new)
|
||||
{
|
||||
if (p.adr.get_type_id() == epee::net_utils::ipv4_network_address::get_type_id())
|
||||
{
|
||||
const epee::net_utils::network_address &na = p.adr;
|
||||
const epee::net_utils::ipv4_network_address &ipv4 = na.as<const epee::net_utils::ipv4_network_address>();
|
||||
local_peerlist.push_back(peerlist_entry_base<network_address_old>({{ipv4.ip(), ipv4.port()}, p.id, p.last_seen, p.pruning_seed, p.rpc_port}));
|
||||
}
|
||||
else
|
||||
MDEBUG("Not including in legacy peer list: " << p.adr.str());
|
||||
}
|
||||
epee::serialization::selector<is_store>::serialize_stl_container_pod_val_as_blob(local_peerlist, stg, hparent_section, "local_peerlist");
|
||||
}
|
||||
else
|
||||
{
|
||||
// loading: load old list only if there is no new one
|
||||
if (!epee::serialization::selector<is_store>::serialize(this_ref.local_peerlist_new, stg, hparent_section, "local_peerlist_new"))
|
||||
{
|
||||
std::vector<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
epee::serialization::selector<is_store>::serialize_stl_container_pod_val_as_blob(local_peerlist, stg, hparent_section, "local_peerlist");
|
||||
for (const auto &p: local_peerlist)
|
||||
((response&)this_ref).local_peerlist_new.push_back(peerlist_entry({epee::net_utils::ipv4_network_address(p.adr.ip, p.adr.port), p.id, p.last_seen, p.pruning_seed, p.rpc_port}));
|
||||
}
|
||||
}
|
||||
KV_SERIALIZE(local_peerlist_new)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
@ -263,37 +232,8 @@ namespace nodetool
|
|||
std::vector<peerlist_entry> local_peerlist_new;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(local_time)
|
||||
KV_SERIALIZE(payload_data)
|
||||
if (is_store)
|
||||
{
|
||||
// saving: save both, so old and new peers can understand it
|
||||
KV_SERIALIZE(local_peerlist_new)
|
||||
std::vector<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
for (const auto &p: this_ref.local_peerlist_new)
|
||||
{
|
||||
if (p.adr.get_type_id() == epee::net_utils::ipv4_network_address::get_type_id())
|
||||
{
|
||||
const epee::net_utils::network_address &na = p.adr;
|
||||
const epee::net_utils::ipv4_network_address &ipv4 = na.as<const epee::net_utils::ipv4_network_address>();
|
||||
local_peerlist.push_back(peerlist_entry_base<network_address_old>({{ipv4.ip(), ipv4.port()}, p.id, p.last_seen, p.pruning_seed}));
|
||||
}
|
||||
else
|
||||
MDEBUG("Not including in legacy peer list: " << p.adr.str());
|
||||
}
|
||||
epee::serialization::selector<is_store>::serialize_stl_container_pod_val_as_blob(local_peerlist, stg, hparent_section, "local_peerlist");
|
||||
}
|
||||
else
|
||||
{
|
||||
// loading: load old list only if there is no new one
|
||||
if (!epee::serialization::selector<is_store>::serialize(this_ref.local_peerlist_new, stg, hparent_section, "local_peerlist_new"))
|
||||
{
|
||||
std::vector<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
epee::serialization::selector<is_store>::serialize_stl_container_pod_val_as_blob(local_peerlist, stg, hparent_section, "local_peerlist");
|
||||
for (const auto &p: local_peerlist)
|
||||
((response&)this_ref).local_peerlist_new.push_back(peerlist_entry({epee::net_utils::ipv4_network_address(p.adr.ip, p.adr.port), p.id, p.last_seen, p.pruning_seed}));
|
||||
}
|
||||
}
|
||||
KV_SERIALIZE(local_peerlist_new)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
|
|
@ -2479,7 +2479,7 @@ namespace wallet_rpc
|
|||
bool get_tx_metadata; // Return the metadata needed to relay the transaction. (Defaults to false)
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE_OPT(subaddr_indices, {});
|
||||
KV_SERIALIZE (subaddr_indices);
|
||||
KV_SERIALIZE (destination);
|
||||
KV_SERIALIZE (amount);
|
||||
KV_SERIALIZE (service_node_key);
|
||||
|
@ -2755,7 +2755,7 @@ For information on updating & signing, refer to COMMAND_RPC_LNS_UPDATE_MAPPING)"
|
|||
KV_SERIALIZE (name);
|
||||
KV_SERIALIZE (value);
|
||||
KV_SERIALIZE_OPT(account_index, (uint32_t)0);
|
||||
KV_SERIALIZE_OPT(subaddr_indices, {});
|
||||
KV_SERIALIZE (subaddr_indices);
|
||||
KV_SERIALIZE_OPT(priority, (uint32_t)0);
|
||||
KV_SERIALIZE (get_tx_key)
|
||||
KV_SERIALIZE_OPT(do_not_relay, false)
|
||||
|
@ -2828,7 +2828,7 @@ Providing the signature is an optional field and if not provided, will default t
|
|||
KV_SERIALIZE (signature);
|
||||
|
||||
KV_SERIALIZE_OPT(account_index, (uint32_t)0);
|
||||
KV_SERIALIZE_OPT(subaddr_indices, {});
|
||||
KV_SERIALIZE (subaddr_indices);
|
||||
KV_SERIALIZE_OPT(priority, (uint32_t)0);
|
||||
KV_SERIALIZE (get_tx_key)
|
||||
KV_SERIALIZE_OPT(do_not_relay, false)
|
||||
|
|
|
@ -169,7 +169,7 @@ class TransferTest():
|
|||
assert e.subaddr_indices == [{'major': 0, 'minor': 0}]
|
||||
assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
||||
assert e.double_spend_seen == False
|
||||
assert e.confirmations == 0
|
||||
assert not 'confirmations' in e or e.confirmations == 0
|
||||
|
||||
running_balances[0] -= 1000000000000 + fee
|
||||
|
||||
|
@ -282,7 +282,7 @@ class TransferTest():
|
|||
assert e.subaddr_indices == [{'major': 0, 'minor': 0}]
|
||||
assert e.address == '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW'
|
||||
assert e.double_spend_seen == False
|
||||
assert e.confirmations == 0
|
||||
assert not 'confirmations' in e or e.confirmations == 0
|
||||
assert e.amount == amount
|
||||
assert e.fee == fee
|
||||
|
||||
|
|
Loading…
Reference in New Issue