Skip to content

Commit

Permalink
feat(igd): expose a feature to completely disable IGD support, downgr…
Browse files Browse the repository at this point in the history
…ading igd crate to v0.11.1
  • Loading branch information
bochaco authored and dirvine committed Feb 20, 2021
1 parent 961cb15 commit 0873b29
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ webpki = "~0.21.3"
features = [ "serde" ]

[dependencies.igd]
version = "~0.12.0"
version = "~0.11.1"
features = [ "aio" ]
optional = true

[dependencies.quinn]
version = "~0.6.1"
Expand All @@ -54,3 +55,7 @@ rand = "~0.7.3"

[target."cfg(any(all(unix, not(any(target_os = \"android\", target_os = \"androideabi\", target_os = \"ios\"))), windows))".dependencies]
dirs-next = "2.0.0"

[features]
default = [ "igd" ]
no-igd = []
6 changes: 5 additions & 1 deletion src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use super::{
use futures::{future, TryFutureExt};
use log::{debug, error, info, trace};
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
use std::path::PathBuf;
use std::{collections::HashSet, path::PathBuf};

/// In the absence of a port supplied by the user via the config we will first try using this
/// before using a random port.
Expand Down Expand Up @@ -302,7 +302,9 @@ fn bind(

fn unwrap_config_or_default(cfg: Option<Config>) -> Result<Config> {
let mut cfg = cfg.map_or(Config::read_or_construct_default(None)?, |cfg| cfg);

if cfg.local_ip.is_none() {
debug!("Realizing local IP by connecting to contacts");
let socket = UdpSocket::bind("0.0.0.0:0")?;
let mut local_ip = None;
for addr in cfg.hard_coded_contacts.iter() {
Expand All @@ -313,8 +315,10 @@ fn unwrap_config_or_default(cfg: Option<Config>) -> Result<Config> {
}
cfg.local_ip = local_ip;
};

if cfg.clean {
Config::clear_config_from_disk(None)?;
}

Ok(cfg)
}
11 changes: 9 additions & 2 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// Software.

use super::error::Error;
use super::igd::forward_port;
use super::wire_msg::WireMsg;
#[cfg(not(feature = "no-igd"))]
use super::{api::DEFAULT_UPNP_LEASE_DURATION_SEC, igd::forward_port};
use super::{
api::DEFAULT_UPNP_LEASE_DURATION_SEC,
connection_deduplicator::ConnectionDeduplicator,
connection_pool::ConnectionPool,
connections::{
Expand All @@ -32,6 +32,7 @@ use tokio::time::timeout;
const CERT_SERVER_NAME: &str = "MaidSAFE.net";

// Number of seconds before timing out the IGD request to forward a port.
#[cfg(not(feature = "no-igd"))]
const PORT_FORWARD_TIMEOUT: u64 = 30;

/// Channel on which incoming messages can be listened to
Expand Down Expand Up @@ -210,6 +211,12 @@ impl Endpoint {

let mut addr = None;

#[cfg(feature = "no-igd")]
if self.qp2p_config.forward_port {
warn!("Ignoring 'forward_port' flag from config since IGD has been disabled (feature 'no-igd' has been set)");
}

#[cfg(not(feature = "no-igd"))]
if self.qp2p_config.forward_port {
// Attempt to use IGD for port forwarding
match timeout(
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ mod connection_pool;
mod connections;
mod endpoint;
mod error;
#[cfg(not(feature = "no-igd"))]
mod igd;
mod peer_config;
#[cfg(test)]
Expand Down

0 comments on commit 0873b29

Please sign in to comment.