From 84616b07ffc85151eaf4bffbab94da144a9fc2b9 Mon Sep 17 00:00:00 2001 From: tsmethurst Date: Sat, 9 Oct 2021 19:30:18 +0200 Subject: [PATCH] rename target => receiving account --- internal/federation/federatingdb/accept.go | 17 ++++++------- internal/federation/federatingdb/announce.go | 13 ++++------ internal/federation/federatingdb/delete.go | 13 ++++------ internal/federation/federatingdb/undo.go | 13 ++++------ internal/federation/federatingdb/update.go | 11 +++------ internal/federation/federatingprotocol.go | 26 ++++++++++---------- internal/federation/federator_test.go | 2 +- internal/util/uri.go | 4 +-- 8 files changed, 42 insertions(+), 57 deletions(-) diff --git a/internal/federation/federatingdb/accept.go b/internal/federation/federatingdb/accept.go index 7ecf41ee4..0d2d3a270 100644 --- a/internal/federation/federatingdb/accept.go +++ b/internal/federation/federatingdb/accept.go @@ -48,12 +48,9 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA l.Debug("entering Accept") } - targetAcct, fromFederatorChan, err := extractFromCtx(ctx) - if err != nil { - return err - } - if targetAcct == nil || fromFederatorChan == nil { - // If the target account or federator channel wasn't set on the context, that means this request didn't pass + receivingAccount, _, fromFederatorChan := extractFromCtx(ctx) + if receivingAccount == nil || fromFederatorChan == nil { + // If the receiving account or federator channel wasn't set on the context, that means this request didn't pass // through the API, but came from inside GtS as the result of another activity on this instance. That being so, // we can safely just ignore this activity, since we know we've already processed it elsewhere. return nil @@ -77,7 +74,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA } // make sure the addressee of the original follow is the same as whatever inbox this landed in - if gtsFollowRequest.AccountID != targetAcct.ID { + if gtsFollowRequest.AccountID != receivingAccount.ID { return errors.New("ACCEPT: follow object account and inbox account were not the same") } follow, err := f.db.AcceptFollowRequest(ctx, gtsFollowRequest.AccountID, gtsFollowRequest.TargetAccountID) @@ -89,7 +86,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA APObjectType: ap.ActivityFollow, APActivityType: ap.ActivityAccept, GTSModel: follow, - ReceivingAccount: targetAcct, + ReceivingAccount: receivingAccount, } return nil @@ -114,7 +111,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA return fmt.Errorf("ACCEPT: error converting asfollow to gtsfollow: %s", err) } // make sure the addressee of the original follow is the same as whatever inbox this landed in - if gtsFollow.AccountID != targetAcct.ID { + if gtsFollow.AccountID != receivingAccount.ID { return errors.New("ACCEPT: follow object account and inbox account were not the same") } follow, err := f.db.AcceptFollowRequest(ctx, gtsFollow.AccountID, gtsFollow.TargetAccountID) @@ -126,7 +123,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA APObjectType: ap.ActivityFollow, APActivityType: ap.ActivityAccept, GTSModel: follow, - ReceivingAccount: targetAcct, + ReceivingAccount: receivingAccount, } return nil diff --git a/internal/federation/federatingdb/announce.go b/internal/federation/federatingdb/announce.go index 9a03ede92..49ec84509 100644 --- a/internal/federation/federatingdb/announce.go +++ b/internal/federation/federatingdb/announce.go @@ -44,12 +44,9 @@ func (f *federatingDB) Announce(ctx context.Context, announce vocab.ActivityStre l.Debug("entering Announce") } - targetAcct, fromFederatorChan, err := extractFromCtx(ctx) - if err != nil { - return err - } - if targetAcct == nil || fromFederatorChan == nil { - // If the target account or federator channel wasn't set on the context, that means this request didn't pass + receivingAccount, _, fromFederatorChan := extractFromCtx(ctx) + if receivingAccount == nil || fromFederatorChan == nil { + // If the receiving account or federator channel wasn't set on the context, that means this request didn't pass // through the API, but came from inside GtS as the result of another activity on this instance. That being so, // we can safely just ignore this activity, since we know we've already processed it elsewhere. return nil @@ -57,7 +54,7 @@ func (f *federatingDB) Announce(ctx context.Context, announce vocab.ActivityStre boost, isNew, err := f.typeConverter.ASAnnounceToStatus(ctx, announce) if err != nil { - return fmt.Errorf("ANNOUNCE: error converting announce to boost: %s", err) + return fmt.Errorf("Announce: error converting announce to boost: %s", err) } if !isNew { @@ -70,7 +67,7 @@ func (f *federatingDB) Announce(ctx context.Context, announce vocab.ActivityStre APObjectType: ap.ActivityAnnounce, APActivityType: ap.ActivityCreate, GTSModel: boost, - ReceivingAccount: targetAcct, + ReceivingAccount: receivingAccount, } return nil diff --git a/internal/federation/federatingdb/delete.go b/internal/federation/federatingdb/delete.go index fc77f8025..77c3f502b 100644 --- a/internal/federation/federatingdb/delete.go +++ b/internal/federation/federatingdb/delete.go @@ -44,12 +44,9 @@ func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error { ) l.Debug("entering Delete") - targetAcct, fromFederatorChan, err := extractFromCtx(ctx) - if err != nil { - return err - } - if targetAcct == nil || fromFederatorChan == nil { - // If the target account or federator channel wasn't set on the context, that means this request didn't pass + receivingAccount, _, fromFederatorChan := extractFromCtx(ctx) + if receivingAccount == nil || fromFederatorChan == nil { + // If the receiving account or federator channel wasn't set on the context, that means this request didn't pass // through the API, but came from inside GtS as the result of another activity on this instance. That being so, // we can safely just ignore this activity, since we know we've already processed it elsewhere. return nil @@ -68,7 +65,7 @@ func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error { APObjectType: ap.ObjectNote, APActivityType: ap.ActivityDelete, GTSModel: s, - ReceivingAccount: targetAcct, + ReceivingAccount: receivingAccount, } } @@ -80,7 +77,7 @@ func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error { APObjectType: ap.ObjectProfile, APActivityType: ap.ActivityDelete, GTSModel: a, - ReceivingAccount: targetAcct, + ReceivingAccount: receivingAccount, } } diff --git a/internal/federation/federatingdb/undo.go b/internal/federation/federatingdb/undo.go index 082d76e60..3d4cb1d53 100644 --- a/internal/federation/federatingdb/undo.go +++ b/internal/federation/federatingdb/undo.go @@ -46,12 +46,9 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo) l.Debug("entering Undo") } - targetAcct, fromFederatorChan, err := extractFromCtx(ctx) - if err != nil { - return err - } - if targetAcct == nil || fromFederatorChan == nil { - // If the target account or federator channel wasn't set on the context, that means this request didn't pass + receivingAccount, _, fromFederatorChan := extractFromCtx(ctx) + if receivingAccount == nil || fromFederatorChan == nil { + // If the receiving account or federator channel wasn't set on the context, that means this request didn't pass // through the API, but came from inside GtS as the result of another activity on this instance. That being so, // we can safely just ignore this activity, since we know we've already processed it elsewhere. return nil @@ -83,7 +80,7 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo) return fmt.Errorf("UNDO: error converting asfollow to gtsfollow: %s", err) } // make sure the addressee of the original follow is the same as whatever inbox this landed in - if gtsFollow.TargetAccountID != targetAcct.ID { + if gtsFollow.TargetAccountID != receivingAccount.ID { return errors.New("UNDO: follow object account and inbox account were not the same") } // delete any existing FOLLOW @@ -116,7 +113,7 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo) return fmt.Errorf("UNDO: error converting asblock to gtsblock: %s", err) } // make sure the addressee of the original block is the same as whatever inbox this landed in - if gtsBlock.TargetAccountID != targetAcct.ID { + if gtsBlock.TargetAccountID != receivingAccount.ID { return errors.New("UNDO: block object account and inbox account were not the same") } // delete any existing BLOCK diff --git a/internal/federation/federatingdb/update.go b/internal/federation/federatingdb/update.go index 6ce08ccb6..b3a27b462 100644 --- a/internal/federation/federatingdb/update.go +++ b/internal/federation/federatingdb/update.go @@ -56,12 +56,9 @@ func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error { l.Debug("entering Update") } - targetAcct, fromFederatorChan, err := extractFromCtx(ctx) - if err != nil { - return err - } - if targetAcct == nil || fromFederatorChan == nil { - // If the target account or federator channel wasn't set on the context, that means this request didn't pass + receivingAccount, _, fromFederatorChan := extractFromCtx(ctx) + if receivingAccount == nil || fromFederatorChan == nil { + // If the receiving account or federator channel wasn't set on the context, that means this request didn't pass // through the API, but came from inside GtS as the result of another activity on this instance. That being so, // we can safely just ignore this activity, since we know we've already processed it elsewhere. return nil @@ -153,7 +150,7 @@ func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error { APObjectType: ap.ObjectProfile, APActivityType: ap.ActivityUpdate, GTSModel: updatedAcct, - ReceivingAccount: targetAcct, + ReceivingAccount: receivingAccount, } } diff --git a/internal/federation/federatingprotocol.go b/internal/federation/federatingprotocol.go index c0ed97d5c..afa763d98 100644 --- a/internal/federation/federatingprotocol.go +++ b/internal/federation/federatingprotocol.go @@ -113,12 +113,12 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr return nil, false, errors.New("username was empty") } - requestedAccount, err := f.db.GetLocalAccountByUsername(ctx, username) + receivingAccount, err := f.db.GetLocalAccountByUsername(ctx, username) if err != nil { - return nil, false, fmt.Errorf("could not fetch requested account with username %s: %s", username, err) + return nil, false, fmt.Errorf("could not fetch receiving account with username %s: %s", username, err) } - publicKeyOwnerURI, authenticated, err := f.AuthenticateFederatedRequest(ctx, requestedAccount.Username) + publicKeyOwnerURI, authenticated, err := f.AuthenticateFederatedRequest(ctx, receivingAccount.Username) if err != nil { l.Debugf("request not authenticated: %s", err) return ctx, false, err @@ -154,12 +154,12 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr requestingAccount, _, err := f.GetRemoteAccount(ctx, username, publicKeyOwnerURI, false) if err != nil { - return nil, false, fmt.Errorf("couldn't get remote account: %s", err) + return nil, false, fmt.Errorf("couldn't get requesting account %s: %s", publicKeyOwnerURI, err) } - withRequester := context.WithValue(ctx, util.APRequestingAccount, requestingAccount) - withRequested := context.WithValue(withRequester, util.APAccount, requestedAccount) - return withRequested, true, nil + withRequesting := context.WithValue(ctx, util.APRequestingAccount, requestingAccount) + withReceiving := context.WithValue(withRequesting, util.APReceivingAccount, receivingAccount) + return withReceiving, true, nil } // Blocked should determine whether to permit a set of actors given by @@ -182,11 +182,11 @@ func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, er }) l.Debugf("entering BLOCKED function with IRI list: %+v", actorIRIs) - requestedAccountI := ctx.Value(util.APAccount) - requestedAccount, ok := requestedAccountI.(*gtsmodel.Account) + receivingAccountI := ctx.Value(util.APReceivingAccount) + receivingAccount, ok := receivingAccountI.(*gtsmodel.Account) if !ok { - f.log.Errorf("requested account not set on request context") - return false, errors.New("requested account not set on request context, so couldn't determine blocks") + f.log.Errorf("receiving account not set on request context") + return false, errors.New("receiving account not set on request context, so couldn't determine blocks") } blocked, err := f.db.AreURIsBlocked(ctx, actorIRIs) @@ -209,12 +209,12 @@ func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, er return false, fmt.Errorf("error getting account with uri %s: %s", uri.String(), err) } - blocked, err = f.db.IsBlocked(ctx, requestedAccount.ID, requestingAccount.ID, false) + blocked, err = f.db.IsBlocked(ctx, receivingAccount.ID, requestingAccount.ID, false) if err != nil { return false, fmt.Errorf("error checking account block: %s", err) } if blocked { - l.Tracef("local account %s blocks account with uri %s", requestedAccount.Username, uri) + l.Tracef("local account %s blocks account with uri %s", receivingAccount.Username, uri) return true, nil } } diff --git a/internal/federation/federator_test.go b/internal/federation/federator_test.go index 5a7056e6b..76e16a04f 100644 --- a/internal/federation/federator_test.go +++ b/internal/federation/federator_test.go @@ -125,7 +125,7 @@ func (suite *ProtocolTestSuite) TestAuthenticatePostInbox() { ctx := context.Background() // by the time AuthenticatePostInbox is called, PostInboxRequestBodyHook should have already been called, // which should have set the account and username onto the request. We can replicate that behavior here: - ctxWithAccount := context.WithValue(ctx, util.APAccount, inboxAccount) + ctxWithAccount := context.WithValue(ctx, util.APReceivingAccount, inboxAccount) ctxWithActivity := context.WithValue(ctxWithAccount, util.APActivity, activity) ctxWithVerifier := context.WithValue(ctxWithActivity, util.APRequestingPublicKeyVerifier, verifier) ctxWithSignature := context.WithValue(ctxWithVerifier, util.APRequestingPublicKeySignature, activity.SignatureHeader) diff --git a/internal/util/uri.go b/internal/util/uri.go index 734becf13..5945c7bdd 100644 --- a/internal/util/uri.go +++ b/internal/util/uri.go @@ -62,8 +62,8 @@ type APContextKey string const ( // APActivity can be used to set and retrieve the actual go-fed pub.Activity within a context. APActivity APContextKey = "activity" - // APAccount can be used the set and retrieve the account being interacted with - APAccount APContextKey = "account" + // APReceivingAccount can be used the set and retrieve the account being interacted with / receiving an activity in their inbox. + APReceivingAccount APContextKey = "account" // APRequestingAccount can be used to set and retrieve the account of an incoming federation request. // This will often be the actor of the instance that's posting the request. APRequestingAccount APContextKey = "requestingAccount"