diff options
| author | JP Dillingham <jp@dillingham.me> | 2024-01-05 18:31:11 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2024-01-05 18:31:11 -0600 |
| commit | eb14f632df9f8f487335db643fdea4b9c1547be1 (patch) | |
| tree | 4db8ae5133d7e31eb5e144a03e3e1491700b3ebb /src/slskd/Users/IUserService.cs | |
| parent | 1cd4b10a25052e4e82c1f86a9bc92f06f5605114 (diff) | |
| download | slskd-eb14f632df9f8f487335db643fdea4b9c1547be1.tar.gz | |
finish refactor of UserService
Diffstat (limited to 'src/slskd/Users/IUserService.cs')
| -rw-r--r-- | src/slskd/Users/IUserService.cs | 79 |
1 files changed, 61 insertions, 18 deletions
diff --git a/src/slskd/Users/IUserService.cs b/src/slskd/Users/IUserService.cs index 04ef1527..2d30949b 100644 --- a/src/slskd/Users/IUserService.cs +++ b/src/slskd/Users/IUserService.cs @@ -24,6 +24,38 @@ namespace slskd.Users /// <summary> /// Provides information and operations for network peers. /// </summary> + /// <remarks> + /// <para> + /// This class maintains a <see cref="UserDictionary"/> that acts as a non-expiring cache of information + /// collected about a user. This includes their statistics (share counts, speed, etc), their status (privileged, etc) + /// and, if they are a member of a user-defined group, their group. + /// </para> + /// <para> + /// This class also maintains a <see cref="WatchedUsernamesDictionary"/> to keep track of which usernames have been + /// "watched" server side and for which we will therefore receive events when their status changes. + /// </para> + /// <para> + /// If a user's information is in the <see cref="UserDictionary"/>, it's because we requested it at some point. If that user + /// is also "watched", we can assume that the data in the dictionary is up to date and will be kept so. + /// </para> + /// <para> + /// The data in the <see cref="UserDictionary"/> can continue to grow until -- unlikely -- it contains a record for every + /// user on or that was on the network at any point since the last client connect. This is a calculated risk, roughly + /// knowing the size of the network, the size of the data being stored, and balanced against the consequences of not having + /// a user's data when it is needed (for queue positioning, speed limits, etc) + /// </para> + /// <para> + /// The <see cref="GetGroup(string)"/> method acts on cached data _only_. This method should be called within hot paths, + /// such as a transfer governor or from the upload queue. We care more that it is fast than if it is stale. If no data for the + /// requested user is cached, that user is assumed to be in the default group. + /// </para> + /// <para> + /// The <see cref="GetOrFetchGroupAsync(string, bool)"/> method is similar to <see cref="GetGroup(string)"/>, except that if + /// the requested user is not cached, it will fetch the user's data and cache it before returning. This method accepts an optional + /// parameter that can be used to force a "refresh" of the requested user's data, useful for times when we want the latest data, + /// and can afford to wait for it. + /// </para> + /// </remarks> public interface IUserService { /// <summary> @@ -39,28 +71,12 @@ namespace slskd.Users /// <summary> /// Gets the name of the group for the specified <paramref name="username"/>. /// </summary> - /// <remarks> - /// The group name is fetched from cached data, and lookups should always be fast. - /// </remarks> + /// <remarks>The group name is fetched from cached data, and lookups should always be fast.</remarks> /// <param name="username">The username of the peer.</param> /// <returns>The group for the specified username.</returns> string GetGroup(string username); /// <summary> - /// Gets the name of the group for the specified <paramref name="username"/>. - /// </summary> - /// <remarks> - /// An alternative to <see cref="GetGroup(string)"/> that does not rely on the - /// internal cache. This method allows privilege and leech detection for users - /// that are not watched. - /// </remarks> - /// <param name="username">The username of the peer.</param> - /// <param name="status">The peer's status.</param> - /// <param name="statistics">The peer's statistics</param> - /// <returns>The group for the specified username.</returns> - string GetGroup(string username, Status status, Statistics statistics); - - /// <summary> /// Retrieves peer <see cref="Info"/>. /// </summary> /// <param name="username">The username of the peer.</param> @@ -75,7 +91,26 @@ namespace slskd.Users Task<IPEndPoint> GetIPEndPointAsync(string username); /// <summary> - /// Retrieves the current <see cref="Status"/> of a peer. + /// Gets the name of the group for the specified <paramref name="username"/>, or, if the user's information isn't + /// cached, fetches and caches the user's information from the server, then returns the group. + /// </summary> + /// <remarks>The fetch of fresh data can be forced by specifying <paramref name="forceFetch"/> = true.</remarks> + /// <param name="username">The username of the peer.</param> + /// <param name="forceFetch"> + /// A value determining whether the user's information should be fetched from the server, regardless of local cache. + /// </param> + /// <returns>The group for the specified username.</returns> + Task<string> GetOrFetchGroupAsync(string username, bool forceFetch = false); + + /// <summary> + /// Retrieves the current <see cref="Statistics"/> of a peer, and caches the result. + /// </summary> + /// <param name="username">The username of the peer.</param> + /// <returns>The retrieved statistics.</returns> + Task<Statistics> GetStatisticsAsync(string username); + + /// <summary> + /// Retrieves the current <see cref="Status"/> of a peer, and caches the result. /// </summary> /// <param name="username">The username of the peer.</param> /// <returns>The retrieved status.</returns> @@ -90,6 +125,14 @@ namespace slskd.Users Task GrantPrivilegesAsync(string username, int days); /// <summary> + /// Gets a value indicating whether the specified <paramref name="username"/> and/or <paramref name="ipAddress"/> are blacklisted. + /// </summary> + /// <param name="username">The username to check.</param> + /// <param name="ipAddress">The IPAddress to check, if available.</param> + /// <returns>A value indicating whether the specified user and/or IP are blacklisted.</returns> + bool IsBlacklisted(string username, IPAddress ipAddress = null); + + /// <summary> /// Retrieves a value indicating whether the specified peer is privileged. /// </summary> /// <param name="username">The username of the peer.</param> |
