mirror of
https://github.com/creating2morrow/neveko.git
synced 2025-01-03 09:29:39 +00:00
fix incorrect proxy for remote nodes over i2p
This commit is contained in:
parent
582154c72c
commit
f50cb91842
5 changed files with 79 additions and 48 deletions
|
@ -26,7 +26,7 @@ NEVidebla-EKOnomia (invisible economy)
|
|||
* `git clone https://github.com/creating2morrow/neveko`
|
||||
* `cd neveko && ./scripts/build_all_and_run.sh "-- -h"`
|
||||
* Example to start neveko with remote stagenet node / i2p proxy remote for development:
|
||||
* `./scripts/build_all_and_run.sh "-- --monero-rpc-daemon xmr3kaacphwkk4z2gp35bdl47lrrnzimmyqj4oliauqrjzqecofa.b32.i2p --monero-location /path/to/monero-x86_64-linux-gnu-v0.18.2.2/ --i2p-proxy-host x.x.x.x:port --i2p-tunnels-json /path/to/manual-i2p/config/ --i2p-advanced`
|
||||
* `./scripts/build_all_and_run.sh "-- --monero-rpc-daemon http://xmr3kaacphwkk4z2gp35bdl47lrrnzimmyqj4oliauqrjzqecofa.b32.i2p:38081 --monero-location /path/to/monero-x86_64-linux-gnu-v0.18.2.2/ --i2p-proxy-host x.x.x.x:port --i2p-tunnels-json /path/to/manual-i2p/config/ --i2p-advanced --i2p-socks-proxy-host x.x.x.x:xxxx`
|
||||
* the `--monero-location` flag is needed even when using a remote node because
|
||||
neveko has its own monero-wallet-rpc instance
|
||||
* remote nodes are forced over the `--i2p-proxy-host`
|
||||
|
|
|
@ -113,6 +113,13 @@ pub struct Args {
|
|||
default_value = "http://localhost:4444"
|
||||
)]
|
||||
pub i2p_proxy_host: String,
|
||||
/// i2p wallet proxy host (i2p socks)
|
||||
#[arg(
|
||||
long,
|
||||
help = "i2p remote node socks proxy host",
|
||||
default_value = "http://localhost:9051"
|
||||
)]
|
||||
pub i2p_socks_proxy_host: String,
|
||||
/// Connect wallet rpc for a remote-node, WARNING: may harm privacy
|
||||
#[arg(
|
||||
long,
|
||||
|
@ -162,7 +169,7 @@ pub struct Args {
|
|||
default_value = "false"
|
||||
)]
|
||||
pub i2p_normal: bool,
|
||||
/// anonymous inbound port, must be localhost
|
||||
#[arg(long, help = "Set app marketplace admin port", default_value = "38089")]
|
||||
/// i2p anonymous inbound port
|
||||
#[arg(long, help = "Set i2p anon inbound connectivity", default_value = "38089")]
|
||||
pub anon_inbound_port: u16,
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ impl Default for Tunnels {
|
|||
///
|
||||
/// and attempts to extract the app and http proxy tunnel information.
|
||||
async fn find_tunnels() {
|
||||
let args = args::Args::parse();
|
||||
let app_port = utils::get_app_port();
|
||||
let file_path = format!(
|
||||
"/home/{}/.i2p-zero/config/tunnels.json",
|
||||
|
@ -76,7 +77,8 @@ async fn find_tunnels() {
|
|||
let tx_proxy_port = monero::get_daemon_port();
|
||||
let has_http_tunnel = contents.contains(&proxy_port);
|
||||
let has_tx_proxy_tunnel = contents.contains(&format!("{}", &tx_proxy_port));
|
||||
if !has_app_tunnel || !has_http_tunnel {
|
||||
let has_anon_inbound_tunnel = contents.contains(&format!("{}", args.anon_inbound_port));
|
||||
if !has_app_tunnel || !has_http_tunnel || !has_anon_inbound_tunnel {
|
||||
tokio::time::sleep(Duration::new(120, 0)).await;
|
||||
}
|
||||
if !has_app_tunnel {
|
||||
|
@ -87,6 +89,10 @@ async fn find_tunnels() {
|
|||
debug!("creating http tunnel");
|
||||
create_http_proxy();
|
||||
}
|
||||
if !has_anon_inbound_tunnel {
|
||||
debug!("creating anon inbound tunnel");
|
||||
create_anon_inbound_tunnel();
|
||||
}
|
||||
let env = utils::get_release_env();
|
||||
// only use tx proxy on mainnet
|
||||
if env == utils::ReleaseEnvironment::Production {
|
||||
|
@ -147,15 +153,31 @@ fn create_tx_proxy_tunnel() {
|
|||
let path = args.i2p_zero_dir;
|
||||
let output = Command::new(format!("{}/router/bin/tunnel-control.sh", path))
|
||||
.args([
|
||||
"server.create",
|
||||
"socks.create",
|
||||
"127.0.0.1",
|
||||
&format!("{}", monero::get_daemon_port()),
|
||||
&format!("{}", utils::get_i2p_wallet_proxy_host()),
|
||||
])
|
||||
.spawn()
|
||||
.expect("i2p-zero failed to create a tx proxy tunnel");
|
||||
debug!("{:?}", output.stdout);
|
||||
}
|
||||
|
||||
/// Create an i2p tunnel for the monero tx proxy
|
||||
fn create_anon_inbound_tunnel() {
|
||||
info!("creating monerod anon inbound 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([
|
||||
"server.create",
|
||||
"127.0.0.1",
|
||||
&format!("{}", args.anon_inbound_port),
|
||||
])
|
||||
.spawn()
|
||||
.expect("i2p-zero failed to create a anon inbound tunnel");
|
||||
debug!("{:?}", output.stdout);
|
||||
}
|
||||
|
||||
/// Extract i2p port from command line arg
|
||||
fn get_i2p_proxy_port() -> String {
|
||||
let proxy_host = utils::get_i2p_http_proxy();
|
||||
|
|
|
@ -149,8 +149,6 @@ impl LockTimeLimit {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO(c2m): make inbound connections for i2p tx proxy configurable
|
||||
|
||||
/// Start monerod from the -`-monero-location` flag
|
||||
///
|
||||
/// default: /home/$USER/monero-xxx-xxx
|
||||
|
@ -159,27 +157,23 @@ pub fn start_daemon() {
|
|||
let blockchain_dir = get_blockchain_dir();
|
||||
let bin_dir = get_monero_location();
|
||||
let release_env = utils::get_release_env();
|
||||
let tx_proxy = format!("i2p,{}", utils::get_i2p_http_proxy());
|
||||
let tx_proxy = format!("i2p,{}", utils::get_i2p_wallet_proxy_host());
|
||||
let port = get_anon_inbound_port();
|
||||
let destination = i2p::get_destination(Some(port));
|
||||
let anon_inbound = format!("{},127.0.0.1:{}", destination, port);
|
||||
let mut args = vec!["--data-dir", &blockchain_dir, "--detach"];
|
||||
if release_env == utils::ReleaseEnvironment::Development {
|
||||
let args = ["--data-dir", &blockchain_dir, "--stagenet", "--detach"];
|
||||
args.push("--stagenet");
|
||||
let output = Command::new(format!("{}/monerod", bin_dir))
|
||||
.args(args)
|
||||
.spawn()
|
||||
.expect("monerod failed to start");
|
||||
debug!("{:?}", output.stdout);
|
||||
} else {
|
||||
let args = [
|
||||
"--data-dir",
|
||||
&blockchain_dir,
|
||||
"--tx-proxy",
|
||||
&tx_proxy,
|
||||
"--anonymous-inbound",
|
||||
&anon_inbound,
|
||||
"--detach",
|
||||
];
|
||||
args.push("--tx-proxy");
|
||||
args.push(&tx_proxy);
|
||||
args.push("--anonymous-inbound");
|
||||
args.push(&anon_inbound);
|
||||
let output = Command::new(format!("{}/monerod", bin_dir))
|
||||
.args(args)
|
||||
.spawn()
|
||||
|
@ -197,61 +191,49 @@ pub fn start_rpc() {
|
|||
let login = get_rpc_creds();
|
||||
let daemon_address = cli_args.monero_rpc_daemon;
|
||||
let rpc_login = format!("{}:{}", &login.username, &login.credential);
|
||||
let mut wallet_dir = format!(
|
||||
"/home/{}/.neveko/stagenet/wallet/",
|
||||
std::env::var("USER").unwrap_or(String::from("user")),
|
||||
);
|
||||
let release_env = utils::get_release_env();
|
||||
let is_dev = release_env == utils::ReleaseEnvironment::Development;
|
||||
let wallet_path = if is_dev { ".neveko/stagenet/wallet/" } else { ".neveko/wallet/" };
|
||||
let wallet_dir = format!(
|
||||
"/home/{}/{}", std::env::var("USER").unwrap_or(String::from("user")), wallet_path
|
||||
);
|
||||
if cli_args.remote_node && !&daemon_address.contains(".i2p") {
|
||||
warn!("invalid i2p monero remote node detected");
|
||||
}
|
||||
// proxy host can't have protocol
|
||||
let mut proxy_host = utils::get_i2p_http_proxy();
|
||||
let mut proxy_host = utils::get_i2p_wallet_proxy_host();
|
||||
if proxy_host.contains("http://") {
|
||||
let values = proxy_host.split("http://");
|
||||
let mut v: Vec<String> = values.map(|s| String::from(s)).collect();
|
||||
proxy_host = v.remove(1);
|
||||
}
|
||||
if release_env == utils::ReleaseEnvironment::Development {
|
||||
let mut args = vec![
|
||||
let mut args = vec![
|
||||
"--rpc-bind-port",
|
||||
&port,
|
||||
"--wallet-dir",
|
||||
&wallet_dir,
|
||||
"--rpc-login",
|
||||
&rpc_login,
|
||||
"--daemon-address",
|
||||
&daemon_address,
|
||||
"--stagenet",
|
||||
];
|
||||
if cli_args.remote_node {
|
||||
args.push("--proxy");
|
||||
args.push(&proxy_host);
|
||||
args.push("--daemon-address");
|
||||
args.push(&daemon_address);
|
||||
args.push("--trusted-daemon");
|
||||
args.push("--daemon-ssl-allow-any-cert");
|
||||
} else {
|
||||
args.push("--daemon-address");
|
||||
args.push(&daemon_address);
|
||||
}
|
||||
if is_dev {
|
||||
args.push("--stagenet");
|
||||
let output = Command::new(format!("{}/monero-wallet-rpc", bin_dir))
|
||||
.args(args)
|
||||
.spawn()
|
||||
.expect("monero-wallet-rpc failed to start");
|
||||
debug!("{:?}", output.stdout);
|
||||
} else {
|
||||
wallet_dir = format!(
|
||||
"/home/{}/.neveko/wallet/",
|
||||
std::env::var("USER").unwrap_or(String::from("user")),
|
||||
);
|
||||
let mut args = vec![
|
||||
"--rpc-bind-port",
|
||||
&port,
|
||||
"--wallet-dir",
|
||||
&wallet_dir,
|
||||
"--rpc-login",
|
||||
&rpc_login,
|
||||
"--daemon-address",
|
||||
&daemon_address,
|
||||
];
|
||||
if cli_args.remote_node {
|
||||
args.push("--proxy");
|
||||
args.push(&proxy_host);
|
||||
}
|
||||
let output = Command::new(format!("{}/monero-wallet-rpc", bin_dir))
|
||||
.args(args)
|
||||
.spawn()
|
||||
|
@ -275,7 +257,7 @@ pub fn get_daemon_port() -> u16 {
|
|||
let rpc = String::from(args.monero_rpc_daemon);
|
||||
let values = rpc.split(":");
|
||||
let mut v: Vec<String> = values.map(|s| String::from(s)).collect();
|
||||
let port = if !args.remote_node { v.remove(2) } else { String::from("0") };
|
||||
let port = v.remove(2);
|
||||
debug!("monerod port: {}", port);
|
||||
match port.parse::<u16>() {
|
||||
Ok(p) => p,
|
||||
|
@ -283,6 +265,19 @@ pub fn get_daemon_port() -> u16 {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_tx_proxy_port() -> u16 {
|
||||
let args = args::Args::parse();
|
||||
let rpc = String::from(args.i2p_socks_proxy_host);
|
||||
let values = rpc.split(":");
|
||||
let mut v: Vec<String> = values.map(|s| String::from(s)).collect();
|
||||
let port = v.remove(2);
|
||||
debug!("i2p socks port: {}", port);
|
||||
match port.parse::<u16>() {
|
||||
Ok(p) => p,
|
||||
Err(_) => 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_anon_inbound_port() -> u16 {
|
||||
let args = args::Args::parse();
|
||||
args.anon_inbound_port
|
||||
|
|
|
@ -236,6 +236,13 @@ pub fn get_i2p_http_proxy() -> String {
|
|||
}
|
||||
}
|
||||
|
||||
/// wallet proxy host
|
||||
pub fn get_i2p_wallet_proxy_host() -> String {
|
||||
let args = args::Args::parse();
|
||||
args.i2p_socks_proxy_host
|
||||
}
|
||||
|
||||
|
||||
/// app auth port
|
||||
pub fn get_app_auth_port() -> u16 {
|
||||
let args = args::Args::parse();
|
||||
|
|
Loading…
Reference in a new issue