mirror of
https://github.com/creating2morrow/neveko.git
synced 2024-12-22 11:39:22 +00:00
patches for socks on startup and proxy from gui
This commit is contained in:
parent
fc3524ed76
commit
c5bd5c407f
4 changed files with 180 additions and 13 deletions
|
@ -94,7 +94,7 @@ async fn find_tunnels() {
|
|||
}
|
||||
if !has_socks_proxy_tunnel {
|
||||
debug!("creating socks proxy tunnel");
|
||||
create_tx_proxy_tunnel();
|
||||
create_socks_proxy_tunnel();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,14 +142,13 @@ fn create_tunnel() {
|
|||
}
|
||||
|
||||
/// Create an i2p tunnel for the monero wallet socks proxy
|
||||
fn create_tx_proxy_tunnel() {
|
||||
fn create_socks_proxy_tunnel() {
|
||||
info!("creating monerod socks proxy tunnel");
|
||||
let args = args::Args::parse();
|
||||
let path = args.i2p_zero_dir;
|
||||
let output = Command::new(format!("{}/router/bin/tunnel-control.sh", path))
|
||||
.args([
|
||||
"socks.create",
|
||||
"127.0.0.1",
|
||||
&format!("{}", get_i2p_socks_proxy_port()),
|
||||
])
|
||||
.spawn()
|
||||
|
|
|
@ -46,6 +46,13 @@ pub const NEVEKO_I2P_PROXY_HOST: &str = "NEVEKO_I2P_PROXY_HOST";
|
|||
pub const NEVEKO_I2P_TUNNELS_JSON: &str = "NEVEKO_I2P_TUNNELS_JSON";
|
||||
/// Environment variable for I2P advanced mode
|
||||
pub const NEVEKO_I2P_ADVANCED_MODE: &str = "NEVEKO_I2P_ADVANCED_MODE";
|
||||
/// Environment variable for I2P advanced mode
|
||||
pub const MONERO_DAEMON_HOST: &str = "MONERO_DAEMON_HOST";
|
||||
/// Environment variable for I2P advanced mode
|
||||
pub const MONERO_WALLET_RPC_HOST: &str = "MONERO_WALLET_RPC_HOST";
|
||||
/// Reference to check if gui set remote node flag
|
||||
pub const GUI_REMOTE_NODE: &str = "GUI_REMOTE_NODE";
|
||||
pub const GUI_SET_REMOTE_NODE: &str = "1";
|
||||
|
||||
/// The latest monero release download
|
||||
pub const MONERO_RELEASE_VERSION: &str = "monero-linux-x64-v0.18.2.2.tar.bz2";
|
||||
|
|
|
@ -13,7 +13,7 @@ use log::{
|
|||
info,
|
||||
warn,
|
||||
};
|
||||
use std::process::Command;
|
||||
use std::{process::Command, error::Error};
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use std::sync::Mutex;
|
||||
|
@ -311,7 +311,12 @@ fn get_monero_location() -> String {
|
|||
/// Get monero rpc host from the `--monero-rpc-host` cli arg
|
||||
fn get_rpc_host() -> String {
|
||||
let args = args::Args::parse();
|
||||
let rpc = String::from(args.monero_rpc_host);
|
||||
let gui_host = std::env::var(crate::MONERO_WALLET_RPC_HOST).unwrap_or(utils::empty_string());
|
||||
let rpc = if gui_host == utils::empty_string() {
|
||||
String::from(args.monero_rpc_host)
|
||||
} else {
|
||||
gui_host
|
||||
};
|
||||
format!("{}/json_rpc", rpc)
|
||||
}
|
||||
|
||||
|
@ -328,7 +333,12 @@ fn get_rpc_creds() -> RpcLogin {
|
|||
|
||||
fn get_rpc_daemon() -> String {
|
||||
let args = args::Args::parse();
|
||||
let daemon = String::from(args.monero_rpc_daemon);
|
||||
let gui_host = std::env::var(crate::MONERO_DAEMON_HOST).unwrap_or(utils::empty_string());
|
||||
let daemon = if gui_host == utils::empty_string() {
|
||||
String::from(args.monero_rpc_daemon)
|
||||
} else {
|
||||
gui_host
|
||||
};
|
||||
format!("{}/json_rpc", daemon)
|
||||
}
|
||||
|
||||
|
@ -1143,6 +1153,7 @@ pub async fn create_address() -> reqres::XmrRpcCreateAddressResponse {
|
|||
|
||||
// Daemon requests
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
/// Performs the xmr daemon 'get_info' method
|
||||
pub async fn get_info() -> reqres::XmrDaemonGetInfoResponse {
|
||||
info!("fetching daemon info");
|
||||
|
@ -1166,6 +1177,31 @@ pub async fn get_info() -> reqres::XmrDaemonGetInfoResponse {
|
|||
}
|
||||
}
|
||||
|
||||
/// Performs the xmr daemon 'get_info' method
|
||||
pub async fn p_get_info() -> Result<reqres::XmrDaemonGetInfoResponse, Box<dyn Error>> {
|
||||
info!("fetching proxy daemon info");
|
||||
let host = utils::get_i2p_http_proxy();
|
||||
let proxy = reqwest::Proxy::http(&host)?;
|
||||
let client = reqwest::Client::builder().proxy(proxy).build();
|
||||
let host = get_rpc_daemon();
|
||||
let req = reqres::XmrRpcRequest {
|
||||
jsonrpc: DaemonFields::Version.value(),
|
||||
id: DaemonFields::Id.value(),
|
||||
method: DaemonFields::GetInfo.value(),
|
||||
};
|
||||
match client?.post(host).json(&req).send().await {
|
||||
Ok(response) => {
|
||||
let res = response.json::<reqres::XmrDaemonGetInfoResponse>().await;
|
||||
// add debug log here if needed for adding more info to home screen in gui
|
||||
match res {
|
||||
Ok(res) => Ok(res),
|
||||
_ => Ok(Default::default()),
|
||||
}
|
||||
}
|
||||
Err(_) => Ok(Default::default()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Performs the xmr daemon 'get_height' method
|
||||
pub async fn get_height() -> reqres::XmrDaemonGetHeightResponse {
|
||||
info!("fetching daemon height");
|
||||
|
@ -1186,6 +1222,28 @@ pub async fn get_height() -> reqres::XmrDaemonGetHeightResponse {
|
|||
}
|
||||
}
|
||||
|
||||
/// Performs the xmr daemon 'get_height' method for remote daemon
|
||||
pub async fn p_get_height() -> Result<reqres::XmrDaemonGetHeightResponse, Box<dyn Error>> {
|
||||
info!("fetching proxy daemon height");
|
||||
let host = utils::get_i2p_http_proxy();
|
||||
let proxy = reqwest::Proxy::http(&host)?;
|
||||
let client = reqwest::Client::builder().proxy(proxy).build();
|
||||
let args = args::Args::parse();
|
||||
let daemon = String::from(args.monero_rpc_daemon);
|
||||
let req = format!("{}/{}", daemon, DaemonFields::GetHeight.value());
|
||||
match client?.post(req).send().await {
|
||||
Ok(response) => {
|
||||
let res = response.json::<reqres::XmrDaemonGetHeightResponse>().await;
|
||||
// don't log this one. The fee estimator blows up logs (T_T)
|
||||
match res {
|
||||
Ok(res) => Ok(res),
|
||||
_ => Ok(Default::default()),
|
||||
}
|
||||
}
|
||||
Err(_) => Ok(Default::default()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Performs the xmr daemon 'get_block' method
|
||||
pub async fn get_block(height: u64) -> reqres::XmrDaemonGetBlockResponse {
|
||||
info!("fetching block at height: {}", height);
|
||||
|
@ -1211,6 +1269,33 @@ pub async fn get_block(height: u64) -> reqres::XmrDaemonGetBlockResponse {
|
|||
}
|
||||
}
|
||||
|
||||
/// Performs the xmr daemon 'get_block' method for remone daemon
|
||||
pub async fn p_get_block(height: u64) -> Result<reqres::XmrDaemonGetBlockResponse, Box<dyn Error>> {
|
||||
info!("fetching proxy block at height: {}", height);
|
||||
let host = utils::get_i2p_http_proxy();
|
||||
let proxy = reqwest::Proxy::http(&host)?;
|
||||
let client = reqwest::Client::builder().proxy(proxy).build();
|
||||
let host = get_rpc_daemon();
|
||||
let params: reqres::XmrDaemonGetBlockParams = reqres::XmrDaemonGetBlockParams { height };
|
||||
let req = reqres::XmrDaemonGetBlockRequest {
|
||||
jsonrpc: DaemonFields::Version.value(),
|
||||
id: DaemonFields::Id.value(),
|
||||
method: DaemonFields::GetBlock.value(),
|
||||
params,
|
||||
};
|
||||
match client?.post(host).json(&req).send().await {
|
||||
Ok(response) => {
|
||||
let res = response.json::<reqres::XmrDaemonGetBlockResponse>().await;
|
||||
// don't log this one. The fee estimator blows up logs (T_T)
|
||||
match res {
|
||||
Ok(res) => Ok(res),
|
||||
_ => Ok(Default::default()),
|
||||
}
|
||||
}
|
||||
Err(_) => Ok(Default::default()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Performs the xmr daemon 'get_transactions' method
|
||||
pub async fn get_transactions(txs_hashes: Vec<String>) -> reqres::XmrDaemonGetTransactionsResponse {
|
||||
info!("fetching {} transactions", txs_hashes.len());
|
||||
|
@ -1236,3 +1321,31 @@ pub async fn get_transactions(txs_hashes: Vec<String>) -> reqres::XmrDaemonGetTr
|
|||
Err(_) => Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Performs the xmr daemon 'get_transactions' method for remote daemon
|
||||
pub async fn p_get_transactions(txs_hashes: Vec<String>) -> Result<reqres::XmrDaemonGetTransactionsResponse, Box<dyn Error>> {
|
||||
info!("fetching {} transactions", txs_hashes.len());
|
||||
let host = utils::get_i2p_http_proxy();
|
||||
let proxy = reqwest::Proxy::http(&host)?;
|
||||
let client = reqwest::Client::builder().proxy(proxy).build();
|
||||
let args = args::Args::parse();
|
||||
let daemon = String::from(args.monero_rpc_daemon);
|
||||
let url = format!("{}/{}", daemon, DaemonFields::GetTransactions.value());
|
||||
let req = reqres::XmrDaemonGetTransactionsRequest {
|
||||
txs_hashes,
|
||||
decode_as_json: true,
|
||||
};
|
||||
match client?.post(url).json(&req).send().await {
|
||||
Ok(response) => {
|
||||
let res = response
|
||||
.json::<reqres::XmrDaemonGetTransactionsResponse>()
|
||||
.await;
|
||||
// don't log this one. The fee estimator blows up logs (T_T)
|
||||
match res {
|
||||
Ok(res) => Ok(res),
|
||||
_ => Ok(Default::default()),
|
||||
}
|
||||
}
|
||||
Err(_) => Ok(Default::default()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,6 +88,7 @@ pub struct Connections {
|
|||
pub blockchain_dir: String,
|
||||
pub daemon_host: String,
|
||||
pub i2p_proxy_host: String,
|
||||
pub i2p_socks_host: String,
|
||||
/// path to manually created tunnels json
|
||||
pub i2p_tunnels_json: String,
|
||||
pub i2p_zero_dir: String,
|
||||
|
@ -104,8 +105,9 @@ impl Default for Connections {
|
|||
fn default() -> Self {
|
||||
Connections {
|
||||
blockchain_dir: String::from("/home/user/.bitmonero"),
|
||||
daemon_host: String::from("http://localhost:38081"),
|
||||
i2p_proxy_host: String::from("http://localhost:4444"),
|
||||
daemon_host: String::from("http://127.0.0.1:38081"),
|
||||
i2p_proxy_host: String::from("http://127.0.0.1:4444"),
|
||||
i2p_socks_host: String::from("http://127.0.0.1:9051"),
|
||||
i2p_tunnels_json: String::from("/home/user/neveko/i2p-manual"),
|
||||
i2p_zero_dir: String::from("/home/user/i2p-zero-linux.v1.21"),
|
||||
is_remote_node: false,
|
||||
|
@ -114,7 +116,7 @@ impl Default for Connections {
|
|||
monero_location: String::from("/home/user/monero-x86_64-linux-gnu-v0.18.2.2"),
|
||||
rpc_credential: String::from("pass"),
|
||||
rpc_username: String::from("user"),
|
||||
rpc_host: String::from("http://localhost:38083"),
|
||||
rpc_host: String::from("http://127.0.0.1:38083"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +185,35 @@ pub fn start_core(conn: &Connections) {
|
|||
i2p_advanced,
|
||||
"--i2p-proxy-host",
|
||||
&conn.i2p_proxy_host,
|
||||
"--i2p-socks-proxy-host",
|
||||
&conn.i2p_socks_host,
|
||||
];
|
||||
if conn.is_i2p_advanced {
|
||||
// set the i2p proxy host for advanced user re-use
|
||||
std::env::set_var(
|
||||
crate::NEVEKO_I2P_PROXY_HOST,
|
||||
&conn.i2p_proxy_host.clone(),
|
||||
);
|
||||
std::env::set_var(
|
||||
crate::NEVEKO_I2P_TUNNELS_JSON,
|
||||
&conn.i2p_tunnels_json.clone(),
|
||||
);
|
||||
std::env::set_var(crate::NEVEKO_I2P_ADVANCED_MODE, String::from("1"));
|
||||
}
|
||||
if conn.is_remote_node {
|
||||
std::env::set_var(
|
||||
crate::MONERO_DAEMON_HOST,
|
||||
&conn.daemon_host.clone(),
|
||||
);
|
||||
std::env::set_var(
|
||||
crate::MONERO_WALLET_RPC_HOST,
|
||||
&conn.rpc_host.clone(),
|
||||
);
|
||||
std::env::set_var(
|
||||
crate::GUI_REMOTE_NODE,
|
||||
crate::GUI_SET_REMOTE_NODE,
|
||||
)
|
||||
}
|
||||
let output = std::process::Command::new("./neveko")
|
||||
.args(args)
|
||||
.spawn()
|
||||
|
@ -715,17 +745,35 @@ pub async fn estimate_fee() -> u128 {
|
|||
if v_fee.len() >= 30 {
|
||||
break;
|
||||
}
|
||||
let r_height = monero::get_height().await;
|
||||
let mut r_height: reqres::XmrDaemonGetHeightResponse = Default::default();
|
||||
let remote_var = std::env::var(crate::GUI_REMOTE_NODE).unwrap_or(utils::empty_string());
|
||||
if remote_var == String::from(crate::GUI_SET_REMOTE_NODE) {
|
||||
let p_height = monero::p_get_height().await;
|
||||
r_height = p_height.unwrap_or(r_height);
|
||||
} else {
|
||||
r_height = monero::get_height().await;
|
||||
}
|
||||
if r_height.height == ESTIMATE_FEE_FAILURE as u64 {
|
||||
error!("error fetching height");
|
||||
return ESTIMATE_FEE_FAILURE;
|
||||
}
|
||||
height = r_height.height - count;
|
||||
let block = monero::get_block(height).await;
|
||||
let mut block: reqres::XmrDaemonGetBlockResponse = Default::default();
|
||||
if remote_var == String::from(crate::GUI_SET_REMOTE_NODE) {
|
||||
let p_block = monero::p_get_block(height).await;
|
||||
block = p_block.unwrap_or(block);
|
||||
} else {
|
||||
block = monero::get_block(height).await;
|
||||
}
|
||||
if block.result.block_header.num_txes > 0 {
|
||||
debug!("fetching {} txs", block.result.block_header.num_txes);
|
||||
let tx_hashes: Option<Vec<String>> = block.result.tx_hashes;
|
||||
let transactions = monero::get_transactions(tx_hashes.unwrap()).await;
|
||||
let mut transactions: reqres::XmrDaemonGetTransactionsResponse = Default::default();
|
||||
if remote_var == String::from(crate::GUI_SET_REMOTE_NODE) {
|
||||
let p_txs = monero::p_get_transactions(tx_hashes.unwrap()).await;
|
||||
transactions = p_txs.unwrap_or(transactions);
|
||||
} else {
|
||||
transactions = monero::get_transactions(tx_hashes.unwrap()).await;
|
||||
}
|
||||
for tx in transactions.txs_as_json {
|
||||
let pre_fee_split = tx.split("txnFee\":");
|
||||
let mut v1: Vec<String> = pre_fee_split.map(|s| String::from(s)).collect();
|
||||
|
|
Loading…
Reference in a new issue