diff --git a/handle.go b/handle.go index 699abb5..f69252b 100644 --- a/handle.go +++ b/handle.go @@ -152,6 +152,9 @@ func suitableRelay(activity *activitypub.Activity, actor *activitypub.Actor) boo if receivers != 0 { return false } + if relConfig.blockService && actor.Type == "Service" { + return false + } return true } diff --git a/main.go b/main.go index 751642d..648ffbb 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,23 @@ var Actor activitypub.Actor // WebfingerResource : Relay's Webfinger resource var WebfingerResource activitypub.WebfingerResource +type relayConfig struct { + blockService bool +} + +var relConfig relayConfig + +func loadConfig() relayConfig { + blockService, err := RedClient.HGet("relay:config", "block_service").Result() + if err != nil { + RedClient.HSet("relay:config", "block_service", 0) + blockService = "0" + } + return relayConfig{ + blockService: blockService == "1", + } +} + func main() { pemPath := os.Getenv("ACTOR_PEM") if pemPath == "" { @@ -71,6 +88,9 @@ func main() { Actor = activitypub.GenerateActor(Hostname, &Hostkey.PublicKey) WebfingerResource = activitypub.GenerateWebfingerResource(Hostname, &Actor) + // Load Config + relConfig = loadConfig() + http.HandleFunc("/.well-known/webfinger", handleWebfinger) http.HandleFunc("/actor", handleActor) http.HandleFunc("/inbox", handleInbox)