fullnode-config no longer depends on src/
This commit is contained in:
@@ -11,10 +11,15 @@ homepage = "https://solana.com/"
|
||||
clap = "2.32.0"
|
||||
dirs = "1.0.2"
|
||||
log = "0.4.2"
|
||||
serde = "1.0.82"
|
||||
serde_derive = "1.0.82"
|
||||
serde_json = "1.0.10"
|
||||
solana = { path = "..", version = "0.11.0" }
|
||||
solana-logger = { path = "../logger", version = "0.11.0" }
|
||||
solana-netutil = { path = "../netutil", version = "0.11.0" }
|
||||
solana-sdk = { path = "../sdk", version = "0.11.0" }
|
||||
untrusted = "0.6.2"
|
||||
|
||||
[features]
|
||||
cuda = []
|
||||
|
||||
[lib]
|
||||
name = "solana_fullnode_config"
|
||||
|
48
fullnode-config/src/lib.rs
Normal file
48
fullnode-config/src/lib.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::signature::Keypair;
|
||||
use std::net::SocketAddr;
|
||||
use untrusted::Input;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct Config {
|
||||
/// Bind to port or address
|
||||
pub bind_port_or_address: Option<String>,
|
||||
|
||||
/// Detect public network address using public servers
|
||||
pub use_public_address: bool,
|
||||
|
||||
/// Detect network address from local machine configuration
|
||||
pub use_local_address: bool,
|
||||
|
||||
/// Fullnode identity
|
||||
pub identity_pkcs8: Vec<u8>,
|
||||
|
||||
/// Fullnode vote account
|
||||
pub vote_account_pkcs8: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn bind_addr(&self, default_port: u16) -> SocketAddr {
|
||||
let mut bind_addr =
|
||||
solana_netutil::parse_port_or_addr(&self.bind_port_or_address, default_port);
|
||||
if self.use_local_address {
|
||||
let ip = solana_netutil::get_ip_addr().unwrap();
|
||||
bind_addr.set_ip(ip);
|
||||
}
|
||||
if self.use_public_address {
|
||||
let ip = solana_netutil::get_public_ip_addr().unwrap();
|
||||
bind_addr.set_ip(ip);
|
||||
}
|
||||
bind_addr
|
||||
}
|
||||
|
||||
pub fn keypair(&self) -> Keypair {
|
||||
Keypair::from_pkcs8(Input::from(&self.identity_pkcs8))
|
||||
.expect("from_pkcs8 in fullnode::Config keypair")
|
||||
}
|
||||
pub fn vote_account_keypair(&self) -> Keypair {
|
||||
Keypair::from_pkcs8(Input::from(&self.vote_account_pkcs8))
|
||||
.expect("from_pkcs8 in fullnode::Config vote_account_keypair")
|
||||
}
|
||||
}
|
@@ -1,31 +1,18 @@
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
use dirs;
|
||||
|
||||
use serde_json;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use solana::cluster_info::FULLNODE_PORT_RANGE;
|
||||
use solana::fullnode::Config;
|
||||
|
||||
use solana::netutil::{get_ip_addr, get_public_ip_addr, parse_port_or_addr};
|
||||
use solana_sdk::signature::{gen_pkcs8, read_pkcs8};
|
||||
use std::io;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
fn main() {
|
||||
solana_logger::setup();
|
||||
let matches = App::new("fullnode-config")
|
||||
.version(crate_version!())
|
||||
let matches = clap::App::new("fullnode-config")
|
||||
.version(clap::crate_version!())
|
||||
.arg(
|
||||
Arg::with_name("local")
|
||||
clap::Arg::with_name("local")
|
||||
.short("l")
|
||||
.long("local")
|
||||
.takes_value(false)
|
||||
.help("Detect network address from local machine configuration"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("keypair")
|
||||
clap::Arg::with_name("keypair")
|
||||
.short("k")
|
||||
.long("keypair")
|
||||
.value_name("PATH")
|
||||
@@ -33,14 +20,14 @@ fn main() {
|
||||
.help("/path/to/id.json"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("public")
|
||||
clap::Arg::with_name("public")
|
||||
.short("p")
|
||||
.long("public")
|
||||
.takes_value(false)
|
||||
.help("Detect public network address using public servers"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("bind")
|
||||
clap::Arg::with_name("bind")
|
||||
.short("b")
|
||||
.long("bind")
|
||||
.value_name("PORT")
|
||||
@@ -49,19 +36,6 @@ fn main() {
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let bind_addr: SocketAddr = {
|
||||
let mut bind_addr = parse_port_or_addr(matches.value_of("bind"), FULLNODE_PORT_RANGE.0);
|
||||
if matches.is_present("local") {
|
||||
let ip = get_ip_addr().unwrap();
|
||||
bind_addr.set_ip(ip);
|
||||
}
|
||||
if matches.is_present("public") {
|
||||
let ip = get_public_ip_addr().unwrap();
|
||||
bind_addr.set_ip(ip);
|
||||
}
|
||||
bind_addr
|
||||
};
|
||||
|
||||
let mut path = dirs::home_dir().expect("home directory");
|
||||
let id_path = if matches.is_present("keypair") {
|
||||
matches.value_of("keypair").unwrap()
|
||||
@@ -69,13 +43,15 @@ fn main() {
|
||||
path.extend(&[".config", "solana", "id.json"]);
|
||||
path.to_str().unwrap()
|
||||
};
|
||||
let pkcs8 = read_pkcs8(id_path).expect("client keypair");
|
||||
|
||||
let vote_account_pkcs8 = gen_pkcs8().unwrap();
|
||||
let config = solana_fullnode_config::Config {
|
||||
bind_port_or_address: matches.value_of("bind").map(|s| s.to_string()),
|
||||
use_local_address: matches.is_present("local"),
|
||||
use_public_address: matches.is_present("public"),
|
||||
identity_pkcs8: read_pkcs8(id_path).expect("invalid keypair"),
|
||||
vote_account_pkcs8: gen_pkcs8().unwrap(),
|
||||
};
|
||||
|
||||
// we need all the receiving sockets to be bound within the expected
|
||||
// port range that we open on aws
|
||||
let config = Config::new(&bind_addr, pkcs8, vote_account_pkcs8);
|
||||
let stdout = io::stdout();
|
||||
serde_json::to_writer(stdout, &config).expect("serialize");
|
||||
}
|
||||
|
Reference in New Issue
Block a user