aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-09-12 11:07:19 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-09-12 11:07:19 -0500
commit32b6e44f6db7a77905e45e7bbbe94f91be02fdee (patch)
tree72af386ab592d9a00ed949103816aaa5aa15015a
parent495ac50e153904b421aa5c459a1006d27dd59d54 (diff)
downloadslskd-32b6e44f6db7a77905e45e7bbbe94f91be02fdee.tar.gz
remove ISoulseekClient from PeerService
-rw-r--r--src/slskd/Application/Application.cs15
-rw-r--r--src/slskd/Application/IApplication.cs7
-rw-r--r--src/slskd/Application/Peer/PeerService.cs21
3 files changed, 29 insertions, 14 deletions
diff --git a/src/slskd/Application/Application.cs b/src/slskd/Application/Application.cs
index 2f5fc9f3..87f589f7 100644
--- a/src/slskd/Application/Application.cs
+++ b/src/slskd/Application/Application.cs
@@ -269,7 +269,8 @@ namespace slskd
public Task StartPublicChatAsync() => SoulseekClient.StartPublicChatAsync();
public Task StopPublicChatAsync() => SoulseekClient.StopPublicChatAsync();
- public Task AcknowledgePrivateMessageAsnyc(int id) => SoulseekClient.AcknowledgePrivateMessageAsync(id);
+ public Task SendPrivateMessageAsync(string username, string message) => SoulseekClient.SendPrivateMessageAsync(username, message);
+ public Task AcknowledgePrivateMessageAsync(int id) => SoulseekClient.AcknowledgePrivateMessageAsync(id);
public Task SendRoomMessageAsync(string roomName, string message)
=> SoulseekClient.SendRoomMessageAsync(roomName, message);
public Task SetRoomTickerAsync(string roomName, string message)
@@ -277,12 +278,18 @@ namespace slskd
public Task AddPrivateRoomMemberAsync(string roomName, string username)
=> SoulseekClient.AddPrivateRoomMemberAsync(roomName, username);
public Task<RoomList> GetRoomListAsync() => SoulseekClient.GetRoomListAsync();
- public Task<RoomData> JoinRoomAsync(string roomName) => SoulseekClient.JoinRoomAsync(roomName);
public Task LeaveRoomAsync(string roomName) => SoulseekClient.LeaveRoomAsync(roomName);
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);
public Task<int> GetDownloadPlaceInQueueAsync(string username, string filename)
=> SoulseekClient.GetDownloadPlaceInQueueAsync(username, filename);
+ public Task<IPEndPoint> GetUserEndPointAsync(string username) => SoulseekClient.GetUserEndPointAsync(username);
+ public Task<UserStatus> GetUserStatusAsync(string username) => SoulseekClient.GetUserStatusAsync(username);
+ public Task GrantUserPrivilegesAsync(string username, int days) => SoulseekClient.GrantUserPrivilegesAsync(username, days);
+ public Task<bool> GetUserPrivilegedAsync(string username) => SoulseekClient.GetUserPrivilegedAsync(username);
+ public Task AddUserAsync(string username) => SoulseekClient.AddUserAsync(username);
+ public Task<BrowseResponse> BrowseAsync(string username) => SoulseekClient.BrowseAsync(username);
+ public Task<UserInfo> GetUserInfoAsync(string username) => SoulseekClient.GetUserInfoAsync(username);
private async Task OptionsMonitor_OnChange(Options newOptions)
{
@@ -558,7 +565,7 @@ namespace slskd
}
}
- private async Task JoinRoomAsync(string roomName)
+ public async Task<RoomData> JoinRoomAsync(string roomName)
{
Logger.Debug("Joining room {Room}", roomName);
@@ -567,10 +574,12 @@ namespace slskd
var data = await SoulseekClient.JoinRoomAsync(roomName);
Logger.Information("Joined room {Room}", roomName);
Logger.Debug("Room data for {Room}: {Info}", roomName, data.ToJson());
+ return data;
}
catch (Exception ex)
{
Logger.Warning("Failed to join room {Room}: {Message}", roomName, ex.Message);
+ throw;
}
}
diff --git a/src/slskd/Application/IApplication.cs b/src/slskd/Application/IApplication.cs
index 0bf83899..78a05151 100644
--- a/src/slskd/Application/IApplication.cs
+++ b/src/slskd/Application/IApplication.cs
@@ -19,6 +19,7 @@ namespace slskd
{
using System;
using System.IO;
+ using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
@@ -43,5 +44,11 @@ namespace slskd
public Task DownloadAsync(string username, string filename, Stream outputStream, long? size, long startOffset = 0, int? token = null, TransferOptions options = null, CancellationToken? cancellationToken = null);
public Task<int> GetDownloadPlaceInQueueAsync(string username, string filename);
public Task<BrowseResponse> BrowseAsync(string username);
+ public Task<UserInfo> GetUserInfoAsync(string username);
+ public Task<IPEndPoint> GetUserEndPointAsync(string username);
+ public Task<UserStatus> GetUserStatusAsync(string username);
+ public Task GrantUserPrivilegesAsync(string username, int days);
+ public Task<bool> GetUserPrivilegedAsync(string username);
+ public Task AddUserAsync(string username);
}
}
diff --git a/src/slskd/Application/Peer/PeerService.cs b/src/slskd/Application/Peer/PeerService.cs
index e0e03fa6..96d65bd5 100644
--- a/src/slskd/Application/Peer/PeerService.cs
+++ b/src/slskd/Application/Peer/PeerService.cs
@@ -22,7 +22,6 @@ namespace slskd.Peer
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
- using ISoulseekClient = Soulseek.ISoulseekClient;
/// <summary>
/// Provides information and operations for network peers.
@@ -34,20 +33,20 @@ namespace slskd.Peer
/// <summary>
/// Initializes a new instance of the <see cref="PeerService"/> class.
/// </summary>
- /// <param name="client">The client instance to use.</param>
+ /// <param name="application"></param>
/// <param name="contextFactory">The database context to use.</param>
/// <param name="log">The logger.</param>
public PeerService(
- ISoulseekClient client,
+ IApplication application,
IDbContextFactory<PeerDbContext> contextFactory,
ILogger<PeerService> log)
{
- Client = client;
+ Application = application;
ContextFactory = contextFactory;
Log = log;
}
- private ISoulseekClient Client { get; }
+ private IApplication Application { get; }
private IDbContextFactory<PeerDbContext> ContextFactory { get; }
private ILogger<PeerService> Log { get; set; }
@@ -69,7 +68,7 @@ namespace slskd.Peer
return info;
}
- var soulseekUserInfo = await Client.GetUserInfoAsync(username);
+ var soulseekUserInfo = await Application.GetUserInfoAsync(username);
info = Info.FromSoulseekUserInfo(username, soulseekUserInfo);
if (peerExists)
@@ -93,7 +92,7 @@ namespace slskd.Peer
/// <returns>The retrieved endpoint.</returns>
public Task<IPEndPoint> GetIPEndPointAsync(string username)
{
- return Client.GetUserEndPointAsync(username);
+ return Application.GetUserEndPointAsync(username);
}
/// <summary>
@@ -103,7 +102,7 @@ namespace slskd.Peer
/// <returns>The retrieved status.</returns>
public async Task<Status> GetStatusAsync(string username)
{
- var soulseekStatus = await Client.GetUserStatusAsync(username);
+ var soulseekStatus = await Application.GetUserStatusAsync(username);
return Status.FromSoulseekUserStatus(soulseekStatus);
}
@@ -115,7 +114,7 @@ namespace slskd.Peer
/// <param name="days">The number of days to grant.</param>
/// <returns>The operation context.</returns>
public Task GrantPrivilegesAsync(string username, int days)
- => Client.GrantUserPrivilegesAsync(username, days);
+ => Application.GrantUserPrivilegesAsync(username, days);
/// <summary>
/// Retrieves a value indicating whether the specified peer is privileged.
@@ -123,7 +122,7 @@ namespace slskd.Peer
/// <param name="username">The username of the peer.</param>
/// <returns>A value indicating whether the specified peer is privileged.</returns>
public Task<bool> IsPrivilegedAsync(string username)
- => Client.GetUserPrivilegedAsync(username);
+ => Application.GetUserPrivilegedAsync(username);
/// <summary>
/// Adds the specified username to the server-side user list.
@@ -132,7 +131,7 @@ namespace slskd.Peer
/// <returns>The operation context.</returns>
public async Task WatchAsync(string username)
{
- await Client.AddUserAsync(username);
+ await Application.AddUserAsync(username);
}
}
} \ No newline at end of file