summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mullvad-daemon/src/settings.rs34
1 files changed, 24 insertions, 10 deletions
diff --git a/mullvad-daemon/src/settings.rs b/mullvad-daemon/src/settings.rs
index 9d2c77f991..5735c687c9 100644
--- a/mullvad-daemon/src/settings.rs
+++ b/mullvad-daemon/src/settings.rs
@@ -35,22 +35,23 @@ static SETTINGS_FILE: &str = "settings.json";
pub struct Settings {
account_token: Option<String>,
relay_settings: RelaySettings,
+ /// If the app should allow communication with private (LAN) networks.
+ allow_lan: bool,
}
impl Default for Settings {
fn default() -> Self {
- DEFAULT_SETTINGS
+ Settings {
+ account_token: None,
+ relay_settings: RelaySettings::Normal(RelayConstraints {
+ location: Constraint::Any,
+ tunnel: Constraint::Any,
+ }),
+ allow_lan: false,
+ }
}
}
-const DEFAULT_SETTINGS: Settings = Settings {
- account_token: None,
- relay_settings: RelaySettings::Normal(RelayConstraints {
- location: Constraint::Any,
- tunnel: Constraint::Any,
- }),
-};
-
impl Settings {
/// Loads user settings from file. If no file is present it returns the defaults.
pub fn load() -> Result<Settings> {
@@ -65,7 +66,7 @@ impl Settings {
"No settings file at {}, using defaults",
settings_path.to_string_lossy()
);
- Ok(DEFAULT_SETTINGS)
+ Ok(Settings::default())
}
Err(e) => Err(e).chain_err(|| ErrorKind::ReadError(settings_path)),
}
@@ -135,4 +136,17 @@ impl Settings {
Ok(false)
}
}
+
+ pub fn get_allow_lan(&self) -> bool {
+ self.allow_lan
+ }
+
+ pub fn set_allow_lan(&mut self, allow_lan: bool) -> Result<bool> {
+ if allow_lan != self.allow_lan {
+ self.allow_lan = allow_lan;
+ self.save().map(|_| true)
+ } else {
+ Ok(false)
+ }
+ }
}