From c1e107266fc47e59657825f1178f5e79c78ab0e6 Mon Sep 17 00:00:00 2001 From: Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com> Date: Thu, 24 Jun 2021 14:26:08 +0200 Subject: nodeinfo compliance (#61) --- internal/processing/federation.go | 37 ++++++++++++++++++++++++++++++++++--- internal/processing/processor.go | 8 +++++++- 2 files changed, 41 insertions(+), 4 deletions(-) (limited to 'internal/processing') diff --git a/internal/processing/federation.go b/internal/processing/federation.go index 5693caf90..ab84421d0 100644 --- a/internal/processing/federation.go +++ b/internal/processing/federation.go @@ -265,7 +265,7 @@ func (p *processor) GetFediStatus(requestedUsername string, requestedStatusID st return data, nil } -func (p *processor) GetWebfingerAccount(requestedUsername string, request *http.Request) (*apimodel.WebfingerAccountResponse, gtserror.WithCode) { +func (p *processor) GetWebfingerAccount(requestedUsername string, request *http.Request) (*apimodel.WellKnownResponse, gtserror.WithCode) { // get the account the request is referring to requestedAccount := >smodel.Account{} if err := p.db.GetLocalAccountByUsername(requestedUsername, requestedAccount); err != nil { @@ -273,13 +273,13 @@ func (p *processor) GetWebfingerAccount(requestedUsername string, request *http. } // return the webfinger representation - return &apimodel.WebfingerAccountResponse{ + return &apimodel.WellKnownResponse{ Subject: fmt.Sprintf("acct:%s@%s", requestedAccount.Username, p.config.Host), Aliases: []string{ requestedAccount.URI, requestedAccount.URL, }, - Links: []apimodel.WebfingerLink{ + Links: []apimodel.Link{ { Rel: "http://webfinger.net/rel/profile-page", Type: "text/html", @@ -294,6 +294,37 @@ func (p *processor) GetWebfingerAccount(requestedUsername string, request *http. }, nil } +func (p *processor) GetNodeInfoRel(request *http.Request) (*apimodel.WellKnownResponse, gtserror.WithCode) { + return &apimodel.WellKnownResponse{ + Links: []apimodel.Link{ + { + Rel: "http://nodeinfo.diaspora.software/ns/schema/2.0", + Href: fmt.Sprintf("%s://%s/nodeinfo/2.0", p.config.Protocol, p.config.Host), + }, + }, + }, nil +} + +func (p *processor) GetNodeInfo(request *http.Request) (*apimodel.Nodeinfo, gtserror.WithCode) { + return &apimodel.Nodeinfo{ + Version: "2.0", + Software: apimodel.NodeInfoSoftware{ + Name: "gotosocial", + Version: p.config.SoftwareVersion, + }, + Protocols: []string{"activitypub"}, + Services: apimodel.NodeInfoServices{ + Inbound: []string{}, + Outbound: []string{}, + }, + OpenRegistrations: p.config.AccountsConfig.OpenRegistration, + Usage: apimodel.NodeInfoUsage{ + Users: apimodel.NodeInfoUsers{}, + }, + Metadata: make(map[string]interface{}), + }, nil +} + func (p *processor) InboxPost(ctx context.Context, w http.ResponseWriter, r *http.Request) (bool, error) { contextWithChannel := context.WithValue(ctx, util.APFromFederatorChanKey, p.fromFederator) posted, err := p.federator.FederatingActor().PostInbox(contextWithChannel, w, r) diff --git a/internal/processing/processor.go b/internal/processing/processor.go index 2cfa6e4e3..566bec8e5 100644 --- a/internal/processing/processor.go +++ b/internal/processing/processor.go @@ -169,7 +169,13 @@ type Processor interface { GetFediStatus(requestedUsername string, requestedStatusID string, request *http.Request) (interface{}, gtserror.WithCode) // GetWebfingerAccount handles the GET for a webfinger resource. Most commonly, it will be used for returning account lookups. - GetWebfingerAccount(requestedUsername string, request *http.Request) (*apimodel.WebfingerAccountResponse, gtserror.WithCode) + GetWebfingerAccount(requestedUsername string, request *http.Request) (*apimodel.WellKnownResponse, gtserror.WithCode) + + // GetNodeInfoRel returns a well known response giving the path to node info. + GetNodeInfoRel(request *http.Request) (*apimodel.WellKnownResponse, gtserror.WithCode) + + // GetNodeInfo returns a node info struct in response to a node info request. + GetNodeInfo(request *http.Request) (*apimodel.Nodeinfo, gtserror.WithCode) // InboxPost handles POST requests to a user's inbox for new activitypub messages. // -- cgit v1.2.3