sdk: track event relays on kvstore.
This commit is contained in:
@@ -112,6 +112,8 @@ func NewSystem(mods ...SystemModifier) *System {
|
|||||||
sys.Pool = nostr.NewSimplePool(context.Background(),
|
sys.Pool = nostr.NewSimplePool(context.Background(),
|
||||||
nostr.WithAuthorKindQueryMiddleware(sys.TrackQueryAttempts),
|
nostr.WithAuthorKindQueryMiddleware(sys.TrackQueryAttempts),
|
||||||
nostr.WithEventMiddleware(sys.TrackEventHints),
|
nostr.WithEventMiddleware(sys.TrackEventHints),
|
||||||
|
nostr.WithEventMiddleware(sys.TrackEventRelays),
|
||||||
|
nostr.WithDuplicateMiddleware(sys.TrackEventRelaysD),
|
||||||
nostr.WithPenaltyBox(),
|
nostr.WithPenaltyBox(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package sdk
|
package sdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/nbd-wtf/go-nostr"
|
"github.com/nbd-wtf/go-nostr"
|
||||||
@@ -108,3 +109,31 @@ func (sys *System) TrackEventHints(ie nostr.RelayEvent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sys *System) TrackEventRelays(ie nostr.RelayEvent) {
|
||||||
|
// decode the event ID hex into bytes
|
||||||
|
idBytes, err := hex.DecodeString(ie.ID)
|
||||||
|
if err != nil || len(idBytes) < 8 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// store only first 8 bytes of event ID as key
|
||||||
|
key := idBytes[:8]
|
||||||
|
|
||||||
|
// store the relay URL as value
|
||||||
|
sys.KVStore.Set(key, []byte(ie.Relay.URL))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sys *System) TrackEventRelaysD(relay, id string) {
|
||||||
|
// decode the event ID hex into bytes
|
||||||
|
idBytes, err := hex.DecodeString(id)
|
||||||
|
if err != nil || len(idBytes) < 8 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// store only first 8 bytes of event ID as key
|
||||||
|
key := idBytes[:8]
|
||||||
|
|
||||||
|
// store the relay URL as value
|
||||||
|
sys.KVStore.Set(key, []byte(relay))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user