From e397272fe8550e4f81958d5d00bf3233e1bd0bfc Mon Sep 17 00:00:00 2001 From: Daenney Date: Wed, 8 Mar 2023 13:57:41 +0100 Subject: [feature] Discover webfinger through host-meta (#1588) * [feature] Discover webfinger through host-meta This implements a fallback for discovering the webfinger endpoint in case the /.well-known/webfinger endpoint wasn't properly redirected. Some instances do this because the recommendation used to be to use host-meta for the webfinger redirect in the before times. Closes #1558. * [bug] Ensure we only ever update cache on success * [chore] Move finger tests to their own place This adds a test suite for transport and moves the finger cache tests into there instead of abusing the search test suite. * [chore] cleanup the test a bit more We don't really need a separate function for the oddly located webfinger response as we check the full URL string anyway * Address review comments * [chore] update config example * [chore] access DB only through state in controller --- internal/cache/gts.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'internal/cache/gts.go') diff --git a/internal/cache/gts.go b/internal/cache/gts.go index 253dc47b2..568ffb478 100644 --- a/internal/cache/gts.go +++ b/internal/cache/gts.go @@ -20,6 +20,7 @@ package cache import ( "codeberg.org/gruf/go-cache/v3/result" + "codeberg.org/gruf/go-cache/v3/ttl" "github.com/superseriousbusiness/gotosocial/internal/cache/domain" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" @@ -71,6 +72,9 @@ type GTSCaches interface { // User provides access to the gtsmodel User database cache. User() *result.Cache[*gtsmodel.User] + + // Webfinger + Webfinger() *ttl.Cache[string, string] } // NewGTS returns a new default implementation of GTSCaches. @@ -91,6 +95,7 @@ type gtsCaches struct { status *result.Cache[*gtsmodel.Status] tombstone *result.Cache[*gtsmodel.Tombstone] user *result.Cache[*gtsmodel.User] + webfinger *ttl.Cache[string, string] } func (c *gtsCaches) Init() { @@ -106,6 +111,7 @@ func (c *gtsCaches) Init() { c.initStatus() c.initTombstone() c.initUser() + c.initWebfinger() } func (c *gtsCaches) Start() { @@ -145,6 +151,9 @@ func (c *gtsCaches) Start() { tryUntil("starting gtsmodel.User cache", 5, func() bool { return c.user.Start(config.GetCacheGTSUserSweepFreq()) }) + tryUntil("starting gtsmodel.Webfinger cache", 5, func() bool { + return c.webfinger.Start(config.GetCacheGTSWebfingerSweepFreq()) + }) } func (c *gtsCaches) Stop() { @@ -160,6 +169,7 @@ func (c *gtsCaches) Stop() { tryUntil("stopping gtsmodel.Status cache", 5, c.status.Stop) tryUntil("stopping gtsmodel.Tombstone cache", 5, c.tombstone.Stop) tryUntil("stopping gtsmodel.User cache", 5, c.user.Stop) + tryUntil("stopping gtsmodel.Webfinger cache", 5, c.webfinger.Stop) } func (c *gtsCaches) Account() *result.Cache[*gtsmodel.Account] { @@ -210,6 +220,10 @@ func (c *gtsCaches) User() *result.Cache[*gtsmodel.User] { return c.user } +func (c *gtsCaches) Webfinger() *ttl.Cache[string, string] { + return c.webfinger +} + func (c *gtsCaches) initAccount() { c.account = result.New([]result.Lookup{ {Name: "ID"}, @@ -355,3 +369,10 @@ func (c *gtsCaches) initUser() { }, config.GetCacheGTSUserMaxSize()) c.user.SetTTL(config.GetCacheGTSUserTTL(), true) } + +func (c *gtsCaches) initWebfinger() { + c.webfinger = ttl.New[string, string]( + 0, + config.GetCacheGTSWebfingerMaxSize(), + config.GetCacheGTSWebfingerTTL()) +} -- cgit v1.2.3