mirror of
https://github.com/bitvora/wot-relay.git
synced 2025-06-06 18:31:05 +00:00
Merge pull request #32 from bitvora/dev-profileRefresh
customize the trust network by follower count
This commit is contained in:
commit
37a9e1c0cc
@ -8,10 +8,11 @@ RELAY_URL="wss://wot.utxo.one"
|
|||||||
DB_PATH="db"
|
DB_PATH="db"
|
||||||
|
|
||||||
# where we should store the index.html and static files
|
# where we should store the index.html and static files
|
||||||
INDEX_PATH="templates/index.html"
|
INDEX_PATH="/mnt/dev/bitvora/wot-relay/templates/index.html"
|
||||||
STATIC_PATH="templates/static"
|
STATIC_PATH="/mnt/dev/bitvora/wot-relay/templates/static/"
|
||||||
|
|
||||||
# relay behavior
|
# relay behavior
|
||||||
|
|
||||||
# how often to refresh the relay's view of the WoT in HOURS
|
# how often to refresh the relay's view of the WoT in HOURS
|
||||||
REFRESH_INTERVAL_HOURS=1
|
REFRESH_INTERVAL_HOURS=1
|
||||||
|
MINIMUM_FOLLOWERS=5
|
@ -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
|
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
|
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
|
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
|
### 4. Build the project
|
||||||
|
33
main.go
33
main.go
@ -26,6 +26,7 @@ type Config struct {
|
|||||||
IndexPath string
|
IndexPath string
|
||||||
StaticPath string
|
StaticPath string
|
||||||
RefreshInterval int
|
RefreshInterval int
|
||||||
|
MinimumFollowers int
|
||||||
}
|
}
|
||||||
|
|
||||||
var pool *nostr.SimplePool
|
var pool *nostr.SimplePool
|
||||||
@ -36,6 +37,7 @@ var seedRelays []string
|
|||||||
var booted bool
|
var booted bool
|
||||||
var oneHopNetwork []string
|
var oneHopNetwork []string
|
||||||
var trustNetworkMap map[string]bool
|
var trustNetworkMap map[string]bool
|
||||||
|
var pubkeyFollowerCount = make(map[string]int)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
nostr.InfoLogger = log.New(io.Discard, "", 0)
|
nostr.InfoLogger = log.New(io.Discard, "", 0)
|
||||||
@ -162,6 +164,12 @@ func LoadConfig() Config {
|
|||||||
refreshInterval, _ := strconv.Atoi(os.Getenv("REFRESH_INTERVAL_HOURS"))
|
refreshInterval, _ := strconv.Atoi(os.Getenv("REFRESH_INTERVAL_HOURS"))
|
||||||
log.Println("🔄 refresh interval set to", refreshInterval, "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{
|
config := Config{
|
||||||
RelayName: getEnv("RELAY_NAME"),
|
RelayName: getEnv("RELAY_NAME"),
|
||||||
RelayPubkey: getEnv("RELAY_PUBKEY"),
|
RelayPubkey: getEnv("RELAY_PUBKEY"),
|
||||||
@ -171,6 +179,7 @@ func LoadConfig() Config {
|
|||||||
IndexPath: getEnv("INDEX_PATH"),
|
IndexPath: getEnv("INDEX_PATH"),
|
||||||
StaticPath: getEnv("STATIC_PATH"),
|
StaticPath: getEnv("STATIC_PATH"),
|
||||||
RefreshInterval: refreshInterval,
|
RefreshInterval: refreshInterval,
|
||||||
|
MinimumFollowers: minimumFollowers,
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
@ -187,11 +196,15 @@ func getEnv(key string) string {
|
|||||||
func updateTrustNetworkFilter() {
|
func updateTrustNetworkFilter() {
|
||||||
trustNetworkMap = make(map[string]bool)
|
trustNetworkMap = make(map[string]bool)
|
||||||
|
|
||||||
nKeys := uint64(len(trustNetwork))
|
log.Println("🌐 updating trust network map")
|
||||||
log.Println("🌐 updating trust network map with", nKeys, "keys")
|
for pubkey, count := range pubkeyFollowerCount {
|
||||||
for _, trustedPubkey := range trustNetwork {
|
if count >= config.MinimumFollowers {
|
||||||
trustNetworkMap[trustedPubkey] = true
|
trustNetworkMap[pubkey] = true
|
||||||
|
appendPubkey(pubkey)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("🌐 trust network map updated with", len(trustNetwork), "keys")
|
||||||
}
|
}
|
||||||
|
|
||||||
func refreshProfiles(ctx context.Context, relay *khatru.Relay) {
|
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")
|
log.Println("🔍 fetching owner's follows")
|
||||||
for ev := range pool.SubManyEose(timeoutCtx, seedRelays, filters) {
|
for ev := range pool.SubManyEose(timeoutCtx, seedRelays, filters) {
|
||||||
for _, contact := range ev.Event.Tags.GetAll([]string{"p"}) {
|
for _, contact := range ev.Event.Tags.GetAll([]string{"p"}) {
|
||||||
|
pubkeyFollowerCount[contact[1]]++ // Increment follower count for the pubkey
|
||||||
appendOneHopNetwork(contact[1])
|
appendOneHopNetwork(contact[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,9 +265,7 @@ func refreshTrustNetwork(relay *khatru.Relay, ctx context.Context) {
|
|||||||
|
|
||||||
for ev := range pool.SubManyEose(timeout, seedRelays, filters) {
|
for ev := range pool.SubManyEose(timeout, seedRelays, filters) {
|
||||||
for _, contact := range ev.Event.Tags.GetAll([]string{"p"}) {
|
for _, contact := range ev.Event.Tags.GetAll([]string{"p"}) {
|
||||||
if len(contact) > 1 {
|
pubkeyFollowerCount[contact[1]]++ // Increment follower count for the pubkey
|
||||||
appendPubkey(contact[1])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, relay := range ev.Event.Tags.GetAll([]string{"r"}) {
|
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)
|
relay.AddEvent(ctx, ev.Event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
log.Println("🫂 network size:", len(trustNetwork))
|
log.Println("🫂 total network size:", len(pubkeyFollowerCount))
|
||||||
log.Println("🔗 relays discovered:", len(relays))
|
log.Println("🔗 relays discovered:", len(relays))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,7 +366,7 @@ func archiveTrustedNotes(relay *khatru.Relay, ctx context.Context) {
|
|||||||
|
|
||||||
case ev, ok := <-eventChan:
|
case ev, ok := <-eventChan:
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Println("📦 SubMany channel closed")
|
log.Println("📦 subscription channel closed")
|
||||||
log.Println("📦 archived", trustedNotes, "trusted notes and discarded", untrustedNotes, "untrusted notes")
|
log.Println("📦 archived", trustedNotes, "trusted notes and discarded", untrustedNotes, "untrusted notes")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -367,7 +378,7 @@ func archiveTrustedNotes(relay *khatru.Relay, ctx context.Context) {
|
|||||||
|
|
||||||
relay.AddEvent(ctx, ev.Event)
|
relay.AddEvent(ctx, ev.Event)
|
||||||
trustedNotes++
|
trustedNotes++
|
||||||
log.Println("📦 archived note: ", ev.Event.ID)
|
//log.Println("📦 archived note: ", ev.Event.ID)
|
||||||
} else {
|
} else {
|
||||||
untrustedNotes++
|
untrustedNotes++
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user