summaryrefslogtreecommitdiff
path: root/internal/federation
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-08-25 15:34:33 +0200
committerLibravatar GitHub <noreply@github.com>2021-08-25 15:34:33 +0200
commit2dc9fc1626507bb54417fc4a1920b847cafb27a2 (patch)
tree4ddeac479b923db38090aac8bd9209f3646851c1 /internal/federation
parentManually approves followers (#146) (diff)
downloadgotosocial-2dc9fc1626507bb54417fc4a1920b847cafb27a2.tar.xz
Pg to bun (#148)
* start moving to bun * changing more stuff * more * and yet more * tests passing * seems stable now * more big changes * small fix * little fixes
Diffstat (limited to 'internal/federation')
-rw-r--r--internal/federation/authenticate.go6
-rw-r--r--internal/federation/dereference.go29
-rw-r--r--internal/federation/dereferencing/account.go67
-rw-r--r--internal/federation/dereferencing/announce.go9
-rw-r--r--internal/federation/dereferencing/blocked.go41
-rw-r--r--internal/federation/dereferencing/collectionpage.go6
-rw-r--r--internal/federation/dereferencing/dereferencer.go17
-rw-r--r--internal/federation/dereferencing/handshake.go7
-rw-r--r--internal/federation/dereferencing/instance.go6
-rw-r--r--internal/federation/dereferencing/status.go52
-rw-r--r--internal/federation/dereferencing/thread.go34
-rw-r--r--internal/federation/federatingdb/accept.go8
-rw-r--r--internal/federation/federatingdb/announce.go2
-rw-r--r--internal/federation/federatingdb/create.go16
-rw-r--r--internal/federation/federatingdb/delete.go10
-rw-r--r--internal/federation/federatingdb/followers.go22
-rw-r--r--internal/federation/federatingdb/following.go22
-rw-r--r--internal/federation/federatingdb/get.go14
-rw-r--r--internal/federation/federatingdb/outbox.go8
-rw-r--r--internal/federation/federatingdb/owns.go18
-rw-r--r--internal/federation/federatingdb/undo.go10
-rw-r--r--internal/federation/federatingdb/update.go5
-rw-r--r--internal/federation/federatingdb/util.go12
-rw-r--r--internal/federation/federatingprotocol.go16
-rw-r--r--internal/federation/federator.go18
-rw-r--r--internal/federation/finger.go6
-rw-r--r--internal/federation/handshake.go9
-rw-r--r--internal/federation/transport.go2
28 files changed, 233 insertions, 239 deletions
diff --git a/internal/federation/authenticate.go b/internal/federation/authenticate.go
index 699691ca6..81ac84544 100644
--- a/internal/federation/authenticate.go
+++ b/internal/federation/authenticate.go
@@ -148,7 +148,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
// LOCAL ACCOUNT REQUEST
// the request is coming from INSIDE THE HOUSE so skip the remote dereferencing
l.Tracef("proceeding without dereference for local public key %s", requestingPublicKeyID)
- if err := f.db.GetWhere([]db.Where{{Key: "public_key_uri", Value: requestingPublicKeyID.String()}}, requestingLocalAccount); err != nil {
+ if err := f.db.GetWhere(ctx, []db.Where{{Key: "public_key_uri", Value: requestingPublicKeyID.String()}}, requestingLocalAccount); err != nil {
return nil, false, fmt.Errorf("couldn't get local account with public key uri %s from the database: %s", requestingPublicKeyID.String(), err)
}
publicKey = requestingLocalAccount.PublicKey
@@ -156,7 +156,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
if err != nil {
return nil, false, fmt.Errorf("error parsing url %s: %s", requestingLocalAccount.URI, err)
}
- } else if err := f.db.GetWhere([]db.Where{{Key: "public_key_uri", Value: requestingPublicKeyID.String()}}, requestingRemoteAccount); err == nil {
+ } else if err := f.db.GetWhere(ctx, []db.Where{{Key: "public_key_uri", Value: requestingPublicKeyID.String()}}, requestingRemoteAccount); err == nil {
// REMOTE ACCOUNT REQUEST WITH KEY CACHED LOCALLY
// this is a remote account and we already have the public key for it so use that
l.Tracef("proceeding without dereference for cached public key %s", requestingPublicKeyID)
@@ -170,7 +170,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
// the request is remote and we don't have the public key yet,
// so we need to authenticate the request properly by dereferencing the remote key
l.Tracef("proceeding with dereference for uncached public key %s", requestingPublicKeyID)
- transport, err := f.transportController.NewTransportForUsername(requestedUsername)
+ transport, err := f.transportController.NewTransportForUsername(ctx, requestedUsername)
if err != nil {
return nil, false, fmt.Errorf("transport err: %s", err)
}
diff --git a/internal/federation/dereference.go b/internal/federation/dereference.go
index 96a662e32..a09f0f84b 100644
--- a/internal/federation/dereference.go
+++ b/internal/federation/dereference.go
@@ -19,36 +19,37 @@
package federation
import (
+ "context"
"net/url"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
-func (f *federator) GetRemoteAccount(username string, remoteAccountID *url.URL, refresh bool) (*gtsmodel.Account, bool, error) {
- return f.dereferencer.GetRemoteAccount(username, remoteAccountID, refresh)
+func (f *federator) GetRemoteAccount(ctx context.Context, username string, remoteAccountID *url.URL, refresh bool) (*gtsmodel.Account, bool, error) {
+ return f.dereferencer.GetRemoteAccount(ctx, username, remoteAccountID, refresh)
}
-func (f *federator) EnrichRemoteAccount(username string, account *gtsmodel.Account) (*gtsmodel.Account, error) {
- return f.dereferencer.EnrichRemoteAccount(username, account)
+func (f *federator) EnrichRemoteAccount(ctx context.Context, username string, account *gtsmodel.Account) (*gtsmodel.Account, error) {
+ return f.dereferencer.EnrichRemoteAccount(ctx, username, account)
}
-func (f *federator) GetRemoteStatus(username string, remoteStatusID *url.URL, refresh bool) (*gtsmodel.Status, ap.Statusable, bool, error) {
- return f.dereferencer.GetRemoteStatus(username, remoteStatusID, refresh)
+func (f *federator) GetRemoteStatus(ctx context.Context, username string, remoteStatusID *url.URL, refresh bool) (*gtsmodel.Status, ap.Statusable, bool, error) {
+ return f.dereferencer.GetRemoteStatus(ctx, username, remoteStatusID, refresh)
}
-func (f *federator) EnrichRemoteStatus(username string, status *gtsmodel.Status) (*gtsmodel.Status, error) {
- return f.dereferencer.EnrichRemoteStatus(username, status)
+func (f *federator) EnrichRemoteStatus(ctx context.Context, username string, status *gtsmodel.Status) (*gtsmodel.Status, error) {
+ return f.dereferencer.EnrichRemoteStatus(ctx, username, status)
}
-func (f *federator) DereferenceRemoteThread(username string, statusIRI *url.URL) error {
- return f.dereferencer.DereferenceThread(username, statusIRI)
+func (f *federator) DereferenceRemoteThread(ctx context.Context, username string, statusIRI *url.URL) error {
+ return f.dereferencer.DereferenceThread(ctx, username, statusIRI)
}
-func (f *federator) GetRemoteInstance(username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error) {
- return f.dereferencer.GetRemoteInstance(username, remoteInstanceURI)
+func (f *federator) GetRemoteInstance(ctx context.Context, username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error) {
+ return f.dereferencer.GetRemoteInstance(ctx, username, remoteInstanceURI)
}
-func (f *federator) DereferenceAnnounce(announce *gtsmodel.Status, requestingUsername string) error {
- return f.dereferencer.DereferenceAnnounce(announce, requestingUsername)
+func (f *federator) DereferenceAnnounce(ctx context.Context, announce *gtsmodel.Status, requestingUsername string) error {
+ return f.dereferencer.DereferenceAnnounce(ctx, announce, requestingUsername)
}
diff --git a/internal/federation/dereferencing/account.go b/internal/federation/dereferencing/account.go
index ba6766061..2eee0645d 100644
--- a/internal/federation/dereferencing/account.go
+++ b/internal/federation/dereferencing/account.go
@@ -24,6 +24,7 @@ import (
"errors"
"fmt"
"net/url"
+ "strings"
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/streams/vocab"
@@ -34,18 +35,33 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/transport"
)
+func instanceAccount(account *gtsmodel.Account) bool {
+ return strings.EqualFold(account.Username, account.Domain) ||
+ account.FollowersURI == "" ||
+ account.FollowingURI == "" ||
+ (account.Username == "internal.fetch" && strings.Contains(account.Note, "internal service actor"))
+}
+
// EnrichRemoteAccount takes an account that's already been inserted into the database in a minimal form,
// and populates it with additional fields, media, etc.
//
// EnrichRemoteAccount is mostly useful for calling after an account has been initially created by
// the federatingDB's Create function, or during the federated authorization flow.
-func (d *deref) EnrichRemoteAccount(username string, account *gtsmodel.Account) (*gtsmodel.Account, error) {
- if err := d.PopulateAccountFields(account, username, false); err != nil {
+func (d *deref) EnrichRemoteAccount(ctx context.Context, username string, account *gtsmodel.Account) (*gtsmodel.Account, error) {
+
+ // if we're dealing with an instance account, we don't need to update anything
+ if instanceAccount(account) {
+ return account, nil
+ }
+
+ if err := d.PopulateAccountFields(ctx, account, username, false); err != nil {
return nil, err
}
- if err := d.db.UpdateByID(account.ID, account); err != nil {
- return nil, fmt.Errorf("EnrichRemoteAccount: error updating account: %s", err)
+ var err error
+ account, err = d.db.UpdateAccount(ctx, account)
+ if err != nil {
+ d.log.Errorf("EnrichRemoteAccount: error updating account: %s", err)
}
return account, nil
@@ -60,27 +76,27 @@ func (d *deref) EnrichRemoteAccount(username string, account *gtsmodel.Account)
// the remote instance again.
//
// SIDE EFFECTS: remote account will be stored in the database, or updated if it already exists (and refresh is true).
-func (d *deref) GetRemoteAccount(username string, remoteAccountID *url.URL, refresh bool) (*gtsmodel.Account, bool, error) {
+func (d *deref) GetRemoteAccount(ctx context.Context, username string, remoteAccountID *url.URL, refresh bool) (*gtsmodel.Account, bool, error) {
new := true
// check if we already have the account in our db
- maybeAccount, err := d.db.GetAccountByURI(remoteAccountID.String())
+ maybeAccount, err := d.db.GetAccountByURI(ctx, remoteAccountID.String())
if err == nil {
// we've seen this account before so it's not new
new = false
if !refresh {
// we're not being asked to refresh, but just in case we don't have the avatar/header cached yet....
- maybeAccount, err = d.EnrichRemoteAccount(username, maybeAccount)
+ maybeAccount, err = d.EnrichRemoteAccount(ctx, username, maybeAccount)
return maybeAccount, new, err
}
}
- accountable, err := d.dereferenceAccountable(username, remoteAccountID)
+ accountable, err := d.dereferenceAccountable(ctx, username, remoteAccountID)
if err != nil {
return nil, new, fmt.Errorf("FullyDereferenceAccount: error dereferencing accountable: %s", err)
}
- gtsAccount, err := d.typeConverter.ASRepresentationToAccount(accountable, refresh)
+ gtsAccount, err := d.typeConverter.ASRepresentationToAccount(ctx, accountable, refresh)
if err != nil {
return nil, new, fmt.Errorf("FullyDereferenceAccount: error converting accountable to account: %s", err)
}
@@ -93,23 +109,24 @@ func (d *deref) GetRemoteAccount(username string, remoteAccountID *url.URL, refr
}
gtsAccount.ID = ulid
- if err := d.PopulateAccountFields(gtsAccount, username, refresh); err != nil {
+ if err := d.PopulateAccountFields(ctx, gtsAccount, username, refresh); err != nil {
return nil, new, fmt.Errorf("FullyDereferenceAccount: error populating further account fields: %s", err)
}
- if err := d.db.Put(gtsAccount); err != nil {
+ if err := d.db.Put(ctx, gtsAccount); err != nil {
return nil, new, fmt.Errorf("FullyDereferenceAccount: error putting new account: %s", err)
}
} else {
// take the id we already have and do an update
gtsAccount.ID = maybeAccount.ID
- if err := d.PopulateAccountFields(gtsAccount, username, refresh); err != nil {
+ if err := d.PopulateAccountFields(ctx, gtsAccount, username, refresh); err != nil {
return nil, new, fmt.Errorf("FullyDereferenceAccount: error populating further account fields: %s", err)
}
- if err := d.db.UpdateByID(gtsAccount.ID, gtsAccount); err != nil {
- return nil, new, fmt.Errorf("FullyDereferenceAccount: error updating existing account: %s", err)
+ gtsAccount, err = d.db.UpdateAccount(ctx, gtsAccount)
+ if err != nil {
+ return nil, false, fmt.Errorf("EnrichRemoteAccount: error updating account: %s", err)
}
}
@@ -120,15 +137,15 @@ func (d *deref) GetRemoteAccount(username string, remoteAccountID *url.URL, refr
// it finds as something that an account model can be constructed out of.
//
// Will work for Person, Application, or Service models.
-func (d *deref) dereferenceAccountable(username string, remoteAccountID *url.URL) (ap.Accountable, error) {
+func (d *deref) dereferenceAccountable(ctx context.Context, username string, remoteAccountID *url.URL) (ap.Accountable, error) {
d.startHandshake(username, remoteAccountID)
defer d.stopHandshake(username, remoteAccountID)
- if blocked, err := d.blockedDomain(remoteAccountID.Host); blocked || err != nil {
+ if blocked, err := d.db.IsDomainBlocked(ctx, remoteAccountID.Host); blocked || err != nil {
return nil, fmt.Errorf("DereferenceAccountable: domain %s is blocked", remoteAccountID.Host)
}
- transport, err := d.transportController.NewTransportForUsername(username)
+ transport, err := d.transportController.NewTransportForUsername(ctx, username)
if err != nil {
return nil, fmt.Errorf("DereferenceAccountable: transport err: %s", err)
}
@@ -174,7 +191,7 @@ func (d *deref) dereferenceAccountable(username string, remoteAccountID *url.URL
// PopulateAccountFields populates any fields on the given account that weren't populated by the initial
// dereferencing. This includes things like header and avatar etc.
-func (d *deref) PopulateAccountFields(account *gtsmodel.Account, requestingUsername string, refresh bool) error {
+func (d *deref) PopulateAccountFields(ctx context.Context, account *gtsmodel.Account, requestingUsername string, refresh bool) error {
l := d.log.WithFields(logrus.Fields{
"func": "PopulateAccountFields",
"requestingUsername": requestingUsername,
@@ -184,17 +201,17 @@ func (d *deref) PopulateAccountFields(account *gtsmodel.Account, requestingUsern
if err != nil {
return fmt.Errorf("PopulateAccountFields: couldn't parse account URI %s: %s", account.URI, err)
}
- if blocked, err := d.blockedDomain(accountURI.Host); blocked || err != nil {
+ if blocked, err := d.db.IsDomainBlocked(ctx, accountURI.Host); blocked || err != nil {
return fmt.Errorf("PopulateAccountFields: domain %s is blocked", accountURI.Host)
}
- t, err := d.transportController.NewTransportForUsername(requestingUsername)
+ t, err := d.transportController.NewTransportForUsername(ctx, requestingUsername)
if err != nil {
return fmt.Errorf("PopulateAccountFields: error getting transport for user: %s", err)
}
// fetch the header and avatar
- if err := d.fetchHeaderAndAviForAccount(account, t, refresh); err != nil {
+ if err := d.fetchHeaderAndAviForAccount(ctx, account, t, refresh); err != nil {
// if this doesn't work, just skip it -- we can do it later
l.Debugf("error fetching header/avi for account: %s", err)
}
@@ -208,17 +225,17 @@ func (d *deref) PopulateAccountFields(account *gtsmodel.Account, requestingUsern
// targetAccount's AvatarMediaAttachmentID and HeaderMediaAttachmentID will be updated as necessary.
//
// SIDE EFFECTS: remote header and avatar will be stored in local storage.
-func (d *deref) fetchHeaderAndAviForAccount(targetAccount *gtsmodel.Account, t transport.Transport, refresh bool) error {
+func (d *deref) fetchHeaderAndAviForAccount(ctx context.Context, targetAccount *gtsmodel.Account, t transport.Transport, refresh bool) error {
accountURI, err := url.Parse(targetAccount.URI)
if err != nil {
return fmt.Errorf("fetchHeaderAndAviForAccount: couldn't parse account URI %s: %s", targetAccount.URI, err)
}
- if blocked, err := d.blockedDomain(accountURI.Host); blocked || err != nil {
+ if blocked, err := d.db.IsDomainBlocked(ctx, accountURI.Host); blocked || err != nil {
return fmt.Errorf("fetchHeaderAndAviForAccount: domain %s is blocked", accountURI.Host)
}
if targetAccount.AvatarRemoteURL != "" && (targetAccount.AvatarMediaAttachmentID == "" || refresh) {
- a, err := d.mediaHandler.ProcessRemoteHeaderOrAvatar(t, &gtsmodel.MediaAttachment{
+ a, err := d.mediaHandler.ProcessRemoteHeaderOrAvatar(ctx, t, &gtsmodel.MediaAttachment{
RemoteURL: targetAccount.AvatarRemoteURL,
Avatar: true,
}, targetAccount.ID)
@@ -229,7 +246,7 @@ func (d *deref) fetchHeaderAndAviForAccount(targetAccount *gtsmodel.Account, t t
}
if targetAccount.HeaderRemoteURL != "" && (targetAccount.HeaderMediaAttachmentID == "" || refresh) {
- a, err := d.mediaHandler.ProcessRemoteHeaderOrAvatar(t, &gtsmodel.MediaAttachment{
+ a, err := d.mediaHandler.ProcessRemoteHeaderOrAvatar(ctx, t, &gtsmodel.MediaAttachment{
RemoteURL: targetAccount.HeaderRemoteURL,
Header: true,
}, targetAccount.ID)
diff --git a/internal/federation/dereferencing/announce.go b/internal/federation/dereferencing/announce.go
index 6773db425..33af74ebe 100644
--- a/internal/federation/dereferencing/announce.go
+++ b/internal/federation/dereferencing/announce.go
@@ -19,6 +19,7 @@
package dereferencing
import (
+ "context"
"errors"
"fmt"
"net/url"
@@ -26,7 +27,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
-func (d *deref) DereferenceAnnounce(announce *gtsmodel.Status, requestingUsername string) error {
+func (d *deref) DereferenceAnnounce(ctx context.Context, announce *gtsmodel.Status, requestingUsername string) error {
if announce.BoostOf == nil || announce.BoostOf.URI == "" {
// we can't do anything unfortunately
return errors.New("DereferenceAnnounce: no URI to dereference")
@@ -36,16 +37,16 @@ func (d *deref) DereferenceAnnounce(announce *gtsmodel.Status, requestingUsernam
if err != nil {
return fmt.Errorf("DereferenceAnnounce: couldn't parse boosted status URI %s: %s", announce.BoostOf.URI, err)
}
- if blocked, err := d.blockedDomain(boostedStatusURI.Host); blocked || err != nil {
+ if blocked, err := d.db.IsDomainBlocked(ctx, boostedStatusURI.Host); blocked || err != nil {
return fmt.Errorf("DereferenceAnnounce: domain %s is blocked", boostedStatusURI.Host)
}
// dereference statuses in the thread of the boosted status
- if err := d.DereferenceThread(requestingUsername, boostedStatusURI); err != nil {
+ if err := d.DereferenceThread(ctx, requestingUsername, boostedStatusURI); err != nil {
return fmt.Errorf("DereferenceAnnounce: error dereferencing thread of boosted status: %s", err)
}
- boostedStatus, _, _, err := d.GetRemoteStatus(requestingUsername, boostedStatusURI, false)
+ boostedStatus, _, _, err := d.GetRemoteStatus(ctx, requestingUsername, boostedStatusURI, false)
if err != nil {
return fmt.Errorf("DereferenceAnnounce: error dereferencing remote status with id %s: %s", announce.BoostOf.URI, err)
}
diff --git a/internal/federation/dereferencing/blocked.go b/internal/federation/dereferencing/blocked.go
deleted file mode 100644
index c8a4c6ade..000000000
--- a/internal/federation/dereferencing/blocked.go
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package dereferencing
-
-import (
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
-)
-
-func (d *deref) blockedDomain(host string) (bool, error) {
- b := &gtsmodel.DomainBlock{}
- err := d.db.GetWhere([]db.Where{{Key: "domain", Value: host, CaseInsensitive: true}}, b)
- if err == nil {
- // block exists
- return true, nil
- }
-
- if err == db.ErrNoEntries {
- // there are no entries so there's no block
- return false, nil
- }
-
- // there's an actual error
- return false, err
-}
diff --git a/internal/federation/dereferencing/collectionpage.go b/internal/federation/dereferencing/collectionpage.go
index 5feadc1ad..6f0beeaf6 100644
--- a/internal/federation/dereferencing/collectionpage.go
+++ b/internal/federation/dereferencing/collectionpage.go
@@ -32,12 +32,12 @@ import (
)
// DereferenceCollectionPage returns the activitystreams CollectionPage at the specified IRI, or an error if something goes wrong.
-func (d *deref) DereferenceCollectionPage(username string, pageIRI *url.URL) (ap.CollectionPageable, error) {
- if blocked, err := d.blockedDomain(pageIRI.Host); blocked || err != nil {
+func (d *deref) DereferenceCollectionPage(ctx context.Context, username string, pageIRI *url.URL) (ap.CollectionPageable, error) {
+ if blocked, err := d.db.IsDomainBlocked(ctx, pageIRI.Host); blocked || err != nil {
return nil, fmt.Errorf("DereferenceCollectionPage: domain %s is blocked", pageIRI.Host)
}
- transport, err := d.transportController.NewTransportForUsername(username)
+ transport, err := d.transportController.NewTransportForUsername(ctx, username)
if err != nil {
return nil, fmt.Errorf("DereferenceCollectionPage: error creating transport: %s", err)
}
diff --git a/internal/federation/dereferencing/dereferencer.go b/internal/federation/dereferencing/dereferencer.go
index 03b90569a..71625ed88 100644
--- a/internal/federation/dereferencing/dereferencer.go
+++ b/internal/federation/dereferencing/dereferencer.go
@@ -19,6 +19,7 @@
package dereferencing
import (
+ "context"
"net/url"
"sync"
@@ -34,18 +35,18 @@ import (
// Dereferencer wraps logic and functionality for doing dereferencing of remote accounts, statuses, etc, from federated instances.
type Dereferencer interface {
- GetRemoteAccount(username string, remoteAccountID *url.URL, refresh bool) (*gtsmodel.Account, bool, error)
- EnrichRemoteAccount(username string, account *gtsmodel.Account) (*gtsmodel.Account, error)
+ GetRemoteAccount(ctx context.Context, username string, remoteAccountID *url.URL, refresh bool) (*gtsmodel.Account, bool, error)
+ EnrichRemoteAccount(ctx context.Context, username string, account *gtsmodel.Account) (*gtsmodel.Account, error)
- GetRemoteStatus(username string, remoteStatusID *url.URL, refresh bool) (*gtsmodel.Status, ap.Statusable, bool, error)
- EnrichRemoteStatus(username string, status *gtsmodel.Status) (*gtsmodel.Status, error)
+ GetRemoteStatus(ctx context.Context, username string, remoteStatusID *url.URL, refresh bool) (*gtsmodel.Status, ap.Statusable, bool, error)
+ EnrichRemoteStatus(ctx context.Context, username string, status *gtsmodel.Status) (*gtsmodel.Status, error)
- GetRemoteInstance(username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error)
+ GetRemoteInstance(ctx context.Context, username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error)
- DereferenceAnnounce(announce *gtsmodel.Status, requestingUsername string) error
- DereferenceThread(username string, statusIRI *url.URL) error
+ DereferenceAnnounce(ctx context.Context, announce *gtsmodel.Status, requestingUsername string) error
+ DereferenceThread(ctx context.Context, username string, statusIRI *url.URL) error
- Handshaking(username string, remoteAccountID *url.URL) bool
+ Handshaking(ctx context.Context, username string, remoteAccountID *url.URL) bool
}
type deref struct {
diff --git a/internal/federation/dereferencing/handshake.go b/internal/federation/dereferencing/handshake.go
index cda8eafd0..17003be84 100644
--- a/internal/federation/dereferencing/handshake.go
+++ b/internal/federation/dereferencing/handshake.go
@@ -18,9 +18,12 @@
package dereferencing
-import "net/url"
+import (
+ "context"
+ "net/url"
+)
-func (d *deref) Handshaking(username string, remoteAccountID *url.URL) bool {
+func (d *deref) Handshaking(ctx context.Context, username string, remoteAccountID *url.URL) bool {
d.handshakeSync.Lock()
defer d.handshakeSync.Unlock()
diff --git a/internal/federation/dereferencing/instance.go b/internal/federation/dereferencing/instance.go
index 80f626662..ec3c3f13d 100644
--- a/internal/federation/dereferencing/instance.go
+++ b/internal/federation/dereferencing/instance.go
@@ -26,12 +26,12 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
-func (d *deref) GetRemoteInstance(username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error) {
- if blocked, err := d.blockedDomain(remoteInstanceURI.Host); blocked || err != nil {
+func (d *deref) GetRemoteInstance(ctx context.Context, username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error) {
+ if blocked, err := d.db.IsDomainBlocked(ctx, remoteInstanceURI.Host); blocked || err != nil {
return nil, fmt.Errorf("GetRemoteInstance: domain %s is blocked", remoteInstanceURI.Host)
}
- transport, err := d.transportController.NewTransportForUsername(username)
+ transport, err := d.transportController.NewTransportForUsername(ctx, username)
if err != nil {
return nil, fmt.Errorf("transport err: %s", err)
}
diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go
index 68693c021..93ead6523 100644
--- a/internal/federation/dereferencing/status.go
+++ b/internal/federation/dereferencing/status.go
@@ -39,12 +39,12 @@ import (
//
// EnrichRemoteStatus is mostly useful for calling after a status has been initially created by
// the federatingDB's Create function, but additional dereferencing is needed on it.
-func (d *deref) EnrichRemoteStatus(username string, status *gtsmodel.Status) (*gtsmodel.Status, error) {
- if err := d.populateStatusFields(status, username); err != nil {
+func (d *deref) EnrichRemoteStatus(ctx context.Context, username string, status *gtsmodel.Status) (*gtsmodel.Status, error) {
+ if err := d.populateStatusFields(ctx, status, username); err != nil {
return nil, err
}
- if err := d.db.UpdateByID(status.ID, status); err != nil {
+ if err := d.db.UpdateByID(ctx, status.ID, status); err != nil {
return nil, fmt.Errorf("EnrichRemoteStatus: error updating status: %s", err)
}
@@ -62,11 +62,11 @@ func (d *deref) EnrichRemoteStatus(username string, status *gtsmodel.Status) (*g
// If a dereference was performed, then the function also returns the ap.Statusable representation for further processing.
//
// SIDE EFFECTS: remote status will be stored in the database, and the remote status owner will also be stored.
-func (d *deref) GetRemoteStatus(username string, remoteStatusID *url.URL, refresh bool) (*gtsmodel.Status, ap.Statusable, bool, error) {
+func (d *deref) GetRemoteStatus(ctx context.Context, username string, remoteStatusID *url.URL, refresh bool) (*gtsmodel.Status, ap.Statusable, bool, error) {
new := true
// check if we already have the status in our db
- maybeStatus, err := d.db.GetStatusByURI(remoteStatusID.String())
+ maybeStatus, err := d.db.GetStatusByURI(ctx, remoteStatusID.String())
if err == nil {
// we've seen this status before so it's not new
new = false
@@ -77,7 +77,7 @@ func (d *deref) GetRemoteStatus(username string, remoteStatusID *url.URL, refres
}
}
- statusable, err := d.dereferenceStatusable(username, remoteStatusID)
+ statusable, err := d.dereferenceStatusable(ctx, username, remoteStatusID)
if err != nil {
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: error dereferencing statusable: %s", err)
}
@@ -88,12 +88,12 @@ func (d *deref) GetRemoteStatus(username string, remoteStatusID *url.URL, refres
}
// do this so we know we have the remote account of the status in the db
- _, _, err = d.GetRemoteAccount(username, accountURI, false)
+ _, _, err = d.GetRemoteAccount(ctx, username, accountURI, false)
if err != nil {
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: couldn't derive status author: %s", err)
}
- gtsStatus, err := d.typeConverter.ASStatusToStatus(statusable)
+ gtsStatus, err := d.typeConverter.ASStatusToStatus(ctx, statusable)
if err != nil {
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: error converting statusable to status: %s", err)
}
@@ -105,21 +105,21 @@ func (d *deref) GetRemoteStatus(username string, remoteStatusID *url.URL, refres
}
gtsStatus.ID = ulid
- if err := d.populateStatusFields(gtsStatus, username); err != nil {
+ if err := d.populateStatusFields(ctx, gtsStatus, username); err != nil {
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: error populating status fields: %s", err)
}
- if err := d.db.PutStatus(gtsStatus); err != nil {
+ if err := d.db.PutStatus(ctx, gtsStatus); err != nil {
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: error putting new status: %s", err)
}
} else {
gtsStatus.ID = maybeStatus.ID
- if err := d.populateStatusFields(gtsStatus, username); err != nil {
+ if err := d.populateStatusFields(ctx, gtsStatus, username); err != nil {
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: error populating status fields: %s", err)
}
- if err := d.db.UpdateByID(gtsStatus.ID, gtsStatus); err != nil {
+ if err := d.db.UpdateByID(ctx, gtsStatus.ID, gtsStatus); err != nil {
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: error updating status: %s", err)
}
}
@@ -127,12 +127,12 @@ func (d *deref) GetRemoteStatus(username string, remoteStatusID *url.URL, refres
return gtsStatus, statusable, new, nil
}
-func (d *deref) dereferenceStatusable(username string, remoteStatusID *url.URL) (ap.Statusable, error) {
- if blocked, err := d.blockedDomain(remoteStatusID.Host); blocked || err != nil {
+func (d *deref) dereferenceStatusable(ctx context.Context, username string, remoteStatusID *url.URL) (ap.Statusable, error) {
+ if blocked, err := d.db.IsDomainBlocked(ctx, remoteStatusID.Host); blocked || err != nil {
return nil, fmt.Errorf("DereferenceStatusable: domain %s is blocked", remoteStatusID.Host)
}
- transport, err := d.transportController.NewTransportForUsername(username)
+ transport, err := d.transportController.NewTransportForUsername(ctx, username)
if err != nil {
return nil, fmt.Errorf("DereferenceStatusable: transport err: %s", err)
}
@@ -236,7 +236,7 @@ func (d *deref) dereferenceStatusable(username string, remoteStatusID *url.URL)
// This function will deference all of the above, insert them in the database as necessary,
// and attach them to the status. The status itself will not be added to the database yet,
// that's up the caller to do.
-func (d *deref) populateStatusFields(status *gtsmodel.Status, requestingUsername string) error {
+func (d *deref) populateStatusFields(ctx context.Context, status *gtsmodel.Status, requestingUsername string) error {
l := d.log.WithFields(logrus.Fields{
"func": "dereferenceStatusFields",
"status": fmt.Sprintf("%+v", status),
@@ -248,12 +248,12 @@ func (d *deref) populateStatusFields(status *gtsmodel.Status, requestingUsername
if err != nil {
return fmt.Errorf("DereferenceStatusFields: couldn't parse status URI %s: %s", status.URI, err)
}
- if blocked, err := d.blockedDomain(statusURI.Host); blocked || err != nil {
+ if blocked, err := d.db.IsDomainBlocked(ctx, statusURI.Host); blocked || err != nil {
return fmt.Errorf("DereferenceStatusFields: domain %s is blocked", statusURI.Host)
}
// we can continue -- create a new transport here because we'll probably need it
- t, err := d.transportController.NewTransportForUsername(requestingUsername)
+ t, err := d.transportController.NewTransportForUsername(ctx, requestingUsername)
if err != nil {
return fmt.Errorf("error creating transport: %s", err)
}
@@ -281,7 +281,7 @@ func (d *deref) populateStatusFields(status *gtsmodel.Status, requestingUsername
// it might have been processed elsewhere so check first if it's already in the database or not
maybeAttachment := &gtsmodel.MediaAttachment{}
- err := d.db.GetWhere([]db.Where{{Key: "remote_url", Value: a.RemoteURL}}, maybeAttachment)
+ err := d.db.GetWhere(ctx, []db.Where{{Key: "remote_url", Value: a.RemoteURL}}, maybeAttachment)
if err == nil {
// we already have it in the db, dereferenced, no need to do it again
l.Tracef("attachment already exists with id %s", maybeAttachment.ID)
@@ -294,7 +294,7 @@ func (d *deref) populateStatusFields(status *gtsmodel.Status, requestingUsername
}
// it just doesn't exist yet so carry on
l.Debug("attachment doesn't exist yet, calling ProcessRemoteAttachment", a)
- deferencedAttachment, err := d.mediaHandler.ProcessRemoteAttachment(t, a, status.AccountID)
+ deferencedAttachment, err := d.mediaHandler.ProcessRemoteAttachment(ctx, t, a, status.AccountID)
if err != nil {
l.Errorf("error dereferencing status attachment: %s", err)
continue
@@ -302,7 +302,7 @@ func (d *deref) populateStatusFields(status *gtsmodel.Status, requestingUsername
l.Debugf("dereferenced attachment: %+v", deferencedAttachment)
deferencedAttachment.StatusID = status.ID
deferencedAttachment.Description = a.Description
- if err := d.db.Put(deferencedAttachment); err != nil {
+ if err := d.db.Put(ctx, deferencedAttachment); err != nil {
return fmt.Errorf("error inserting dereferenced attachment with remote url %s: %s", a.RemoteURL, err)
}
attachmentIDs = append(attachmentIDs, deferencedAttachment.ID)
@@ -338,9 +338,9 @@ func (d *deref) populateStatusFields(status *gtsmodel.Status, requestingUsername
}
var targetAccount *gtsmodel.Account
- if a, err := d.db.GetAccountByURL(targetAccountURI.String()); err == nil {
+ if a, err := d.db.GetAccountByURL(ctx, targetAccountURI.String()); err == nil {
targetAccount = a
- } else if a, _, err := d.GetRemoteAccount(requestingUsername, targetAccountURI, false); err == nil {
+ } else if a, _, err := d.GetRemoteAccount(ctx, requestingUsername, targetAccountURI, false); err == nil {
targetAccount = a
} else {
// we can't find the target account so bail
@@ -369,7 +369,7 @@ func (d *deref) populateStatusFields(status *gtsmodel.Status, requestingUsername
TargetAccountURL: targetAccount.URL,
}
- if err := d.db.Put(m); err != nil {
+ if err := d.db.Put(ctx, m); err != nil {
return fmt.Errorf("error creating mention: %s", err)
}
mentionIDs = append(mentionIDs, m.ID)
@@ -382,13 +382,13 @@ func (d *deref) populateStatusFields(status *gtsmodel.Status, requestingUsername
if err != nil {
return err
}
- if replyToStatus, err := d.db.GetStatusByURI(status.InReplyToURI); err == nil {
+ if replyToStatus, err := d.db.GetStatusByURI(ctx, status.InReplyToURI); err == nil {
// we have the status
status.InReplyToID = replyToStatus.ID
status.InReplyTo = replyToStatus
status.InReplyToAccountID = replyToStatus.AccountID
status.InReplyToAccount = replyToStatus.Account
- } else if replyToStatus, _, _, err := d.GetRemoteStatus(requestingUsername, statusURI, false); err == nil {
+ } else if replyToStatus, _, _, err := d.GetRemoteStatus(ctx, requestingUsername, statusURI, false); err == nil {
// we got the status
status.InReplyToID = replyToStatus.ID
status.InReplyTo = replyToStatus
diff --git a/internal/federation/dereferencing/thread.go b/internal/federation/dereferencing/thread.go
index 2a407f923..f9dd9aa09 100644
--- a/internal/federation/dereferencing/thread.go
+++ b/internal/federation/dereferencing/thread.go
@@ -19,12 +19,12 @@
package dereferencing
import (
+ "context"
"fmt"
"net/url"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/ap"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
@@ -34,7 +34,7 @@ import (
// This process involves working up and down the chain of replies, and parsing through the collections of IDs
// presented by remote instances as part of their replies collections, and will likely involve making several calls to
// multiple different hosts.
-func (d *deref) DereferenceThread(username string, statusIRI *url.URL) error {
+func (d *deref) DereferenceThread(ctx context.Context, username string, statusIRI *url.URL) error {
l := d.log.WithFields(logrus.Fields{
"func": "DereferenceThread",
"username": username,
@@ -49,18 +49,18 @@ func (d *deref) DereferenceThread(username string, statusIRI *url.URL) error {
}
// first make sure we have this status in our db
- _, statusable, _, err := d.GetRemoteStatus(username, statusIRI, true)
+ _, statusable, _, err := d.GetRemoteStatus(ctx, username, statusIRI, true)
if err != nil {
return fmt.Errorf("DereferenceThread: error getting status with id %s: %s", statusIRI.String(), err)
}
// first iterate up through ancestors, dereferencing if necessary as we go
- if err := d.iterateAncestors(username, *statusIRI); err != nil {
+ if err := d.iterateAncestors(ctx, username, *statusIRI); err != nil {
return fmt.Errorf("error iterating ancestors of status %s: %s", statusIRI.String(), err)
}
// now iterate down through descendants, again dereferencing as we go
- if err := d.iterateDescendants(username, *statusIRI, statusable); err != nil {
+ if err := d.iterateDescendants(ctx, username, *statusIRI, statusable); err != nil {
return fmt.Errorf("error iterating descendants of status %s: %s", statusIRI.String(), err)
}
@@ -68,7 +68,7 @@ func (d *deref) DereferenceThread(username string, statusIRI *url.URL) error {
}
// iterateAncestors has the goal of reaching the oldest ancestor of a given status, and stashing all statuses along the way.
-func (d *deref) iterateAncestors(username string, statusIRI url.URL) error {
+func (d *deref) iterateAncestors(ctx context.Context, username string, statusIRI url.URL) error {
l := d.log.WithFields(logrus.Fields{
"func": "iterateAncestors",
"username": username,
@@ -86,8 +86,8 @@ func (d *deref) iterateAncestors(username string, statusIRI url.URL) error {
return err
}
- status := &gtsmodel.Status{}
- if err := d.db.GetByID(id, status); err != nil {
+ status, err := d.db.GetStatusByID(ctx, id)
+ if err != nil {
return err
}
@@ -99,12 +99,12 @@ func (d *deref) iterateAncestors(username string, statusIRI url.URL) error {
if err != nil {
return err
}
- return d.iterateAncestors(username, *nextIRI)
+ return d.iterateAncestors(ctx, username, *nextIRI)
}
// If we reach here, we're looking at a remote status -- make sure we have it in our db by calling GetRemoteStatus
// We call it with refresh to true because we want the statusable representation to parse inReplyTo from.
- status, statusable, _, err := d.GetRemoteStatus(username, &statusIRI, true)
+ status, statusable, _, err := d.GetRemoteStatus(ctx, username, &statusIRI, true)
if err != nil {
l.Debugf("error getting remote status: %s", err)
return nil
@@ -117,22 +117,22 @@ func (d *deref) iterateAncestors(username string, statusIRI url.URL) error {
}
// get the ancestor status into our database if we don't have it yet
- if _, _, _, err := d.GetRemoteStatus(username, inReplyTo, false); err != nil {
+ if _, _, _, err := d.GetRemoteStatus(ctx, username, inReplyTo, false); err != nil {
l.Debugf("error getting remote status: %s", err)
return nil
}
// now enrich the current status, since we should have the ancestor in the db
- if _, err := d.EnrichRemoteStatus(username, status); err != nil {
+ if _, err := d.EnrichRemoteStatus(ctx, username, status); err != nil {
l.Debugf("error enriching remote status: %s", err)
return nil
}
// now move up to the next ancestor
- return d.iterateAncestors(username, *inReplyTo)
+ return d.iterateAncestors(ctx, username, *inReplyTo)
}
-func (d *deref) iterateDescendants(username string, statusIRI url.URL, statusable ap.Statusable) error {
+func (d *deref) iterateDescendants(ctx context.Context, username string, statusIRI url.URL, statusable ap.Statusable) error {
l := d.log.WithFields(logrus.Fields{
"func": "iterateDescendants",
"username": username,
@@ -182,7 +182,7 @@ func (d *deref) iterateDescendants(username string, statusIRI url.URL, statusabl
pageLoop:
for {
l.Debugf("dereferencing page %s", currentPageIRI)
- nextPage, err := d.DereferenceCollectionPage(username, currentPageIRI)
+ nextPage, err := d.DereferenceCollectionPage(ctx, username, currentPageIRI)
if err != nil {
return nil
}
@@ -226,10 +226,10 @@ pageLoop:
foundReplies = foundReplies + 1
// get the remote statusable and put it in the db
- _, statusable, new, err := d.GetRemoteStatus(username, itemURI, false)
+ _, statusable, new, err := d.GetRemoteStatus(ctx, username, itemURI, false)
if new && err == nil && statusable != nil {
// now iterate descendants of *that* status
- if err := d.iterateDescendants(username, *itemURI, statusable); err != nil {
+ if err := d.iterateDescendants(ctx, username, *itemURI, statusable); err != nil {
continue
}
}
diff --git a/internal/federation/federatingdb/accept.go b/internal/federation/federatingdb/accept.go
index 91d9df86f..0b14e8a6a 100644
--- a/internal/federation/federatingdb/accept.go
+++ b/internal/federation/federatingdb/accept.go
@@ -86,7 +86,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
if util.IsFollowPath(acceptedObjectIRI) {
// ACCEPT FOLLOW
gtsFollowRequest := &gtsmodel.FollowRequest{}
- if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: acceptedObjectIRI.String()}}, gtsFollowRequest); err != nil {
+ if err := f.db.GetWhere(ctx, []db.Where{{Key: "uri", Value: acceptedObjectIRI.String()}}, gtsFollowRequest); err != nil {
return fmt.Errorf("ACCEPT: couldn't get follow request with id %s from the database: %s", acceptedObjectIRI.String(), err)
}
@@ -94,7 +94,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
if gtsFollowRequest.AccountID != targetAcct.ID {
return errors.New("ACCEPT: follow object account and inbox account were not the same")
}
- follow, err := f.db.AcceptFollowRequest(gtsFollowRequest.AccountID, gtsFollowRequest.TargetAccountID)
+ follow, err := f.db.AcceptFollowRequest(ctx, gtsFollowRequest.AccountID, gtsFollowRequest.TargetAccountID)
if err != nil {
return err
}
@@ -123,7 +123,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
return errors.New("ACCEPT: couldn't parse follow into vocab.ActivityStreamsFollow")
}
// convert the follow to something we can understand
- gtsFollow, err := f.typeConverter.ASFollowToFollow(asFollow)
+ gtsFollow, err := f.typeConverter.ASFollowToFollow(ctx, asFollow)
if err != nil {
return fmt.Errorf("ACCEPT: error converting asfollow to gtsfollow: %s", err)
}
@@ -131,7 +131,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
if gtsFollow.AccountID != targetAcct.ID {
return errors.New("ACCEPT: follow object account and inbox account were not the same")
}
- follow, err := f.db.AcceptFollowRequest(gtsFollow.AccountID, gtsFollow.TargetAccountID)
+ follow, err := f.db.AcceptFollowRequest(ctx, gtsFollow.AccountID, gtsFollow.TargetAccountID)
if err != nil {
return err
}
diff --git a/internal/federation/federatingdb/announce.go b/internal/federation/federatingdb/announce.go
index 981eaf1ef..5cd34285e 100644
--- a/internal/federation/federatingdb/announce.go
+++ b/internal/federation/federatingdb/announce.go
@@ -71,7 +71,7 @@ func (f *federatingDB) Announce(ctx context.Context, announce vocab.ActivityStre
return nil
}
- boost, isNew, err := f.typeConverter.ASAnnounceToStatus(announce)
+ boost, isNew, err := f.typeConverter.ASAnnounceToStatus(ctx, announce)
if err != nil {
return fmt.Errorf("ANNOUNCE: error converting announce to boost: %s", err)
}
diff --git a/internal/federation/federatingdb/create.go b/internal/federation/federatingdb/create.go
index fb4353cd4..8ea549c5a 100644
--- a/internal/federation/federatingdb/create.go
+++ b/internal/federation/federatingdb/create.go
@@ -100,7 +100,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
case gtsmodel.ActivityStreamsNote:
// CREATE A NOTE
note := objectIter.GetActivityStreamsNote()
- status, err := f.typeConverter.ASStatusToStatus(note)
+ status, err := f.typeConverter.ASStatusToStatus(ctx, note)
if err != nil {
return fmt.Errorf("CREATE: error converting note to status: %s", err)
}
@@ -112,7 +112,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
}
status.ID = statusID
- if err := f.db.PutStatus(status); err != nil {
+ if err := f.db.PutStatus(ctx, status); err != nil {
if err == db.ErrAlreadyExists {
// the status already exists in the database, which means we've already handled everything else,
// so we can just return nil here and be done with it.
@@ -137,7 +137,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
return errors.New("CREATE: could not convert type to follow")
}
- followRequest, err := f.typeConverter.ASFollowToFollowRequest(follow)
+ followRequest, err := f.typeConverter.ASFollowToFollowRequest(ctx, follow)
if err != nil {
return fmt.Errorf("CREATE: could not convert Follow to follow request: %s", err)
}
@@ -148,7 +148,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
}
followRequest.ID = newID
- if err := f.db.Put(followRequest); err != nil {
+ if err := f.db.Put(ctx, followRequest); err != nil {
return fmt.Errorf("CREATE: database error inserting follow request: %s", err)
}
@@ -165,7 +165,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
return errors.New("CREATE: could not convert type to like")
}
- fave, err := f.typeConverter.ASLikeToFave(like)
+ fave, err := f.typeConverter.ASLikeToFave(ctx, like)
if err != nil {
return fmt.Errorf("CREATE: could not convert Like to fave: %s", err)
}
@@ -176,7 +176,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
}
fave.ID = newID
- if err := f.db.Put(fave); err != nil {
+ if err := f.db.Put(ctx, fave); err != nil {
return fmt.Errorf("CREATE: database error inserting fave: %s", err)
}
@@ -193,7 +193,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
return errors.New("CREATE: could not convert type to block")
}
- block, err := f.typeConverter.ASBlockToBlock(blockable)
+ block, err := f.typeConverter.ASBlockToBlock(ctx, blockable)
if err != nil {
return fmt.Errorf("CREATE: could not convert Block to gts model block")
}
@@ -204,7 +204,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
}
block.ID = newID
- if err := f.db.Put(block); err != nil {
+ if err := f.db.Put(ctx, block); err != nil {
return fmt.Errorf("CREATE: database error inserting block: %s", err)
}
diff --git a/internal/federation/federatingdb/delete.go b/internal/federation/federatingdb/delete.go
index ee9310789..11b818168 100644
--- a/internal/federation/federatingdb/delete.go
+++ b/internal/federation/federatingdb/delete.go
@@ -69,11 +69,11 @@ func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error {
// in a delete we only get the URI, we can't know if we have a status or a profile or something else,
// so we have to try a few different things...
- s, err := f.db.GetStatusByURI(id.String())
+ s, err := f.db.GetStatusByURI(ctx, id.String())
if err == nil {
// it's a status
l.Debugf("uri is for status with id: %s", s.ID)
- if err := f.db.DeleteByID(s.ID, &gtsmodel.Status{}); err != nil {
+ if err := f.db.DeleteByID(ctx, s.ID, &gtsmodel.Status{}); err != nil {
return fmt.Errorf("DELETE: err deleting status: %s", err)
}
fromFederatorChan <- gtsmodel.FromFederator{
@@ -84,11 +84,11 @@ func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error {
}
}
- a, err := f.db.GetAccountByURI(id.String())
+ a, err := f.db.GetAccountByURI(ctx, id.String())
if err == nil {
// it's an account
- l.Debugf("uri is for an account with id: %s", s.ID)
- if err := f.db.DeleteByID(a.ID, &gtsmodel.Account{}); err != nil {
+ l.Debugf("uri is for an account with id: %s", a.ID)
+ if err := f.db.DeleteByID(ctx, a.ID, &gtsmodel.Account{}); err != nil {
return fmt.Errorf("DELETE: err deleting account: %s", err)
}
fromFederatorChan <- gtsmodel.FromFederator{
diff --git a/internal/federation/federatingdb/followers.go b/internal/federation/federatingdb/followers.go
index 241362fc1..c7f636a12 100644
--- a/internal/federation/federatingdb/followers.go
+++ b/internal/federation/federatingdb/followers.go
@@ -19,7 +19,7 @@ import (
// If modified, the library will then call Update.
//
// The library makes this call only after acquiring a lock first.
-func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) {
+func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) {
l := f.log.WithFields(
logrus.Fields{
"func": "Followers",
@@ -31,19 +31,19 @@ func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (follower
acct := &gtsmodel.Account{}
if util.IsUserPath(actorIRI) {
- acct, err = f.db.GetAccountByURI(actorIRI.String())
+ acct, err = f.db.GetAccountByURI(ctx, actorIRI.String())
if err != nil {
return nil, fmt.Errorf("FOLLOWERS: db error getting account with uri %s: %s", actorIRI.String(), err)
}
} else if util.IsFollowersPath(actorIRI) {
- if err := f.db.GetWhere([]db.Where{{Key: "followers_uri", Value: actorIRI.String()}}, acct); err != nil {
+ if err := f.db.GetWhere(ctx, []db.Where{{Key: "followers_uri", Value: actorIRI.String()}}, acct); err != nil {
return nil, fmt.Errorf("FOLLOWERS: db error getting account with followers uri %s: %s", actorIRI.String(), err)
}
} else {
return nil, fmt.Errorf("FOLLOWERS: could not parse actor IRI %s as users or followers path", actorIRI.String())
}
- acctFollowers, err := f.db.GetAccountFollowedBy(acct.ID, false)
+ acctFollowers, err := f.db.GetAccountFollowedBy(ctx, acct.ID, false)
if err != nil {
return nil, fmt.Errorf("FOLLOWERS: db error getting followers for account id %s: %s", acct.ID, err)
}
@@ -51,13 +51,17 @@ func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (follower
followers = streams.NewActivityStreamsCollection()
items := streams.NewActivityStreamsItemsProperty()
for _, follow := range acctFollowers {
- gtsFollower := &gtsmodel.Account{}
- if err := f.db.GetByID(follow.AccountID, gtsFollower); err != nil {
- return nil, fmt.Errorf("FOLLOWERS: db error getting account id %s: %s", follow.AccountID, err)
+ if follow.Account == nil {
+ followAccount, err := f.db.GetAccountByID(ctx, follow.AccountID)
+ if err != nil {
+ return nil, fmt.Errorf("FOLLOWERS: db error getting account id %s: %s", follow.AccountID, err)
+ }
+ follow.Account = followAccount
}
- uri, err := url.Parse(gtsFollower.URI)
+
+ uri, err := url.Parse(follow.Account.URI)
if err != nil {
- return nil, fmt.Errorf("FOLLOWERS: error parsing %s as url: %s", gtsFollower.URI, err)
+ return nil, fmt.Errorf("FOLLOWERS: error parsing %s as url: %s", follow.Account.URI, err)
}
items.AppendIRI(uri)
}
diff --git a/internal/federation/federatingdb/following.go b/internal/federation/federatingdb/following.go
index 45785c671..9d5c0693c 100644
--- a/internal/federation/federatingdb/following.go
+++ b/internal/federation/federatingdb/following.go
@@ -18,7 +18,7 @@ import (
// If modified, the library will then call Update.
//
// The library makes this call only after acquiring a lock first.
-func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (following vocab.ActivityStreamsCollection, err error) {
+func (f *federatingDB) Following(ctx context.Context, actorIRI *url.URL) (following vocab.ActivityStreamsCollection, err error) {
l := f.log.WithFields(
logrus.Fields{
"func": "Following",
@@ -34,7 +34,7 @@ func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (followin
return nil, fmt.Errorf("FOLLOWING: error parsing user path: %s", err)
}
- a, err := f.db.GetLocalAccountByUsername(username)
+ a, err := f.db.GetLocalAccountByUsername(ctx, username)
if err != nil {
return nil, fmt.Errorf("FOLLOWING: db error getting account with uri %s: %s", actorIRI.String(), err)
}
@@ -46,7 +46,7 @@ func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (followin
return nil, fmt.Errorf("FOLLOWING: error parsing following path: %s", err)
}
- a, err := f.db.GetLocalAccountByUsername(username)
+ a, err := f.db.GetLocalAccountByUsername(ctx, username)
if err != nil {
return nil, fmt.Errorf("FOLLOWING: db error getting account with following uri %s: %s", actorIRI.String(), err)
}
@@ -56,7 +56,7 @@ func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (followin
return nil, fmt.Errorf("FOLLOWING: could not parse actor IRI %s as users or following path", actorIRI.String())
}
- acctFollowing, err := f.db.GetAccountFollows(acct.ID)
+ acctFollowing, err := f.db.GetAccountFollows(ctx, acct.ID)
if err != nil {
return nil, fmt.Errorf("FOLLOWING: db error getting following for account id %s: %s", acct.ID, err)
}
@@ -64,13 +64,17 @@ func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (followin
following = streams.NewActivityStreamsCollection()
items := streams.NewActivityStreamsItemsProperty()
for _, follow := range acctFollowing {
- gtsFollowing := &gtsmodel.Account{}
- if err := f.db.GetByID(follow.AccountID, gtsFollowing); err != nil {
- return nil, fmt.Errorf("FOLLOWING: db error getting account id %s: %s", follow.AccountID, err)
+ if follow.Account == nil {
+ followAccount, err := f.db.GetAccountByID(ctx, follow.AccountID)
+ if err != nil {
+ return nil, fmt.Errorf("FOLLOWING: db error getting account id %s: %s", follow.AccountID, err)
+ }
+ follow.Account = followAccount
}
- uri, err := url.Parse(gtsFollowing.URI)
+
+ uri, err := url.Parse(follow.Account.URI)
if err != nil {
- return nil, fmt.Errorf("FOLLOWING: error parsing %s as url: %s", gtsFollowing.URI, err)
+ return nil, fmt.Errorf("FOLLOWING: error parsing %s as url: %s", follow.Account.URI, err)
}
items.AppendIRI(uri)
}
diff --git a/internal/federation/federatingdb/get.go b/internal/federation/federatingdb/get.go
index 0265080f9..cc04dd851 100644
--- a/internal/federation/federatingdb/get.go
+++ b/internal/federation/federatingdb/get.go
@@ -33,7 +33,7 @@ import (
// Get returns the database entry for the specified id.
//
// The library makes this call only after acquiring a lock first.
-func (f *federatingDB) Get(c context.Context, id *url.URL) (value vocab.Type, err error) {
+func (f *federatingDB) Get(ctx context.Context, id *url.URL) (value vocab.Type, err error) {
l := f.log.WithFields(
logrus.Fields{
"func": "Get",
@@ -43,17 +43,17 @@ func (f *federatingDB) Get(c context.Context, id *url.URL) (value vocab.Type, er
l.Debug("entering GET function")
if util.IsUserPath(id) {
- acct, err := f.db.GetAccountByURI(id.String())
+ acct, err := f.db.GetAccountByURI(ctx, id.String())
if err != nil {
return nil, err
}
l.Debug("is user path! returning account")
- return f.typeConverter.AccountToAS(acct)
+ return f.typeConverter.AccountToAS(ctx, acct)
}
if util.IsFollowersPath(id) {
acct := &gtsmodel.Account{}
- if err := f.db.GetWhere([]db.Where{{Key: "followers_uri", Value: id.String()}}, acct); err != nil {
+ if err := f.db.GetWhere(ctx, []db.Where{{Key: "followers_uri", Value: id.String()}}, acct); err != nil {
return nil, err
}
@@ -62,12 +62,12 @@ func (f *federatingDB) Get(c context.Context, id *url.URL) (value vocab.Type, er
return nil, err
}
- return f.Followers(c, followersURI)
+ return f.Followers(ctx, followersURI)
}
if util.IsFollowingPath(id) {
acct := &gtsmodel.Account{}
- if err := f.db.GetWhere([]db.Where{{Key: "following_uri", Value: id.String()}}, acct); err != nil {
+ if err := f.db.GetWhere(ctx, []db.Where{{Key: "following_uri", Value: id.String()}}, acct); err != nil {
return nil, err
}
@@ -76,7 +76,7 @@ func (f *federatingDB) Get(c context.Context, id *url.URL) (value vocab.Type, er
return nil, err
}
- return f.Following(c, followingURI)
+ return f.Following(ctx, followingURI)
}
return nil, errors.New("could not get")
diff --git a/internal/federation/federatingdb/outbox.go b/internal/federation/federatingdb/outbox.go
index 849014432..81b90aae2 100644
--- a/internal/federation/federatingdb/outbox.go
+++ b/internal/federation/federatingdb/outbox.go
@@ -35,7 +35,7 @@ import (
// at the specified IRI, for prepending new items.
//
// The library makes this call only after acquiring a lock first.
-func (f *federatingDB) GetOutbox(c context.Context, outboxIRI *url.URL) (inbox vocab.ActivityStreamsOrderedCollectionPage, err error) {
+func (f *federatingDB) GetOutbox(ctx context.Context, outboxIRI *url.URL) (inbox vocab.ActivityStreamsOrderedCollectionPage, err error) {
l := f.log.WithFields(
logrus.Fields{
"func": "GetOutbox",
@@ -51,7 +51,7 @@ func (f *federatingDB) GetOutbox(c context.Context, outboxIRI *url.URL) (inbox v
// database entries. Separate calls to Create will do that.
//
// The library makes this call only after acquiring a lock first.
-func (f *federatingDB) SetOutbox(c context.Context, outbox vocab.ActivityStreamsOrderedCollectionPage) error {
+func (f *federatingDB) SetOutbox(ctx context.Context, outbox vocab.ActivityStreamsOrderedCollectionPage) error {
l := f.log.WithFields(
logrus.Fields{
"func": "SetOutbox",
@@ -66,7 +66,7 @@ func (f *federatingDB) SetOutbox(c context.Context, outbox vocab.ActivityStreams
// actor's inbox IRI.
//
// The library makes this call only after acquiring a lock first.
-func (f *federatingDB) OutboxForInbox(c context.Context, inboxIRI *url.URL) (outboxIRI *url.URL, err error) {
+func (f *federatingDB) OutboxForInbox(ctx context.Context, inboxIRI *url.URL) (outboxIRI *url.URL, err error) {
l := f.log.WithFields(
logrus.Fields{
"func": "OutboxForInbox",
@@ -79,7 +79,7 @@ func (f *federatingDB) OutboxForInbox(c context.Context, inboxIRI *url.URL) (out
return nil, fmt.Errorf("%s is not an inbox URI", inboxIRI.String())
}
acct := &gtsmodel.Account{}
- if err := f.db.GetWhere([]db.Where{{Key: "inbox_uri", Value: inboxIRI.String()}}, acct); err != nil {
+ if err := f.db.GetWhere(ctx, []db.Where{{Key: "inbox_uri", Value: inboxIRI.String()}}, acct); err != nil {
if err == db.ErrNoEntries {
return nil, fmt.Errorf("no actor found that corresponds to inbox %s", inboxIRI.String())
}
diff --git a/internal/federation/federatingdb/owns.go b/internal/federation/federatingdb/owns.go
index 0a65397ff..1c1f2512d 100644
--- a/internal/federation/federatingdb/owns.go
+++ b/internal/federation/federatingdb/owns.go
@@ -32,7 +32,7 @@ import (
// Owns returns true if the IRI belongs to this instance, and if
// the database has an entry for the IRI.
// The library makes this call only after acquiring a lock first.
-func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
+func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {
l := f.log.WithFields(
logrus.Fields{
"func": "Owns",
@@ -54,7 +54,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
if err != nil {
return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)
}
- status, err := f.db.GetStatusByURI(uid)
+ status, err := f.db.GetStatusByURI(ctx, uid)
if err != nil {
if err == db.ErrNoEntries {
// there are no entries for this status
@@ -71,7 +71,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
if err != nil {
return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)
}
- if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
+ if _, err := f.db.GetLocalAccountByUsername(ctx, username); err != nil {
if err == db.ErrNoEntries {
// there are no entries for this username
return false, nil
@@ -88,7 +88,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
if err != nil {
return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)
}
- if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
+ if _, err := f.db.GetLocalAccountByUsername(ctx, username); err != nil {
if err == db.ErrNoEntries {
// there are no entries for this username
return false, nil
@@ -105,7 +105,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
if err != nil {
return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)
}
- if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
+ if _, err := f.db.GetLocalAccountByUsername(ctx, username); err != nil {
if err == db.ErrNoEntries {
// there are no entries for this username
return false, nil
@@ -122,7 +122,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
if err != nil {
return false, fmt.Errorf("error parsing like path for url %s: %s", id.String(), err)
}
- if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
+ if _, err := f.db.GetLocalAccountByUsername(ctx, username); err != nil {
if err == db.ErrNoEntries {
// there are no entries for this username
return false, nil
@@ -130,7 +130,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
// an actual error happened
return false, fmt.Errorf("database error fetching account with username %s: %s", username, err)
}
- if err := f.db.GetByID(likeID, &gtsmodel.StatusFave{}); err != nil {
+ if err := f.db.GetByID(ctx, likeID, &gtsmodel.StatusFave{}); err != nil {
if err == db.ErrNoEntries {
// there are no entries
return false, nil
@@ -147,7 +147,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
if err != nil {
return false, fmt.Errorf("error parsing block path for url %s: %s", id.String(), err)
}
- if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
+ if _, err := f.db.GetLocalAccountByUsername(ctx, username); err != nil {
if err == db.ErrNoEntries {
// there are no entries for this username
return false, nil
@@ -155,7 +155,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
// an actual error happened
return false, fmt.Errorf("database error fetching account with username %s: %s", username, err)
}
- if err := f.db.GetByID(blockID, &gtsmodel.Block{}); err != nil {
+ if err := f.db.GetByID(ctx, blockID, &gtsmodel.Block{}); err != nil {
if err == db.ErrNoEntries {
// there are no entries
return false, nil
diff --git a/internal/federation/federatingdb/undo.go b/internal/federation/federatingdb/undo.go
index c527833b4..0fa38114d 100644
--- a/internal/federation/federatingdb/undo.go
+++ b/internal/federation/federatingdb/undo.go
@@ -83,7 +83,7 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
return errors.New("UNDO: follow actor and activity actor not the same")
}
// convert the follow to something we can understand
- gtsFollow, err := f.typeConverter.ASFollowToFollow(ASFollow)
+ gtsFollow, err := f.typeConverter.ASFollowToFollow(ctx, ASFollow)
if err != nil {
return fmt.Errorf("UNDO: error converting asfollow to gtsfollow: %s", err)
}
@@ -92,11 +92,11 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
return errors.New("UNDO: follow object account and inbox account were not the same")
}
// delete any existing FOLLOW
- if err := f.db.DeleteWhere([]db.Where{{Key: "uri", Value: gtsFollow.URI}}, &gtsmodel.Follow{}); err != nil {
+ if err := f.db.DeleteWhere(ctx, []db.Where{{Key: "uri", Value: gtsFollow.URI}}, &gtsmodel.Follow{}); err != nil {
return fmt.Errorf("UNDO: db error removing follow: %s", err)
}
// delete any existing FOLLOW REQUEST
- if err := f.db.DeleteWhere([]db.Where{{Key: "uri", Value: gtsFollow.URI}}, &gtsmodel.FollowRequest{}); err != nil {
+ if err := f.db.DeleteWhere(ctx, []db.Where{{Key: "uri", Value: gtsFollow.URI}}, &gtsmodel.FollowRequest{}); err != nil {
return fmt.Errorf("UNDO: db error removing follow request: %s", err)
}
l.Debug("follow undone")
@@ -116,7 +116,7 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
return errors.New("UNDO: block actor and activity actor not the same")
}
// convert the block to something we can understand
- gtsBlock, err := f.typeConverter.ASBlockToBlock(ASBlock)
+ gtsBlock, err := f.typeConverter.ASBlockToBlock(ctx, ASBlock)
if err != nil {
return fmt.Errorf("UNDO: error converting asblock to gtsblock: %s", err)
}
@@ -125,7 +125,7 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
return errors.New("UNDO: block object account and inbox account were not the same")
}
// delete any existing BLOCK
- if err := f.db.DeleteWhere([]db.Where{{Key: "uri", Value: gtsBlock.URI}}, &gtsmodel.Block{}); err != nil {
+ if err := f.db.DeleteWhere(ctx, []db.Where{{Key: "uri", Value: gtsBlock.URI}}, &gtsmodel.Block{}); err != nil {
return fmt.Errorf("UNDO: db error removing block: %s", err)
}
l.Debug("block undone")
diff --git a/internal/federation/federatingdb/update.go b/internal/federation/federatingdb/update.go
index 88ffc23b4..e9dfe5315 100644
--- a/internal/federation/federatingdb/update.go
+++ b/internal/federation/federatingdb/update.go
@@ -136,7 +136,7 @@ func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error {
accountable = i
}
- updatedAcct, err := f.typeConverter.ASRepresentationToAccount(accountable, true)
+ updatedAcct, err := f.typeConverter.ASRepresentationToAccount(ctx, accountable, true)
if err != nil {
return fmt.Errorf("UPDATE: error converting to account: %s", err)
}
@@ -152,7 +152,8 @@ func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error {
}
updatedAcct.ID = requestingAcct.ID // set this here so the db will update properly instead of trying to PUT this and getting constraint issues
- if err := f.db.UpdateByID(requestingAcct.ID, updatedAcct); err != nil {
+ updatedAcct, err = f.db.UpdateAccount(ctx, updatedAcct)
+ if err != nil {
return fmt.Errorf("UPDATE: database error inserting updated account: %s", err)
}
diff --git a/internal/federation/federatingdb/util.go b/internal/federation/federatingdb/util.go
index eac70d85c..b5befc613 100644
--- a/internal/federation/federatingdb/util.go
+++ b/internal/federation/federatingdb/util.go
@@ -60,7 +60,7 @@ func sameActor(activityActor vocab.ActivityStreamsActorProperty, followActor voc
//
// The go-fed library will handle setting the 'id' property on the
// activity or object provided with the value returned.
-func (f *federatingDB) NewID(c context.Context, t vocab.Type) (idURL *url.URL, err error) {
+func (f *federatingDB) NewID(ctx context.Context, t vocab.Type) (idURL *url.URL, err error) {
l := f.log.WithFields(
logrus.Fields{
"func": "NewID",
@@ -98,7 +98,7 @@ func (f *federatingDB) NewID(c context.Context, t vocab.Type) (idURL *url.URL, e
// take the IRI of the first actor we can find (there should only be one)
if iter.IsIRI() {
// if there's an error here, just use the fallback behavior -- we don't need to return an error here
- if actorAccount, err := f.db.GetAccountByURI(iter.GetIRI().String()); err == nil {
+ if actorAccount, err := f.db.GetAccountByURI(ctx, iter.GetIRI().String()); err == nil {
newID, err := id.NewRandomULID()
if err != nil {
return nil, err
@@ -199,7 +199,7 @@ func (f *federatingDB) NewID(c context.Context, t vocab.Type) (idURL *url.URL, e
// ActorForOutbox fetches the actor's IRI for the given outbox IRI.
//
// The library makes this call only after acquiring a lock first.
-func (f *federatingDB) ActorForOutbox(c context.Context, outboxIRI *url.URL) (actorIRI *url.URL, err error) {
+func (f *federatingDB) ActorForOutbox(ctx context.Context, outboxIRI *url.URL) (actorIRI *url.URL, err error) {
l := f.log.WithFields(
logrus.Fields{
"func": "ActorForOutbox",
@@ -212,7 +212,7 @@ func (f *federatingDB) ActorForOutbox(c context.Context, outboxIRI *url.URL) (ac
return nil, fmt.Errorf("%s is not an outbox URI", outboxIRI.String())
}
acct := &gtsmodel.Account{}
- if err := f.db.GetWhere([]db.Where{{Key: "outbox_uri", Value: outboxIRI.String()}}, acct); err != nil {
+ if err := f.db.GetWhere(ctx, []db.Where{{Key: "outbox_uri", Value: outboxIRI.String()}}, acct); err != nil {
if err == db.ErrNoEntries {
return nil, fmt.Errorf("no actor found that corresponds to outbox %s", outboxIRI.String())
}
@@ -224,7 +224,7 @@ func (f *federatingDB) ActorForOutbox(c context.Context, outboxIRI *url.URL) (ac
// ActorForInbox fetches the actor's IRI for the given outbox IRI.
//
// The library makes this call only after acquiring a lock first.
-func (f *federatingDB) ActorForInbox(c context.Context, inboxIRI *url.URL) (actorIRI *url.URL, err error) {
+func (f *federatingDB) ActorForInbox(ctx context.Context, inboxIRI *url.URL) (actorIRI *url.URL, err error) {
l := f.log.WithFields(
logrus.Fields{
"func": "ActorForInbox",
@@ -237,7 +237,7 @@ func (f *federatingDB) ActorForInbox(c context.Context, inboxIRI *url.URL) (acto
return nil, fmt.Errorf("%s is not an inbox URI", inboxIRI.String())
}
acct := &gtsmodel.Account{}
- if err := f.db.GetWhere([]db.Where{{Key: "inbox_uri", Value: inboxIRI.String()}}, acct); err != nil {
+ if err := f.db.GetWhere(ctx, []db.Where{{Key: "inbox_uri", Value: inboxIRI.String()}}, acct); err != nil {
if err == db.ErrNoEntries {
return nil, fmt.Errorf("no actor found that corresponds to inbox %s", inboxIRI.String())
}
diff --git a/internal/federation/federatingprotocol.go b/internal/federation/federatingprotocol.go
index 5da68afd3..7f8958111 100644
--- a/internal/federation/federatingprotocol.go
+++ b/internal/federation/federatingprotocol.go
@@ -113,7 +113,7 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr
return nil, false, errors.New("username was empty")
}
- requestedAccount, err := f.db.GetLocalAccountByUsername(username)
+ requestedAccount, 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)
}
@@ -131,14 +131,14 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr
// authentication has passed, so add an instance entry for this instance if it hasn't been done already
i := &gtsmodel.Instance{}
- if err := f.db.GetWhere([]db.Where{{Key: "domain", Value: publicKeyOwnerURI.Host, CaseInsensitive: true}}, i); err != nil {
+ if err := f.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: publicKeyOwnerURI.Host, CaseInsensitive: true}}, i); err != nil {
if err != db.ErrNoEntries {
// there's been an actual error
return ctx, false, fmt.Errorf("error getting requesting account with public key id %s: %s", publicKeyOwnerURI.String(), err)
}
// we don't have an entry for this instance yet so dereference it
- i, err = f.GetRemoteInstance(username, &url.URL{
+ i, err = f.GetRemoteInstance(ctx, username, &url.URL{
Scheme: publicKeyOwnerURI.Scheme,
Host: publicKeyOwnerURI.Host,
})
@@ -147,12 +147,12 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr
}
// and put it in the db
- if err := f.db.Put(i); err != nil {
+ if err := f.db.Put(ctx, i); err != nil {
return nil, false, fmt.Errorf("error inserting newly dereferenced instance %s: %s", publicKeyOwnerURI.Host, err)
}
}
- requestingAccount, _, err := f.GetRemoteAccount(username, publicKeyOwnerURI, false)
+ requestingAccount, _, err := f.GetRemoteAccount(ctx, username, publicKeyOwnerURI, false)
if err != nil {
return nil, false, fmt.Errorf("couldn't get remote account: %s", err)
}
@@ -189,7 +189,7 @@ func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, er
return false, errors.New("requested account not set on request context, so couldn't determine blocks")
}
- blocked, err := f.db.AreURIsBlocked(actorIRIs)
+ blocked, err := f.db.AreURIsBlocked(ctx, actorIRIs)
if err != nil {
return false, fmt.Errorf("error checking domain blocks: %s", err)
}
@@ -198,7 +198,7 @@ func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, er
}
for _, uri := range actorIRIs {
- requestingAccount, err := f.db.GetAccountByURI(uri.String())
+ requestingAccount, err := f.db.GetAccountByURI(ctx, uri.String())
if err != nil {
if err == db.ErrNoEntries {
// we don't have an entry for this account so it's not blocked
@@ -208,7 +208,7 @@ 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(requestedAccount.ID, requestingAccount.ID, true)
+ blocked, err = f.db.IsBlocked(ctx, requestedAccount.ID, requestingAccount.ID, true)
if err != nil {
return false, fmt.Errorf("error checking account block: %s", err)
}
diff --git a/internal/federation/federator.go b/internal/federation/federator.go
index 1b5f5441a..5eddcbb99 100644
--- a/internal/federation/federator.go
+++ b/internal/federation/federator.go
@@ -54,21 +54,21 @@ type Federator interface {
// FingerRemoteAccount performs a webfinger lookup for a remote account, using the .well-known path. It will return the ActivityPub URI for that
// account, or an error if it doesn't exist or can't be retrieved.
- FingerRemoteAccount(requestingUsername string, targetUsername string, targetDomain string) (*url.URL, error)
+ FingerRemoteAccount(ctx context.Context, requestingUsername string, targetUsername string, targetDomain string) (*url.URL, error)
- DereferenceRemoteThread(username string, statusURI *url.URL) error
- DereferenceAnnounce(announce *gtsmodel.Status, requestingUsername string) error
+ DereferenceRemoteThread(ctx context.Context, username string, statusURI *url.URL) error
+ DereferenceAnnounce(ctx context.Context, announce *gtsmodel.Status, requestingUsername string) error
- GetRemoteAccount(username string, remoteAccountID *url.URL, refresh bool) (*gtsmodel.Account, bool, error)
- EnrichRemoteAccount(username string, account *gtsmodel.Account) (*gtsmodel.Account, error)
+ GetRemoteAccount(ctx context.Context, username string, remoteAccountID *url.URL, refresh bool) (*gtsmodel.Account, bool, error)
+ EnrichRemoteAccount(ctx context.Context, username string, account *gtsmodel.Account) (*gtsmodel.Account, error)
- GetRemoteStatus(username string, remoteStatusID *url.URL, refresh bool) (*gtsmodel.Status, ap.Statusable, bool, error)
- EnrichRemoteStatus(username string, status *gtsmodel.Status) (*gtsmodel.Status, error)
+ GetRemoteStatus(ctx context.Context, username string, remoteStatusID *url.URL, refresh bool) (*gtsmodel.Status, ap.Statusable, bool, error)
+ EnrichRemoteStatus(ctx context.Context, username string, status *gtsmodel.Status) (*gtsmodel.Status, error)
- GetRemoteInstance(username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error)
+ GetRemoteInstance(ctx context.Context, username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error)
// Handshaking returns true if the given username is currently in the process of dereferencing the remoteAccountID.
- Handshaking(username string, remoteAccountID *url.URL) bool
+ Handshaking(ctx context.Context, username string, remoteAccountID *url.URL) bool
pub.CommonBehavior
pub.FederatingProtocol
}
diff --git a/internal/federation/finger.go b/internal/federation/finger.go
index a5a4fa0e7..5cdd4c04d 100644
--- a/internal/federation/finger.go
+++ b/internal/federation/finger.go
@@ -29,12 +29,12 @@ import (
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
)
-func (f *federator) FingerRemoteAccount(requestingUsername string, targetUsername string, targetDomain string) (*url.URL, error) {
- if blocked, err := f.db.IsDomainBlocked(targetDomain); blocked || err != nil {
+func (f *federator) FingerRemoteAccount(ctx context.Context, requestingUsername string, targetUsername string, targetDomain string) (*url.URL, error) {
+ if blocked, err := f.db.IsDomainBlocked(ctx, targetDomain); blocked || err != nil {
return nil, fmt.Errorf("FingerRemoteAccount: domain %s is blocked", targetDomain)
}
- t, err := f.transportController.NewTransportForUsername(requestingUsername)
+ t, err := f.transportController.NewTransportForUsername(ctx, requestingUsername)
if err != nil {
return nil, fmt.Errorf("FingerRemoteAccount: error getting transport for username %s while dereferencing @%s@%s: %s", requestingUsername, targetUsername, targetDomain, err)
}
diff --git a/internal/federation/handshake.go b/internal/federation/handshake.go
index 0671e78a9..b973680b3 100644
--- a/internal/federation/handshake.go
+++ b/internal/federation/handshake.go
@@ -18,8 +18,11 @@
package federation
-import "net/url"
+import (
+ "context"
+ "net/url"
+)
-func (f *federator) Handshaking(username string, remoteAccountID *url.URL) bool {
- return f.dereferencer.Handshaking(username, remoteAccountID)
+func (f *federator) Handshaking(ctx context.Context, username string, remoteAccountID *url.URL) bool {
+ return f.dereferencer.Handshaking(ctx, username, remoteAccountID)
}
diff --git a/internal/federation/transport.go b/internal/federation/transport.go
index 20aee964b..9e2e38e19 100644
--- a/internal/federation/transport.go
+++ b/internal/federation/transport.go
@@ -68,5 +68,5 @@ func (f *federator) NewTransport(ctx context.Context, actorBoxIRI *url.URL, gofe
return nil, fmt.Errorf("id %s was neither an inbox path nor an outbox path", actorBoxIRI.String())
}
- return f.transportController.NewTransportForUsername(username)
+ return f.transportController.NewTransportForUsername(ctx, username)
}