Add noop and hellthread policies
This commit is contained in:
commit
1d3bc34b91
5
.vscode/extensions.json
vendored
Normal file
5
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"denoland.vscode-deno"
|
||||
]
|
||||
}
|
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"deno.enable": true,
|
||||
"path-intellisense.extensionOnImport": true
|
||||
}
|
24
LICENSE
Normal file
24
LICENSE
Normal file
@ -0,0 +1,24 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <https://unlicense.org>
|
9
README.md
Normal file
9
README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# strfry policies
|
||||
|
||||
A collection of policies for the [strfry](https://github.com/hoytech/strfry) relay, written in Deno.
|
||||
|
||||
For more information about installing these policies and how they work, see [Write policy plugins](https://github.com/hoytech/strfry/blob/master/docs/plugins.md).
|
||||
|
||||
## License
|
||||
|
||||
This is free and unencumbered software released into the public domain.
|
27
deno.json
Normal file
27
deno.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"lock": false,
|
||||
"tasks": {
|
||||
},
|
||||
"lint": {
|
||||
"files": {
|
||||
"include": ["."]
|
||||
},
|
||||
"rules": {
|
||||
"tags": ["recommended"],
|
||||
"exclude": ["no-explicit-any"]
|
||||
}
|
||||
},
|
||||
"fmt": {
|
||||
"files": {
|
||||
"include": ["."]
|
||||
},
|
||||
"options": {
|
||||
"useTabs": false,
|
||||
"lineWidth": 120,
|
||||
"indentWidth": 2,
|
||||
"semiColons": true,
|
||||
"singleQuote": true,
|
||||
"proseWrap": "preserve"
|
||||
}
|
||||
}
|
||||
}
|
50
hellthread-policy.ts
Executable file
50
hellthread-policy.ts
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env -S deno run
|
||||
import { readLines } from 'https://deno.land/std@0.178.0/io/mod.ts';
|
||||
|
||||
const HELLTHREAD_LIMIT = Number(Deno.env.get('HELLTHREAD_LIMIT') || 20);
|
||||
|
||||
interface InputMessage {
|
||||
type: 'new' | 'lookback';
|
||||
event: Event;
|
||||
receivedAt: number;
|
||||
sourceType: 'IP4' | 'IP6' | 'Import' | 'Stream' | 'Sync';
|
||||
sourceInfo: string;
|
||||
}
|
||||
|
||||
interface OutputMessage {
|
||||
id: string;
|
||||
action: 'accept' | 'reject' | 'shadowReject';
|
||||
msg: string;
|
||||
}
|
||||
|
||||
interface Event {
|
||||
id: string;
|
||||
sig: string;
|
||||
kind: number;
|
||||
tags: string[][];
|
||||
pubkey: string;
|
||||
content: string;
|
||||
created_at: number;
|
||||
}
|
||||
|
||||
function handleMessage(msg: InputMessage): OutputMessage {
|
||||
const p = msg.event.tags.filter((tag) => tag[0] === 'p');
|
||||
|
||||
if (p.length > HELLTHREAD_LIMIT) {
|
||||
return {
|
||||
id: msg.event.id,
|
||||
action: 'reject',
|
||||
msg: `Event rejected due to ${p.length} "p" tags (${HELLTHREAD_LIMIT} is the limit).`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
id: msg.event.id,
|
||||
action: 'accept',
|
||||
msg: '',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
for await (const line of readLines(Deno.stdin)) {
|
||||
console.log(JSON.stringify(handleMessage(JSON.parse(line))));
|
||||
}
|
38
noop-policy.ts
Executable file
38
noop-policy.ts
Executable file
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env -S deno run
|
||||
import { readLines } from 'https://deno.land/std@0.178.0/io/mod.ts';
|
||||
|
||||
interface InputMessage {
|
||||
type: 'new' | 'lookback';
|
||||
event: Event;
|
||||
receivedAt: number;
|
||||
sourceType: 'IP4' | 'IP6' | 'Import' | 'Stream' | 'Sync';
|
||||
sourceInfo: string;
|
||||
}
|
||||
|
||||
interface OutputMessage {
|
||||
id: string;
|
||||
action: 'accept' | 'reject' | 'shadowReject';
|
||||
msg: string;
|
||||
}
|
||||
|
||||
interface Event {
|
||||
id: string;
|
||||
sig: string;
|
||||
kind: number;
|
||||
tags: string[][];
|
||||
pubkey: string;
|
||||
content: string;
|
||||
created_at: number;
|
||||
}
|
||||
|
||||
function handleMessage(msg: InputMessage): OutputMessage {
|
||||
return {
|
||||
id: msg.event.id,
|
||||
action: 'accept',
|
||||
msg: '',
|
||||
};
|
||||
}
|
||||
|
||||
for await (const line of readLines(Deno.stdin)) {
|
||||
console.log(JSON.stringify(handleMessage(JSON.parse(line))));
|
||||
}
|
Loading…
Reference in New Issue
Block a user