Use event store in relay
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
package sqlite
|
package sqlite
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -10,4 +10,4 @@ func (s *SqliteBackend) DeleteEvent(id nostr.ID) error {
|
|||||||
|
|
||||||
_, err := s.db.Exec("DELETE FROM events WHERE id = ?", id.Hex())
|
_, err := s.db.Exec("DELETE FROM events WHERE id = ?", id.Hex())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -5,4 +5,4 @@ package sqlite
|
|||||||
const (
|
const (
|
||||||
// Database configuration
|
// Database configuration
|
||||||
defaultTimeout = 30 // seconds
|
defaultTimeout = 30 // seconds
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ func EnableBlossom(instance *Instance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
store := &sqlite.SqliteBackend{
|
store := &sqlite.SqliteBackend{
|
||||||
Path: instance.Config.Data.Blossom,
|
Path: instance.Config.Data.Blossom,
|
||||||
}
|
}
|
||||||
|
|
||||||
backend := blossom.New(instance.Relay, "https://"+instance.Host)
|
backend := blossom.New(instance.Relay, "https://"+instance.Host)
|
||||||
|
|||||||
+3
-3
@@ -32,12 +32,12 @@ type Config struct {
|
|||||||
} `toml:"blossom"`
|
} `toml:"blossom"`
|
||||||
|
|
||||||
Roles map[string]struct {
|
Roles map[string]struct {
|
||||||
Pubkeys []string `toml:"pubkeys"`
|
Pubkeys []string `toml:"pubkeys"`
|
||||||
CanInvite bool `toml:"can_invite"`
|
CanInvite bool `toml:"can_invite"`
|
||||||
} `toml:"roles"`
|
} `toml:"roles"`
|
||||||
|
|
||||||
Data struct {
|
Data struct {
|
||||||
Events string `toml:"events"`
|
Events string `toml:"events"`
|
||||||
Blossom string `toml:"blossom"`
|
Blossom string `toml:"blossom"`
|
||||||
} `toml:"data"`
|
} `toml:"data"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
package zooid
|
package zooid
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
func EnableGroups(instance *Instance) {
|
func EnableGroups(instance *Instance) {
|
||||||
instance.Relay.Info.SupportedNIPs = append(instance.Relay.Info.SupportedNIPs, 29)
|
instance.Relay.Info.SupportedNIPs = append(instance.Relay.Info.SupportedNIPs, 29)
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-14
@@ -1,18 +1,23 @@
|
|||||||
package zooid
|
package zooid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
"iter"
|
|
||||||
"net/http"
|
|
||||||
"context"
|
"context"
|
||||||
|
"iter"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"fiatjaf.com/nostr/khatru"
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
|
"fiatjaf.com/nostr/eventstore"
|
||||||
|
"fiatjaf.com/nostr/khatru"
|
||||||
|
"zooid/sqlite"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Instance struct {
|
type Instance struct {
|
||||||
Host string
|
Host string
|
||||||
Config *Config
|
Config *Config
|
||||||
|
Events eventstore.Store
|
||||||
Relay *khatru.Relay
|
Relay *khatru.Relay
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +40,7 @@ func MakeInstance(hostname string) (*Instance, error) {
|
|||||||
instance := &Instance{
|
instance := &Instance{
|
||||||
Host: hostname,
|
Host: hostname,
|
||||||
Config: config,
|
Config: config,
|
||||||
|
Events: &sqlite.SqliteBackend{Path: config.Data.Events},
|
||||||
Relay: khatru.NewRelay(),
|
Relay: khatru.NewRelay(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,6 +52,8 @@ func MakeInstance(hostname string) (*Instance, error) {
|
|||||||
instance.Relay.Info.Software = "https://github.com/coracle-social/zooid"
|
instance.Relay.Info.Software = "https://github.com/coracle-social/zooid"
|
||||||
instance.Relay.Info.Version = "v0.1.0"
|
instance.Relay.Info.Version = "v0.1.0"
|
||||||
|
|
||||||
|
instance.Relay.UseEventstore(instance.Events, 400)
|
||||||
|
|
||||||
instance.Relay.OnConnect = instance.OnConnect
|
instance.Relay.OnConnect = instance.OnConnect
|
||||||
instance.Relay.OnEvent = instance.OnEvent
|
instance.Relay.OnEvent = instance.OnEvent
|
||||||
instance.Relay.StoreEvent = instance.StoreEvent
|
instance.Relay.StoreEvent = instance.StoreEvent
|
||||||
@@ -70,6 +78,16 @@ func MakeInstance(hostname string) (*Instance, error) {
|
|||||||
EnableManagement(instance)
|
EnableManagement(instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize stuff
|
||||||
|
|
||||||
|
if err := os.MkdirAll(instance.Config.Data.Events, 0755); err != nil {
|
||||||
|
log.Fatal("Failed to create event store path:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := instance.Events.Init(); err != nil {
|
||||||
|
log.Fatal("Failed to initialize event store:", err)
|
||||||
|
}
|
||||||
|
|
||||||
return instance, nil
|
return instance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,23 +132,23 @@ func (instance *Instance) IsMember(pubkey nostr.PubKey) bool {
|
|||||||
// Handlers
|
// Handlers
|
||||||
|
|
||||||
func (instance *Instance) OnConnect(ctx context.Context) {
|
func (instance *Instance) OnConnect(ctx context.Context) {
|
||||||
khatru.RequestAuth(ctx)
|
khatru.RequestAuth(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) OnEvent(ctx context.Context, event nostr.Event) (reject bool, msg string) {
|
func (instance *Instance) OnEvent(ctx context.Context, event nostr.Event) (reject bool, msg string) {
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) StoreEvent(ctx context.Context, event nostr.Event) error {
|
func (instance *Instance) StoreEvent(ctx context.Context, event nostr.Event) error {
|
||||||
return nil
|
return instance.Events.SaveEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) ReplaceEvent(ctx context.Context, event nostr.Event) error {
|
func (instance *Instance) ReplaceEvent(ctx context.Context, event nostr.Event) error {
|
||||||
return nil
|
return instance.Events.ReplaceEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) DeleteEvent(ctx context.Context, id nostr.ID) error {
|
func (instance *Instance) DeleteEvent(ctx context.Context, id nostr.ID) error {
|
||||||
return nil
|
return instance.Events.DeleteEvent(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) OnEventSaved(ctx context.Context, event nostr.Event) {
|
func (instance *Instance) OnEventSaved(ctx context.Context, event nostr.Event) {
|
||||||
@@ -140,20 +158,23 @@ func (instance *Instance) OnEphemeralEvent(ctx context.Context, event nostr.Even
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) OnRequest(ctx context.Context, filter nostr.Filter) (reject bool, msg string) {
|
func (instance *Instance) OnRequest(ctx context.Context, filter nostr.Filter) (reject bool, msg string) {
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) QueryStored(ctx context.Context, filter nostr.Filter) iter.Seq[nostr.Event] {
|
func (instance *Instance) QueryStored(ctx context.Context, filter nostr.Filter) iter.Seq[nostr.Event] {
|
||||||
return func(yield func(nostr.Event) bool) {
|
return func(yield func(nostr.Event) bool) {
|
||||||
// TODO: Implement actual event querying logic
|
for evt := range instance.Events.QueryEvents(filter, 400) {
|
||||||
// For now, return empty sequence
|
if !yield(evt) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) RejectConnection(r *http.Request) bool {
|
func (instance *Instance) RejectConnection(r *http.Request) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) PreventBroadcast(ws *khatru.WebSocket, event nostr.Event) bool {
|
func (instance *Instance) PreventBroadcast(ws *khatru.WebSocket, event nostr.Event) bool {
|
||||||
return event.Kind == 28934
|
return event.Kind == 28934
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
package zooid
|
package zooid
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
func EnableManagement(instance *Instance) {
|
func EnableManagement(instance *Instance) {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user