2018-07-09 18:04:49 -07:00
|
|
|
extern crate clap;
|
2018-05-31 14:45:03 -07:00
|
|
|
extern crate serde_json;
|
|
|
|
extern crate solana;
|
|
|
|
|
2018-07-09 18:04:49 -07:00
|
|
|
use clap::{App, Arg};
|
2018-07-05 12:01:40 -07:00
|
|
|
use solana::crdt::{get_ip_addr, parse_port_or_addr};
|
|
|
|
use solana::fullnode::Config;
|
2018-06-29 16:49:23 -07:00
|
|
|
use solana::nat::get_public_ip_addr;
|
2018-07-12 16:26:56 -07:00
|
|
|
use solana::signature::read_pkcs8;
|
|
|
|
use std::env;
|
2018-05-31 14:45:03 -07:00
|
|
|
use std::io;
|
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
|
|
|
fn main() {
|
2018-07-09 18:04:49 -07:00
|
|
|
let matches = App::new("fullnode-config")
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("local")
|
|
|
|
.short("l")
|
|
|
|
.long("local")
|
|
|
|
.takes_value(false)
|
|
|
|
.help("detect network address from local machine configuration"),
|
|
|
|
)
|
2018-07-12 16:26:56 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("keypair")
|
|
|
|
.short("k")
|
|
|
|
.long("keypair")
|
|
|
|
.value_name("PATH")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("/path/to/id.json"),
|
|
|
|
)
|
2018-07-09 18:04:49 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("public")
|
|
|
|
.short("p")
|
|
|
|
.long("public")
|
|
|
|
.takes_value(false)
|
|
|
|
.help("detect public network address using public servers"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("bind")
|
|
|
|
.short("b")
|
|
|
|
.long("bind")
|
|
|
|
.value_name("PORT")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("bind to port or address"),
|
|
|
|
)
|
|
|
|
.get_matches();
|
2018-05-31 14:45:03 -07:00
|
|
|
|
|
|
|
let bind_addr: SocketAddr = {
|
2018-07-09 18:04:49 -07:00
|
|
|
let mut bind_addr = parse_port_or_addr({
|
|
|
|
if let Some(b) = matches.value_of("bind") {
|
|
|
|
Some(b.to_string())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if matches.is_present("local") {
|
2018-05-31 14:45:03 -07:00
|
|
|
let ip = get_ip_addr().unwrap();
|
|
|
|
bind_addr.set_ip(ip);
|
|
|
|
}
|
2018-07-09 18:04:49 -07:00
|
|
|
if matches.is_present("public") {
|
2018-06-29 16:49:23 -07:00
|
|
|
let ip = get_public_ip_addr().unwrap();
|
|
|
|
bind_addr.set_ip(ip);
|
|
|
|
}
|
2018-05-31 14:45:03 -07:00
|
|
|
bind_addr
|
|
|
|
};
|
|
|
|
|
2018-07-12 16:26:56 -07:00
|
|
|
let mut path = env::home_dir().expect("home directory");
|
|
|
|
let id_path = if matches.is_present("keypair") {
|
|
|
|
matches.value_of("keypair").unwrap()
|
|
|
|
} else {
|
|
|
|
path.extend(&[".config", "solana", "id.json"]);
|
|
|
|
path.to_str().unwrap()
|
|
|
|
};
|
|
|
|
let pkcs8 = read_pkcs8(id_path).expect("client keypair");
|
|
|
|
|
2018-05-31 14:45:03 -07:00
|
|
|
// we need all the receiving sockets to be bound within the expected
|
|
|
|
// port range that we open on aws
|
2018-07-12 16:26:56 -07:00
|
|
|
let config = Config::new(&bind_addr, pkcs8);
|
2018-05-31 14:45:03 -07:00
|
|
|
let stdout = io::stdout();
|
2018-07-05 12:01:40 -07:00
|
|
|
serde_json::to_writer(stdout, &config).expect("serialize");
|
2018-05-31 14:45:03 -07:00
|
|
|
}
|