gitlab.com/SkynetLabs/skyd@v1.6.9/skymodules/renter/contractor/uptime.go (about) 1 package contractor 2 3 import ( 4 "gitlab.com/SkynetLabs/skyd/skymodules" 5 "go.sia.tech/siad/types" 6 ) 7 8 // IsOffline indicates whether a contract's host should be considered offline, 9 // based on its scan metrics. 10 func (c *Contractor) IsOffline(pk types.SiaPublicKey) bool { 11 host, ok, err := c.staticHDB.Host(pk) 12 if !ok || err != nil { 13 // No host or error, assume offline. 14 return true 15 } 16 return isOffline(host) 17 } 18 19 // isOffline indicates whether a host should be considered offline, based on 20 // its scan metrics. 21 func isOffline(host skymodules.HostDBEntry) bool { 22 // See if the host has a scan history. 23 if len(host.ScanHistory) < 1 { 24 // No scan history, assume offline. 25 return true 26 } 27 // If we only have one scan in the history we return false if it was 28 // successful. 29 if len(host.ScanHistory) == 1 { 30 return !host.ScanHistory[0].Success 31 } 32 // Otherwise we use the last 2 scans. This way a short connectivity problem 33 // won't mark the host as offline. 34 success1 := host.ScanHistory[len(host.ScanHistory)-1].Success 35 success2 := host.ScanHistory[len(host.ScanHistory)-2].Success 36 return !(success1 || success2) 37 }