gossip sync: sync with random 20 peers per cycle instead of all peers
This commit is contained in:
parent
38d594ac50
commit
4b98779122
3 changed files with 15 additions and 2 deletions
|
|
@ -47,6 +47,8 @@ All moderation is local — you control your view:
|
||||||
- Forum instances auto-discover each other via RNS announces
|
- Forum instances auto-discover each other via RNS announces
|
||||||
- Content is exchanged as JSON over RNS links every 5 minutes
|
- Content is exchanged as JSON over RNS links every 5 minutes
|
||||||
- Peer discovery propagates through gossip — each instance shares its known peers
|
- Peer discovery propagates through gossip — each instance shares its known peers
|
||||||
|
- At scale (>20 peers), sync uses random gossip: each cycle picks 20 random peers instead of all peers
|
||||||
|
- This ensures content converges epidemically regardless of network size (content reaches all nodes within ~O(log N) cycles)
|
||||||
- Block lists and retractions are gossiped alongside content
|
- Block lists and retractions are gossiped alongside content
|
||||||
- Only new/updated content is transferred (timestamp-based)
|
- Only new/updated content is transferred (timestamp-based)
|
||||||
- Auto-discovery can be disabled in the moderation page
|
- Auto-discovery can be disabled in the moderation page
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,14 @@ class ForumDB:
|
||||||
"CREATE TABLE IF NOT EXISTS synced_instances ("
|
"CREATE TABLE IF NOT EXISTS synced_instances ("
|
||||||
" instance_hash TEXT PRIMARY KEY,"
|
" instance_hash TEXT PRIMARY KEY,"
|
||||||
" name TEXT DEFAULT '',"
|
" name TEXT DEFAULT '',"
|
||||||
" last_sync TEXT DEFAULT ''"
|
" last_sync TEXT DEFAULT '',"
|
||||||
|
" status TEXT DEFAULT 'active'"
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
db.execute("ALTER TABLE synced_instances ADD COLUMN status TEXT DEFAULT 'active'")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
db.execute(
|
db.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS settings ("
|
"CREATE TABLE IF NOT EXISTS settings ("
|
||||||
" key TEXT PRIMARY KEY,"
|
" key TEXT PRIMARY KEY,"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
import random
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import RNS
|
import RNS
|
||||||
|
|
@ -6,6 +7,7 @@ import RNS
|
||||||
FORUM_APP = "tinyweb-forum"
|
FORUM_APP = "tinyweb-forum"
|
||||||
SYNC_INTERVAL = 300 # 5 minutes
|
SYNC_INTERVAL = 300 # 5 minutes
|
||||||
REQUEST_TIMEOUT = 60
|
REQUEST_TIMEOUT = 60
|
||||||
|
GOSSIP_FANOUT = 20 # random peers to sync per cycle
|
||||||
|
|
||||||
|
|
||||||
class _ForumAnnounceHandler:
|
class _ForumAnnounceHandler:
|
||||||
|
|
@ -90,7 +92,11 @@ class ForumSync:
|
||||||
while self._running:
|
while self._running:
|
||||||
try:
|
try:
|
||||||
instances = self.fdb.get_synced_instances()
|
instances = self.fdb.get_synced_instances()
|
||||||
for inst in instances:
|
# Gossip: sync with random subset for scaling
|
||||||
|
# If <= GOSSIP_FANOUT peers, sync with all (current behavior)
|
||||||
|
# If more, sync with random FANOUT per cycle — content spreads epidemically
|
||||||
|
random.shuffle(instances)
|
||||||
|
for inst in instances[:GOSSIP_FANOUT]:
|
||||||
if not self._running:
|
if not self._running:
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue