Skip to content

Commit

Permalink
fix RHPPruneContractResponse, remove unused type, update ipfilter cac…
Browse files Browse the repository at this point in the history
…he (#661)

* worker: return sizes

* api: remove unused type
  • Loading branch information
peterjan authored Oct 13, 2023
1 parent bc9ea4e commit 8df905c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
21 changes: 8 additions & 13 deletions api/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"`
Expand All @@ -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"`
Expand Down
19 changes: 12 additions & 7 deletions autopilot/ipfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down

0 comments on commit 8df905c

Please sign in to comment.