From 8df905c7049d79288709ae30b7cf5d1959415af3 Mon Sep 17 00:00:00 2001 From: Peter-Jan Brone Date: Fri, 13 Oct 2023 14:50:14 +0200 Subject: [PATCH] fix RHPPruneContractResponse, remove unused type, update ipfilter cache (#661) * worker: return sizes * api: remove unused type --- api/autopilot.go | 21 ++++++++------------- autopilot/ipfilter.go | 19 ++++++++++++------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/api/autopilot.go b/api/autopilot.go index f735b66f1..e8517e8a7 100644 --- a/api/autopilot.go +++ b/api/autopilot.go @@ -69,13 +69,6 @@ type ( ) type ( - // An Action is an autopilot operation. - Action struct { - Timestamp time.Time - Type string - Action interface{ isAction() } - } - // AutopilotTriggerRequest is the request object used by the /debug/trigger // endpoint AutopilotTriggerRequest struct { @@ -101,6 +94,14 @@ type ( StartTime time.Time `json:"startTime"` BuildState } +) + +type ( + // HostHandlerResponse is the response type for the /host/:hostkey endpoint. + HostHandlerResponse struct { + Host hostdb.Host `json:"host"` + Checks *HostHandlerResponseChecks `json:"checks,omitempty"` + } HostHandlerResponseChecks struct { Gouging bool `json:"gouging"` @@ -111,12 +112,6 @@ type ( UnusableReasons []string `json:"unusableReasons"` } - // HostHandlerResponse is the response type for the /host/:hostkey endpoint. - HostHandlerResponse struct { - Host hostdb.Host `json:"host"` - Checks *HostHandlerResponseChecks `json:"checks,omitempty"` - } - HostGougingBreakdown struct { V2 GougingChecks `json:"v2"` V3 GougingChecks `json:"v3"` diff --git a/autopilot/ipfilter.go b/autopilot/ipfilter.go index 559fa986f..861897c16 100644 --- a/autopilot/ipfilter.go +++ b/autopilot/ipfilter.go @@ -135,10 +135,13 @@ func (r *ipResolver) lookup(hostIP string) ([]string, error) { // lookup IP addresses addrs, err := r.resolver.LookupIPAddr(ctx, host) - if err != nil && (isErr(err, errIOTimeout) || isErr(err, errServerMisbehaving)) { - if entry, found := r.cache[hostIP]; found && time.Since(entry.created) < ipCacheEntryValidity { - r.logger.Debugf("using cached IP addresses for %v, err: %v", hostIP, err) - return entry.subnets, nil + if err != nil { + // check the cache if it's an i/o timeout or server misbehaving error + if isErr(err, errIOTimeout) || isErr(err, errServerMisbehaving) { + if entry, found := r.cache[hostIP]; found && time.Since(entry.created) < ipCacheEntryValidity { + r.logger.Debugf("using cached IP addresses for %v, err: %v", hostIP, err) + return entry.subnets, nil + } } return nil, err } @@ -152,9 +155,11 @@ func (r *ipResolver) lookup(hostIP string) ([]string, error) { subnets := parseSubnets(addrs) // add to cache - r.cache[hostIP] = ipCacheEntry{ - created: time.Now(), - subnets: subnets, + if len(subnets) > 0 { + r.cache[hostIP] = ipCacheEntry{ + created: time.Now(), + subnets: subnets, + } } return subnets, nil