First commit, has ability to create, merge, and modify lists
This commit is contained in:
commit
38b5defebf
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
230
Cargo.lock
generated
Normal file
230
Cargo.lock
generated
Normal file
|
@ -0,0 +1,230 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
|
||||
|
||||
[[package]]
|
||||
name = "env_filter"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea"
|
||||
dependencies = [
|
||||
"log",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"env_filter",
|
||||
"humantime",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fediloom"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"env_logger",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "fediloom"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
env_logger = "0.11.3"
|
||||
log = "0.4.21"
|
69
src/list/mod.rs
Normal file
69
src/list/mod.rs
Normal file
|
@ -0,0 +1,69 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
pub struct SourceList {
|
||||
pub blocks: Vec<String>,
|
||||
pub confidence: u8,
|
||||
}
|
||||
|
||||
impl SourceList {
|
||||
pub fn new() -> Self {
|
||||
SourceList {
|
||||
blocks: Vec::new(),
|
||||
confidence: 100,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<String>> for SourceList {
|
||||
fn from(blocked: Vec<String>) -> Self {
|
||||
SourceList {
|
||||
blocks: blocked,
|
||||
confidence: 100,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TrustMaps {
|
||||
pub blocks: HashMap<String, usize>,
|
||||
}
|
||||
|
||||
impl TrustMaps {
|
||||
pub fn new() -> TrustMaps {
|
||||
TrustMaps {
|
||||
blocks: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_source(&mut self, src: &SourceList) -> &mut TrustMaps {
|
||||
for host in src.blocks.iter() {
|
||||
let entry = self.blocks.entry(host.to_string()).or_insert(0);
|
||||
*entry += src.confidence as usize;
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn remove_source(&mut self, src: &SourceList) -> &mut TrustMaps {
|
||||
// If blocks already empty, nothing to remove so just return
|
||||
if self.blocks.is_empty() {
|
||||
return self;
|
||||
}
|
||||
|
||||
// Iterate over host strings in source list
|
||||
for host in src.blocks.iter() {
|
||||
// If the host isn't in the output list, then skip
|
||||
if !self.blocks.contains_key(host) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Host is valid entry, subtract confidence value and saturate at 0
|
||||
self.blocks.entry(host.to_string()).and_modify(|v| {
|
||||
*v = v.saturating_sub(src.confidence as usize);
|
||||
});
|
||||
}
|
||||
|
||||
// Finally, if any value became zero, remove the pair from the map
|
||||
self.blocks.retain(|_, v| *v != 0);
|
||||
|
||||
self
|
||||
}
|
||||
}
|
20
src/main.rs
Normal file
20
src/main.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
// src/main.rs
|
||||
|
||||
mod list;
|
||||
mod tests;
|
||||
|
||||
// things we need to do:
|
||||
// - import 2 or more lists
|
||||
// - assign "trust" percent to each list
|
||||
// - combine lists together and weight each element by trust %s
|
||||
// - export 1 or more lists filtered by heat rating
|
||||
// - tiered lists, e.g.:
|
||||
// - tier 0: instances uniformly blocked
|
||||
// - tier 1: instances mixed blocked and silenced
|
||||
// - tier 2: instances silenced
|
||||
// - tier 3: instances mixed silenced and no action
|
||||
// - tier 4: instances no action (i.e., below all thresholds)
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
62
src/tests.rs
Normal file
62
src/tests.rs
Normal file
|
@ -0,0 +1,62 @@
|
|||
#![cfg(test)]
|
||||
|
||||
use super::*;
|
||||
use list::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[test]
|
||||
fn add_lists() {
|
||||
let hosts1 = vec![
|
||||
String::from("example.com"),
|
||||
String::from("example.org"),
|
||||
String::from("example.net"),
|
||||
];
|
||||
let hosts2 = vec![String::from("example.com"), String::from("example.org")];
|
||||
let hosts3 = vec![String::from("example.com")];
|
||||
|
||||
let src1 = SourceList::from(hosts1);
|
||||
let src2 = SourceList::from(hosts2);
|
||||
let src3 = SourceList::from(hosts3);
|
||||
|
||||
let mut output = TrustMaps::new();
|
||||
output.add_source(&src1).add_source(&src2).add_source(&src3);
|
||||
|
||||
let test_map = HashMap::from([
|
||||
(String::from("example.com"), 300),
|
||||
(String::from("example.org"), 200),
|
||||
(String::from("example.net"), 100),
|
||||
]);
|
||||
assert_eq!(test_map, output.blocks);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_lists() {
|
||||
let hosts1 = vec![
|
||||
String::from("example.com"),
|
||||
String::from("example.org"),
|
||||
String::from("example.net"),
|
||||
];
|
||||
let hosts2 = vec![String::from("example.com"), String::from("example.org")];
|
||||
let hosts3 = vec![String::from("example.com")];
|
||||
|
||||
let src1 = SourceList::from(hosts1);
|
||||
let src2 = SourceList::from(hosts2);
|
||||
let src3 = SourceList::from(hosts3);
|
||||
|
||||
let mut output = TrustMaps::new();
|
||||
output
|
||||
.add_source(&src1)
|
||||
.add_source(&src2)
|
||||
.add_source(&src3)
|
||||
.remove_source(&src3)
|
||||
.remove_source(&src3)
|
||||
.remove_source(&src3)
|
||||
.remove_source(&src3);
|
||||
|
||||
let test_map = HashMap::from([
|
||||
(String::from("example.org"), 200),
|
||||
(String::from("example.net"), 100),
|
||||
]);
|
||||
|
||||
assert_eq!(test_map, output.blocks);
|
||||
}
|
Loading…
Reference in a new issue