Skip to content

Commit

Permalink
Chage ConfigureCommand to ConfigCode
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvhood committed Nov 21, 2021
1 parent a4c4499 commit 21e0894
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
6 changes: 4 additions & 2 deletions VpnHood.Server.Access/ServerCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace VpnHood.Server
using System;

namespace VpnHood.Server
{
public class ServerCommand
{
public bool Reconfigure { get; set; }
public Guid? ConfigCode { get; set; }
}
}
1 change: 1 addition & 0 deletions VpnHood.Server.Access/ServerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ public ServerInfo(Version version,
public string? OsInfo { get; set; }
public long TotalMemory { get; set; }
public string? MachineName { get; set; }
public Guid? ConfigCode { get; set; }
}
}
11 changes: 6 additions & 5 deletions VpnHood.Server/VpnHoodServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public async Task Start()
await Configure();
}

private async Task Configure()
private async Task Configure(Guid? configurationCode = null)
{
if (_tcpHost.IsDisposed)
throw new ObjectDisposedException($"Could not configure after disposing {nameof(TcpHost)}!");
Expand All @@ -138,6 +138,7 @@ private async Task Configure()
MachineName = Environment.MachineName,
OsInfo = SystemInfoProvider.GetOperatingSystemInfo(),
TotalMemory = SystemInfoProvider.GetSystemInfo().TotalMemory,
ConfigCode = configurationCode
};

// get configuration from access server
Expand Down Expand Up @@ -224,22 +225,22 @@ public ServerStatus Status

private async Task SendStatusToAccessServer()
{
bool reconfigure = false;
Guid? configurationCode = null;
try
{
var res = await AccessServer.Server_UpdateStatus(Status);
reconfigure = res.Reconfigure;
configurationCode = res.ConfigCode;
}
catch (Exception ex)
{
VhLogger.Instance.LogError(ex, "Could not send server status!");
}

// reconfigure
if (reconfigure)
if (configurationCode!=null)
{
VhLogger.Instance.LogInformation("Reconfiguration is requiested.");
_ = Configure();
_ = Configure(configurationCode);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions VpnHood.ZTest/TestAccessServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@ public TestAccessServer(IAccessServer baseAccessServer)

public bool IsMaintenanceMode => _restAccessServer.IsMaintenanceMode;

public bool Reconfigure { get; set; }
public Guid? ConfigCode { get; set; }

public async Task<ServerCommand> Server_UpdateStatus(ServerStatus serverStatus)
{
var ret = await _restAccessServer.Server_UpdateStatus(serverStatus);
ret.Reconfigure = Reconfigure;
Reconfigure = false;
ret.ConfigCode = ConfigCode;
return ret;
}

public Task<ServerConfig> Server_Configure(ServerInfo serverInfo)
{
LastConfigureTime = DateTime.Now;
if (ConfigCode == serverInfo.ConfigCode)
ConfigCode = null;
return _restAccessServer.Server_Configure(serverInfo);
}

Expand Down
4 changes: 2 additions & 2 deletions VpnHood.ZTest/Tests/ServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public async Task Reconfigure()
Assert.IsTrue(testAccessServer.LastConfigureTime > dateTime);

dateTime = DateTime.Now;
testAccessServer.Reconfigure = true;
testAccessServer.ConfigCode = Guid.NewGuid();
await Task.Delay(2000);
Assert.IsFalse(testAccessServer.Reconfigure);
Assert.IsNull(testAccessServer.ConfigCode);
Assert.IsTrue(testAccessServer.LastConfigureTime > dateTime);
}
}
Expand Down

0 comments on commit 21e0894

Please sign in to comment.