forked from lthn/blockchain
changes in protocol for relayin over tor
This commit is contained in:
parent
3ca1485646
commit
7f82a13e62
3 changed files with 84 additions and 26 deletions
|
|
@ -174,6 +174,34 @@ namespace currency
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/************************************************************************/
|
||||
struct INVOKE_NEW_TRANSACTION
|
||||
{
|
||||
const static int ID = BC_COMMANDS_POOL_BASE + 8;
|
||||
|
||||
struct request
|
||||
{
|
||||
blobdata tx;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(tx)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
std::string code;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(code)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include "currency_protocol_defs_print.h"
|
||||
|
|
|
|||
|
|
@ -57,7 +57,8 @@ namespace tools
|
|||
m_minimum_height(WALLET_MINIMUM_HEIGHT_UNSET_CONST),
|
||||
m_pos_mint_packing_size(WALLET_DEFAULT_POS_MINT_PACKING_SIZE),
|
||||
m_current_wallet_file_size(0),
|
||||
m_use_deffered_global_outputs(false)
|
||||
m_use_deffered_global_outputs(false),
|
||||
m_disable_tor_relay(false)
|
||||
{
|
||||
m_core_runtime_config = currency::get_default_core_runtime_config();
|
||||
}
|
||||
|
|
@ -4586,39 +4587,60 @@ uint64_t wallet2::get_needed_money(uint64_t fee, const std::vector<currency::tx_
|
|||
}
|
||||
return needed_money;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------
|
||||
void wallet2::set_disable_tor_relay(bool disable)
|
||||
{
|
||||
m_disable_tor_relay = disable;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------
|
||||
void wallet2::notify_state_change(const std::string& state_code, const std::string& details)
|
||||
{
|
||||
m_wcallback->on_tor_status_change(state_code);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------
|
||||
void wallet2::send_transaction_to_network(const transaction& tx)
|
||||
{
|
||||
#define ENABLE_TOR_RELAY
|
||||
#ifdef ENABLE_TOR_RELAY
|
||||
//TODO check that core synchronized
|
||||
//epee::net_utils::levin_client2 p2p_client;
|
||||
tools::levin_over_tor_client p2p_client;
|
||||
if (!p2p_client.connect("144.76.183.143", 2121, 10000))
|
||||
// if (!p2p_client.connect("144.76.183.143", 1001, 10000))
|
||||
if (!m_disable_tor_relay)
|
||||
{
|
||||
THROW_IF_FALSE_WALLET_EX(false, error::no_connection_to_daemon, "Failed to connect to TOR node");
|
||||
//TODO check that core synchronized
|
||||
//epee::net_utils::levin_client2 p2p_client;
|
||||
|
||||
//make few attempts
|
||||
tools::levin_over_tor_client p2p_client;
|
||||
p2p_client.get_transport().set_notifier(this);
|
||||
for (size_t i = 0; i != 3; i++)
|
||||
{
|
||||
if (!p2p_client.connect("144.76.183.143", 2121, 10000))
|
||||
{
|
||||
continue;//THROW_IF_FALSE_WALLET_EX(false, error::no_connection_to_daemon, "Failed to connect to TOR node");
|
||||
}
|
||||
currency::NOTIFY_NEW_TRANSACTIONS::request p2p_req = AUTO_VAL_INIT(p2p_req);
|
||||
p2p_req.txs.push_back(t_serializable_object_to_blob(tx));
|
||||
std::string blob;
|
||||
epee::serialization::store_t_to_binary(p2p_req, blob);
|
||||
p2p_client.notify(NOTIFY_NEW_TRANSACTIONS::ID, blob);
|
||||
p2p_client.disconnect();
|
||||
|
||||
//checking if transaction got relayed
|
||||
//return;
|
||||
}
|
||||
}
|
||||
currency::NOTIFY_NEW_TRANSACTIONS::request p2p_req = AUTO_VAL_INIT(p2p_req);
|
||||
p2p_req.txs.push_back(t_serializable_object_to_blob(tx));
|
||||
std::string blob;
|
||||
epee::serialization::store_t_to_binary(p2p_req, blob);
|
||||
else
|
||||
{
|
||||
COMMAND_RPC_SEND_RAW_TX::request req;
|
||||
req.tx_as_hex = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(tx));
|
||||
COMMAND_RPC_SEND_RAW_TX::response daemon_send_resp;
|
||||
bool r = m_core_proxy->call_COMMAND_RPC_SEND_RAW_TX(req, daemon_send_resp);
|
||||
THROW_IF_TRUE_WALLET_EX(!r, error::no_connection_to_daemon, "sendrawtransaction");
|
||||
THROW_IF_TRUE_WALLET_EX(daemon_send_resp.status == API_RETURN_CODE_BUSY, error::daemon_busy, "sendrawtransaction");
|
||||
THROW_IF_TRUE_WALLET_EX(daemon_send_resp.status == API_RETURN_CODE_DISCONNECTED, error::no_connection_to_daemon, "Transfer attempt while daemon offline");
|
||||
THROW_IF_TRUE_WALLET_EX(daemon_send_resp.status != API_RETURN_CODE_OK, error::tx_rejected, tx, daemon_send_resp.status);
|
||||
|
||||
p2p_client.notify(NOTIFY_NEW_TRANSACTIONS::ID, blob);
|
||||
p2p_client.disconnect();
|
||||
return;
|
||||
WLT_LOG_L2("transaction " << get_transaction_hash(tx) << " generated ok and sent to daemon:" << ENDL << currency::obj_to_json_str(tx));
|
||||
}
|
||||
#endif //
|
||||
COMMAND_RPC_SEND_RAW_TX::request req;
|
||||
req.tx_as_hex = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(tx));
|
||||
COMMAND_RPC_SEND_RAW_TX::response daemon_send_resp;
|
||||
bool r = m_core_proxy->call_COMMAND_RPC_SEND_RAW_TX(req, daemon_send_resp);
|
||||
THROW_IF_TRUE_WALLET_EX(!r, error::no_connection_to_daemon, "sendrawtransaction");
|
||||
THROW_IF_TRUE_WALLET_EX(daemon_send_resp.status == API_RETURN_CODE_BUSY, error::daemon_busy, "sendrawtransaction");
|
||||
THROW_IF_TRUE_WALLET_EX(daemon_send_resp.status == API_RETURN_CODE_DISCONNECTED, error::no_connection_to_daemon, "Transfer attempt while daemon offline");
|
||||
THROW_IF_TRUE_WALLET_EX(daemon_send_resp.status != API_RETURN_CODE_OK, error::tx_rejected, tx, daemon_send_resp.status);
|
||||
|
||||
WLT_LOG_L2("transaction " << get_transaction_hash(tx) << " generated ok and sent to daemon:" << ENDL << currency::obj_to_json_str(tx));
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------
|
||||
void wallet2::add_sent_tx_detailed_info(const transaction& tx,
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ namespace tools
|
|||
virtual void on_sync_progress(const uint64_t& /*percents*/) {}
|
||||
virtual void on_transfer_canceled(const wallet_public::wallet_transfer_info& wti) {}
|
||||
virtual void on_message(message_severity /*severity*/, const std::string& /*m*/) {}
|
||||
virtual void on_tor_status_change(const std::string& state) {}
|
||||
};
|
||||
|
||||
struct tx_dust_policy
|
||||
|
|
@ -338,7 +339,7 @@ namespace tools
|
|||
// END_SERIALIZE()
|
||||
// };
|
||||
|
||||
class wallet2
|
||||
class wallet2: public tools::tor::t_transport_state_notifier
|
||||
{
|
||||
wallet2(const wallet2&) = delete;
|
||||
public:
|
||||
|
|
@ -861,6 +862,7 @@ namespace tools
|
|||
uint64_t get_wallet_file_size()const;
|
||||
void set_use_deffered_global_outputs(bool use);
|
||||
construct_tx_param get_default_construct_tx_param_inital();
|
||||
void set_disable_tor_relay(bool disable);
|
||||
|
||||
void export_transaction_history(std::ostream& ss, const std::string& format, bool include_pos_transactions = true);
|
||||
|
||||
|
|
@ -876,6 +878,11 @@ namespace tools
|
|||
bool check_htlc_redeemed(const crypto::hash& htlc_tx_id, std::string& origin, crypto::hash& redeem_tx_id);
|
||||
private:
|
||||
|
||||
// -------- t_transport_state_notifier ------------------------------------------------
|
||||
virtual void notify_state_change(const std::string& state_code, const std::string& details = std::string());
|
||||
// ------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void add_transfers_to_expiration_list(const std::vector<uint64_t>& selected_transfers, uint64_t expiration, uint64_t change_amount, const crypto::hash& related_tx_id);
|
||||
void remove_transfer_from_expiration_list(uint64_t transfer_index);
|
||||
void load_keys(const std::string& keys_file_name, const std::string& password, uint64_t file_signature, keys_file_data& kf_data);
|
||||
|
|
@ -1060,6 +1067,7 @@ private:
|
|||
|
||||
mutable uint64_t m_current_wallet_file_size;
|
||||
bool m_use_deffered_global_outputs;
|
||||
bool m_disable_tor_relay;
|
||||
//this needed to access wallets state in coretests, for creating abnormal blocks and tranmsactions
|
||||
friend class test_generator;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue