summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-01-22 16:17:04 +0100
committerLibravatar GitHub <noreply@github.com>2024-01-22 15:17:04 +0000
commit138cbe4d602838d0b4d431cb934d533cf5516ea9 (patch)
treee11ef1601133910f57a82dcd1d275b19d3f9c996 /cmd
parent[bugfix] Don't return Internal Server Error when searching for URIs that don'... (diff)
downloadgotosocial-138cbe4d602838d0b4d431cb934d533cf5516ea9.tar.xz
[feature] Ratelimit + serve emoji images on separate router group (#2548)
* [feature] Serve + rate limit emoji files separately from attachments * add a wee little warning about uploading loads of emojis
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gotosocial/action/server/server.go21
-rw-r--r--cmd/gotosocial/action/testrig/testrig.go8
2 files changed, 23 insertions, 6 deletions
diff --git a/cmd/gotosocial/action/server/server.go b/cmd/gotosocial/action/server/server.go
index 537f338b1..de9b3b3f1 100644
--- a/cmd/gotosocial/action/server/server.go
+++ b/cmd/gotosocial/action/server/server.go
@@ -104,6 +104,13 @@ var Start action.GTSAction = func(ctx context.Context) error {
return fmt.Errorf("error creating instance instance: %s", err)
}
+ // Get the instance account
+ // (we'll need this later).
+ instanceAccount, err := dbService.GetInstanceAccount(ctx, "")
+ if err != nil {
+ return fmt.Errorf("error retrieving instance account: %w", err)
+ }
+
// Open the storage backend
storage, err := gtsstorage.AutoConfig()
if err != nil {
@@ -311,16 +318,17 @@ var Start action.GTSAction = func(ctx context.Context) error {
// rate limiting
rlLimit := config.GetAdvancedRateLimitRequests()
rlExceptions := config.GetAdvancedRateLimitExceptions()
- clLimit := middleware.RateLimit(rlLimit, rlExceptions) // client api
- s2sLimit := middleware.RateLimit(rlLimit, rlExceptions) // server-to-server (AP)
- fsLimit := middleware.RateLimit(rlLimit, rlExceptions) // fileserver / web templates
+ clLimit := middleware.RateLimit(rlLimit, rlExceptions) // client api
+ s2sLimit := middleware.RateLimit(rlLimit, rlExceptions) // server-to-server (AP)
+ fsMainLimit := middleware.RateLimit(rlLimit, rlExceptions) // fileserver / web templates
+ fsEmojiLimit := middleware.RateLimit(rlLimit*2, rlExceptions) // fileserver (emojis only, use high limit)
// throttling
cpuMultiplier := config.GetAdvancedThrottlingMultiplier()
retryAfter := config.GetAdvancedThrottlingRetryAfter()
clThrottle := middleware.Throttle(cpuMultiplier, retryAfter) // client api
s2sThrottle := middleware.Throttle(cpuMultiplier, retryAfter) // server-to-server (AP)
- fsThrottle := middleware.Throttle(cpuMultiplier, retryAfter) // fileserver / web templates
+ fsThrottle := middleware.Throttle(cpuMultiplier, retryAfter) // fileserver / web templates / emojis
pkThrottle := middleware.Throttle(cpuMultiplier, retryAfter) // throttle public key endpoint separately
gzip := middleware.Gzip() // applied to all except fileserver
@@ -330,12 +338,13 @@ var Start action.GTSAction = func(ctx context.Context) error {
authModule.Route(router, clLimit, clThrottle, gzip)
clientModule.Route(router, clLimit, clThrottle, gzip)
metricsModule.Route(router, clLimit, clThrottle, gzip)
- fileserverModule.Route(router, fsLimit, fsThrottle)
+ fileserverModule.Route(router, fsMainLimit, fsThrottle)
+ fileserverModule.RouteEmojis(router, instanceAccount.ID, fsEmojiLimit, fsThrottle)
wellKnownModule.Route(router, gzip, s2sLimit, s2sThrottle)
nodeInfoModule.Route(router, s2sLimit, s2sThrottle, gzip)
activityPubModule.Route(router, s2sLimit, s2sThrottle, gzip)
activityPubModule.RoutePublicKey(router, s2sLimit, pkThrottle, gzip)
- webModule.Route(router, fsLimit, fsThrottle, gzip)
+ webModule.Route(router, fsMainLimit, fsThrottle, gzip)
// Start the GoToSocial server.
server := gotosocial.NewServer(dbService, router, cleaner)
diff --git a/cmd/gotosocial/action/testrig/testrig.go b/cmd/gotosocial/action/testrig/testrig.go
index d6bc92215..bf2c74f2f 100644
--- a/cmd/gotosocial/action/testrig/testrig.go
+++ b/cmd/gotosocial/action/testrig/testrig.go
@@ -83,6 +83,13 @@ var Start action.GTSAction = func(ctx context.Context) error {
testrig.StandardDBSetup(state.DB, nil)
+ // Get the instance account
+ // (we'll need this later).
+ instanceAccount, err := state.DB.GetInstanceAccount(ctx, "")
+ if err != nil {
+ return fmt.Errorf("error retrieving instance account: %w", err)
+ }
+
if os.Getenv("GTS_STORAGE_BACKEND") == "s3" {
var err error
state.Storage, err = storage.NewS3Storage()
@@ -225,6 +232,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
clientModule.Route(router)
metricsModule.Route(router)
fileserverModule.Route(router)
+ fileserverModule.RouteEmojis(router, instanceAccount.ID)
wellKnownModule.Route(router)
nodeInfoModule.Route(router)
activityPubModule.Route(router)