From bada0bf8073201c135d30b43dfdf4cca232fa6d4 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 20 Aug 2020 16:15:40 +0100 Subject: [PATCH] Review comments and linting --- federationsender/internal/api.go | 12 ++++++------ federationsender/statistics/statistics_test.go | 5 +---- go.mod | 2 +- go.sum | 2 ++ 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/federationsender/internal/api.go b/federationsender/internal/api.go index f108d293e..6b5f4c342 100644 --- a/federationsender/internal/api.go +++ b/federationsender/internal/api.go @@ -55,7 +55,7 @@ func (a *FederationSenderInternalAPI) isBlacklistedOrBackingOff(s gomatrixserver now := time.Now() if until != nil && now.Before(*until) { return stats, &api.FederationClientError{ - RetryAfter: until.Sub(now), + RetryAfter: time.Until(*until), } } @@ -77,7 +77,7 @@ func failBlacklistableError(err error, stats *statistics.ServerStatistics) (unti } func (a *FederationSenderInternalAPI) doRequest( - ctx context.Context, s gomatrixserverlib.ServerName, request func() (interface{}, error), + s gomatrixserverlib.ServerName, request func() (interface{}, error), ) (interface{}, error) { stats, err := a.isBlacklistedOrBackingOff(s) if err != nil { @@ -89,7 +89,7 @@ func (a *FederationSenderInternalAPI) doRequest( now := time.Now() var retryAfter time.Duration if until.After(now) { - retryAfter = until.Sub(now) + retryAfter = time.Until(until) } return res, &api.FederationClientError{ Err: err.Error(), @@ -104,7 +104,7 @@ func (a *FederationSenderInternalAPI) doRequest( func (a *FederationSenderInternalAPI) GetUserDevices( ctx context.Context, s gomatrixserverlib.ServerName, userID string, ) (gomatrixserverlib.RespUserDevices, error) { - ires, err := a.doRequest(ctx, s, func() (interface{}, error) { + ires, err := a.doRequest(s, func() (interface{}, error) { return a.federation.GetUserDevices(ctx, s, userID) }) if err != nil { @@ -116,7 +116,7 @@ func (a *FederationSenderInternalAPI) GetUserDevices( func (a *FederationSenderInternalAPI) ClaimKeys( ctx context.Context, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string, ) (gomatrixserverlib.RespClaimKeys, error) { - ires, err := a.doRequest(ctx, s, func() (interface{}, error) { + ires, err := a.doRequest(s, func() (interface{}, error) { return a.federation.ClaimKeys(ctx, s, oneTimeKeys) }) if err != nil { @@ -128,7 +128,7 @@ func (a *FederationSenderInternalAPI) ClaimKeys( func (a *FederationSenderInternalAPI) QueryKeys( ctx context.Context, s gomatrixserverlib.ServerName, keys map[string][]string, ) (gomatrixserverlib.RespQueryKeys, error) { - ires, err := a.doRequest(ctx, s, func() (interface{}, error) { + ires, err := a.doRequest(s, func() (interface{}, error) { return a.federation.QueryKeys(ctx, s, keys) }) if err != nil { diff --git a/federationsender/statistics/statistics_test.go b/federationsender/statistics/statistics_test.go index 235430494..7e083de68 100644 --- a/federationsender/statistics/statistics_test.go +++ b/federationsender/statistics/statistics_test.go @@ -36,10 +36,7 @@ func TestBackoff(t *testing.T) { // completes but we will find out how long the backoff should // have been. interrupt := make(chan bool, 1) - go func() { - time.Sleep(10 * time.Millisecond) - close(interrupt) - }() + close(interrupt) // Get the duration. duration, blacklist := server.BackoffIfRequired(backingOff, interrupt) diff --git a/go.mod b/go.mod index 1f4087062..3125cf588 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ require ( github.com/Shopify/sarama v1.26.1 github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect github.com/gologme/log v1.2.0 - github.com/gorilla/mux v1.7.3 + github.com/gorilla/mux v1.7.4 github.com/hashicorp/golang-lru v0.5.4 github.com/lib/pq v1.2.0 github.com/libp2p/go-libp2p v0.6.0 diff --git a/go.sum b/go.sum index 06c295233..ef4ba1c4e 100644 --- a/go.sum +++ b/go.sum @@ -151,6 +151,8 @@ github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE0 github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= +github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=