interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / server / tests / ratelim.om

68 lines · 1274 bytes Raw Blame History
1note server/tests/ratelim.om -- unit gate for fratelim (server/util.om), run by server/tests/check.sh.
2note Composed after every forged unit (main.om's main renamed), so it calls the real fratelim.
3note Exit 0 = pass; 1/2 = one IP not limited to 30 writes; 3 = another IP refused; 4 = an IP whose
4note old 32-bit FNV bucket (rem h 256) equals the exhausted IP's was refused (the P3-3 collision);
5note 5 = no colliding IP found; 6 = a fresh IP refused while the table fills.
6text ttipa "10.0.0.1"
7fn tsetip t view uchar * to void
8for i ulong len t bound 64
9put fip i get t i
10end
11put fipl 0 len t
12end
13fn tsetn n ulong to void
14put fip 0 105
15put fip 1 uchar and n 255
16put fip 2 uchar and shr n 8 255
17put fipl 0 3
18end
19fn toldb to ulong
20h = ulong 2166136261
21for i ulong get fipl 0 bound 64
22h = and mul xor h ulong get fip i 16777619 4294967295
23end
24ret rem h 256
25end
26fn tcoll ob ulong to ulong
27for n ulong 65536
28tsetn n
29if eq toldb ob
30ret n
31end
32end
33ret 65536
34end
35fn tfill to int
36for n ulong 300
37tsetn add n 1000
38if not fratelim
39ret 6
40end
41end
42ret 0
43end
44fn main to int
45tsetip ttipa
46for i ulong 30
47if not fratelim
48ret 1
49end
50end
51if fratelim
52ret 2
53end
54ob = toldb
55tsetn 70000
56if not fratelim
57ret 3
58end
59n = tcoll ob
60if eq n 65536
61ret 5
62end
63tsetn n
64if not fratelim
65ret 4
66end
67ret tfill
68end