From 07d27709957248008c61d6b8d553e3d2eb14d154 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 4 Feb 2025 16:52:42 +0100 Subject: [feature] Change `instance-stats-randomize` to `instance-stats-mode` with multiple options; implement nodeinfo 2.1 (#3734) * [feature] Change `instance-stats-randomize` to `instance-stats-mode` with multiple options; implement nodeinfo 2.1 * swaggalaggadingdong --- internal/processing/fedi/wellknown.go | 50 ++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-) (limited to 'internal/processing') diff --git a/internal/processing/fedi/wellknown.go b/internal/processing/fedi/wellknown.go index ac92370c8..42a8e38e4 100644 --- a/internal/processing/fedi/wellknown.go +++ b/internal/processing/fedi/wellknown.go @@ -31,9 +31,11 @@ const ( hostMetaRel = "lrdd" hostMetaType = "application/xrd+xml" hostMetaTemplate = ".well-known/webfinger?resource={uri}" - nodeInfoVersion = "2.0" nodeInfoSoftwareName = "gotosocial" - nodeInfoRel = "http://nodeinfo.diaspora.software/ns/schema/" + nodeInfoVersion + nodeInfo20Rel = "http://nodeinfo.diaspora.software/ns/schema/2.0" + nodeInfo21Rel = "http://nodeinfo.diaspora.software/ns/schema/2.1" + nodeInfoRepo = "https://github.com/superseriousbusiness/gotosocial" + nodeInfoHomepage = "https://docs.gotosocial.org" webfingerProfilePage = "http://webfinger.net/rel/profile-page" webFingerProfilePageContentType = "text/html" webfingerSelf = "self" @@ -56,27 +58,43 @@ func (p *Processor) NodeInfoRelGet(ctx context.Context) (*apimodel.WellKnownResp return &apimodel.WellKnownResponse{ Links: []apimodel.Link{ { - Rel: nodeInfoRel, - Href: fmt.Sprintf("%s://%s/nodeinfo/%s", protocol, host, nodeInfoVersion), + Rel: nodeInfo20Rel, + Href: fmt.Sprintf("%s://%s/nodeinfo/2.0", protocol, host), + }, + { + Rel: nodeInfo21Rel, + Href: fmt.Sprintf("%s://%s/nodeinfo/2.1", protocol, host), }, }, }, nil } -// NodeInfoGet returns a node info struct in response to a node info request. -func (p *Processor) NodeInfoGet(ctx context.Context) (*apimodel.Nodeinfo, gtserror.WithCode) { +// NodeInfoGet returns a node info struct in response to a 2.0 or 2.1 node info request. +func (p *Processor) NodeInfoGet(ctx context.Context, schemaVersion string) (*apimodel.Nodeinfo, gtserror.WithCode) { + const () + var ( userCount int postCount int + mau int err error ) - if config.GetInstanceStatsRandomize() { + switch config.GetInstanceStatsMode() { + + case config.InstanceStatsModeBaffle: // Use randomized stats. stats := p.converter.RandomStats() userCount = int(stats.TotalUsers) postCount = int(stats.Statuses) - } else { + mau = int(stats.MonthlyActiveUsers) + + case config.InstanceStatsModeZero: + // Use zeroed stats + // (don't count anything). + + default: + // Mode is either "serve" or "default". // Count actual stats. host := config.GetHost() @@ -91,8 +109,8 @@ func (p *Processor) NodeInfoGet(ctx context.Context) (*apimodel.Nodeinfo, gtserr } } - return &apimodel.Nodeinfo{ - Version: nodeInfoVersion, + nodeInfo := &apimodel.Nodeinfo{ + Version: schemaVersion, Software: apimodel.NodeInfoSoftware{ Name: nodeInfoSoftwareName, Version: config.GetSoftwareVersion(), @@ -105,12 +123,20 @@ func (p *Processor) NodeInfoGet(ctx context.Context) (*apimodel.Nodeinfo, gtserr OpenRegistrations: config.GetAccountsRegistrationOpen(), Usage: apimodel.NodeInfoUsage{ Users: apimodel.NodeInfoUsers{ - Total: userCount, + Total: userCount, + ActiveMonth: mau, }, LocalPosts: postCount, }, Metadata: nodeInfoMetadata, - }, nil + } + + if schemaVersion == "2.0" { + nodeInfo.Software.Repository = nodeInfoRepo + nodeInfo.Software.Homepage = nodeInfoHomepage + } + + return nodeInfo, nil } // HostMetaGet returns a host-meta struct in response to a host-meta request. -- cgit v1.2.3