storj/pkg/overlay/config.go
Cameron 4058c29ca4
filter duplicate node IPs (#1890)
* add last_ip field to dbx model node, generate dbx

* add last_ip to node proto, generate pb

* migrate

* resolve address in transport.DialNode, update lastIp in cache.UpdateAddress

* use net.SplitHostPort to isolate host address from port

* define DistinctIPs flag

* add test for GetIP

* select last_ip when querying for nodes

* if distinctIPs flag == true, query for nodes with distinct IPs

* some basic tests

* change last_ip to field 14 in proto

* remove comments

* check err

* change distinctIPs to distinctIP

* exclude IPs from newNodes in query for reputable nodes

* add index on last_ip

* only add to excludedIPs if flag is true

* test half new nodes returns distinct IPs

* fix alignment

* add test

* rework ip filter query, add retry logic, add switch for database driver

* add retry to SelectNewNodes

* change discovery intervals so IPs don't get overwritten

* remove TestGetIP

* edit updating node stats in test

* split exclude into nodeIDs and IPs

* separate non-distinct IP query into other function

* trigger checks

* remove else block
2019-05-22 16:06:27 -04:00

64 lines
2.5 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package overlay
import (
"strings"
"time"
"github.com/zeebo/errs"
monkit "gopkg.in/spacemonkeygo/monkit.v2"
"storj.io/storj/pkg/storj"
)
var (
mon = monkit.Package()
// Error represents an overlay error
Error = errs.Class("overlay error")
)
// Config is a configuration struct for everything you need to start the
// Overlay cache responsibility.
type Config struct {
Node NodeSelectionConfig
}
// LookupConfig is a configuration struct for querying the overlay cache with one or more node IDs
type LookupConfig struct {
NodeIDsString string `help:"one or more string-encoded node IDs, delimited by Delimiter"`
Delimiter string `help:"delimiter used for parsing node IDs" default:","`
}
// NodeSelectionConfig is a configuration struct to determine the minimum
// values for nodes to select
type NodeSelectionConfig struct {
UptimeRatio float64 `help:"a node's ratio of being up/online vs. down/offline" releaseDefault:"0.9" devDefault:"0"`
UptimeCount int64 `help:"the number of times a node's uptime has been checked to not be considered a New Node" releaseDefault:"500" devDefault:"0"`
AuditSuccessRatio float64 `help:"a node's ratio of successful audits" releaseDefault:"0.4" devDefault:"0"` // TODO: update after beta
AuditCount int64 `help:"the number of times a node has been audited to not be considered a New Node" releaseDefault:"500" devDefault:"0"`
NewNodePercentage float64 `help:"the percentage of new nodes allowed per request" default:"0.05"` // TODO: fix, this is not percentage, it's ratio
MinimumVersion string `help:"the minimum node software version for node selection queries" default:""`
OnlineWindow time.Duration `help:"the amount of time without seeing a node before its considered offline" default:"1h"`
DistinctIP bool `help:"require distinct IPs when choosing nodes for upload" releaseDefault:"true" devDefault:"false"`
}
// ParseIDs converts the base58check encoded node ID strings from the config into node IDs
func (c LookupConfig) ParseIDs() (ids storj.NodeIDList, err error) {
var idErrs []error
idStrs := strings.Split(c.NodeIDsString, c.Delimiter)
for _, s := range idStrs {
id, err := storj.NodeIDFromString(s)
if err != nil {
idErrs = append(idErrs, err)
continue
}
ids = append(ids, id)
}
if err := errs.Combine(idErrs...); err != nil {
return nil, err
}
return ids, nil
}