Support config mechanism, service block feature.

This commit is contained in:
Naoki Kosaka 2018-11-07 10:39:17 +09:00
parent c6ac334429
commit 54e6a11010
2 changed files with 23 additions and 0 deletions

View File

@ -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
}

20
main.go
View File

@ -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)