Synchronous UPnP.
This commit is contained in:
parent
39d5b68785
commit
637ca97dc6
@ -90,7 +90,6 @@ fn setup_log(init: &str) {
|
|||||||
builder.init().unwrap();
|
builder.init().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(feature = "rpc")]
|
#[cfg(feature = "rpc")]
|
||||||
fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>, url: &str) {
|
fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>, url: &str) {
|
||||||
use rpc::v1::*;
|
use rpc::v1::*;
|
||||||
@ -107,18 +106,8 @@ fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>, url: &str) {
|
|||||||
fn setup_rpc_server(_client: Arc<Client>, _sync: Arc<EthSync>, _url: &str) {
|
fn setup_rpc_server(_client: Arc<Client>, _sync: Arc<EthSync>, _url: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Configuration {
|
fn print_version() {
|
||||||
args: Args
|
println!("\
|
||||||
}
|
|
||||||
impl Configuration {
|
|
||||||
fn parse() -> Self {
|
|
||||||
Configuration {
|
|
||||||
args: Args::docopt().decode().unwrap_or_else(|e| e.exit())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_version(&self) {
|
|
||||||
println!("\
|
|
||||||
Parity version {} ({}-{}-{})
|
Parity version {} ({}-{}-{})
|
||||||
Copyright 2015, 2016 Ethcore (UK) Limited
|
Copyright 2015, 2016 Ethcore (UK) Limited
|
||||||
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
|
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
|
||||||
@ -127,6 +116,17 @@ There is NO WARRANTY, to the extent permitted by law.
|
|||||||
|
|
||||||
By Wood/Paronyan/Kotewicz/Drwięga/Volf.\
|
By Wood/Paronyan/Kotewicz/Drwięga/Volf.\
|
||||||
", env!("CARGO_PKG_VERSION"), Target::arch(), Target::env(), Target::os());
|
", env!("CARGO_PKG_VERSION"), Target::arch(), Target::env(), Target::os());
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Configuration {
|
||||||
|
args: Args
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Configuration {
|
||||||
|
fn parse() -> Self {
|
||||||
|
Configuration {
|
||||||
|
args: Args::docopt().decode().unwrap_or_else(|e| e.exit())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_spec(&self) -> Spec {
|
fn get_spec(&self) -> Spec {
|
||||||
@ -179,7 +179,7 @@ fn wait_for_exit(client_service: &ClientService) {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let conf = Configuration::parse();
|
let conf = Configuration::parse();
|
||||||
if conf.args.flag_version {
|
if conf.args.flag_version {
|
||||||
conf.print_version();
|
print_version();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,10 +191,10 @@ fn main() {
|
|||||||
unsafe { ::fdlimit::raise_fd_limit(); }
|
unsafe { ::fdlimit::raise_fd_limit(); }
|
||||||
|
|
||||||
// Configure network
|
// Configure network
|
||||||
let init_nodes = conf.get_init_nodes(&spec);
|
|
||||||
let (listen, public) = conf.get_net_addresses();
|
|
||||||
let mut net_settings = NetworkConfiguration::new();
|
let mut net_settings = NetworkConfiguration::new();
|
||||||
net_settings.boot_nodes = init_nodes;
|
net_settings.nat_enabled = conf.args.flag_upnp;
|
||||||
|
net_settings.boot_nodes = conf.get_init_nodes(&spec);
|
||||||
|
let (listen, public) = conf.get_net_addresses();
|
||||||
net_settings.listen_address = listen;
|
net_settings.listen_address = listen;
|
||||||
net_settings.public_address = public;
|
net_settings.public_address = public;
|
||||||
|
|
||||||
|
@ -29,3 +29,4 @@ serde = "0.6.7"
|
|||||||
clippy = "0.0.37"
|
clippy = "0.0.37"
|
||||||
json-tests = { path = "json-tests" }
|
json-tests = { path = "json-tests" }
|
||||||
target_info = "0.1.0"
|
target_info = "0.1.0"
|
||||||
|
igd = "0.4.2"
|
||||||
|
@ -100,6 +100,7 @@ extern crate crossbeam;
|
|||||||
extern crate serde;
|
extern crate serde;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log as rlog;
|
extern crate log as rlog;
|
||||||
|
extern crate igd;
|
||||||
|
|
||||||
pub mod standard;
|
pub mod standard;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::net::{SocketAddr};
|
use std::net::{SocketAddr, SocketAddrV4};
|
||||||
use std::collections::{HashMap};
|
use std::collections::{HashMap};
|
||||||
use std::hash::{Hasher};
|
use std::hash::{Hasher};
|
||||||
use std::str::{FromStr};
|
use std::str::{FromStr};
|
||||||
@ -36,6 +36,7 @@ use network::NetworkProtocolHandler;
|
|||||||
use network::node::*;
|
use network::node::*;
|
||||||
use network::stats::NetworkStats;
|
use network::stats::NetworkStats;
|
||||||
use network::error::DisconnectReason;
|
use network::error::DisconnectReason;
|
||||||
|
use igd::{PortMappingProtocol,search_gateway};
|
||||||
|
|
||||||
type Slab<T> = ::slab::Slab<T, usize>;
|
type Slab<T> = ::slab::Slab<T, usize>;
|
||||||
|
|
||||||
@ -89,11 +90,27 @@ impl NetworkConfiguration {
|
|||||||
|
|
||||||
/// Conduct NAT if needed.
|
/// Conduct NAT if needed.
|
||||||
pub fn prepared(self) -> Self {
|
pub fn prepared(self) -> Self {
|
||||||
let listen = self.listen_address;
|
let mut listen = self.listen_address;
|
||||||
let public = self.public_address;
|
let mut public = self.public_address;
|
||||||
|
|
||||||
if self.nat_enabled {
|
if self.nat_enabled {
|
||||||
info!("Enabling NAT");
|
info!("Enabling NAT...");
|
||||||
|
match search_gateway() {
|
||||||
|
Err(ref err) => info!("Error: {}", err),
|
||||||
|
Ok(gateway) => {
|
||||||
|
let int_addr = SocketAddrV4::from_str("127.0.0.1:30304").unwrap();
|
||||||
|
match gateway.get_any_address(PortMappingProtocol::TCP, int_addr, 0, "Parity Node/TCP") {
|
||||||
|
Err(ref err) => {
|
||||||
|
info!("There was an error! {}", err);
|
||||||
|
},
|
||||||
|
Ok(ext_addr) => {
|
||||||
|
info!("Local gateway: {}, External ip address: {}", gateway, ext_addr);
|
||||||
|
public = SocketAddr::V4(ext_addr);
|
||||||
|
listen = SocketAddr::V4(int_addr);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkConfiguration {
|
NetworkConfiguration {
|
||||||
|
Loading…
Reference in New Issue
Block a user