Add pre-commit config Update default consensus with more sources Move IP version spec to Source so that dual-stack sites can be used Add tests for HTTPSource and consensus
25 lines
746 B
Go
25 lines
746 B
Go
package externalip
|
|
|
|
import (
|
|
"log"
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
// Source defines the part of a voter which gives the actual voting value (IP).
|
|
type Source interface {
|
|
// IP returns IPv4/IPv6 address in a non-error case
|
|
// net.IP should never be <nil> when error is <nil>
|
|
// It is recommended that the IP function times out,
|
|
// if no result could be found, after the given timeout duration.
|
|
IP(timeout time.Duration, logger *log.Logger) (net.IP, error)
|
|
IPVersion() uint
|
|
}
|
|
|
|
// voter adds weight to the IP given by a source.
|
|
// The weight has to be at least 1, and the more it is, the more power the voter has.
|
|
type voter struct {
|
|
source Source // provides the IP (see: vote)
|
|
weight uint // provides the weight of its vote (acts as a multiplier)
|
|
}
|