diff options
Diffstat (limited to 'internal/federation/federatingdb')
-rw-r--r-- | internal/federation/federatingdb/db.go | 7 | ||||
-rw-r--r-- | internal/federation/federatingdb/federatingdb_test.go | 6 | ||||
-rw-r--r-- | internal/federation/federatingdb/owns.go | 7 | ||||
-rw-r--r-- | internal/federation/federatingdb/reject_test.go | 2 | ||||
-rw-r--r-- | internal/federation/federatingdb/update.go | 5 | ||||
-rw-r--r-- | internal/federation/federatingdb/util.go | 9 |
6 files changed, 21 insertions, 15 deletions
diff --git a/internal/federation/federatingdb/db.go b/internal/federation/federatingdb/db.go index 4b2f92fd4..64e5ad359 100644 --- a/internal/federation/federatingdb/db.go +++ b/internal/federation/federatingdb/db.go @@ -25,7 +25,6 @@ import ( "github.com/superseriousbusiness/activity/pub" "github.com/superseriousbusiness/activity/streams/vocab" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) @@ -46,19 +45,17 @@ type federatingDB struct { locks map[string]*mutex pool sync.Pool db db.DB - config *config.Config typeConverter typeutils.TypeConverter } // New returns a DB interface using the given database and config -func New(db db.DB, config *config.Config) DB { +func New(db db.DB) DB { fdb := federatingDB{ mutex: sync.Mutex{}, locks: make(map[string]*mutex, 100), pool: sync.Pool{New: func() interface{} { return &mutex{} }}, db: db, - config: config, - typeConverter: typeutils.NewConverter(config, db), + typeConverter: typeutils.NewConverter(db), } go fdb.cleanupLocks() return &fdb diff --git a/internal/federation/federatingdb/federatingdb_test.go b/internal/federation/federatingdb/federatingdb_test.go index 24cbfed98..d51e0a825 100644 --- a/internal/federation/federatingdb/federatingdb_test.go +++ b/internal/federation/federatingdb/federatingdb_test.go @@ -22,7 +22,6 @@ import ( "context" "github.com/stretchr/testify/suite" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/federation/federatingdb" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" @@ -34,7 +33,6 @@ import ( type FederatingDBTestSuite struct { suite.Suite - config *config.Config db db.DB tc typeutils.TypeConverter federatingDB federatingdb.DB @@ -59,13 +57,13 @@ func (suite *FederatingDBTestSuite) SetupSuite() { suite.testAttachments = testrig.NewTestAttachments() suite.testStatuses = testrig.NewTestStatuses() suite.testBlocks = testrig.NewTestBlocks() - suite.testActivities = testrig.NewTestActivities(suite.testAccounts) } func (suite *FederatingDBTestSuite) SetupTest() { testrig.InitTestLog() - suite.config = testrig.NewTestConfig() + testrig.InitTestConfig() suite.db = testrig.NewTestDB() + suite.testActivities = testrig.NewTestActivities(suite.testAccounts) suite.tc = testrig.NewTestTypeConverter(suite.db) suite.federatingDB = testrig.NewTestFederatingDB(suite.db) testrig.StandardDBSetup(suite.db, suite.testAccounts) diff --git a/internal/federation/federatingdb/owns.go b/internal/federation/federatingdb/owns.go index 8846c52bb..2603c9aa2 100644 --- a/internal/federation/federatingdb/owns.go +++ b/internal/federation/federatingdb/owns.go @@ -24,6 +24,8 @@ import ( "net/url" "github.com/sirupsen/logrus" + "github.com/spf13/viper" + "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/util" @@ -42,8 +44,9 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) { l.Debug("entering Owns") // if the id host isn't this instance host, we don't own this IRI - if id.Host != f.config.Host { - l.Tracef("we DO NOT own activity because the host is %s not %s", id.Host, f.config.Host) + host := viper.GetString(config.Keys.Host) + if id.Host != host { + l.Tracef("we DO NOT own activity because the host is %s not %s", id.Host, host) return false, nil } diff --git a/internal/federation/federatingdb/reject_test.go b/internal/federation/federatingdb/reject_test.go index 2b213a3f0..9930d83d2 100644 --- a/internal/federation/federatingdb/reject_test.go +++ b/internal/federation/federatingdb/reject_test.go @@ -48,7 +48,7 @@ func (suite *RejectTestSuite) TestRejectFollowRequest() { ID: "01FJ1S8DX3STJJ6CEYPMZ1M0R3", CreatedAt: time.Now(), UpdatedAt: time.Now(), - URI: util.GenerateURIForFollow(followingAccount.Username, "http", "localhost:8080", "01FJ1S8DX3STJJ6CEYPMZ1M0R3"), + URI: util.GenerateURIForFollow(followingAccount.Username, "01FJ1S8DX3STJJ6CEYPMZ1M0R3"), AccountID: followingAccount.ID, TargetAccountID: followedAccount.ID, } diff --git a/internal/federation/federatingdb/update.go b/internal/federation/federatingdb/update.go index 8f318ce71..1d56b931f 100644 --- a/internal/federation/federatingdb/update.go +++ b/internal/federation/federatingdb/update.go @@ -24,8 +24,10 @@ import ( "fmt" "github.com/sirupsen/logrus" + "github.com/spf13/viper" "github.com/superseriousbusiness/activity/streams/vocab" "github.com/superseriousbusiness/gotosocial/internal/ap" + "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/messages" "github.com/superseriousbusiness/gotosocial/internal/util" @@ -124,7 +126,8 @@ func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error { return fmt.Errorf("UPDATE: error converting to account: %s", err) } - if updatedAcct.Domain == f.config.Host { + host := viper.GetString(config.Keys.Host) + if updatedAcct.Domain == host { // no need to update local accounts // in fact, if we do this will break the shit out of things so do NOT return nil diff --git a/internal/federation/federatingdb/util.go b/internal/federation/federatingdb/util.go index f35fbbb2d..afa09e39d 100644 --- a/internal/federation/federatingdb/util.go +++ b/internal/federation/federatingdb/util.go @@ -26,9 +26,11 @@ import ( "net/url" "github.com/sirupsen/logrus" + "github.com/spf13/viper" "github.com/superseriousbusiness/activity/streams" "github.com/superseriousbusiness/activity/streams/vocab" "github.com/superseriousbusiness/gotosocial/internal/ap" + "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/id" @@ -104,7 +106,7 @@ func (f *federatingDB) NewID(ctx context.Context, t vocab.Type) (idURL *url.URL, if err != nil { return nil, err } - return url.Parse(util.GenerateURIForFollow(actorAccount.Username, f.config.Protocol, f.config.Host, newID)) + return url.Parse(util.GenerateURIForFollow(actorAccount.Username, newID)) } } } @@ -207,7 +209,10 @@ func (f *federatingDB) NewID(ctx context.Context, t vocab.Type) (idURL *url.URL, if err != nil { return nil, err } - return url.Parse(fmt.Sprintf("%s://%s/%s", f.config.Protocol, f.config.Host, newID)) + + protocol := viper.GetString(config.Keys.Protocol) + host := viper.GetString(config.Keys.Host) + return url.Parse(fmt.Sprintf("%s://%s/%s", protocol, host, newID)) } // ActorForOutbox fetches the actor's IRI for the given outbox IRI. |