Commit 9322f6b1 authored by David Vorick's avatar David Vorick

code readability + cleanliness

parent 100a4e4e
......@@ -87,13 +87,12 @@ type HostDBEntry struct {
// measurements are kept in full detail, historic ones are compressed into
// the historic values.
HistoricDowntime time.Duration `json:"historicdowntime"`
HistoricUptime time.Duration `json:"historicuptime"`
ScanHistory HostDBScans `json:"scanhistory"`
HistoricUptime time.Duration `json:"historicuptime"`
ScanHistory HostDBScans `json:"scanhistory"`
// The public key of the host, stored separately to minimize risk of certain
// MitM based vulnerabilities.
PublicKey types.SiaPublicKey `json:"publickey"`
}
// HostDBScan represents a single scan event.
......
......@@ -156,6 +156,7 @@ func (hdb *HostDB) updateEntry(entry modules.HostDBEntry, netErr error) {
} else {
newEntry.HistoricDowntime += timePassed
}
newEntry.ScanHistory = newEntry.ScanHistory[1:]
}
// Add the updated entry
......@@ -284,19 +285,17 @@ func (hdb *HostDB) threadedScan() {
// Grab a set of hosts to scan, grab hosts that are active, inactive,
// and offline to get high diversity.
var onlineHosts, offlineHosts []modules.HostDBEntry
hosts := hdb.hostTree.All()
for i := 0; i < len(hosts) && (len(onlineHosts) < hostCheckupQuantity || len(offlineHosts) < hostCheckupQuantity); i++ {
// Figure out if the host is online or offline.
online := false
scanLen := len(hosts[i].ScanHistory)
if scanLen > 0 && hosts[i].ScanHistory[scanLen-1].Success {
online = true
for _, host := range hdb.hostTree.All() {
if len(onlineHosts) >= hostCheckupQuantity && len(offlineHosts) >= hostCheckupQuantity {
break
}
// Figure out if the host is online or offline.
online := len(host.ScanHistory) > 0 && host.ScanHistory[len(host.ScanHistory)-1].Success
if online && len(onlineHosts) < hostCheckupQuantity {
onlineHosts = append(onlineHosts, hosts[i])
onlineHosts = append(onlineHosts, host)
} else if !online && len(offlineHosts) < hostCheckupQuantity {
offlineHosts = append(onlineHosts, hosts[i])
offlineHosts = append(onlineHosts, host)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment