aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-09-12 21:57:06 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-09-12 21:57:06 -0500
commit86b64362b6b41991d2f012c7954ebc2f206f75fd (patch)
treef11ee67ba2ecb0f67f646260ba824e468be0c087 /src
parentfbe4be554fb16ca4cd37288171c2e086c6f7ee20 (diff)
downloadslskd-86b64362b6b41991d2f012c7954ebc2f206f75fd.tar.gz
add SoulseekClientFactory, remove public static prop
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Application/Application.cs57
-rw-r--r--src/slskd/Application/ISoulseekClientFactory.cs26
-rw-r--r--src/slskd/Application/SoulseekClientFactory.cs26
-rw-r--r--src/slskd/Startup.cs2
4 files changed, 81 insertions, 30 deletions
diff --git a/src/slskd/Application/Application.cs b/src/slskd/Application/Application.cs
index 1e5f3584..617e665f 100644
--- a/src/slskd/Application/Application.cs
+++ b/src/slskd/Application/Application.cs
@@ -46,6 +46,7 @@ namespace slskd
OptionsAtStartup optionsAtStartup,
IOptionsMonitor<Options> optionsMonitor,
IManagedState<State> state,
+ ISoulseekClientFactory soulseekClientFactory,
ITransferTracker transferTracker,
IBrowseTracker browseTracker,
IConversationTracker conversationTracker,
@@ -110,7 +111,7 @@ namespace slskd
searchResponseCache: new SearchResponseCache(),
searchResponseResolver: SearchResponseResolver);
- Client = new SoulseekClient(options: clientOptions);
+ Client = soulseekClientFactory.Create(options: clientOptions);
Client.DiagnosticGenerated += Client_DiagnosticGenerated;
@@ -134,12 +135,8 @@ namespace slskd
Client.Connected += Client_Connected;
Client.LoggedIn += Client_LoggedIn;
Client.StateChanged += Client_StateChanged;
-
- SoulseekClient = Client;
}
- public static ISoulseekClient SoulseekClient { get; private set; }
-
private IBrowseTracker BrowseTracker { get; set; }
private ISoulseekClient Client { get; set; }
private IConversationTracker ConversationTracker { get; set; }
@@ -157,14 +154,14 @@ namespace slskd
private IManagedState<State> State { get; }
private ITransferTracker TransferTracker { get; set; }
- public Task AcknowledgePrivateMessageAsync(int id) => SoulseekClient.AcknowledgePrivateMessageAsync(id);
+ public Task AcknowledgePrivateMessageAsync(int id) => Client.AcknowledgePrivateMessageAsync(id);
public Task AddPrivateRoomMemberAsync(string roomName, string username)
- => SoulseekClient.AddPrivateRoomMemberAsync(roomName, username);
+ => Client.AddPrivateRoomMemberAsync(roomName, username);
- public Task AddUserAsync(string username) => SoulseekClient.AddUserAsync(username);
+ public Task AddUserAsync(string username) => Client.AddUserAsync(username);
- public Task<BrowseResponse> BrowseAsync(string username) => SoulseekClient.BrowseAsync(username);
+ public Task<BrowseResponse> BrowseAsync(string username) => Client.BrowseAsync(username);
/// <summary>
/// Gets the version of the latest application release.
@@ -221,24 +218,24 @@ namespace slskd
=> Client.Disconnect(message, exception ?? new IntentionalDisconnectException(message));
public Task DownloadAsync(string username, string filename, Stream outputStream, long? size, long startOffset = 0, int? token = null, TransferOptions options = null, CancellationToken? cancellationToken = null)
- => SoulseekClient.DownloadAsync(username, filename, outputStream, size, startOffset, token, options, cancellationToken);
+ => Client.DownloadAsync(username, filename, outputStream, size, startOffset, token, options, cancellationToken);
public Task<int> GetDownloadPlaceInQueueAsync(string username, string filename)
- => SoulseekClient.GetDownloadPlaceInQueueAsync(username, filename);
+ => Client.GetDownloadPlaceInQueueAsync(username, filename);
- public int GetNextToken() => SoulseekClient.GetNextToken();
+ public int GetNextToken() => Client.GetNextToken();
- public Task<RoomList> GetRoomListAsync() => SoulseekClient.GetRoomListAsync();
+ public Task<RoomList> GetRoomListAsync() => Client.GetRoomListAsync();
- public Task<IPEndPoint> GetUserEndPointAsync(string username) => SoulseekClient.GetUserEndPointAsync(username);
+ public Task<IPEndPoint> GetUserEndPointAsync(string username) => Client.GetUserEndPointAsync(username);
- public Task<UserInfo> GetUserInfoAsync(string username) => SoulseekClient.GetUserInfoAsync(username);
+ public Task<UserInfo> GetUserInfoAsync(string username) => Client.GetUserInfoAsync(username);
- public Task<bool> GetUserPrivilegedAsync(string username) => SoulseekClient.GetUserPrivilegedAsync(username);
+ public Task<bool> GetUserPrivilegedAsync(string username) => Client.GetUserPrivilegedAsync(username);
- public Task<UserStatus> GetUserStatusAsync(string username) => SoulseekClient.GetUserStatusAsync(username);
+ public Task<UserStatus> GetUserStatusAsync(string username) => Client.GetUserStatusAsync(username);
- public Task GrantUserPrivilegesAsync(string username, int days) => SoulseekClient.GrantUserPrivilegesAsync(username, days);
+ public Task GrantUserPrivilegesAsync(string username, int days) => Client.GrantUserPrivilegesAsync(username, days);
public async Task<RoomData> JoinRoomAsync(string roomName)
{
@@ -246,7 +243,7 @@ namespace slskd
try
{
- var data = await SoulseekClient.JoinRoomAsync(roomName);
+ var data = await Client.JoinRoomAsync(roomName);
Logger.Information("Joined room {Room}", roomName);
Logger.Debug("Room data for {Room}: {Info}", roomName, data.ToJson());
return data;
@@ -258,7 +255,7 @@ namespace slskd
}
}
- public Task LeaveRoomAsync(string roomName) => SoulseekClient.LeaveRoomAsync(roomName);
+ public Task LeaveRoomAsync(string roomName) => Client.LeaveRoomAsync(roomName);
/// <summary>
/// Re-scans shared directories.
@@ -267,15 +264,15 @@ namespace slskd
public Task RescanSharesAsync() => SharedFileCache.FillAsync();
public Task<Soulseek.Search> SearchAsync(SearchQuery query, Action<SearchResponse> responseReceived, SearchScope scope = null, int? token = null, SearchOptions options = null, CancellationToken? cancellationToken = null)
- => SoulseekClient.SearchAsync(query, responseReceived, scope, token, options, cancellationToken);
+ => Client.SearchAsync(query, responseReceived, scope, token, options, cancellationToken);
- public Task SendPrivateMessageAsync(string username, string message) => SoulseekClient.SendPrivateMessageAsync(username, message);
+ public Task SendPrivateMessageAsync(string username, string message) => Client.SendPrivateMessageAsync(username, message);
public Task SendRoomMessageAsync(string roomName, string message)
- => SoulseekClient.SendRoomMessageAsync(roomName, message);
+ => Client.SendRoomMessageAsync(roomName, message);
public Task SetRoomTickerAsync(string roomName, string message)
- => SoulseekClient.SetRoomTickerAsync(roomName, message);
+ => Client.SetRoomTickerAsync(roomName, message);
public async Task StartAsync(CancellationToken cancellationToken)
{
@@ -315,7 +312,7 @@ namespace slskd
}
}
- public Task StartPublicChatAsync() => SoulseekClient.StartPublicChatAsync();
+ public Task StartPublicChatAsync() => Client.StartPublicChatAsync();
public Task StopAsync(CancellationToken cancellationToken)
{
@@ -325,7 +322,7 @@ namespace slskd
return Task.CompletedTask;
}
- public Task StopPublicChatAsync() => SoulseekClient.StopPublicChatAsync();
+ public Task StopPublicChatAsync() => Client.StopPublicChatAsync();
private Task AutoJoinRoomsAsync(string[] rooms)
{
@@ -445,7 +442,7 @@ namespace slskd
// send whatever counts we have currently. we'll probably connect before the cache is primed, so these will be zero
// initially, but we'll update them when the cache is filled.
- _ = SoulseekClient.SetSharedCountsAsync(State.CurrentValue.SharedFileCache.Directories, State.CurrentValue.SharedFileCache.Files);
+ _ = Client.SetSharedCountsAsync(State.CurrentValue.SharedFileCache.Directories, State.CurrentValue.SharedFileCache.Files);
// rejoin any rooms that we might have been in during the previous session
await JoinRoomsAsync(RoomTracker.Rooms.Keys);
@@ -730,7 +727,7 @@ namespace slskd
Logger.Debug("Patching Soulseek options with {Patch}", patch.ToJson());
- soulseekRequiresReconnect = await SoulseekClient.ReconfigureOptionsAsync(patch);
+ soulseekRequiresReconnect = await Client.ReconfigureOptionsAsync(patch);
}
// require a reconnect if the client is connected and any options marked [RequiresReconnect] changed, OR if the
@@ -789,7 +786,7 @@ namespace slskd
Console.WriteLine($"[SENDING SEARCH RESULTS]: {results.Count()} records to {username} for query {query.SearchText}");
return new SearchResponse(
- SoulseekClient.Username,
+ Client.Username,
token,
freeUploadSlots: 1,
uploadSpeed: 0,
@@ -838,7 +835,7 @@ namespace slskd
if (Client.State.HasFlag(SoulseekClientStates.Connected | SoulseekClientStates.LoggedIn))
{
- _ = SoulseekClient.SetSharedCountsAsync(State.CurrentValue.SharedFileCache.Directories, State.CurrentValue.SharedFileCache.Files);
+ _ = Client.SetSharedCountsAsync(State.CurrentValue.SharedFileCache.Directories, State.CurrentValue.SharedFileCache.Files);
}
}
}
diff --git a/src/slskd/Application/ISoulseekClientFactory.cs b/src/slskd/Application/ISoulseekClientFactory.cs
new file mode 100644
index 00000000..67daa1b8
--- /dev/null
+++ b/src/slskd/Application/ISoulseekClientFactory.cs
@@ -0,0 +1,26 @@
+// <copyright file="ISoulseekClientFactory.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 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/.
+// </copyright>
+
+namespace slskd
+{
+ using Soulseek;
+
+ public interface ISoulseekClientFactory
+ {
+ ISoulseekClient Create(SoulseekClientOptions options);
+ }
+}
diff --git a/src/slskd/Application/SoulseekClientFactory.cs b/src/slskd/Application/SoulseekClientFactory.cs
new file mode 100644
index 00000000..cf5e524d
--- /dev/null
+++ b/src/slskd/Application/SoulseekClientFactory.cs
@@ -0,0 +1,26 @@
+// <copyright file="SoulseekClientFactory.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 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/.
+// </copyright>
+
+namespace slskd
+{
+ using Soulseek;
+
+ public class SoulseekClientFactory : ISoulseekClientFactory
+ {
+ public ISoulseekClient Create(SoulseekClientOptions options) => new SoulseekClient(options);
+ }
+}
diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs
index c03f8603..c8c96584 100644
--- a/src/slskd/Startup.cs
+++ b/src/slskd/Startup.cs
@@ -214,6 +214,8 @@ namespace slskd
services.AddSingleton<IPushbulletService, PushbulletService>();
+ services.AddTransient<ISoulseekClientFactory, SoulseekClientFactory>();
+
services.AddSingleton<IApplication, Application>();
services.AddHostedService(p => p.GetRequiredService<IApplication>());
}