Skip to content

Commit

Permalink
Added restart.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisdb2009 committed Jan 3, 2024
1 parent 3d9a657 commit 3454c2e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Tikhole.Engine/Committer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Committer
public static uint Committed = 0;
public static uint ComitterTimeoutMS = 1000;
public static uint ComitterDelayMS = 100;
public static uint TotalInstances { get; private set; } = 0;
public static uint TotalInstances { get; set; } = 0;
public static uint NeededInstances = 2;
public static IPEndPoint RouterOSIPEndPoint = new(IPAddress.Parse("192.168.200.1"), 8728);
public TcpClient TcpClient = new();
Expand Down
3 changes: 2 additions & 1 deletion Tikhole.Engine/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Listener()
Client.Client.Bind(IPEndPoint);
Task listener = new Task(() =>
{
while (Client != null)
while (Client.Client != null)
{
IPEndPoint? ipEndPoint = null;
try
Expand All @@ -32,6 +32,7 @@ public Listener()
Logger.Warning("Error receiving request.");
}
}
Logger.Info("Listener stopped.");
}, TaskCreationOptions.LongRunning);
listener.Start();
Logger.Success("Listener started on " + IPEndPoint.ToString() + ".");
Expand Down
1 change: 1 addition & 0 deletions Tikhole.Engine/Tikhole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public Tikhole()
Forwarder = new Forwarder();
Parser = new Parser();
Matcher = new Matcher();
Committer.TotalInstances = 0;
for (int i = 0; i < Committer.NeededInstances; i++) new Committer();
new Responder();
}
Expand Down
31 changes: 28 additions & 3 deletions Tikhole.Website/Components/Pages/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<small>A list of Tikhole settings. Changes made here are in real-time.</small>
</p>
<hr />
<button @onclick="StopTikhole" class="btn d-block ms-auto btn-dark">🛑 Stop Tikhole</button>
<button @onclick="RestartTikhole" class="btn btn-dark">🔃 Restart Tikhole</button>
<button @onclick="StopTikhole" class="btn btn-dark">🛑 Stop Tikhole</button>
<hr />
@if (Error != "")
{
Expand All @@ -21,6 +22,17 @@
</div>
</div>
}
@if (Info != "")
{
<div class="toast show position-fixed bottom-0 end-0 m-3">
<div class="toast-header">
<strong class="me-auto">ℹ️ Info</strong>
</div>
<div class="toast-body">
@Info
</div>
</div>
}
<div style="max-width:500px;">
<h5>🌎 RouterOS Settings</h5>
<hr />
Expand Down Expand Up @@ -79,9 +91,22 @@

@code {
private string Error { get; set; } = "";
private void StopTikhole()
private string Info { get; set; } = "";
private async void RestartTikhole()
{
Tikhole.RestartTikhole();
Info = "Tikhole engine restarted.";
await Task.Delay(3000);
Info = "";
StateHasChanged();
}
private async void StopTikhole()
{
if (Tikhole.WebApplication != null) Tikhole.WebApplication.StopAsync();
Tikhole.StopTikhole();
Info = "Tikhole engine stopped.";
await Task.Delay(3000);
Info = "";
StateHasChanged();
}
private string CommitterEndpoint
{
Expand Down
9 changes: 9 additions & 0 deletions Tikhole.Website/Tikhole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,14 @@ public static void Main(string[] args)
WebApplication.MapRazorComponents<App>().AddInteractiveServerRenderMode();
WebApplication.Run();
}
public static void StopTikhole()
{
Engine.Tikhole.Listener?.Client.Close();
}
public static void RestartTikhole()
{
Engine.Tikhole.Listener?.Client.Close();
_ = Task.Run(() => new Engine.Tikhole());
}
}
}

0 comments on commit 3454c2e

Please sign in to comment.