Initial import: ICE-NET research docs and Rust workspace (v0.4)
Some checks failed
rust-ci / checks (push) Has been cancelled
Some checks failed
rust-ci / checks (push) Has been cancelled
- Rust workspace: 7 library crates, icenetd CLI, icenet-city (Slint GUI) - Sim: fix false Delivered after a route cut, derive traffic class from payload size, per-link airtime slots (link capacity, queueing) - Docs: single docs/STATUS.md for all figures, remove v0.2/egui leftovers, drop unimplemented seed claims, uncheck store-and-forward - License: LGPL-3.0-or-later (LICENSE, LICENSES/GPL-3.0.txt)
This commit is contained in:
commit
2e61688eb3
141 changed files with 13993 additions and 0 deletions
46
workspace/crates/icenet-guard/tests/policy.rs
Normal file
46
workspace/crates/icenet-guard/tests/policy.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
use icenet_core::{NodeId, ServiceId};
|
||||
use icenet_guard::{Context, Guard, Limits, Verdict};
|
||||
|
||||
fn context() -> Context {
|
||||
Context {
|
||||
authenticated: true,
|
||||
peer: NodeId(1),
|
||||
service: ServiceId(77_777),
|
||||
payload_bytes: 5,
|
||||
sequence: 1,
|
||||
now_ms: 0,
|
||||
queue_depth: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn limits() -> Limits {
|
||||
Limits {
|
||||
max_payload_bytes: 128,
|
||||
..Limits::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn denies_untrusted_and_unknown_service() {
|
||||
let mut guard = Guard::new([ServiceId(77_777)], limits());
|
||||
let mut request = context();
|
||||
request.authenticated = false;
|
||||
assert_eq!(guard.check(request), Verdict::Deny("unauthenticated"));
|
||||
request.authenticated = true;
|
||||
request.service = ServiceId(1);
|
||||
assert_eq!(guard.check(request), Verdict::Deny("service_denied"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn permits_bounded_known_service() {
|
||||
let mut guard = Guard::new([ServiceId(77_777)], limits());
|
||||
assert_eq!(guard.check(context()), Verdict::Permit);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn denies_oversized_payload() {
|
||||
let mut guard = Guard::new([ServiceId(77_777)], limits());
|
||||
let mut request = context();
|
||||
request.payload_bytes = 129;
|
||||
assert_eq!(guard.check(request), Verdict::Deny("oversized"));
|
||||
}
|
||||
37
workspace/crates/icenet-guard/tests/queue.rs
Normal file
37
workspace/crates/icenet-guard/tests/queue.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
use icenet_core::{NodeId, ServiceId};
|
||||
use icenet_guard::{Context, Guard, Limits, Verdict};
|
||||
|
||||
fn context(queue_depth: usize, sequence: u64) -> Context {
|
||||
Context {
|
||||
authenticated: true,
|
||||
peer: NodeId(1),
|
||||
service: ServiceId(7),
|
||||
payload_bytes: 1,
|
||||
sequence,
|
||||
now_ms: 0,
|
||||
queue_depth,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn full_queue_is_denied_before_accepting_more_work() {
|
||||
let limits = Limits {
|
||||
max_queue_depth: 2,
|
||||
rate_per_second: 0,
|
||||
..Limits::default()
|
||||
};
|
||||
let mut guard = Guard::new([ServiceId(7)], limits);
|
||||
assert_eq!(guard.check(context(1, 1)), Verdict::Permit);
|
||||
assert_eq!(guard.check(context(2, 2)), Verdict::Deny("queue_full"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_queue_below_the_cap_is_permitted() {
|
||||
let limits = Limits {
|
||||
max_queue_depth: 2,
|
||||
rate_per_second: 0,
|
||||
..Limits::default()
|
||||
};
|
||||
let mut guard = Guard::new([ServiceId(7)], limits);
|
||||
assert_eq!(guard.check(context(0, 1)), Verdict::Permit);
|
||||
}
|
||||
52
workspace/crates/icenet-guard/tests/rate.rs
Normal file
52
workspace/crates/icenet-guard/tests/rate.rs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
use icenet_core::{NodeId, ServiceId};
|
||||
use icenet_guard::{Context, Guard, Limits, Verdict};
|
||||
|
||||
fn limits(rate: u64, burst: u64) -> Limits {
|
||||
Limits {
|
||||
rate_per_second: rate,
|
||||
burst,
|
||||
replay_window: 64,
|
||||
..Limits::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn context(peer: u64, sequence: u64, now_ms: u64) -> Context {
|
||||
Context {
|
||||
authenticated: true,
|
||||
peer: NodeId(peer),
|
||||
service: ServiceId(7),
|
||||
payload_bytes: 1,
|
||||
sequence,
|
||||
now_ms,
|
||||
queue_depth: 0,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn burst_is_allowed_then_requests_are_limited_until_refill() {
|
||||
let mut guard = Guard::new([ServiceId(7)], limits(2, 2));
|
||||
assert_eq!(guard.check(context(1, 1, 0)), Verdict::Permit);
|
||||
assert_eq!(guard.check(context(1, 2, 0)), Verdict::Permit);
|
||||
assert_eq!(guard.check(context(1, 3, 0)), Verdict::Deny("rate_limited"));
|
||||
assert_eq!(guard.check(context(1, 4, 500)), Verdict::Permit);
|
||||
assert_eq!(
|
||||
guard.check(context(1, 5, 500)),
|
||||
Verdict::Deny("rate_limited")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rate_buckets_are_per_peer() {
|
||||
let mut guard = Guard::new([ServiceId(7)], limits(1, 1));
|
||||
assert_eq!(guard.check(context(1, 1, 0)), Verdict::Permit);
|
||||
assert_eq!(guard.check(context(1, 2, 0)), Verdict::Deny("rate_limited"));
|
||||
assert_eq!(guard.check(context(2, 1, 0)), Verdict::Permit);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_rate_disables_limiting() {
|
||||
let mut guard = Guard::new([ServiceId(7)], limits(0, 0));
|
||||
for sequence in 0..50 {
|
||||
assert_eq!(guard.check(context(1, sequence, 0)), Verdict::Permit);
|
||||
}
|
||||
}
|
||||
54
workspace/crates/icenet-guard/tests/replay.rs
Normal file
54
workspace/crates/icenet-guard/tests/replay.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
use icenet_core::{NodeId, ServiceId};
|
||||
use icenet_guard::{Context, Guard, Limits, Verdict};
|
||||
|
||||
fn limits(window: u64) -> Limits {
|
||||
Limits {
|
||||
replay_window: window,
|
||||
rate_per_second: 0,
|
||||
..Limits::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn context(peer: u64, sequence: u64) -> Context {
|
||||
Context {
|
||||
authenticated: true,
|
||||
peer: NodeId(peer),
|
||||
service: ServiceId(7),
|
||||
payload_bytes: 1,
|
||||
sequence,
|
||||
now_ms: 0,
|
||||
queue_depth: 0,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_sequence_is_denied() {
|
||||
let mut guard = Guard::new([ServiceId(7)], limits(4));
|
||||
assert_eq!(guard.check(context(1, 1)), Verdict::Permit);
|
||||
assert_eq!(guard.check(context(1, 1)), Verdict::Deny("replay"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sequence_below_the_window_is_denied() {
|
||||
let mut guard = Guard::new([ServiceId(7)], limits(4));
|
||||
assert_eq!(guard.check(context(1, 10)), Verdict::Permit);
|
||||
assert_eq!(guard.check(context(1, 6)), Verdict::Deny("replay"));
|
||||
assert_eq!(guard.check(context(1, 7)), Verdict::Permit);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn higher_sequence_advances_and_prunes_the_window() {
|
||||
let mut guard = Guard::new([ServiceId(7)], limits(4));
|
||||
assert_eq!(guard.check(context(1, 4)), Verdict::Permit);
|
||||
assert_eq!(guard.check(context(1, 5)), Verdict::Permit);
|
||||
assert_eq!(guard.check(context(1, 1)), Verdict::Deny("replay"));
|
||||
assert_eq!(guard.check(context(1, 2)), Verdict::Permit);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replay_state_is_per_peer() {
|
||||
let mut guard = Guard::new([ServiceId(7)], limits(4));
|
||||
assert_eq!(guard.check(context(1, 5)), Verdict::Permit);
|
||||
assert_eq!(guard.check(context(2, 5)), Verdict::Permit);
|
||||
assert_eq!(guard.check(context(2, 5)), Verdict::Deny("replay"));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue