diff options
| author | JP Dillingham <jp@dillingham.me> | 2024-01-05 18:40:43 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2024-01-05 18:40:43 -0600 |
| commit | 805e1ed565a1898c158931b322a8d0db5a83ef05 (patch) | |
| tree | d46c85aecb0a29fff99aece530470f84de7c4036 /src | |
| parent | eb14f632df9f8f487335db643fdea4b9c1547be1 (diff) | |
| download | slskd-805e1ed565a1898c158931b322a8d0db5a83ef05.tar.gz | |
move IsBlacklisted, fetch user info if they request our info
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 506f08ac..fd2a2487 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -1162,7 +1162,7 @@ namespace slskd { Metrics.Search.RequestsReceived.Inc(1); - if (IsBlacklisted(username)) + if (Users.IsBlacklisted(username)) { Log.Information("Returned empty search response for blacklisted user {Username}", username); return new SearchResponse(username, token, hasFreeUploadSlot: false, uploadSpeed: 0, queueLength: int.MaxValue, fileList: Enumerable.Empty<Soulseek.File>()); @@ -1197,6 +1197,9 @@ namespace slskd // make sure our average speed (as reported by the server) is reasonably up to date await RefreshUserStatistics(); + // note: the following uses cached user data to determine group, so if the user's data + // isn't cached they may get a forecast based on the wrong group. this is a hot path though, + // and we don't want to incur the massive penalties that would caching data for each request. var forecastedPosition = Transfers.Uploads.Queue.ForecastPosition(username); Log.Information("[{Context}]: Sending {Count} records to {Username} for query '{Query}'", "SEARCH RESULT SENT", results.Count(), username, query.SearchText); @@ -1357,7 +1360,7 @@ namespace slskd /// <returns>A Task resolving the UserInfo instance.</returns> private Task<UserInfo> UserInfoResolver(string username, IPEndPoint endpoint) { - if (IsBlacklisted(username, endpoint.Address)) + if (Users.IsBlacklisted(username, endpoint.Address)) { return Task.FromResult(new UserInfo( description: Options.Soulseek.Description, @@ -1371,7 +1374,7 @@ namespace slskd // note: users must first be watched or cached for leech and privilege detection to work. // we are deliberately skipping it here; if the username is watched // leech detection works and they get accurate info, if not, they won't - var groupName = Users.GetGroup(username); + var groupName = Users.GetOrFetchGroup(username); var group = Transfers.Uploads.Queue.GetGroupInfo(groupName); // forecast the position at which this user would enter the queue if they were to request @@ -1397,20 +1400,5 @@ namespace slskd throw; } } - - private bool IsBlacklisted(string username, IPAddress ipAddress = null) - { - if (Options.Groups.Blacklisted.Members.Contains(username)) - { - return true; - } - - if (ipAddress is not null && Options.Groups.Blacklisted.Cidrs.Select(c => IPAddressRange.Parse(c)).Any(range => range.Contains(ipAddress))) - { - return true; - } - - return false; - } } } |
