Add inactive config
This commit is contained in:
@@ -24,6 +24,7 @@ Configuration files are written using [toml](https://toml.io). Top level configu
|
||||
- `host` - a hostname to serve this relay on.
|
||||
- `schema` - a string that identifies this relay. This cannot be changed, and must be usable as a sqlite identifier.
|
||||
- `secret` - the nostr secret key of the relay. Will be used to populate the relay's NIP 11 `self` field and sign generated events.
|
||||
- `inactive` - a boolean indicating whether the relay is currently inactive. The relay will not be available if set.
|
||||
|
||||
### `[info]`
|
||||
|
||||
|
||||
+5
-4
@@ -16,10 +16,11 @@ type Role struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Host string `toml:"host" json:"host"`
|
||||
Schema string `toml:"schema" json:"schema"`
|
||||
Secret string `toml:"secret" json:"secret"`
|
||||
Info struct {
|
||||
Host string `toml:"host" json:"host"`
|
||||
Schema string `toml:"schema" json:"schema"`
|
||||
Secret string `toml:"secret" json:"secret"`
|
||||
Inactive bool `toml:"inactive" json:"inactive"`
|
||||
Info struct {
|
||||
Name string `toml:"name" json:"name"`
|
||||
Icon string `toml:"icon" json:"icon"`
|
||||
Pubkey string `toml:"pubkey" json:"pubkey"`
|
||||
|
||||
@@ -21,6 +21,9 @@ func Dispatch(hostname string) (*Instance, bool) {
|
||||
defer instancesMux.RUnlock()
|
||||
|
||||
instance, exists := instancesByHost[hostname]
|
||||
if !exists || instance.Config.Inactive {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return instance, exists
|
||||
}
|
||||
@@ -60,6 +63,8 @@ func Start() {
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Failed to make instance for %s: %v", entry.Name(), err)
|
||||
} else if instance.Config.Inactive {
|
||||
log.Printf("Skipped inactive %s", entry.Name())
|
||||
} else {
|
||||
instancesByHost[instance.Config.Host] = instance
|
||||
instancesByName[entry.Name()] = instance
|
||||
@@ -105,6 +110,8 @@ func Start() {
|
||||
instance, err := MakeInstance(filename)
|
||||
if err != nil {
|
||||
log.Printf("Failed to reload %s: %v", filename, err)
|
||||
} else if instance.Config.Inactive {
|
||||
log.Printf("Skipped inactive %s", filename)
|
||||
} else {
|
||||
instancesByHost[instance.Config.Host] = instance
|
||||
instancesByName[filename] = instance
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package zooid
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDispatch_IgnoresInactiveInstances(t *testing.T) {
|
||||
instancesOnce.Do(func() {})
|
||||
|
||||
instancesMux.Lock()
|
||||
instancesByHost = map[string]*Instance{
|
||||
"active.example.com": {
|
||||
Config: &Config{Host: "active.example.com"},
|
||||
},
|
||||
"inactive.example.com": {
|
||||
Config: &Config{Host: "inactive.example.com", Inactive: true},
|
||||
},
|
||||
}
|
||||
instancesMux.Unlock()
|
||||
|
||||
if _, exists := Dispatch("active.example.com"); !exists {
|
||||
t.Fatal("expected active instance to be dispatched")
|
||||
}
|
||||
|
||||
if _, exists := Dispatch("inactive.example.com"); exists {
|
||||
t.Fatal("expected inactive instance to not be dispatched")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user