aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/p2p/net_node.inl69
-rw-r--r--src/wallet/wallet2.cpp36
-rw-r--r--src/wallet/wallet2.h1
-rw-r--r--src/wallet/wallet_rpc_server.cpp20
4 files changed, 86 insertions, 40 deletions
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 3454e112c..ee4a10789 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -259,53 +259,66 @@ namespace nodetool
std::vector<std::vector<std::string>> dns_results;
dns_results.resize(m_seed_nodes_list.size());
- std::unique_ptr<std::atomic_flag[]> dns_finished(new std::atomic_flag[m_seed_nodes_list.size()]);
-
- // set each flag, thread will release when finished
- for (uint64_t i = 0; i < m_seed_nodes_list.size(); ++i)
- dns_finished[i].test_and_set();
-
+ std::list<boost::thread*> dns_threads;
uint64_t result_index = 0;
for (const std::string& addr_str : m_seed_nodes_list)
{
-
- uint64_t result_index_capture = result_index++;
- boost::thread t([&]
+ boost::thread* th = new boost::thread([=, &dns_results, &addr_str]
{
+ LOG_PRINT_L4("dns_threads[" << result_index << "] created for: " << addr_str)
// TODO: care about dnssec avail/valid
bool avail, valid;
- std::vector<std::string> addr_list = tools::DNSResolver().get_ipv4(addr_str, avail, valid);
-
- dns_results[result_index_capture] = addr_list;
- dns_finished[result_index_capture].clear();
+ std::vector<std::string> addr_list;
+
+ try
+ {
+ addr_list = tools::DNSResolver().get_ipv4(addr_str, avail, valid);
+ LOG_PRINT_L4("dns_threads[" << result_index << "] DNS resolve done");
+ boost::this_thread::interruption_point();
+ }
+ catch(const boost::thread_interrupted&)
+ {
+ // thread interruption request
+ // even if we now have results, finish thread without setting
+ // result variables, which are now out of scope in main thread
+ LOG_PRINT_L4("dns_threads[" << result_index << "] interrupted");
+ return;
+ }
+
+ LOG_PRINT_L4("dns_threads[" << result_index << "] addr_str: " << addr_str << " number of results: " << addr_list.size());
+ dns_results[result_index] = addr_list;
});
+ dns_threads.push_back(th);
+ ++result_index;
}
- uint64_t sleep_count = 0;
- uint64_t sleep_interval_ms = 100;
- while (sleep_count++ * sleep_interval_ms < CRYPTONOTE_DNS_TIMEOUT_MS)
+ LOG_PRINT_L4("dns_threads created, now waiting for completion or timeout of " << CRYPTONOTE_DNS_TIMEOUT_MS << "ms");
+ boost::chrono::system_clock::time_point deadline = boost::chrono::system_clock::now() + boost::chrono::milliseconds(CRYPTONOTE_DNS_TIMEOUT_MS);
+ uint64_t i = 0;
+ for (boost::thread* th : dns_threads)
{
- boost::this_thread::sleep(boost::posix_time::milliseconds(sleep_interval_ms));
- bool all_done = false;
- for (uint64_t i = 0; i < m_seed_nodes_list.size(); ++i)
+ if (! th->try_join_until(deadline))
{
- if (dns_finished[i].test_and_set())
- break;
- else
- dns_finished[i].clear();
- all_done = true;
+ LOG_PRINT_L4("dns_threads[" << i << "] timed out, sending interrupt");
+ th->interrupt();
}
- if (all_done)
- break;
+ ++i;
}
+ i = 0;
for (const auto& result : dns_results)
{
- for (const auto& addr_string : result)
+ LOG_PRINT_L4("DNS lookup for " << m_seed_nodes_list[i] << ": " << result.size() << " results");
+ // if no results for node, thread's lookup likely timed out
+ if (result.size())
{
- append_net_address(m_seed_nodes, addr_string + ":18080");
+ for (const auto& addr_string : result)
+ {
+ append_net_address(m_seed_nodes, addr_string + ":18080");
+ }
}
+ ++i;
}
if (!m_seed_nodes.size())
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index da8898132..6698e7296 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -227,24 +227,25 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
}
tx_extra_nonce extra_nonce;
+ crypto::hash payment_id = null_hash;
if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce))
{
- crypto::hash payment_id;
if(get_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id))
{
- uint64_t received = (tx_money_spent_in_ins < tx_money_got_in_outs) ? tx_money_got_in_outs - tx_money_spent_in_ins : 0;
- if (0 < received && null_hash != payment_id)
- {
- payment_details payment;
- payment.m_tx_hash = cryptonote::get_transaction_hash(tx);
- payment.m_amount = received;
- payment.m_block_height = height;
- payment.m_unlock_time = tx.unlock_time;
- m_payments.emplace(payment_id, payment);
- LOG_PRINT_L2("Payment found: " << payment_id << " / " << payment.m_tx_hash << " / " << payment.m_amount);
- }
+ // We got a payment ID to go with this tx
}
}
+ uint64_t received = (tx_money_spent_in_ins < tx_money_got_in_outs) ? tx_money_got_in_outs - tx_money_spent_in_ins : 0;
+ if (0 < received)
+ {
+ payment_details payment;
+ payment.m_tx_hash = cryptonote::get_transaction_hash(tx);
+ payment.m_amount = received;
+ payment.m_block_height = height;
+ payment.m_unlock_time = tx.unlock_time;
+ m_payments.emplace(payment_id, payment);
+ LOG_PRINT_L2("Payment found: " << payment_id << " / " << payment.m_tx_hash << " / " << payment.m_amount);
+ }
}
//----------------------------------------------------------------------------------------------------
void wallet2::process_unconfirmed(const cryptonote::transaction& tx)
@@ -816,6 +817,17 @@ void wallet2::get_payments(const crypto::hash& payment_id, std::list<wallet2::pa
});
}
//----------------------------------------------------------------------------------------------------
+void wallet2::get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments, uint64_t min_height) const
+{
+ auto range = std::make_pair(m_payments.begin(), m_payments.end());
+ std::for_each(range.first, range.second, [&payments, &min_height](const payment_container::value_type& x) {
+ if (min_height < x.second.m_block_height)
+ {
+ payments.push_back(x);
+ }
+ });
+}
+//----------------------------------------------------------------------------------------------------
bool wallet2::is_transfer_unlocked(const transfer_details& td) const
{
if(!is_tx_spendtime_unlocked(td.m_tx.unlock_time))
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 314d8f4af..1febfba39 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -212,6 +212,7 @@ namespace tools
bool check_connection();
void get_transfers(wallet2::transfer_container& incoming_transfers) const;
void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height = 0) const;
+ void get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments, uint64_t min_height) const;
uint64_t get_blockchain_current_height() const { return m_local_bc_height; }
template <class t_archive>
inline void serialize(t_archive &a, const unsigned int ver)
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index be20f05de..f856e5b8a 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -336,6 +336,26 @@ namespace tools
{
res.payments.clear();
+ /* If the payment ID list is empty, we get payments to any payment ID (or lack thereof) */
+ if (req.payment_ids.empty())
+ {
+ std::list<std::pair<crypto::hash,wallet2::payment_details>> payment_list;
+ m_wallet.get_payments(payment_list, req.min_block_height);
+
+ for (auto & payment : payment_list)
+ {
+ wallet_rpc::payment_details rpc_payment;
+ rpc_payment.payment_id = epee::string_tools::pod_to_hex(payment.first);
+ rpc_payment.tx_hash = epee::string_tools::pod_to_hex(payment.second.m_tx_hash);
+ rpc_payment.amount = payment.second.m_amount;
+ rpc_payment.block_height = payment.second.m_block_height;
+ rpc_payment.unlock_time = payment.second.m_unlock_time;
+ res.payments.push_back(std::move(rpc_payment));
+ }
+
+ return true;
+ }
+
for (auto & payment_id_str : req.payment_ids)
{
crypto::hash payment_id;