summaryrefslogtreecommitdiff
path: root/internal/federation/federatingprotocol.go
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-06-27 16:52:18 +0200
committerLibravatar GitHub <noreply@github.com>2021-06-27 16:52:18 +0200
commit87cf621e21283728b2bb5517c6a6981087cc7ce5 (patch)
treebd53f99ac3a0f242668bc33a3aeb0b3350957fb7 /internal/federation/federatingprotocol.go
parentGo fmt (diff)
downloadgotosocial-87cf621e21283728b2bb5517c6a6981087cc7ce5.tar.xz
Remote instance dereferencing (#70)
Remote instances are now dereferenced when they post to an inbox on a GtS instance. Dereferencing will be done first by checking the /api/v1/instance endpoint of an instance. If that doesn't work, /.well-known/nodeinfo will be checked. If that doesn't work, only a minimal representation of the instance will be stored. A new field was added to the Instance database model. To create it: alter table instances add column contact_account_username text;
Diffstat (limited to 'internal/federation/federatingprotocol.go')
-rw-r--r--internal/federation/federatingprotocol.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/federation/federatingprotocol.go b/internal/federation/federatingprotocol.go
index 8784c32e2..bd540af2c 100644
--- a/internal/federation/federatingprotocol.go
+++ b/internal/federation/federatingprotocol.go
@@ -125,6 +125,29 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr
return ctx, false, fmt.Errorf("not authenticated: %s", err)
}
+ // 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 _, ok := err.(db.ErrNoEntries); !ok {
+ // 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.DereferenceRemoteInstance(username, &url.URL{
+ Scheme: publicKeyOwnerURI.Scheme,
+ Host: publicKeyOwnerURI.Host,
+ })
+ if err != nil {
+ return nil, false, fmt.Errorf("could not dereference new remote instance %s during AuthenticatePostInbox: %s", publicKeyOwnerURI.Host, err)
+ }
+
+ // and put it in the db
+ if err := f.db.Put(i); err != nil {
+ return nil, false, fmt.Errorf("error inserting newly dereferenced instance %s: %s", publicKeyOwnerURI.Host, err)
+ }
+ }
+
requestingAccount := &gtsmodel.Account{}
if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: publicKeyOwnerURI.String()}}, requestingAccount); err != nil {
// there's been a proper error so return it