diff --git a/.env.example b/.env.example index be45312..d4e4f7a 100644 --- a/.env.example +++ b/.env.example @@ -8,10 +8,11 @@ RELAY_URL="wss://wot.utxo.one" DB_PATH="db" # where we should store the index.html and static files -INDEX_PATH="templates/index.html" -STATIC_PATH="templates/static" +INDEX_PATH="/mnt/dev/bitvora/wot-relay/templates/index.html" +STATIC_PATH="/mnt/dev/bitvora/wot-relay/templates/static/" # relay behavior # how often to refresh the relay's view of the WoT in HOURS -REFRESH_INTERVAL_HOURS=1 \ No newline at end of file +REFRESH_INTERVAL_HOURS=1 +MINIMUM_FOLLOWERS=5 \ No newline at end of file diff --git a/README.md b/README.md index 7bc4ff6..529f39a 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ DB_PATH="/home/ubuntu/wot-relay/db" # any path you would like the database to be INDEX_PATH="/home/ubuntu/wot-relay/templates/index.html" # path to the index.html file STATIC_PATH="/home/ubuntu/wot-relay/templates/static" # path to the static folder REFRESH_INTERVAL_HOURS=24 # interval in hours to refresh the web of trust +MINIMUM_FOLLOWERS=3 #how many followers before they're allowed in the WoT ``` ### 4. Build the project diff --git a/main.go b/main.go index 454f185..4cdd34e 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ type Config struct { IndexPath string StaticPath string RefreshInterval int + MinimumFollowers int } var pool *nostr.SimplePool @@ -36,6 +37,7 @@ var seedRelays []string var booted bool var oneHopNetwork []string var trustNetworkMap map[string]bool +var pubkeyFollowerCount = make(map[string]int) func main() { nostr.InfoLogger = log.New(io.Discard, "", 0) @@ -162,6 +164,12 @@ func LoadConfig() Config { refreshInterval, _ := strconv.Atoi(os.Getenv("REFRESH_INTERVAL_HOURS")) log.Println("🔄 refresh interval set to", refreshInterval, "hours") + if os.Getenv("MINIMUM_FOLLOWERS") == "" { + os.Setenv("MINIMUM_FOLLOWERS", "1") + } + + minimumFollowers, _ := strconv.Atoi(os.Getenv("MINIMUM_FOLLOWERS")) + config := Config{ RelayName: getEnv("RELAY_NAME"), RelayPubkey: getEnv("RELAY_PUBKEY"), @@ -171,6 +179,7 @@ func LoadConfig() Config { IndexPath: getEnv("INDEX_PATH"), StaticPath: getEnv("STATIC_PATH"), RefreshInterval: refreshInterval, + MinimumFollowers: minimumFollowers, } return config @@ -187,11 +196,15 @@ func getEnv(key string) string { func updateTrustNetworkFilter() { trustNetworkMap = make(map[string]bool) - nKeys := uint64(len(trustNetwork)) - log.Println("🌐 updating trust network map with", nKeys, "keys") - for _, trustedPubkey := range trustNetwork { - trustNetworkMap[trustedPubkey] = true + log.Println("🌐 updating trust network map") + for pubkey, count := range pubkeyFollowerCount { + if count >= config.MinimumFollowers { + trustNetworkMap[pubkey] = true + appendPubkey(pubkey) + } } + + log.Println("🌐 trust network map updated with", len(trustNetwork), "keys") } func refreshProfiles(ctx context.Context, relay *khatru.Relay) { @@ -230,6 +243,7 @@ func refreshTrustNetwork(relay *khatru.Relay, ctx context.Context) { log.Println("🔍 fetching owner's follows") for ev := range pool.SubManyEose(timeoutCtx, seedRelays, filters) { for _, contact := range ev.Event.Tags.GetAll([]string{"p"}) { + pubkeyFollowerCount[contact[1]]++ // Increment follower count for the pubkey appendOneHopNetwork(contact[1]) } } @@ -251,9 +265,7 @@ func refreshTrustNetwork(relay *khatru.Relay, ctx context.Context) { for ev := range pool.SubManyEose(timeout, seedRelays, filters) { for _, contact := range ev.Event.Tags.GetAll([]string{"p"}) { - if len(contact) > 1 { - appendPubkey(contact[1]) - } + pubkeyFollowerCount[contact[1]]++ // Increment follower count for the pubkey } for _, relay := range ev.Event.Tags.GetAll([]string{"r"}) { @@ -264,9 +276,8 @@ func refreshTrustNetwork(relay *khatru.Relay, ctx context.Context) { relay.AddEvent(ctx, ev.Event) } } - } - log.Println("🫂 network size:", len(trustNetwork)) + log.Println("🫂 total network size:", len(pubkeyFollowerCount)) log.Println("🔗 relays discovered:", len(relays)) } @@ -355,7 +366,7 @@ func archiveTrustedNotes(relay *khatru.Relay, ctx context.Context) { case ev, ok := <-eventChan: if !ok { - log.Println("📦 SubMany channel closed") + log.Println("📦 subscription channel closed") log.Println("📦 archived", trustedNotes, "trusted notes and discarded", untrustedNotes, "untrusted notes") return } @@ -367,7 +378,7 @@ func archiveTrustedNotes(relay *khatru.Relay, ctx context.Context) { relay.AddEvent(ctx, ev.Event) trustedNotes++ - log.Println("📦 archived note: ", ev.Event.ID) + //log.Println("📦 archived note: ", ev.Event.ID) } else { untrustedNotes++ }