aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-08-05 07:53:24 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-08-05 07:53:24 -0500
commita56bfb47abe33d259ba9d12d492123ab4baa3739 (patch)
tree74a52bed87b31733b79cf8b5c14e33a6c5efa479 /src
parent86aeebf6a900e44461aa0094b8bf3cf1d81adcbe (diff)
downloadslskd-a56bfb47abe33d259ba9d12d492123ab4baa3739.tar.gz
rename more stuff
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Application/Application.cs (renamed from src/slskd/Application/Service.cs)26
-rw-r--r--src/slskd/Application/ApplicationState.cs (renamed from src/slskd/Application/ServiceState.cs)4
-rw-r--r--src/slskd/Application/ISharedFileCache.cs (renamed from src/slskd/Application/Shares/ISharedFileCache.cs)7
-rw-r--r--src/slskd/Application/Management/API/Controllers/ApplicationController.cs2
-rw-r--r--src/slskd/Application/Management/API/Controllers/ConfigurationController.cs8
-rw-r--r--src/slskd/Application/Management/API/Controllers/ServerController.cs6
-rw-r--r--src/slskd/Application/Management/IManagementService.cs27
-rw-r--r--src/slskd/Application/Management/ManagementService.cs61
-rw-r--r--src/slskd/Application/SharedFileCache.cs (renamed from src/slskd/Application/Shares/SharedFileCache.cs)27
-rw-r--r--src/slskd/Application/SharedFileCacheState.cs (renamed from src/slskd/Application/Shares/SharedFileCacheState.cs)9
-rw-r--r--src/slskd/Common/IStateMonitor.cs2
-rw-r--r--src/slskd/Common/StateMonitor.cs2
-rw-r--r--src/slskd/Startup.cs12
13 files changed, 97 insertions, 96 deletions
diff --git a/src/slskd/Application/Service.cs b/src/slskd/Application/Application.cs
index 469d4227..fc359b43 100644
--- a/src/slskd/Application/Service.cs
+++ b/src/slskd/Application/Application.cs
@@ -1,4 +1,4 @@
-// <copyright file="Service.cs" company="slskd Team">
+// <copyright file="Application.cs" company="slskd Team">
// Copyright (c) slskd Team. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
@@ -34,20 +34,18 @@ namespace slskd
using slskd.Messaging;
using slskd.Peer;
using slskd.Search;
- using slskd.Shares;
using slskd.Transfer;
using Soulseek;
using Soulseek.Diagnostics;
- public class Service : IHostedService
+ public class Application : IHostedService
{
private static readonly int ReconnectMaxDelayMilliseconds = 300000; // 5 minutes
- public Service(
+ public Application(
OptionsAtStartup optionsAtStartup,
IOptionsMonitor<Options> optionsMonitor,
- IStateMonitor<ServiceState> stateMonitor,
- IStateMonitor<SharedFileCacheState> sharedFileCacheStateMonitor,
+ IStateMonitor<ApplicationState> stateMonitor,
ITransferTracker transferTracker,
IBrowseTracker browseTracker,
IConversationTracker conversationTracker,
@@ -65,14 +63,13 @@ namespace slskd
StateMonitor = stateMonitor;
StateMonitor.OnChange(state => StateMonitor_OnChange(state));
- SharedFileCacheStateMonitor = sharedFileCacheStateMonitor;
- SharedFileCacheStateMonitor.OnChange(state => SharedFileCacheStateMonitor_OnChange(state));
+ SharedFileCache = sharedFileCache;
+ SharedFileCache.State.OnChange(state => SharedFileCacheState_OnChange(state));
TransferTracker = transferTracker;
BrowseTracker = browseTracker;
ConversationTracker = conversationTracker;
RoomTracker = roomTracker;
- SharedFileCache = sharedFileCache;
Pushbullet = pushbulletService;
ProxyOptions proxyOptions = default;
@@ -145,16 +142,15 @@ namespace slskd
private IBrowseTracker BrowseTracker { get; set; }
private ISoulseekClient Client { get; set; }
private IConversationTracker ConversationTracker { get; set; }
- private ILogger Logger { get; set; } = Log.ForContext<Service>();
+ private ILogger Logger { get; set; } = Log.ForContext<Application>();
private ConcurrentDictionary<string, ILogger> Loggers { get; } = new ConcurrentDictionary<string, ILogger>();
private IOptionsMonitor<Options> OptionsMonitor { get; set; }
private Options Options => OptionsMonitor.CurrentValue;
private OptionsAtStartup OptionsAtStartup { get; set; }
private Options PreviousOptions { get; set; }
private IRoomTracker RoomTracker { get; set; }
- private IStateMonitor<ServiceState> StateMonitor { get; set; }
- private ServiceState State => StateMonitor.CurrentValue;
- private IStateMonitor<SharedFileCacheState> SharedFileCacheStateMonitor { get; set; }
+ private IStateMonitor<ApplicationState> StateMonitor { get; set; }
+ private ApplicationState State => StateMonitor.CurrentValue;
private ISharedFileCache SharedFileCache { get; set; }
private ITransferTracker TransferTracker { get; set; }
private IPushbulletService Pushbullet { get; }
@@ -328,12 +324,12 @@ namespace slskd
}
}
- private void StateMonitor_OnChange((ServiceState Previous, ServiceState Current) state)
+ private void StateMonitor_OnChange((ApplicationState Previous, ApplicationState Current) state)
{
Logger.Debug("State changed from {Previous} to {Current}", state.Previous.ToJson(), state.Current.ToJson());
}
- private void SharedFileCacheStateMonitor_OnChange((SharedFileCacheState Previous, SharedFileCacheState Current) state)
+ private void SharedFileCacheState_OnChange((SharedFileCacheState Previous, SharedFileCacheState Current) state)
{
if (!state.Previous.Filling && state.Current.Filling)
{
diff --git a/src/slskd/Application/ServiceState.cs b/src/slskd/Application/ApplicationState.cs
index 3f3eda05..2e3f627f 100644
--- a/src/slskd/Application/ServiceState.cs
+++ b/src/slskd/Application/ApplicationState.cs
@@ -1,4 +1,4 @@
-// <copyright file="ServiceState.cs" company="slskd Team">
+// <copyright file="ApplicationState.cs" company="slskd Team">
// Copyright (c) slskd Team. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
@@ -20,7 +20,7 @@ namespace slskd
/// <summary>
/// Application service state.
/// </summary>
- public record ServiceState()
+ public record ApplicationState()
{
public bool PendingReconnect { get; init; }
public bool PendingRestart { get; init; }
diff --git a/src/slskd/Application/Shares/ISharedFileCache.cs b/src/slskd/Application/ISharedFileCache.cs
index 163f4eea..291d78e4 100644
--- a/src/slskd/Application/Shares/ISharedFileCache.cs
+++ b/src/slskd/Application/ISharedFileCache.cs
@@ -15,7 +15,7 @@
// along with this program. If not, see https://www.gnu.org/licenses/.
// </copyright>
-namespace slskd.Shares
+namespace slskd
{
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -27,6 +27,11 @@ namespace slskd.Shares
public interface ISharedFileCache
{
/// <summary>
+ /// Gets the cache state.
+ /// </summary>
+ IStateMonitor<SharedFileCacheState> State { get; }
+
+ /// <summary>
/// Returns the contents of the cache.
/// </summary>
/// <returns>The contents of the cache.</returns>
diff --git a/src/slskd/Application/Management/API/Controllers/ApplicationController.cs b/src/slskd/Application/Management/API/Controllers/ApplicationController.cs
index 43029aa5..dd115786 100644
--- a/src/slskd/Application/Management/API/Controllers/ApplicationController.cs
+++ b/src/slskd/Application/Management/API/Controllers/ApplicationController.cs
@@ -50,7 +50,7 @@ namespace slskd.Management.API
[Authorize]
public IActionResult State()
{
- return Ok(Management.GetServiceState());
+ return Ok(Management.ApplicationState);
}
/// <summary>
diff --git a/src/slskd/Application/Management/API/Controllers/ConfigurationController.cs b/src/slskd/Application/Management/API/Controllers/ConfigurationController.cs
index c44cf2f2..f2b90718 100644
--- a/src/slskd/Application/Management/API/Controllers/ConfigurationController.cs
+++ b/src/slskd/Application/Management/API/Controllers/ConfigurationController.cs
@@ -17,12 +17,11 @@
using Microsoft.Extensions.Options;
-namespace slskd.Application.Management.API
+namespace slskd.Management.API
{
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using slskd.Management;
- using slskd.Shares;
/// <summary>
/// Configuration.
@@ -36,17 +35,14 @@ namespace slskd.Application.Management.API
{
public ConfigurationController(
IOptionsSnapshot<Options> optionsShapshot,
- IStateMonitor<SharedFileCacheState> sharedFileCacheMonitor,
IManagementService managementService)
{
OptionsShapshot = optionsShapshot;
- SharedFileCacheMonitor = sharedFileCacheMonitor;
ManagementService = managementService;
}
private IManagementService ManagementService { get; }
private IOptionsSnapshot<Options> OptionsShapshot { get; }
- private IStateMonitor<SharedFileCacheState> SharedFileCacheMonitor { get; }
[HttpGet]
[Route("")]
@@ -62,7 +58,7 @@ namespace slskd.Application.Management.API
[Authorize]
public IActionResult RescanSharesAsync()
{
- if (SharedFileCacheMonitor.CurrentValue.Filling)
+ if (ManagementService.SharedFileCacheState.Filling)
{
return Conflict("A share scan is already in progress.");
}
diff --git a/src/slskd/Application/Management/API/Controllers/ServerController.cs b/src/slskd/Application/Management/API/Controllers/ServerController.cs
index 6468063c..fc47f475 100644
--- a/src/slskd/Application/Management/API/Controllers/ServerController.cs
+++ b/src/slskd/Application/Management/API/Controllers/ServerController.cs
@@ -50,7 +50,7 @@ namespace slskd.Management.API
[ProducesResponseType(403)]
public async Task<IActionResult> Connect()
{
- if (!Management.GetServerState().IsConnected)
+ if (!Management.ServerState.IsConnected)
{
await Management.ConnectServerAsync();
}
@@ -70,7 +70,7 @@ namespace slskd.Management.API
[ProducesResponseType(403)]
public IActionResult Disconnect([FromBody] string message)
{
- if (Management.GetServerState().IsConnected)
+ if (Management.ServerState.IsConnected)
{
Management.DisconnectServer(message);
}
@@ -90,7 +90,7 @@ namespace slskd.Management.API
[ProducesResponseType(403)]
public IActionResult Get()
{
- return Ok(Management.GetServerState());
+ return Ok(Management.ServerState);
}
}
} \ No newline at end of file
diff --git a/src/slskd/Application/Management/IManagementService.cs b/src/slskd/Application/Management/IManagementService.cs
index 6c5f3784..9a06d961 100644
--- a/src/slskd/Application/Management/IManagementService.cs
+++ b/src/slskd/Application/Management/IManagementService.cs
@@ -26,6 +26,21 @@ namespace slskd.Management
public interface IManagementService
{
/// <summary>
+ /// Gets the current state of the slskd service.
+ /// </summary>
+ ApplicationState ApplicationState { get; }
+
+ /// <summary>
+ /// Gets the current state of the connection to the Soulseek server.
+ /// </summary>
+ ServerState ServerState { get; }
+
+ /// <summary>
+ /// Gets the current state of the shared file cache.
+ /// </summary>
+ SharedFileCacheState SharedFileCacheState { get; }
+
+ /// <summary>
/// Connects the Soulseek client to the server using the configured username and password.
/// </summary>
/// <returns>The operation context.</returns>
@@ -39,18 +54,6 @@ namespace slskd.Management
void DisconnectServer(string message = null, Exception exception = null);
/// <summary>
- /// Gets the current state of the connection to the Soulseek server.
- /// </summary>
- /// <returns>The current server state.</returns>
- ServerState GetServerState();
-
- /// <summary>
- /// Gets the current state of the slskd service.
- /// </summary>
- /// <returns></returns>
- ServiceState GetServiceState();
-
- /// <summary>
/// Re-scans shared directories.
/// </summary>
/// <returns>The operation context.</returns>
diff --git a/src/slskd/Application/Management/ManagementService.cs b/src/slskd/Application/Management/ManagementService.cs
index 2f79f496..3d7bd442 100644
--- a/src/slskd/Application/Management/ManagementService.cs
+++ b/src/slskd/Application/Management/ManagementService.cs
@@ -1,13 +1,18 @@
// <copyright file="ManagementService.cs" company="slskd Team">
// Copyright (c) slskd Team. All rights reserved.
//
-// This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public
-// License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
//
-// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
//
-// You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see https://www.gnu.org/licenses/.
// </copyright>
using Microsoft.Extensions.Options;
@@ -16,7 +21,6 @@ namespace slskd.Management
{
using System;
using System.Threading.Tasks;
- using slskd.Shares;
using Soulseek;
/// <summary>
@@ -33,7 +37,7 @@ namespace slskd.Management
/// <param name="sharedFileCache">The shared file cache.</param>
public ManagementService(
IOptionsMonitor<Options> optionsMonitor,
- IStateMonitor<ServiceState> serviceStateMonitor,
+ IStateMonitor<ApplicationState> serviceStateMonitor,
ISoulseekClient soulseekClient,
ISharedFileCache sharedFileCache)
{
@@ -43,10 +47,32 @@ namespace slskd.Management
SharedFileCache = sharedFileCache;
}
+ /// <summary>
+ /// Gets the current state of the slskd service.
+ /// </summary>
+ public ApplicationState ApplicationState => ServiceStateMonitor.CurrentValue;
+
+ /// <summary>
+ /// Gets the current state of the connection to the Soulseek server.
+ /// </summary>
+ public ServerState ServerState =>
+ new ServerState()
+ {
+ Address = Client.Address,
+ IPEndPoint = Client.IPEndPoint,
+ State = Client.State,
+ Username = Client.Username,
+ };
+
+ /// <summary>
+ /// Gets the current state of the connection to the Soulseek server.
+ /// </summary>
+ public SharedFileCacheState SharedFileCacheState => SharedFileCache.State.CurrentValue;
+
private ISoulseekClient Client { get; }
private Options Options => OptionsMonitor.CurrentValue;
private IOptionsMonitor<Options> OptionsMonitor { get; }
- private IStateMonitor<ServiceState> ServiceStateMonitor { get; }
+ private IStateMonitor<ApplicationState> ServiceStateMonitor { get; }
private ISharedFileCache SharedFileCache { get; }
/// <summary>
@@ -65,25 +91,6 @@ namespace slskd.Management
=> Client.Disconnect(message, exception ?? new IntentionalDisconnectException(message));
/// <summary>
- /// Gets the current state of the connection to the Soulseek server.
- /// </summary>
- /// <returns>The current server state.</returns>
- public ServerState GetServerState() =>
- new ServerState()
- {
- Address = Client.Address,
- IPEndPoint = Client.IPEndPoint,
- State = Client.State,
- Username = Client.Username,
- };
-
- /// <summary>
- /// Gets the current state of the slskd service.
- /// </summary>
- /// <returns></returns>
- public ServiceState GetServiceState() => ServiceStateMonitor.CurrentValue;
-
- /// <summary>
/// Re-scans shared directories.
/// </summary>
/// <returns>The operation context.</returns>
diff --git a/src/slskd/Application/Shares/SharedFileCache.cs b/src/slskd/Application/SharedFileCache.cs
index e9bddb09..a3edad9d 100644
--- a/src/slskd/Application/Shares/SharedFileCache.cs
+++ b/src/slskd/Application/SharedFileCache.cs
@@ -18,7 +18,7 @@
using System.IO;
using Microsoft.Extensions.Options;
-namespace slskd.Shares
+namespace slskd
{
using System;
using System.Collections.Concurrent;
@@ -39,23 +39,24 @@ namespace slskd.Shares
/// <summary>
/// Initializes a new instance of the <see cref="SharedFileCache"/> class.
/// </summary>
- /// <param name="stateMonitor"></param>
/// <param name="optionsMonitor"></param>
public SharedFileCache(
- IStateMonitor<SharedFileCacheState> stateMonitor,
IOptionsMonitor<Options> optionsMonitor)
{
- StateMonitor = stateMonitor;
OptionsMonitor = optionsMonitor;
}
+ /// <summary>
+ /// Gets the cache state.
+ /// </summary>
+ public IStateMonitor<SharedFileCacheState> State { get; } = new StateMonitor<SharedFileCacheState>();
+
private HashSet<string> Directories { get; set; }
private Dictionary<string, File> Files { get; set; }
+ private ILogger Log { get; } = Serilog.Log.ForContext<SharedFileCache>();
private IOptionsMonitor<Options> OptionsMonitor { get; set; }
private SqliteConnection SQLite { get; set; }
- private IStateMonitor<SharedFileCacheState> StateMonitor { get; set; }
private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1);
- private ILogger Log { get; } = Serilog.Log.ForContext<SharedFileCache>();
/// <summary>
/// Returns the contents of the cache.
@@ -116,19 +117,19 @@ namespace slskd.Shares
try
{
- StateMonitor.SetValue(state => state with { Filling = true, FillProgress = 0 });
+ State.SetValue(state => state with { Filling = true, FillProgress = 0 });
Log.Debug("Starting shared file scan");
var sw = new Stopwatch();
sw.Start();
var swSnapshot = 0L;
- // this destroys the old table and creates a new one. empty the other cached fields to reflect this
+ // this destroys the old table and creates a new one. empty the other cached fields to reflect this
// todo: use an A/B style table naming schema so that the cache remains available while it is filling
CreateTable();
Directories = new HashSet<string>();
Files = new Dictionary<string, File>();
- StateMonitor.SetValue(state => state with { Directories = 0, Files = 0 });
+ State.SetValue(state => state with { Directories = 0, Files = 0 });
Log.Debug("Enumerating shared directories");
swSnapshot = sw.ElapsedMilliseconds;
@@ -137,7 +138,7 @@ namespace slskd.Shares
.SelectMany(share => System.IO.Directory.GetDirectories(share, "*", SearchOption.AllDirectories))
.ToHashSet();
- StateMonitor.SetValue(state => state with { Directories = directories.Count });
+ State.SetValue(state => state with { Directories = directories.Count });
Log.Debug("Found {Directories} shared directories in {Elapsed}ms. Starting recursive scan.", sw.ElapsedMilliseconds - swSnapshot, directories.Count);
swSnapshot = sw.ElapsedMilliseconds;
@@ -166,7 +167,7 @@ namespace slskd.Shares
}
current++;
- StateMonitor.SetValue(state => state with { FillProgress = current / (double)directories.Count, Files = files.Count });
+ State.SetValue(state => state with { FillProgress = current / (double)directories.Count, Files = files.Count });
}
Log.Debug("Directory scan found {Files} in {Elapsed}ms. Populating filename database", files.Count, sw.ElapsedMilliseconds - swSnapshot);
@@ -183,7 +184,7 @@ namespace slskd.Shares
Directories = directories;
Files = files;
- StateMonitor.SetValue(state => state with
+ State.SetValue(state => state with
{
Filling = false,
Faulted = false,
@@ -196,7 +197,7 @@ namespace slskd.Shares
}
catch (Exception ex)
{
- StateMonitor.SetValue(state => state with
+ State.SetValue(state => state with
{
Filling = false,
Faulted = true,
diff --git a/src/slskd/Application/Shares/SharedFileCacheState.cs b/src/slskd/Application/SharedFileCacheState.cs
index 37ac9f86..54b56c22 100644
--- a/src/slskd/Application/Shares/SharedFileCacheState.cs
+++ b/src/slskd/Application/SharedFileCacheState.cs
@@ -15,14 +15,14 @@
// along with this program. If not, see https://www.gnu.org/licenses/.
// </copyright>
-namespace slskd.Shares
+namespace slskd
{
using System;
/// <summary>
/// Share cache state.
/// </summary>
- public record SharedFileCacheState()
+ public record SharedFileCacheState
{
/// <summary>
/// Gets a value indicating whether the cache is being filled.
@@ -48,10 +48,5 @@ namespace slskd.Shares
/// Gets the number of cached files.
/// </summary>
public int Files { get; init; }
-
- /// <summary>
- /// Gets the UTC timestamp of the last fill.
- /// </summary>
- public DateTime? LastFilled { get; init; }
}
} \ No newline at end of file
diff --git a/src/slskd/Common/IStateMonitor.cs b/src/slskd/Common/IStateMonitor.cs
index b2286aac..57055450 100644
--- a/src/slskd/Common/IStateMonitor.cs
+++ b/src/slskd/Common/IStateMonitor.cs
@@ -20,7 +20,7 @@ namespace slskd
using System;
/// <summary>
- /// Used for notifications when <see cref="ServiceState"/> changes.
+ /// Used for notifications when <see cref="ApplicationState"/> changes.
/// </summary>
/// <typeparam name="T">The type of the tracked state object.</typeparam>
public interface IStateMonitor<T>
diff --git a/src/slskd/Common/StateMonitor.cs b/src/slskd/Common/StateMonitor.cs
index 22704398..1d52b9e9 100644
--- a/src/slskd/Common/StateMonitor.cs
+++ b/src/slskd/Common/StateMonitor.cs
@@ -20,7 +20,7 @@ namespace slskd
using System;
/// <summary>
- /// Used for notifications when <see cref="ServiceState"/> changes.
+ /// Used for notifications when <see cref="ApplicationState"/> changes.
/// </summary>
/// <typeparam name="T">The type of the tracked state object.</typeparam>
public class StateMonitor<T> : IStateMonitor<T>
diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs
index c15e9f8a..ef955df9 100644
--- a/src/slskd/Startup.cs
+++ b/src/slskd/Startup.cs
@@ -41,7 +41,6 @@ namespace slskd
using slskd.Messaging;
using slskd.Peer;
using slskd.Search;
- using slskd.Shares;
using slskd.Transfer;
using slskd.Validation;
@@ -105,11 +104,10 @@ namespace slskd
return true;
});
- // add IStateMonitor instances to DI, to track application state in an observable way.
- // imilar to IOptionsMonitor, but state is managed by the application itself.
+ // add IStateMonitor instance to DI, to track application state in an observable way.
+ // similar to IOptionsMonitor, but state is managed by the application itself.
// Usage is roughly the same.
- services.AddSingleton<IStateMonitor<ServiceState>, StateMonitor<ServiceState>>();
- services.AddSingleton<IStateMonitor<SharedFileCacheState>, StateMonitor<SharedFileCacheState>>();
+ services.AddSingleton<IStateMonitor<ApplicationState>, StateMonitor<ApplicationState>>();
services.AddCors(options => options.AddPolicy("AllowAll", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));
@@ -220,8 +218,8 @@ namespace slskd
services.AddSingleton<IPushbulletService, PushbulletService>();
- services.AddHostedService<Service>();
- services.AddSingleton(_ => Service.SoulseekClient);
+ services.AddHostedService<Application>();
+ services.AddSingleton(_ => Application.SoulseekClient);
}
/// <summary>