summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gotosocial/action/admin/account/account.go4
-rw-r--r--cmd/gotosocial/action/admin/media/list.go4
-rw-r--r--cmd/gotosocial/action/admin/media/prune/common.go4
-rw-r--r--cmd/gotosocial/action/server/server.go64
4 files changed, 68 insertions, 8 deletions
diff --git a/cmd/gotosocial/action/admin/account/account.go b/cmd/gotosocial/action/admin/account/account.go
index 7dfb6b1d4..aa241177d 100644
--- a/cmd/gotosocial/action/admin/account/account.go
+++ b/cmd/gotosocial/action/admin/account/account.go
@@ -38,7 +38,9 @@ import (
func initState(ctx context.Context) (*state.State, error) {
var state state.State
state.Caches.Init()
- state.Caches.Start()
+ if err := state.Caches.Start(); err != nil {
+ return nil, fmt.Errorf("error starting caches: %w", err)
+ }
// Only set state DB connection.
// Don't need Actions or Workers for this (yet).
diff --git a/cmd/gotosocial/action/admin/media/list.go b/cmd/gotosocial/action/admin/media/list.go
index a017539ed..e80c0da51 100644
--- a/cmd/gotosocial/action/admin/media/list.go
+++ b/cmd/gotosocial/action/admin/media/list.go
@@ -125,7 +125,9 @@ func setupList(ctx context.Context) (*list, error) {
}
state.Caches.Init()
- state.Caches.Start()
+ if err := state.Caches.Start(); err != nil {
+ return nil, fmt.Errorf("error starting caches: %w", err)
+ }
// Only set state DB connection.
// Don't need Actions or Workers for this.
diff --git a/cmd/gotosocial/action/admin/media/prune/common.go b/cmd/gotosocial/action/admin/media/prune/common.go
index d73676f5b..fce445fb0 100644
--- a/cmd/gotosocial/action/admin/media/prune/common.go
+++ b/cmd/gotosocial/action/admin/media/prune/common.go
@@ -42,7 +42,9 @@ func setupPrune(ctx context.Context) (*prune, error) {
var state state.State
state.Caches.Init()
- state.Caches.Start()
+ if err := state.Caches.Start(); err != nil {
+ return nil, fmt.Errorf("error starting caches: %w", err)
+ }
// Scheduler is required for the
// cleaner, but no other workers
diff --git a/cmd/gotosocial/action/server/server.go b/cmd/gotosocial/action/server/server.go
index 3c37c6ff6..8c4fad247 100644
--- a/cmd/gotosocial/action/server/server.go
+++ b/cmd/gotosocial/action/server/server.go
@@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"net/http"
+ "net/netip"
"os"
"os/signal"
"runtime"
@@ -117,8 +118,9 @@ var Start action.GTSAction = func(ctx context.Context) error {
)
defer func() {
- // Stop caches with
- // background tasks.
+ // Stop any started caches.
+ //
+ // Noop if never started.
state.Caches.Stop()
if route != nil {
@@ -133,6 +135,8 @@ var Start action.GTSAction = func(ctx context.Context) error {
// Stop any currently running
// worker processes / scheduled
// tasks from being executed.
+ //
+ // Noop on unstarted workers.
state.Workers.Stop()
if state.Timelines.Home != nil {
@@ -202,7 +206,9 @@ var Start action.GTSAction = func(ctx context.Context) error {
// Initialize caches
state.Caches.Init()
- state.Caches.Start()
+ if err := state.Caches.Start(); err != nil {
+ return fmt.Errorf("error starting caches: %w", err)
+ }
// Open connection to the database now caches started.
dbService, err := bundb.NewBunDBService(ctx, state)
@@ -240,10 +246,17 @@ var Start action.GTSAction = func(ctx context.Context) error {
return fmt.Errorf("error opening storage backend: %w", err)
}
+ // Parse http client allow
+ // and block range exceptions.
+ ranges, err := parseClientRanges()
+ if err != nil {
+ return err
+ }
+
// Prepare wrapped httpclient with config.
client := httpclient.New(httpclient.Config{
- AllowRanges: config.MustParseIPPrefixes(config.GetHTTPClientAllowIPs()),
- BlockRanges: config.MustParseIPPrefixes(config.GetHTTPClientBlockIPs()),
+ AllowRanges: ranges.allow,
+ BlockRanges: ranges.block,
Timeout: config.GetHTTPClientTimeout(),
TLSInsecureSkipVerify: config.GetHTTPClientTLSInsecureSkipVerify(),
})
@@ -617,3 +630,44 @@ func compileWASM(ctx context.Context) error {
return nil
}
+
+func parseClientRanges() (
+ *struct {
+ allow []netip.Prefix
+ block []netip.Prefix
+ },
+ error,
+) {
+ parseF := func(ips []string, ranges []netip.Prefix, flag string) error {
+ for i, ip := range ips {
+ p, err := netip.ParsePrefix(ip)
+ if err != nil {
+ return fmt.Errorf("error parsing %s value %s: %w", flag, ip, err)
+ }
+ ranges[i] = p
+ }
+ return nil
+ }
+
+ allowIPs := config.GetHTTPClientAllowIPs()
+ allowRanges := make([]netip.Prefix, len(allowIPs))
+ allowFlag := config.HTTPClientAllowIPsFlag()
+ if err := parseF(allowIPs, allowRanges, allowFlag); err != nil {
+ return nil, err
+ }
+
+ blockIPs := config.GetHTTPClientBlockIPs()
+ blockRanges := make([]netip.Prefix, len(blockIPs))
+ blockFlag := config.HTTPClientBlockIPsFlag()
+ if err := parseF(blockIPs, blockRanges, blockFlag); err != nil {
+ return nil, err
+ }
+
+ return &struct {
+ allow []netip.Prefix
+ block []netip.Prefix
+ }{
+ allow: allowRanges,
+ block: blockRanges,
+ }, nil
+}