Added feature to disable special NAT support

This commit is contained in:
Dennis Schwerdel 2019-12-22 23:21:47 +01:00
parent 54a2240f34
commit eb620781a8
3 changed files with 143 additions and 119 deletions

View File

@ -4,6 +4,7 @@ This project follows [semantic versioning](http://semver.org).
### Unreleased
- [added] Added feature to disable special NAT support
- [changed] Improved port forwarding on quirky routers
- [changed] Reduced peer timeout to 5min to work better with NAT

View File

@ -24,7 +24,7 @@ rand = "0.7"
fnv = "1"
net2 = "0.2"
yaml-rust = "0.4"
igd = "0.9"
igd = { version = "0.9", optional = true }
siphasher = "0.3"
daemonize = "0.4"
ring = "0.16"
@ -38,8 +38,9 @@ pkg-config = "0.3"
tempfile = "3"
[features]
default = []
default = ["nat"]
bench = []
nat = ["igd"]
[profile.release]
lto = true

View File

@ -2,20 +2,23 @@
// Copyright (C) 2015-2019 Dennis Schwerdel
// This software is licensed under GPL-3 or newer (see LICENSE.md)
#[cfg(feature = "nat")]
mod internal {
use std::{io, net::SocketAddrV4};
use igd::{search_gateway, AddAnyPortError, AddPortError, Gateway, PortMappingProtocol, SearchError};
use super::util::{get_internal_ip, SystemTimeSource, Time, TimeSource};
use crate::util::{get_internal_ip, SystemTimeSource, Time, TimeSource};
const LEASE_TIME: u32 = 1800;
const DESCRIPTION: &str = "VpnCloud";
const DESCRIPTION: &str = "VpnCloud";
pub struct PortForwarding {
pub internal_addr: SocketAddrV4,
pub external_addr: SocketAddrV4,
pub gateway: Gateway,
gateway: Gateway,
pub next_extension: Option<Time>
}
@ -151,3 +154,22 @@ impl Drop for PortForwarding {
self.deactivate()
}
}
}
#[cfg(not(feature = "nat"))]
mod internal {
pub struct PortForwarding;
impl PortForwarding {
pub fn new(_port: u16) -> Option<Self> {
warn!("Compiled without feature 'nat', skipping port forwarding.");
None
}
pub fn check_extend(&mut self) {
unreachable!()
}
}
}
pub use internal::*;