Review comments and linting

This commit is contained in:
Kegan Dougal 2020-08-20 16:15:40 +01:00
parent ea9ca14c53
commit bada0bf807
4 changed files with 10 additions and 11 deletions

View file

@ -55,7 +55,7 @@ func (a *FederationSenderInternalAPI) isBlacklistedOrBackingOff(s gomatrixserver
now := time.Now() now := time.Now()
if until != nil && now.Before(*until) { if until != nil && now.Before(*until) {
return stats, &api.FederationClientError{ 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( func (a *FederationSenderInternalAPI) doRequest(
ctx context.Context, s gomatrixserverlib.ServerName, request func() (interface{}, error), s gomatrixserverlib.ServerName, request func() (interface{}, error),
) (interface{}, error) { ) (interface{}, error) {
stats, err := a.isBlacklistedOrBackingOff(s) stats, err := a.isBlacklistedOrBackingOff(s)
if err != nil { if err != nil {
@ -89,7 +89,7 @@ func (a *FederationSenderInternalAPI) doRequest(
now := time.Now() now := time.Now()
var retryAfter time.Duration var retryAfter time.Duration
if until.After(now) { if until.After(now) {
retryAfter = until.Sub(now) retryAfter = time.Until(until)
} }
return res, &api.FederationClientError{ return res, &api.FederationClientError{
Err: err.Error(), Err: err.Error(),
@ -104,7 +104,7 @@ func (a *FederationSenderInternalAPI) doRequest(
func (a *FederationSenderInternalAPI) GetUserDevices( func (a *FederationSenderInternalAPI) GetUserDevices(
ctx context.Context, s gomatrixserverlib.ServerName, userID string, ctx context.Context, s gomatrixserverlib.ServerName, userID string,
) (gomatrixserverlib.RespUserDevices, error) { ) (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) return a.federation.GetUserDevices(ctx, s, userID)
}) })
if err != nil { if err != nil {
@ -116,7 +116,7 @@ func (a *FederationSenderInternalAPI) GetUserDevices(
func (a *FederationSenderInternalAPI) ClaimKeys( func (a *FederationSenderInternalAPI) ClaimKeys(
ctx context.Context, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string, ctx context.Context, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string,
) (gomatrixserverlib.RespClaimKeys, error) { ) (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) return a.federation.ClaimKeys(ctx, s, oneTimeKeys)
}) })
if err != nil { if err != nil {
@ -128,7 +128,7 @@ func (a *FederationSenderInternalAPI) ClaimKeys(
func (a *FederationSenderInternalAPI) QueryKeys( func (a *FederationSenderInternalAPI) QueryKeys(
ctx context.Context, s gomatrixserverlib.ServerName, keys map[string][]string, ctx context.Context, s gomatrixserverlib.ServerName, keys map[string][]string,
) (gomatrixserverlib.RespQueryKeys, error) { ) (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) return a.federation.QueryKeys(ctx, s, keys)
}) })
if err != nil { if err != nil {

View file

@ -36,10 +36,7 @@ func TestBackoff(t *testing.T) {
// completes but we will find out how long the backoff should // completes but we will find out how long the backoff should
// have been. // have been.
interrupt := make(chan bool, 1) interrupt := make(chan bool, 1)
go func() { close(interrupt)
time.Sleep(10 * time.Millisecond)
close(interrupt)
}()
// Get the duration. // Get the duration.
duration, blacklist := server.BackoffIfRequired(backingOff, interrupt) duration, blacklist := server.BackoffIfRequired(backingOff, interrupt)

2
go.mod
View file

@ -4,7 +4,7 @@ require (
github.com/Shopify/sarama v1.26.1 github.com/Shopify/sarama v1.26.1
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect
github.com/gologme/log v1.2.0 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/hashicorp/golang-lru v0.5.4
github.com/lib/pq v1.2.0 github.com/lib/pq v1.2.0
github.com/libp2p/go-libp2p v0.6.0 github.com/libp2p/go-libp2p v0.6.0

2
go.sum
View file

@ -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/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 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= 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 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 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= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=