aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Users
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-03-17 18:24:44 -0500
committerJP Dillingham <jp@dillingham.me>2024-03-17 18:24:44 -0500
commitd275223aa4afc588bd0731363c58fa3583b8ff36 (patch)
tree7260c99298df6ccd1431afab9e53a251cc9124ee /src/slskd/Users
parent6abd8142a4b526b562bf1fde2c9fde2164a820cb (diff)
downloadslskd-d275223aa4afc588bd0731363c58fa3583b8ff36.tar.gz
move blacklist to core
Diffstat (limited to 'src/slskd/Users')
-rw-r--r--src/slskd/Users/Blacklist.cs73
1 files changed, 0 insertions, 73 deletions
diff --git a/src/slskd/Users/Blacklist.cs b/src/slskd/Users/Blacklist.cs
deleted file mode 100644
index de8b567b..00000000
--- a/src/slskd/Users/Blacklist.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-// <copyright file="Blacklist.cs" company="slskd Team">
-// Copyright (c) slskd Team. All rights reserved.
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published
-// by the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see https://www.gnu.org/licenses/.
-// </copyright>
-
-namespace slskd.Users;
-
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Net;
-
-/// <summary>
-/// A managed blacklist for CIDRs.
-/// </summary>
-public class Blacklist
-{
- private Dictionary<int, (uint First, uint Last)[]> Cache { get; }
-
- public void Load(string filename)
- {
- // todo:
- // _stream_ contents of file into a ConcurrentDictionary<int, List<>>
- // load that dictionary into the Cache
- // enjoy
- }
-
- public bool Contains(IPAddress ip)
- {
- int first = ip.GetAddressBytes()[0];
-
- if (!Cache.TryGetValue(first, out (uint, uint)[] cidrs))
- {
- return false;
- }
-
- var ipAsUint32 = ToUint32(ip);
-
- foreach (var cidr in cidrs)
- {
- if (ipAsUint32 >= cidr.Item1 && ipAsUint32 <= cidr.Item2)
- {
- return true;
- }
- }
-
- return false;
- }
-
- private uint ToUint32(IPAddress ip)
- {
- byte[] bytes = ip.GetAddressBytes();
-
- if (BitConverter.IsLittleEndian)
- {
- Array.Reverse(bytes);
- }
-
- return BitConverter.ToUInt32(bytes, 0);
- }
-} \ No newline at end of file