From 707de094a0139f475456fda1c6f5750135981aa9 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 5 Apr 2022 18:05:24 +0200 Subject: [PATCH] [dependency] Update superseriousbusiness/activity dependency (#446) * bump superseriousbusiness/activity version * fetch list of follower inbox iris --- go.mod | 3 +- go.sum | 13 +-- internal/federation/federatingdb/inbox.go | 82 ++++++++++++++++--- .../activity/pub/database.go | 18 +++- .../activity/pub/side_effect_actor.go | 19 ++--- vendor/modules.txt | 6 +- 6 files changed, 97 insertions(+), 44 deletions(-) diff --git a/go.mod b/go.mod index cf4c24d953..49f00a6676 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.10.0 github.com/stretchr/testify v1.7.0 - github.com/superseriousbusiness/activity v1.0.1-0.20211113133524-56560b73ace8 + github.com/superseriousbusiness/activity v1.0.1-0.20220405135100-18e8f86a760a github.com/superseriousbusiness/exif-terminator v0.2.0 github.com/superseriousbusiness/oauth2/v4 v4.3.2-SSB github.com/tdewolff/minify/v2 v2.9.22 @@ -71,7 +71,6 @@ require ( github.com/go-xmlfmt/xmlfmt v0.0.0-20211206191508-7fd73a941850 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect - github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/gorilla/context v1.1.1 // indirect diff --git a/go.sum b/go.sum index 0569161b3e..5e2c11650f 100644 --- a/go.sum +++ b/go.sum @@ -108,7 +108,6 @@ github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/dave/jennifer v1.3.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -169,7 +168,6 @@ github.com/go-errors/errors v1.0.2/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWE github.com/go-errors/errors v1.1.1/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWEp4lssFEs= github.com/go-errors/errors v1.4.1 h1:IvVlgbzSsaUNudsw5dcXSzF3EWyXTi5XrAdngnuhRyg= github.com/go-errors/errors v1.4.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= -github.com/go-fed/httpsig v0.1.1-0.20190914113940-c2de3672e5b5/go.mod h1:T56HUNYZUQ1AGUzhAYPugZfp36sKApVnGBgKlIY+aIE= github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI= github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -192,8 +190,7 @@ github.com/go-playground/validator/v10 v10.9.0 h1:NgTtmN58D0m8+UuxtYmGztBJB7VnPg github.com/go-playground/validator/v10 v10.9.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= github.com/go-session/session v3.1.2+incompatible/go.mod h1:8B3iivBQjrz/JtC68Np2T1yBBLxTan3mn/3OM0CyRt0= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-test/deep v1.0.1 h1:UQhStjbkDClarlmv0am7OXXO4/GaPdCGiUiMTvi28sg= -github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= github.com/go-xmlfmt/xmlfmt v0.0.0-20211206191508-7fd73a941850 h1:PSPmmucxGiFBtbQcttHTUc4LQ3P09AW+ldO2qspyKdY= github.com/go-xmlfmt/xmlfmt v0.0.0-20211206191508-7fd73a941850/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -220,7 +217,6 @@ github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -539,8 +535,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/superseriousbusiness/activity v1.0.1-0.20211113133524-56560b73ace8 h1:8Bwy6CSsT33/sF5FhjND4vr7jiJCaq4elNTAW4rUzVc= -github.com/superseriousbusiness/activity v1.0.1-0.20211113133524-56560b73ace8/go.mod h1:ZY9xwFDucvp6zTvM6FQZGl8PSOofPBFIAy6gSc85XkY= +github.com/superseriousbusiness/activity v1.0.1-0.20220405135100-18e8f86a760a h1:tKr18ijUgZ+PCM/n+St6uO2BaPgkReRtM3IJHC/Otf4= +github.com/superseriousbusiness/activity v1.0.1-0.20220405135100-18e8f86a760a/go.mod h1:AZw0Xb4Oju8rmaJCZ21gc5CPg47MmNgyac+Hx5jo8VM= github.com/superseriousbusiness/exif-terminator v0.2.0 h1:C21KOUr54E37qTqYS7WJX0J83sNzzCwBEy0KXyDprqU= github.com/superseriousbusiness/exif-terminator v0.2.0/go.mod h1:DHJuKguXqyOVqB/oyOylutEDIZCbkYsn2GZFNSUDT9E= github.com/superseriousbusiness/go-jpeg-image-structure/v2 v2.0.0-20220321154430-d89a106fdabe h1:ksl2oCx/Qo8sNDc3Grb8WGKBM9nkvhCm25uvlT86azE= @@ -642,7 +638,6 @@ go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= -golang.org/x/crypto v0.0.0-20180527072434-ab813273cd59/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= @@ -763,7 +758,6 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180525142821-c11f84a56e43/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -899,7 +893,6 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.8 h1:P1HhGGuLW4aAclzjtmJdf0mJOjVUZUzOTqkAkWL+l6w= golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= diff --git a/internal/federation/federatingdb/inbox.go b/internal/federation/federatingdb/inbox.go index 1f020d27e3..20a9bb06c3 100644 --- a/internal/federation/federatingdb/inbox.go +++ b/internal/federation/federatingdb/inbox.go @@ -20,11 +20,15 @@ package federatingdb import ( "context" + "fmt" "net/url" + "github.com/spf13/viper" "github.com/superseriousbusiness/activity/streams" "github.com/superseriousbusiness/activity/streams/vocab" + "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" + "github.com/superseriousbusiness/gotosocial/internal/uris" ) // InboxContains returns true if the OrderedCollection at 'inbox' @@ -58,24 +62,76 @@ func (f *federatingDB) SetInbox(c context.Context, inbox vocab.ActivityStreamsOr return nil } -// InboxForActor fetches the inbox corresponding to the given actorIRI. +// InboxesForIRI fetches inboxes corresponding to the given iri. +// This allows your server to skip remote dereferencing of iris +// in order to speed up message delivery, if desired. // -// It is acceptable to just return nil for the inboxIRI. In this case, the library will -// attempt to resolve the inbox of the actor by remote dereferencing instead. +// It is acceptable to just return nil or an empty slice for the inboxIRIs, +// if you don't know the inbox iri, or you don't wish to use this feature. +// In this case, the library will attempt to resolve inboxes of the iri +// by remote dereferencing instead. +// +// If the input iri is the iri of an Actor, then the inbox for the actor +// should be returned as a single-entry slice. +// +// If the input iri is a Collection (such as a Collection of followers), +// then each follower inbox IRI should be returned in the inboxIRIs slice. // // The library makes this call only after acquiring a lock first. -func (f *federatingDB) InboxForActor(c context.Context, actorIRI *url.URL) (inboxIRI *url.URL, err error) { - account, err := f.db.GetAccountByURI(c, actorIRI.String()) - if err != nil { - // if there are just no entries for this account yet it's fine, return nil - // and go-fed will try to dereference it instead - if err == db.ErrNoEntries { - return nil, nil +func (f *federatingDB) InboxesForIRI(c context.Context, iri *url.URL) (inboxIRIs []*url.URL, err error) { + // check if this is a followers collection iri for a local account... + if iri.Host == viper.GetString(config.Keys.Host) && uris.IsFollowersPath(iri) { + localAccountUsername, err := uris.ParseFollowersPath(iri) + if err != nil { + return nil, fmt.Errorf("couldn't extract local account username from uri %s: %s", iri, err) + } + + account, err := f.db.GetLocalAccountByUsername(c, localAccountUsername) + if err != nil { + return nil, fmt.Errorf("couldn't find local account with username %s: %s", localAccountUsername, err) + } + + follows, err := f.db.GetAccountFollowedBy(c, account.ID, false) + if err != nil { + return nil, fmt.Errorf("couldn't get followers of local account %s: %s", localAccountUsername, err) + } + + for _, follow := range follows { + // make sure we retrieved the following account from the db + if follow.Account == nil { + followingAccount, err := f.db.GetAccountByID(c, follow.AccountID) + if err != nil { + if err == db.ErrNoEntries { + continue + } + return nil, fmt.Errorf("error retrieving account with id %s: %s", follow.AccountID, err) + } + follow.Account = followingAccount + } + + inboxIRI, err := url.Parse(follow.Account.InboxURI) + if err != nil { + return nil, fmt.Errorf("error parsing inbox uri of following account %s: %s", follow.Account.InboxURI, err) + } + inboxIRIs = append(inboxIRIs, inboxIRI) + } + return inboxIRIs, nil + } + + // check if this is just an account IRI... + if account, err := f.db.GetAccountByURI(c, iri.String()); err == nil { + inboxIRI, err := url.Parse(account.InboxURI) + if err != nil { + return nil, fmt.Errorf("error parsing account inbox uri %s: %s", account.InboxURI, account.InboxURI) } - // there's been an actual error... + // we've got it + inboxIRIs = append(inboxIRIs, inboxIRI) + return inboxIRIs, nil + } else if err != db.ErrNoEntries { + // there's been a real error return nil, err } - // we got it! - return url.Parse(account.InboxURI) + // no error, we just didn't find anything so let the library handle the rest + return nil, nil } diff --git a/vendor/github.com/superseriousbusiness/activity/pub/database.go b/vendor/github.com/superseriousbusiness/activity/pub/database.go index 1abf98b0d5..8d3bbd4654 100644 --- a/vendor/github.com/superseriousbusiness/activity/pub/database.go +++ b/vendor/github.com/superseriousbusiness/activity/pub/database.go @@ -59,13 +59,23 @@ type Database interface { // // The library makes this call only after acquiring a lock first. OutboxForInbox(c context.Context, inboxIRI *url.URL) (outboxIRI *url.URL, err error) - // InboxForActor fetches the inbox corresponding to the given actorIRI. + // InboxesForIRI fetches inboxes corresponding to the given iri. + // This allows your server to skip remote dereferencing of iris + // in order to speed up message delivery, if desired. // - // It is acceptable to just return nil for the inboxIRI. In this case, the library will - // attempt to resolve the inbox of the actor by remote dereferencing instead. + // It is acceptable to just return nil or an empty slice for the inboxIRIs, + // if you don't know the inbox iri, or you don't wish to use this feature. + // In this case, the library will attempt to resolve inboxes of the iri + // by remote dereferencing instead. + // + // If the input iri is the iri of an Actor, then the inbox for the actor + // should be returned as a single-entry slice. + // + // If the input iri is a Collection (such as a Collection of followers), + // then each follower inbox IRI should be returned in the inboxIRIs slice. // // The library makes this call only after acquiring a lock first. - InboxForActor(c context.Context, actorIRI *url.URL) (inboxIRI *url.URL, err error) + InboxesForIRI(c context.Context, iri *url.URL) (inboxIRIs []*url.URL, err error) // Exists returns true if the database has an entry for the specified // id. It may not be owned by this application instance. // diff --git a/vendor/github.com/superseriousbusiness/activity/pub/side_effect_actor.go b/vendor/github.com/superseriousbusiness/activity/pub/side_effect_actor.go index c58907e3b2..73b6c8a74e 100644 --- a/vendor/github.com/superseriousbusiness/activity/pub/side_effect_actor.go +++ b/vendor/github.com/superseriousbusiness/activity/pub/side_effect_actor.go @@ -681,7 +681,6 @@ func (a *sideEffectActor) prepare(c context.Context, outboxIRI *url.URL, activit // first check if the implemented database logic can return any inboxes // from our list of actor IRIs. foundInboxesFromDB := []*url.URL{} - foundActorsFromDB := []*url.URL{} for _, actorIRI := range r { // BEGIN LOCK err = a.db.Lock(c, actorIRI) @@ -689,16 +688,20 @@ func (a *sideEffectActor) prepare(c context.Context, outboxIRI *url.URL, activit return } - inbox, err := a.db.InboxForActor(c, actorIRI) + inboxes, err := a.db.InboxesForIRI(c, actorIRI) if err != nil { // bail on error a.db.Unlock(c, actorIRI) return nil, err } - if inbox != nil { + + if len(inboxes) > 0 { // we have a hit - foundInboxesFromDB = append(foundInboxesFromDB, inbox) - foundActorsFromDB = append(foundActorsFromDB, actorIRI) + foundInboxesFromDB = append(foundInboxesFromDB, inboxes...) + + // if we found inboxes for this iri, we should remove it from + // the list of actors/iris we still need to dereference + r = removeOne(r, actorIRI) } // END LOCK @@ -708,12 +711,6 @@ func (a *sideEffectActor) prepare(c context.Context, outboxIRI *url.URL, activit } } - // for every actor we found an inbox for in the db, we should - // remove it from the list of actors we still need to dereference - for _, actorIRI := range foundActorsFromDB { - r = removeOne(r, actorIRI) - } - // look for any actors' inboxes that weren't already discovered above; // find these by making dereference calls to remote instances t, err := a.common.NewTransport(c, outboxIRI, goFedUserAgent()) diff --git a/vendor/modules.txt b/vendor/modules.txt index cca94fc56b..4a250d0ebc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -120,8 +120,6 @@ github.com/golang/geo/r2 github.com/golang/geo/r3 github.com/golang/geo/s1 github.com/golang/geo/s2 -# github.com/golang/mock v1.6.0 -## explicit; go 1.11 # github.com/golang/protobuf v1.5.2 ## explicit; go 1.9 github.com/golang/protobuf/proto @@ -286,8 +284,8 @@ github.com/stretchr/testify/suite # github.com/subosito/gotenv v1.2.0 ## explicit github.com/subosito/gotenv -# github.com/superseriousbusiness/activity v1.0.1-0.20211113133524-56560b73ace8 -## explicit; go 1.12 +# github.com/superseriousbusiness/activity v1.0.1-0.20220405135100-18e8f86a760a +## explicit; go 1.18 github.com/superseriousbusiness/activity/pub github.com/superseriousbusiness/activity/streams github.com/superseriousbusiness/activity/streams/impl/activitystreams/property_accuracy