diff options
author | 2021-11-22 08:46:19 +0100 | |
---|---|---|
committer | 2021-11-22 08:46:19 +0100 | |
commit | f8630348b4c14215d87921962a2acbe8d3b6c981 (patch) | |
tree | 8a06b1e91ca408de2451a79fee44de831456d729 /internal/federation | |
parent | tidy up database creation logic a bit (#317) (diff) | |
download | gotosocial-f8630348b4c14215d87921962a2acbe8d3b6c981.tar.xz |
Enable stricter linting with golangci-lint (#316)
* update golangci-lint
* add golangci config file w/ more linters
* correct issues flagged by stricter linters
* add more generous timeout for golangci-lint
* add some style + formatting guidelines
* move timeout to config file
* go fmt
Diffstat (limited to 'internal/federation')
-rw-r--r-- | internal/federation/authenticate.go | 2 | ||||
-rw-r--r-- | internal/federation/dereferencing/thread.go | 12 | ||||
-rw-r--r-- | internal/federation/federatingdb/accept.go | 4 | ||||
-rw-r--r-- | internal/federation/federatingdb/lock.go | 7 | ||||
-rw-r--r-- | internal/federation/federatingdb/reject.go | 5 | ||||
-rw-r--r-- | internal/federation/federatingdb/util.go | 18 | ||||
-rw-r--r-- | internal/federation/transport.go | 7 |
7 files changed, 35 insertions, 20 deletions
diff --git a/internal/federation/authenticate.go b/internal/federation/authenticate.go index eb0e675c3..fea5a765a 100644 --- a/internal/federation/authenticate.go +++ b/internal/federation/authenticate.go @@ -149,7 +149,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU requestingPublicKeyID, err := url.Parse(verifier.KeyId()) if err != nil { l.Debug("couldn't parse public key URL") - return nil, false, nil // couldn't parse the public key ID url + return nil, false, err // couldn't parse the public key ID url } requestingRemoteAccount := >smodel.Account{} diff --git a/internal/federation/dereferencing/thread.go b/internal/federation/dereferencing/thread.go index 4912bc591..db1d336c6 100644 --- a/internal/federation/dereferencing/thread.go +++ b/internal/federation/dereferencing/thread.go @@ -172,7 +172,7 @@ pageLoop: l.Debugf("dereferencing page %s", currentPageIRI) nextPage, err := d.DereferenceCollectionPage(ctx, username, currentPageIRI) if err != nil { - return nil + return err } // next items could be either a list of URLs or a list of statuses @@ -188,19 +188,19 @@ pageLoop: // We're looking for a url to feed to GetRemoteStatus. // Items can be either an IRI, or a Note. // If a note, we grab the ID from it and call it, rather than parsing the note. - var itemURI *url.URL - if iter.IsIRI() { + switch { + case iter.IsIRI(): // iri, easy itemURI = iter.GetIRI() - } else if iter.IsActivityStreamsNote() { + case iter.IsActivityStreamsNote(): // note, get the id from it to use as iri n := iter.GetActivityStreamsNote() id := n.GetJSONLDId() if id != nil && id.IsIRI() { itemURI = id.GetIRI() } - } else { + default: // if it's not an iri or a note, we don't know how to process it continue } @@ -211,7 +211,7 @@ pageLoop: } // we can confidently say now that we found something - foundReplies = foundReplies + 1 + foundReplies++ // get the remote statusable and put it in the db _, statusable, new, err := d.GetRemoteStatus(ctx, username, itemURI, false, false) diff --git a/internal/federation/federatingdb/accept.go b/internal/federation/federatingdb/accept.go index 1509b37bc..8efb29b53 100644 --- a/internal/federation/federatingdb/accept.go +++ b/internal/federation/federatingdb/accept.go @@ -97,9 +97,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA if iter.GetType() == nil { continue } - switch iter.GetType().GetTypeName() { - // we have the whole object so we can figure out what we're accepting - case ap.ActivityFollow: + if iter.GetType().GetTypeName() == ap.ActivityFollow { // ACCEPT FOLLOW asFollow, ok := iter.GetType().(vocab.ActivityStreamsFollow) if !ok { diff --git a/internal/federation/federatingdb/lock.go b/internal/federation/federatingdb/lock.go index 0d35f337f..22be6c793 100644 --- a/internal/federation/federatingdb/lock.go +++ b/internal/federation/federatingdb/lock.go @@ -24,6 +24,8 @@ import ( "net/url" "sync" "sync/atomic" + + "github.com/sirupsen/logrus" ) // Lock takes a lock for the object at the specified id. If an error @@ -54,7 +56,10 @@ func (f *federatingDB) Lock(c context.Context, id *url.URL) error { // Get mutex, or create new mu, ok := f.locks[idStr] if !ok { - mu = f.pool.Get().(*mutex) + mu, ok = f.pool.Get().(*mutex) + if !ok { + logrus.Panic("Lock: pool entry was not a *mutex") + } f.locks[idStr] = mu } diff --git a/internal/federation/federatingdb/reject.go b/internal/federation/federatingdb/reject.go index 2d8687ee9..15d4a87ae 100644 --- a/internal/federation/federatingdb/reject.go +++ b/internal/federation/federatingdb/reject.go @@ -90,9 +90,8 @@ func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsR continue } - switch iter.GetType().GetTypeName() { - // we have the whole object so we can figure out what we're rejecting - case ap.ActivityFollow: + if iter.GetType().GetTypeName() == ap.ActivityFollow { + // we have the whole object so we can figure out what we're rejecting // REJECT FOLLOW asFollow, ok := iter.GetType().(vocab.ActivityStreamsFollow) if !ok { diff --git a/internal/federation/federatingdb/util.go b/internal/federation/federatingdb/util.go index 87b85aed6..f35fbbb2d 100644 --- a/internal/federation/federatingdb/util.go +++ b/internal/federation/federatingdb/util.go @@ -308,17 +308,29 @@ func (f *federatingDB) collectIRIs(ctx context.Context, iris []*url.URL) (vocab. func extractFromCtx(ctx context.Context) (receivingAccount, requestingAccount *gtsmodel.Account, fromFederatorChan chan messages.FromFederator) { receivingAccountI := ctx.Value(util.APReceivingAccount) if receivingAccountI != nil { - receivingAccount = receivingAccountI.(*gtsmodel.Account) + var ok bool + receivingAccount, ok = receivingAccountI.(*gtsmodel.Account) + if !ok { + logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to *gtsmodel.Account", util.APReceivingAccount) + } } requestingAcctI := ctx.Value(util.APRequestingAccount) if requestingAcctI != nil { - requestingAccount = requestingAcctI.(*gtsmodel.Account) + var ok bool + requestingAccount, ok = requestingAcctI.(*gtsmodel.Account) + if !ok { + logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to *gtsmodel.Account", util.APRequestingAccount) + } } fromFederatorChanI := ctx.Value(util.APFromFederatorChanKey) if fromFederatorChanI != nil { - fromFederatorChan = fromFederatorChanI.(chan messages.FromFederator) + var ok bool + fromFederatorChan, ok = fromFederatorChanI.(chan messages.FromFederator) + if !ok { + logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to chan messages.FromFederator", util.APFromFederatorChanKey) + } } return diff --git a/internal/federation/transport.go b/internal/federation/transport.go index 5b5afaad5..3287f6952 100644 --- a/internal/federation/transport.go +++ b/internal/federation/transport.go @@ -54,17 +54,18 @@ func (f *federator) NewTransport(ctx context.Context, actorBoxIRI *url.URL, gofe var username string var err error - if util.IsInboxPath(actorBoxIRI) { + switch { + case util.IsInboxPath(actorBoxIRI): username, err = util.ParseInboxPath(actorBoxIRI) if err != nil { return nil, fmt.Errorf("couldn't parse path %s as an inbox: %s", actorBoxIRI.String(), err) } - } else if util.IsOutboxPath(actorBoxIRI) { + case util.IsOutboxPath(actorBoxIRI): username, err = util.ParseOutboxPath(actorBoxIRI) if err != nil { return nil, fmt.Errorf("couldn't parse path %s as an outbox: %s", actorBoxIRI.String(), err) } - } else { + default: return nil, fmt.Errorf("id %s was neither an inbox path nor an outbox path", actorBoxIRI.String()) } |