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