summaryrefslogtreecommitdiff
path: root/internal/federation
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2022-07-19 09:47:55 +0100
committerLibravatar GitHub <noreply@github.com>2022-07-19 10:47:55 +0200
commit098dbe6ff4f59652181c8e0e3873fbfcf0e65ea3 (patch)
tree17036ad9db68c3080e1e91279c8bce9f9ea6e5c3 /internal/federation
parent[bugfix] Markdown format fixes (#718) (diff)
downloadgotosocial-098dbe6ff4f59652181c8e0e3873fbfcf0e65ea3.tar.xz
[chore] use our own logging implementation (#716)
* first commit Signed-off-by: kim <grufwub@gmail.com> * replace logging with our own log library Signed-off-by: kim <grufwub@gmail.com> * fix imports Signed-off-by: kim <grufwub@gmail.com> * fix log imports Signed-off-by: kim <grufwub@gmail.com> * add license text Signed-off-by: kim <grufwub@gmail.com> * fix package import cycle between config and log package Signed-off-by: kim <grufwub@gmail.com> * fix empty kv.Fields{} being passed to WithFields() Signed-off-by: kim <grufwub@gmail.com> * fix uses of log.WithFields() with whitespace issues and empty slices Signed-off-by: kim <grufwub@gmail.com> * *linter related grumbling* Signed-off-by: kim <grufwub@gmail.com> * gofmt the codebase! also fix more log.WithFields() formatting issues Signed-off-by: kim <grufwub@gmail.com> * update testrig code to match new changes Signed-off-by: kim <grufwub@gmail.com> * fix error wrapping in non fmt.Errorf function Signed-off-by: kim <grufwub@gmail.com> * add benchmarking of log.Caller() vs non-cached Signed-off-by: kim <grufwub@gmail.com> * fix syslog tests, add standard build tags to test runner to ensure consistency Signed-off-by: kim <grufwub@gmail.com> * make syslog tests more robust Signed-off-by: kim <grufwub@gmail.com> * fix caller depth arithmatic (is that how you spell it?) Signed-off-by: kim <grufwub@gmail.com> * update to use unkeyed fields in kv.Field{} instances Signed-off-by: kim <grufwub@gmail.com> * update go-kv library Signed-off-by: kim <grufwub@gmail.com> * update libraries list Signed-off-by: kim <grufwub@gmail.com> * fuck you linter get nerfed Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
Diffstat (limited to 'internal/federation')
-rw-r--r--internal/federation/authenticate.go51
-rw-r--r--internal/federation/dereferencing/account.go7
-rw-r--r--internal/federation/dereferencing/status.go27
-rw-r--r--internal/federation/dereferencing/thread.go33
-rw-r--r--internal/federation/federatingactor.go4
-rw-r--r--internal/federation/federatingdb/accept.go13
-rw-r--r--internal/federation/federatingdb/announce.go13
-rw-r--r--internal/federation/federatingdb/create.go23
-rw-r--r--internal/federation/federatingdb/delete.go13
-rw-r--r--internal/federation/federatingdb/exists.go12
-rw-r--r--internal/federation/federatingdb/followers.go12
-rw-r--r--internal/federation/federatingdb/following.go12
-rw-r--r--internal/federation/federatingdb/get.go12
-rw-r--r--internal/federation/federatingdb/owns.go12
-rw-r--r--internal/federation/federatingdb/reject.go13
-rw-r--r--internal/federation/federatingdb/undo.go11
-rw-r--r--internal/federation/federatingdb/update.go11
-rw-r--r--internal/federation/federatingdb/util.go17
-rw-r--r--internal/federation/federatingprotocol.go30
19 files changed, 139 insertions, 187 deletions
diff --git a/internal/federation/authenticate.go b/internal/federation/authenticate.go
index 5ca2f9806..cb693892e 100644
--- a/internal/federation/authenticate.go
+++ b/internal/federation/authenticate.go
@@ -28,8 +28,6 @@ import (
"net/url"
"strings"
- "github.com/sirupsen/logrus"
-
"github.com/go-fed/httpsig"
"github.com/superseriousbusiness/activity/pub"
"github.com/superseriousbusiness/activity/streams"
@@ -39,6 +37,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
)
/*
@@ -116,8 +115,6 @@ func getPublicKeyFromResponse(c context.Context, b []byte, keyID *url.URL) (voca
// Also note that this function *does not* dereference the remote account that the signature key is associated with.
// Other functions should use the returned URL to dereference the remote account, if required.
func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedUsername string) (*url.URL, gtserror.WithCode) {
- l := logrus.WithField("func", "AuthenticateFederatedRequest")
-
var publicKey interface{}
var pkOwnerURI *url.URL
var err error
@@ -127,7 +124,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
if vi == nil {
err := errors.New("http request wasn't signed or http signature was invalid")
errWithCode := gtserror.NewErrorUnauthorized(err, err.Error())
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
@@ -135,7 +132,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
if !ok {
err := errors.New("http request wasn't signed or http signature was invalid")
errWithCode := gtserror.NewErrorUnauthorized(err, err.Error())
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
@@ -144,7 +141,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
if si == nil {
err := errors.New("http request wasn't signed or http signature was invalid")
errWithCode := gtserror.NewErrorUnauthorized(err, err.Error())
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
@@ -152,7 +149,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
if !ok {
err := errors.New("http request wasn't signed or http signature was invalid")
errWithCode := gtserror.NewErrorUnauthorized(err, err.Error())
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
@@ -160,7 +157,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
requestingPublicKeyID, err := url.Parse(verifier.KeyId())
if err != nil {
errWithCode := gtserror.NewErrorBadRequest(err, fmt.Sprintf("couldn't parse public key URL %s", verifier.KeyId()))
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
@@ -170,39 +167,39 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
if host := config.GetHost(); strings.EqualFold(requestingHost, host) {
// 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)
+ log.Tracef("proceeding without dereference for local public key %s", requestingPublicKeyID)
if err := f.db.GetWhere(ctx, []db.Where{{Key: "public_key_uri", Value: requestingPublicKeyID.String()}}, requestingLocalAccount); err != nil {
errWithCode := gtserror.NewErrorInternalError(fmt.Errorf("couldn't get account with public key uri %s from the database: %s", requestingPublicKeyID.String(), err))
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
publicKey = requestingLocalAccount.PublicKey
pkOwnerURI, err = url.Parse(requestingLocalAccount.URI)
if err != nil {
errWithCode := gtserror.NewErrorBadRequest(err, fmt.Sprintf("couldn't parse public key owner URL %s", requestingLocalAccount.URI))
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
} 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)
+ log.Tracef("proceeding without dereference for cached public key %s", requestingPublicKeyID)
publicKey = requestingRemoteAccount.PublicKey
pkOwnerURI, err = url.Parse(requestingRemoteAccount.URI)
if err != nil {
errWithCode := gtserror.NewErrorBadRequest(err, fmt.Sprintf("couldn't parse public key owner URL %s", requestingRemoteAccount.URI))
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
} else {
// REMOTE ACCOUNT REQUEST WITHOUT KEY CACHED LOCALLY
// 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)
+ log.Tracef("proceeding with dereference for uncached public key %s", requestingPublicKeyID)
transport, err := f.transportController.NewTransportForUsername(ctx, requestedUsername)
if err != nil {
errWithCode := gtserror.NewErrorInternalError(fmt.Errorf("error creating transport for %s: %s", requestedUsername, err))
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
@@ -210,7 +207,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
b, err := transport.Dereference(ctx, requestingPublicKeyID)
if err != nil {
errWithCode := gtserror.NewErrorUnauthorized(fmt.Errorf("error dereferencing public key %s: %s", requestingPublicKeyID, err))
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
@@ -218,7 +215,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
requestingPublicKey, err := getPublicKeyFromResponse(ctx, b, requestingPublicKeyID)
if err != nil {
errWithCode := gtserror.NewErrorUnauthorized(fmt.Errorf("error parsing public key %s: %s", requestingPublicKeyID, err))
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
@@ -226,7 +223,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
pkPemProp := requestingPublicKey.GetW3IDSecurityV1PublicKeyPem()
if pkPemProp == nil || !pkPemProp.IsXMLSchemaString() {
errWithCode := gtserror.NewErrorUnauthorized(errors.New("publicKeyPem property is not provided or it is not embedded as a value"))
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
@@ -235,14 +232,14 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
block, _ := pem.Decode([]byte(pubKeyPem))
if block == nil || block.Type != "PUBLIC KEY" {
errWithCode := gtserror.NewErrorUnauthorized(errors.New("could not decode publicKeyPem to PUBLIC KEY pem block type"))
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
publicKey, err = x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
errWithCode := gtserror.NewErrorUnauthorized(fmt.Errorf("could not parse public key %s from block bytes: %s", requestingPublicKeyID, err))
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
@@ -250,7 +247,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
pkOwnerProp := requestingPublicKey.GetW3IDSecurityV1Owner()
if pkOwnerProp == nil || !pkOwnerProp.IsIRI() {
errWithCode := gtserror.NewErrorUnauthorized(errors.New("publicKeyOwner property is not provided or it is not embedded as a value"))
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
pkOwnerURI = pkOwnerProp.GetIRI()
@@ -259,7 +256,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
// after all that, public key should be defined
if publicKey == nil {
errWithCode := gtserror.NewErrorInternalError(errors.New("returned public key was empty"))
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
@@ -271,16 +268,16 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
}
for _, algo := range algos {
- l.Tracef("trying algo: %s", algo)
+ log.Tracef("trying algo: %s", algo)
err := verifier.Verify(publicKey, algo)
if err == nil {
- l.Tracef("authentication for %s PASSED with algorithm %s", pkOwnerURI, algo)
+ log.Tracef("authentication for %s PASSED with algorithm %s", pkOwnerURI, algo)
return pkOwnerURI, nil
}
- l.Tracef("authentication for %s NOT PASSED with algorithm %s: %s", pkOwnerURI, algo, err)
+ log.Tracef("authentication for %s NOT PASSED with algorithm %s: %s", pkOwnerURI, algo, err)
}
errWithCode := gtserror.NewErrorUnauthorized(fmt.Errorf("authentication not passed for public key owner %s; signature value was '%s'", pkOwnerURI, signature))
- l.Debug(errWithCode)
+ log.Debug(errWithCode)
return nil, errWithCode
}
diff --git a/internal/federation/dereferencing/account.go b/internal/federation/dereferencing/account.go
index c479906d7..a0e2b87ae 100644
--- a/internal/federation/dereferencing/account.go
+++ b/internal/federation/dereferencing/account.go
@@ -29,13 +29,13 @@ import (
"sync"
"time"
- "github.com/sirupsen/logrus"
"github.com/superseriousbusiness/activity/streams"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/transport"
)
@@ -79,7 +79,6 @@ type GetRemoteAccountParams struct {
// GetRemoteAccount completely dereferences a remote account, converts it to a GtS model account,
// puts or updates it in the database (if necessary), and returns it to a caller.
func (d *deref) GetRemoteAccount(ctx context.Context, params GetRemoteAccountParams) (remoteAccount *gtsmodel.Account, err error) {
-
/*
In this function we want to retrieve a gtsmodel representation of a remote account, with its proper
accountDomain set, while making as few calls to remote instances as possible to save time and bandwidth.
@@ -454,7 +453,7 @@ func (d *deref) fetchRemoteAccountMedia(ctx context.Context, targetAccount *gtsm
go func() {
dlCtx, done := context.WithDeadline(context.Background(), time.Now().Add(1*time.Minute))
if err := lockAndLoad(dlCtx, d.dereferencingAvatarsLock, processingMedia, d.dereferencingAvatars, targetAccount.ID); err != nil {
- logrus.Errorf("fetchRemoteAccountMedia: error during async lock and load of avatar: %s", err)
+ log.Errorf("fetchRemoteAccountMedia: error during async lock and load of avatar: %s", err)
}
done()
}()
@@ -512,7 +511,7 @@ func (d *deref) fetchRemoteAccountMedia(ctx context.Context, targetAccount *gtsm
go func() {
dlCtx, done := context.WithDeadline(context.Background(), time.Now().Add(1*time.Minute))
if err := lockAndLoad(dlCtx, d.dereferencingHeadersLock, processingMedia, d.dereferencingHeaders, targetAccount.ID); err != nil {
- logrus.Errorf("fetchRemoteAccountMedia: error during async lock and load of header: %s", err)
+ log.Errorf("fetchRemoteAccountMedia: error during async lock and load of header: %s", err)
}
done()
}()
diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go
index 8cb110f24..e6e03646c 100644
--- a/internal/federation/dereferencing/status.go
+++ b/internal/federation/dereferencing/status.go
@@ -26,12 +26,13 @@ import (
"net/url"
"strings"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-kv"
"github.com/superseriousbusiness/activity/streams"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/media"
)
@@ -224,10 +225,10 @@ func (d *deref) dereferenceStatusable(ctx context.Context, username string, remo
// 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(ctx context.Context, status *gtsmodel.Status, requestingUsername string, includeParent bool) error {
- l := logrus.WithFields(logrus.Fields{
- "func": "dereferenceStatusFields",
- "status": fmt.Sprintf("%+v", status),
- })
+ l := log.WithFields(kv.Fields{
+
+ {"status", status},
+ }...)
l.Debug("entering function")
statusIRI, err := url.Parse(status.URI)
@@ -288,20 +289,20 @@ func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Sta
for _, m := range status.Mentions {
if m.ID != "" {
// we've already populated this mention, since it has an ID
- logrus.Debug("populateStatusMentions: mention already populated")
+ log.Debug("populateStatusMentions: mention already populated")
mentionIDs = append(mentionIDs, m.ID)
newMentions = append(newMentions, m)
continue
}
if m.TargetAccountURI == "" {
- logrus.Debug("populateStatusMentions: target URI not set on mention")
+ log.Debug("populateStatusMentions: target URI not set on mention")
continue
}
targetAccountURI, err := url.Parse(m.TargetAccountURI)
if err != nil {
- logrus.Debugf("populateStatusMentions: error parsing mentioned account uri %s: %s", m.TargetAccountURI, err)
+ log.Debugf("populateStatusMentions: error parsing mentioned account uri %s: %s", m.TargetAccountURI, err)
continue
}
@@ -312,7 +313,7 @@ func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Sta
if a, err := d.db.GetAccountByURI(ctx, targetAccountURI.String()); err != nil {
errs = append(errs, err.Error())
} else {
- logrus.Debugf("populateStatusMentions: got target account %s with id %s through GetAccountByURI", targetAccountURI, a.ID)
+ log.Debugf("populateStatusMentions: got target account %s with id %s through GetAccountByURI", targetAccountURI, a.ID)
targetAccount = a
}
@@ -325,13 +326,13 @@ func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Sta
}); err != nil {
errs = append(errs, err.Error())
} else {
- logrus.Debugf("populateStatusMentions: got target account %s with id %s through GetRemoteAccount", targetAccountURI, a.ID)
+ log.Debugf("populateStatusMentions: got target account %s with id %s through GetRemoteAccount", targetAccountURI, a.ID)
targetAccount = a
}
}
if targetAccount == nil {
- logrus.Debugf("populateStatusMentions: couldn't get target account %s: %s", m.TargetAccountURI, strings.Join(errs, " : "))
+ log.Debugf("populateStatusMentions: couldn't get target account %s: %s", m.TargetAccountURI, strings.Join(errs, " : "))
continue
}
@@ -392,13 +393,13 @@ func (d *deref) populateStatusAttachments(ctx context.Context, status *gtsmodel.
Blurhash: &a.Blurhash,
})
if err != nil {
- logrus.Errorf("populateStatusAttachments: couldn't get remote media %s: %s", a.RemoteURL, err)
+ log.Errorf("populateStatusAttachments: couldn't get remote media %s: %s", a.RemoteURL, err)
continue
}
attachment, err := processingMedia.LoadAttachment(ctx)
if err != nil {
- logrus.Errorf("populateStatusAttachments: couldn't load remote attachment %s: %s", a.RemoteURL, err)
+ log.Errorf("populateStatusAttachments: couldn't load remote attachment %s: %s", a.RemoteURL, err)
continue
}
diff --git a/internal/federation/dereferencing/thread.go b/internal/federation/dereferencing/thread.go
index a299c1220..7d7431110 100644
--- a/internal/federation/dereferencing/thread.go
+++ b/internal/federation/dereferencing/thread.go
@@ -23,9 +23,10 @@ import (
"fmt"
"net/url"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-kv"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/config"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
@@ -36,11 +37,11 @@ import (
// 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(ctx context.Context, username string, statusIRI *url.URL) error {
- l := logrus.WithFields(logrus.Fields{
- "func": "DereferenceThread",
- "username": username,
- "statusIRI": statusIRI.String(),
- })
+ l := log.WithFields(kv.Fields{
+
+ {"username", username},
+ {"statusIRI", statusIRI},
+ }...)
l.Trace("entering DereferenceThread")
// if it's our status we already have everything stashed so we can bail early
@@ -70,11 +71,11 @@ func (d *deref) DereferenceThread(ctx context.Context, username string, statusIR
// iterateAncestors has the goal of reaching the oldest ancestor of a given status, and stashing all statuses along the way.
func (d *deref) iterateAncestors(ctx context.Context, username string, statusIRI url.URL) error {
- l := logrus.WithFields(logrus.Fields{
- "func": "iterateAncestors",
- "username": username,
- "statusIRI": statusIRI.String(),
- })
+ l := log.WithFields(kv.Fields{
+
+ {"username", username},
+ {"statusIRI", statusIRI},
+ }...)
l.Trace("entering iterateAncestors")
// if it's our status we don't need to dereference anything so we can immediately move up the chain
@@ -123,11 +124,11 @@ func (d *deref) iterateAncestors(ctx context.Context, username string, statusIRI
}
func (d *deref) iterateDescendants(ctx context.Context, username string, statusIRI url.URL, statusable ap.Statusable) error {
- l := logrus.WithFields(logrus.Fields{
- "func": "iterateDescendants",
- "username": username,
- "statusIRI": statusIRI.String(),
- })
+ l := log.WithFields(kv.Fields{
+
+ {"username", username},
+ {"statusIRI", statusIRI},
+ }...)
l.Trace("entering iterateDescendants")
// if it's our status we already have descendants stashed so we can bail early
diff --git a/internal/federation/federatingactor.go b/internal/federation/federatingactor.go
index 1d6f4b937..b80e9ff23 100644
--- a/internal/federation/federatingactor.go
+++ b/internal/federation/federatingactor.go
@@ -23,9 +23,9 @@ import (
"net/http"
"net/url"
- "github.com/sirupsen/logrus"
"github.com/superseriousbusiness/activity/pub"
"github.com/superseriousbusiness/activity/streams/vocab"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
)
// federatingActor implements the go-fed federating protocol interface
@@ -56,7 +56,7 @@ func newFederatingActor(c pub.CommonBehavior, s2s pub.FederatingProtocol, db pub
// method will guaranteed work for non-custom Actors. For custom actors,
// care should be used to not call this method if only C2S is supported.
func (f *federatingActor) Send(c context.Context, outbox *url.URL, t vocab.Type) (pub.Activity, error) {
- logrus.Infof("federating actor: send activity %s via outbox %s", t.GetTypeName(), outbox)
+ log.Infof("federating actor: send activity %s via outbox %s", t.GetTypeName(), outbox)
return f.actor.Send(c, outbox, t)
}
diff --git a/internal/federation/federatingdb/accept.go b/internal/federation/federatingdb/accept.go
index f22db38a5..977cf2bba 100644
--- a/internal/federation/federatingdb/accept.go
+++ b/internal/federation/federatingdb/accept.go
@@ -23,28 +23,23 @@ import (
"errors"
"fmt"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-logger/v2/level"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsAccept) error {
- l := logrus.WithFields(
- logrus.Fields{
- "func": "Accept",
- },
- )
-
- if logrus.GetLevel() >= logrus.DebugLevel {
+ if log.Level() >= level.DEBUG {
i, err := marshalItem(accept)
if err != nil {
return err
}
- l = l.WithField("accept", i)
+ l := log.WithField("accept", i)
l.Debug("entering Accept")
}
diff --git a/internal/federation/federatingdb/announce.go b/internal/federation/federatingdb/announce.go
index b70fa1913..47e873ca3 100644
--- a/internal/federation/federatingdb/announce.go
+++ b/internal/federation/federatingdb/announce.go
@@ -22,25 +22,20 @@ import (
"context"
"fmt"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-logger/v2/level"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/messages"
)
func (f *federatingDB) Announce(ctx context.Context, announce vocab.ActivityStreamsAnnounce) error {
- l := logrus.WithFields(
- logrus.Fields{
- "func": "Announce",
- },
- )
-
- if logrus.GetLevel() >= logrus.DebugLevel {
+ if log.Level() >= level.DEBUG {
i, err := marshalItem(announce)
if err != nil {
return err
}
- l = l.WithField("announce", i)
+ l := log.WithField("announce", i)
l.Debug("entering Announce")
}
diff --git a/internal/federation/federatingdb/create.go b/internal/federation/federatingdb/create.go
index 625d75603..a6e55f2ad 100644
--- a/internal/federation/federatingdb/create.go
+++ b/internal/federation/federatingdb/create.go
@@ -24,12 +24,14 @@ import (
"fmt"
"strings"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-kv"
+ "codeberg.org/gruf/go-logger/v2/level"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/messages"
)
@@ -46,18 +48,12 @@ import (
// Under certain conditions and network activities, Create may be called
// multiple times for the same ActivityStreams object.
func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
- l := logrus.WithFields(
- logrus.Fields{
- "func": "Create",
- },
- )
-
- if logrus.GetLevel() >= logrus.DebugLevel {
+ if log.Level() >= level.DEBUG {
i, err := marshalItem(asType)
if err != nil {
return err
}
- l = l.WithField("create", i)
+ l := log.WithField("create", i)
l.Debug("entering Create")
}
@@ -169,11 +165,10 @@ func (f *federatingDB) activityCreate(ctx context.Context, asType vocab.Type, re
// createNote handles a Create activity with a Note type.
func (f *federatingDB) createNote(ctx context.Context, note vocab.ActivityStreamsNote, receivingAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account) error {
- l := logrus.WithFields(logrus.Fields{
- "func": "createNote",
- "receivingAccount": receivingAccount.URI,
- "requestingAccount": requestingAccount.URI,
- })
+ l := log.WithFields(kv.Fields{
+ {"receivingAccount", receivingAccount.URI},
+ {"requestingAccount", requestingAccount.URI},
+ }...)
// Check if we have a forward.
// In other words, was the note posted to our inbox by at least one actor who actually created the note, or are they just forwarding it?
diff --git a/internal/federation/federatingdb/delete.go b/internal/federation/federatingdb/delete.go
index bd0184f76..8c3457fae 100644
--- a/internal/federation/federatingdb/delete.go
+++ b/internal/federation/federatingdb/delete.go
@@ -23,9 +23,10 @@ import (
"fmt"
"net/url"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-kv"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/messages"
)
@@ -36,12 +37,10 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error {
- l := logrus.WithFields(
- logrus.Fields{
- "func": "Delete",
- "id": id,
- },
- )
+ l := log.WithFields(kv.Fields{
+
+ {"id", id},
+ }...)
l.Debug("entering Delete")
receivingAccount, _ := extractFromCtx(ctx)
diff --git a/internal/federation/federatingdb/exists.go b/internal/federation/federatingdb/exists.go
index fe220fc71..65b2a55b3 100644
--- a/internal/federation/federatingdb/exists.go
+++ b/internal/federation/federatingdb/exists.go
@@ -22,7 +22,8 @@ import (
"context"
"net/url"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-kv"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
)
// Exists returns true if the database has an entry for the specified
@@ -32,12 +33,9 @@ import (
//
// Implementation note: this just straight up isn't implemented, and doesn't *really* need to be either.
func (f *federatingDB) Exists(c context.Context, id *url.URL) (exists bool, err error) {
- l := logrus.WithFields(
- logrus.Fields{
- "func": "Exists",
- "id": id,
- },
- )
+ l := log.WithFields(kv.Fields{
+ {"id", id},
+ }...)
l.Debug("entering Exists")
return false, nil
}
diff --git a/internal/federation/federatingdb/followers.go b/internal/federation/federatingdb/followers.go
index 96b824c66..9a80d5f0b 100644
--- a/internal/federation/federatingdb/followers.go
+++ b/internal/federation/federatingdb/followers.go
@@ -5,9 +5,10 @@ import (
"fmt"
"net/url"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-kv"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/db"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
)
// Followers obtains the Followers Collection for an actor with the
@@ -17,12 +18,9 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) {
- l := logrus.WithFields(
- logrus.Fields{
- "func": "Followers",
- "id": actorIRI,
- },
- )
+ l := log.WithFields(kv.Fields{
+ {"id", actorIRI},
+ }...)
l.Debug("entering Followers")
acct, err := f.getAccountForIRI(ctx, actorIRI)
diff --git a/internal/federation/federatingdb/following.go b/internal/federation/federatingdb/following.go
index 62b148d5b..a244cf7ac 100644
--- a/internal/federation/federatingdb/following.go
+++ b/internal/federation/federatingdb/following.go
@@ -23,9 +23,10 @@ import (
"fmt"
"net/url"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-kv"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/db"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
)
// Following obtains the Following Collection for an actor with the
@@ -35,12 +36,9 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Following(ctx context.Context, actorIRI *url.URL) (following vocab.ActivityStreamsCollection, err error) {
- l := logrus.WithFields(
- logrus.Fields{
- "func": "Following",
- "id": actorIRI,
- },
- )
+ l := log.WithFields(kv.Fields{
+ {"id", actorIRI},
+ }...)
l.Debug("entering Following")
acct, err := f.getAccountForIRI(ctx, actorIRI)
diff --git a/internal/federation/federatingdb/get.go b/internal/federation/federatingdb/get.go
index 9fdc08dd9..5467c886d 100644
--- a/internal/federation/federatingdb/get.go
+++ b/internal/federation/federatingdb/get.go
@@ -23,8 +23,9 @@ import (
"errors"
"net/url"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-kv"
"github.com/superseriousbusiness/activity/streams/vocab"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
@@ -32,12 +33,9 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Get(ctx context.Context, id *url.URL) (value vocab.Type, err error) {
- l := logrus.WithFields(
- logrus.Fields{
- "func": "Get",
- "id": id,
- },
- )
+ l := log.WithFields(kv.Fields{
+ {"id", id},
+ }...)
l.Debug("entering Get")
if uris.IsUserPath(id) {
diff --git a/internal/federation/federatingdb/owns.go b/internal/federation/federatingdb/owns.go
index aaa58348f..51d11f018 100644
--- a/internal/federation/federatingdb/owns.go
+++ b/internal/federation/federatingdb/owns.go
@@ -23,10 +23,11 @@ import (
"fmt"
"net/url"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-kv"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
@@ -34,12 +35,9 @@ import (
// the database has an entry for the IRI.
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {
- l := logrus.WithFields(
- logrus.Fields{
- "func": "Owns",
- "id": id,
- },
- )
+ l := log.WithFields(kv.Fields{
+ {"id", id},
+ }...)
l.Debug("entering Owns")
// if the id host isn't this instance host, we don't own this IRI
diff --git a/internal/federation/federatingdb/reject.go b/internal/federation/federatingdb/reject.go
index 9cb81c267..b77c3ce3a 100644
--- a/internal/federation/federatingdb/reject.go
+++ b/internal/federation/federatingdb/reject.go
@@ -23,27 +23,22 @@ import (
"errors"
"fmt"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-logger/v2/level"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsReject) error {
- l := logrus.WithFields(
- logrus.Fields{
- "func": "Reject",
- },
- )
-
- if logrus.GetLevel() >= logrus.DebugLevel {
+ if log.Level() >= level.DEBUG {
i, err := marshalItem(reject)
if err != nil {
return err
}
- l = l.WithField("reject", i)
+ l := log.WithField("reject", i)
l.Debug("entering Reject")
}
diff --git a/internal/federation/federatingdb/undo.go b/internal/federation/federatingdb/undo.go
index 92f24f315..4cb3d0fa8 100644
--- a/internal/federation/federatingdb/undo.go
+++ b/internal/federation/federatingdb/undo.go
@@ -23,21 +23,18 @@ import (
"errors"
"fmt"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-logger/v2/level"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
)
func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo) error {
- l := logrus.WithFields(
- logrus.Fields{
- "func": "Undo",
- },
- )
+ l := log.Entry{}
- if logrus.GetLevel() >= logrus.DebugLevel {
+ if log.Level() >= level.DEBUG {
i, err := marshalItem(undo)
if err != nil {
return err
diff --git a/internal/federation/federatingdb/update.go b/internal/federation/federatingdb/update.go
index 09d5c8fd8..599544e34 100644
--- a/internal/federation/federatingdb/update.go
+++ b/internal/federation/federatingdb/update.go
@@ -23,11 +23,12 @@ import (
"errors"
"fmt"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-logger/v2/level"
"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/log"
"github.com/superseriousbusiness/gotosocial/internal/messages"
)
@@ -41,13 +42,9 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error {
- l := logrus.WithFields(
- logrus.Fields{
- "func": "Update",
- },
- )
+ l := log.Entry{}
- if logrus.GetLevel() >= logrus.DebugLevel {
+ if log.Level() >= level.DEBUG {
i, err := marshalItem(asType)
if err != nil {
return err
diff --git a/internal/federation/federatingdb/util.go b/internal/federation/federatingdb/util.go
index 7f27cc759..9fc35faa4 100644
--- a/internal/federation/federatingdb/util.go
+++ b/internal/federation/federatingdb/util.go
@@ -25,7 +25,7 @@ import (
"fmt"
"net/url"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-logger/v2/level"
"github.com/superseriousbusiness/activity/streams"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
@@ -33,6 +33,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
@@ -63,18 +64,12 @@ 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(ctx context.Context, t vocab.Type) (idURL *url.URL, err error) {
- l := logrus.WithFields(
- logrus.Fields{
- "func": "NewID",
- },
- )
-
- if logrus.GetLevel() >= logrus.DebugLevel {
+ if log.Level() >= level.DEBUG {
i, err := marshalItem(t)
if err != nil {
return nil, err
}
- l = l.WithField("newID", i)
+ l := log.WithField("newID", i)
l.Debug("entering NewID")
}
@@ -312,7 +307,7 @@ func extractFromCtx(ctx context.Context) (receivingAccount, requestingAccount *g
var ok bool
receivingAccount, ok = receivingAccountI.(*gtsmodel.Account)
if !ok {
- logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to *gtsmodel.Account", ap.ContextReceivingAccount)
+ log.Panicf("extractFromCtx: context entry with key %s could not be asserted to *gtsmodel.Account", ap.ContextReceivingAccount)
}
}
@@ -321,7 +316,7 @@ func extractFromCtx(ctx context.Context) (receivingAccount, requestingAccount *g
var ok bool
requestingAccount, ok = requestingAcctI.(*gtsmodel.Account)
if !ok {
- logrus.Panicf("extractFromCtx: context entry with key %s could not be asserted to *gtsmodel.Account", ap.ContextRequestingAccount)
+ log.Panicf("extractFromCtx: context entry with key %s could not be asserted to *gtsmodel.Account", ap.ContextRequestingAccount)
}
}
diff --git a/internal/federation/federatingprotocol.go b/internal/federation/federatingprotocol.go
index 8944987c5..8242ca4b1 100644
--- a/internal/federation/federatingprotocol.go
+++ b/internal/federation/federatingprotocol.go
@@ -25,7 +25,7 @@ import (
"net/http"
"net/url"
- "github.com/sirupsen/logrus"
+ "codeberg.org/gruf/go-kv"
"github.com/superseriousbusiness/activity/pub"
"github.com/superseriousbusiness/activity/streams"
"github.com/superseriousbusiness/activity/streams/vocab"
@@ -33,6 +33,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/uris"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
@@ -137,11 +138,10 @@ func (f *federator) PostInboxRequestBodyHook(ctx context.Context, r *http.Reques
// authenticated must be true and error nil. The request will continue
// to be processed.
func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (context.Context, bool, error) {
- l := logrus.WithFields(logrus.Fields{
- "func": "AuthenticatePostInbox",
- "useragent": r.UserAgent(),
- "url": r.URL.String(),
- })
+ l := log.WithFields(kv.Fields{
+ {"useragent", r.UserAgent()},
+ {"url", r.URL.String()},
+ }...)
l.Trace("received request to authenticate")
if !uris.IsInboxPath(r.URL) {
@@ -226,10 +226,7 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr
// blocked must be false and error nil. The request will continue
// to be processed.
func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, error) {
- l := logrus.WithFields(logrus.Fields{
- "func": "Blocked",
- })
- l.Debugf("entering BLOCKED function with IRI list: %+v", actorIRIs)
+ log.Debugf("entering BLOCKED function with IRI list: %+v", actorIRIs)
// check domain blocks first for the given actor IRIs
blocked, err := f.db.AreURIsBlocked(ctx, actorIRIs)
@@ -244,7 +241,7 @@ func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, er
otherInvolvedIRIsI := ctx.Value(ap.ContextOtherInvolvedIRIs)
otherInvolvedIRIs, ok := otherInvolvedIRIsI.([]*url.URL)
if !ok {
- l.Errorf("other involved IRIs not set on request context")
+ log.Error("other involved IRIs not set on request context")
return false, errors.New("other involved IRIs not set on request context, so couldn't determine blocks")
}
blocked, err = f.db.AreURIsBlocked(ctx, otherInvolvedIRIs)
@@ -259,13 +256,13 @@ func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, er
receivingAccountI := ctx.Value(ap.ContextReceivingAccount)
receivingAccount, ok := receivingAccountI.(*gtsmodel.Account)
if !ok {
- l.Errorf("receiving account not set on request context")
+ log.Error("receiving account not set on request context")
return false, errors.New("receiving account not set on request context, so couldn't determine blocks")
}
requestingAccountI := ctx.Value(ap.ContextRequestingAccount)
requestingAccount, ok := requestingAccountI.(*gtsmodel.Account)
if !ok {
- l.Errorf("requesting account not set on request context")
+ log.Error("requesting account not set on request context")
return false, errors.New("requesting account not set on request context, so couldn't determine blocks")
}
// the receiver shouldn't block the sender
@@ -371,10 +368,9 @@ func (f *federator) FederatingCallbacks(ctx context.Context) (wrapped pub.Federa
// type and extension, so the unhandled ones are passed to
// DefaultCallback.
func (f *federator) DefaultCallback(ctx context.Context, activity pub.Activity) error {
- l := logrus.WithFields(logrus.Fields{
- "func": "DefaultCallback",
- "aptype": activity.GetTypeName(),
- })
+ l := log.WithFields(kv.Fields{
+ {"aptype", activity.GetTypeName()},
+ }...)
l.Debugf("received unhandle-able activity type so ignoring it")
return nil
}