forum trust circle: trust-gated content exchange via subscription graph

This commit is contained in:
blankie 2026-06-17 19:10:32 +00:00
parent 6f700c213f
commit 3a26a726a4
4 changed files with 219 additions and 15 deletions

View file

@ -1,8 +1,14 @@
import os
import sqlite3
import threading
import time
from tinyweb_forum.db import ForumDB
from tinyweb_forum.handlers import ForumHandlers
from tinyweb_forum.sync import ForumSync
FORUM_ENABLED_KEY = "forum_enabled"
TRUST_REFRESH_INTERVAL = 120
class ForumPlugin:
@ -16,19 +22,52 @@ class ForumPlugin:
self.identity = identity
self.reticulum = reticulum
self._started = False
self._data_dir = data_dir
self._core_db_path = os.path.join(data_dir, "index.db")
self._trust_refresh_thread = None
def is_enabled(self):
return self.fdb.get_setting(FORUM_ENABLED_KEY, "0") == "1"
def _seed_trust_from_subscriptions(self):
my_hash = self.identity.hash.hex() if self.identity else "local"
if not os.path.exists(self._core_db_path):
return
try:
core = sqlite3.connect(self._core_db_path)
rows = core.execute(
"SELECT dest_hash FROM subscriptions WHERE forum_enabled = 1"
).fetchall()
core.close()
for row in rows:
self.fdb.add_trust_source(row[0], my_hash, 0)
except Exception:
pass
def _trust_refresh_loop(self):
while self._started:
try:
self._seed_trust_from_subscriptions()
except Exception:
pass
for _ in range(TRUST_REFRESH_INTERVAL):
if not self._started:
return
time.sleep(1)
def enable(self):
self.fdb.set_setting(FORUM_ENABLED_KEY, "1")
if not self._started:
self._seed_trust_from_subscriptions()
self.sync.start()
self._started = True
self._trust_refresh_thread = threading.Thread(
target=self._trust_refresh_loop, daemon=True
)
self._trust_refresh_thread.start()
def disable(self):
self.fdb.set_setting(FORUM_ENABLED_KEY, "0")
# Keep sync running so we still receive content — disable just hides UI
def handle(self, method, path, query, body, cookies=None):
return self.handlers.handle(method, path, query, body, cookies)