From 20c88c027c7daa09c85b146f5b2d57c8f2d40da5 Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Fri, 26 Mar 2021 09:02:05 +0000 Subject: [PATCH] Add more json settings fields for daemon. --- MelonVPNCore/DaemonSocketServer.cs | 10 +++++----- MelonVPNCore/Json.cs | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/MelonVPNCore/DaemonSocketServer.cs b/MelonVPNCore/DaemonSocketServer.cs index 958aba4..6d45f1e 100644 --- a/MelonVPNCore/DaemonSocketServer.cs +++ b/MelonVPNCore/DaemonSocketServer.cs @@ -13,8 +13,8 @@ namespace MelonVPNCore private static Process currentVpnProcess; private static bool shouldBeRunning; private static bool isRestarting; - private const int startingTime = 3000; - private const int restartDelay = 250; + private const int dstartingTime = 3000; + private const int drestartDelay = 250; private static DaemonConfig config; public const string daemonConfigPath = "/etc/melon-vpn/daemon.cfg"; @@ -194,7 +194,7 @@ namespace MelonVPNCore Console.WriteLine("Restarting embedded process"); currentVpnProcess.Dispose(); currentVpnProcess = null; - Thread.Sleep(restartDelay); + Thread.Sleep((config.restartDelay < drestartDelay) ? drestartDelay : config.restartDelay); bool imonline = false; isRestarting = true; while (config.ShouldRestart && shouldBeRunning) @@ -213,7 +213,7 @@ namespace MelonVPNCore { currentVpnProcess.Dispose(); currentVpnProcess = null; - Thread.Sleep(restartDelay); + Thread.Sleep((config.restartDelay < drestartDelay) ? drestartDelay : config.restartDelay); } } isRestarting = false; @@ -239,7 +239,7 @@ namespace MelonVPNCore }; currentVpnProcess.Exited += CurrentVpnProcess_Exited; currentVpnProcess.Start(); - Thread.Sleep(startingTime); + Thread.Sleep((config.StartingTime < dstartingTime) ? dstartingTime : config.StartingTime); return !currentVpnProcess.HasExited; } catch (Exception e) diff --git a/MelonVPNCore/Json.cs b/MelonVPNCore/Json.cs index 6ffa0b0..8eaa312 100644 --- a/MelonVPNCore/Json.cs +++ b/MelonVPNCore/Json.cs @@ -76,5 +76,11 @@ namespace MelonVPNCore [JsonProperty("restart")] public bool ShouldRestart { get; set; } + + [JsonProperty("starting_time")] + public int StartingTime { get; set; } + + [JsonProperty("restart_delay")] + public int restartDelay { get; set; } } }