diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-10-11 19:05:55 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2022-10-11 19:05:55 -0500 |
| commit | 56f164196192ffbe62bb9ba2684d5db45f223f24 (patch) | |
| tree | 55047f8b3b31ea54d4f1b79266810f648ae9ed70 /src | |
| parent | da88bbb819dfa4420c97c09a840748942bc7f081 (diff) | |
| download | slskd-56f164196192ffbe62bb9ba2684d5db45f223f24.tar.gz | |
add agent shares
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Shares/IShareService.cs | 12 | ||||
| -rw-r--r-- | src/slskd/Shares/ShareService.cs | 28 |
2 files changed, 39 insertions, 1 deletions
diff --git a/src/slskd/Shares/IShareService.cs b/src/slskd/Shares/IShareService.cs index 2a18f5b3..3ec5fd56 100644 --- a/src/slskd/Shares/IShareService.cs +++ b/src/slskd/Shares/IShareService.cs @@ -39,6 +39,18 @@ namespace slskd.Shares public IStateMonitor<ShareState> StateMonitor { get; } /// <summary> + /// Adds the shares associated with the specified <paramref name="agent"/>. + /// </summary> + /// <param name="agent">The name of the agent.</param> + void AddAgentShares(string agent); + + /// <summary> + /// Remotes the shares associated with the specified <paramref name="agent"/>. + /// </summary> + /// <param name="agent">The name of the agent.</param> + void RemoveAgentShares(string agent); + + /// <summary> /// Returns the entire contents of the share. /// </summary> /// <returns>The entire contents of the share.</returns> diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index a9c8c629..d500532d 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -24,7 +24,6 @@ namespace slskd.Shares using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; - using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Serilog; @@ -96,6 +95,33 @@ namespace slskd.Shares private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1, 1); private StorageMode CacheStorageMode { get; } private ILogger Log { get; } = Serilog.Log.ForContext<ShareService>(); + private ConcurrentDictionary<string, IReadOnlyShareRepository> AgentRepositories { get; } = new(); + + /// <summary> + /// Adds the shares associated with the specified <paramref name="agent"/>. + /// </summary> + /// <param name="agent">The name of the agent.</param> + public void AddAgentShares(string agent) + { + if (string.IsNullOrEmpty(agent)) + { + throw new ArgumentNullException(nameof(agent)); + } + + AgentRepositories.AddOrUpdate( + key: agent, + addValue: new ShareRepository(BuildConnectionString(agent)), + updateValueFactory: (agent, repository) => new ShareRepository(BuildConnectionString(agent))); + } + + /// <summary> + /// Remotes the shares associated with the specified <paramref name="agent"/>. + /// </summary> + /// <param name="agent">The name of the agent.</param> + public void RemoveAgentShares(string agent) + { + AgentRepositories.TryRemove(agent, out _); + } /// <summary> /// Returns the entire contents of the share. |
