From 0e79985655abcbf10380f60fd50da46c47d8af88 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 22 Apr 2026 18:48:15 -0500 Subject: document GetGroup, remove check of IsBlacklisted within --- src/slskd/Users/UserService.cs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/slskd/Users/UserService.cs b/src/slskd/Users/UserService.cs index 0a620992..95892753 100644 --- a/src/slskd/Users/UserService.cs +++ b/src/slskd/Users/UserService.cs @@ -42,6 +42,7 @@ namespace slskd.Users using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Memory; + using Microsoft.Extensions.Internal; using NetTools; using Serilog; using Soulseek; @@ -173,30 +174,45 @@ namespace slskd.Users private ConcurrentDictionary WatchedUsernamesDictionary { get; set; } = new ConcurrentDictionary(); /// - /// Gets the name of the group for the specified . + /// Gets the name of the group for the specified from cached data. /// - /// The group name is fetched from cached data, and lookups should always be fast. + /// + /// + /// Excludes the 'blacklisted' group for performance; use to guard network operations instead. + /// + /// + /// This is an extremely hot path, and the value returned may be approximated or incorrect in the case of a + /// cache miss in order to provide low latency values. + /// + /// /// The username of the peer. /// The group for the specified username. public string GetGroup(string username) { + // users end up in this dictionary for a few reasons, including but maybe not limited to: + // * they show up in the user defined group list somewhere + // * the server told us they have privileges when we logged in + // * we 'watched' them + // * we fetched statistics or status for them + // if we handle any of their data they'll probably wind up here. if they show up in the config, + // their Group property will be set. otherwise we must resolve their group dynamically. if (UserDictionary.TryGetValue(username ?? string.Empty, out var user)) { - if (IsBlacklisted(user.Username)) - { - return Application.BlacklistedGroup; - } - + // privileged users trump everything, and we resolve their group accordingly regardless of all other factors if (user.Status?.IsPrivileged ?? false) { return Application.PrivilegedGroup; } + // if the user isn't privileged and the user has put their username in any user defined group, that's + // their group. they aren't subjected to leecher checks. if (user.Group != null) { return user.Group; } + // check to see if they are a leecher. they may be in the dictionary because we checked their stats. + // if we don't have their stats we don't have enough info to make the call, group is inconclusive so fall through var thresholds = OptionsMonitor.CurrentValue.Transfers.Groups.Leechers.Thresholds; if (user.Statistics?.FileCount < thresholds.Files || user.Statistics?.DirectoryCount < thresholds.Directories) -- cgit v1.2.3