Documentation ¶
Index ¶
- Constants
- Variables
- func CalculateDestinationCost(proximity float32) (cost float32)
- func CalculateHubCost(load int) (cost float32)
- func CalculateLaneCost(latency time.Duration, capacity int) (cost float32)
- func HubPoliciesAreSet(policies []endpoints.Endpoints) bool
- type AnalysisState
- type DestinationHubOptions
- type HomeHubOptions
- type Hop
- type HubOptions
- type HubType
- type Lane
- type LaneExport
- type Map
- func (m *Map) AddBootstrapHubs(bootstrapTransports []string) error
- func (m *Map) CancelHubUpdateHook()
- func (m *Map) Close()
- func (m *Map) DefaultOptions() *Options
- func (m *Map) FindNearestHubs(locationV4, locationV6 *geoip.Location, opts *Options, matchFor HubType) ([]*hub.Hub, error)
- func (m *Map) FindRouteToHub(hubID string, opts *Options) (*Routes, error)
- func (m *Map) FindRoutes(ip net.IP, opts *Options) (*Routes, error)
- func (m *Map) GetAvailableCountries(opts *Options, forType HubType) map[string]*geoip.CountryInfo
- func (m *Map) GetHome() (*Pin, *docks.CraneTerminal)
- func (m *Map) GetIntel() *hub.Intel
- func (m *Map) GetPin(hubID string) (pin *Pin, ok bool)
- func (m *Map) InitializeFromDatabase() error
- func (m *Map) Optimize(opts *HubOptions) (result *OptimizationResult, err error)
- func (m *Map) PushPinChanges()
- func (m *Map) RegisterHubUpdateHook() (err error)
- func (m *Map) RemoveHub(id string)
- func (m *Map) ResetFailingStates()
- func (m *Map) SaveMeasuredHubs()
- func (m *Map) SetHome(id string, t *docks.CraneTerminal) (ok bool)
- func (m *Map) Stats() *MapStats
- func (m *Map) UpdateConfigQuickSettings(wc *mgr.WorkerCtx) error
- func (m *Map) UpdateHub(h *hub.Hub)
- func (m *Map) UpdateIntel(update *hub.Intel, trustNodes []string) error
- type MapStats
- type Navigator
- type OptimizationResult
- type Options
- type Pin
- func (pin *Pin) Export() *PinExport
- func (pin *Pin) GetActiveTerminal() *docks.ExpansionTerminal
- func (pin *Pin) GetLocation(ip net.IP) *geoip.Location
- func (pin *Pin) GetState() PinState
- func (pin *Pin) HasActiveTerminal() bool
- func (pin *Pin) IsFailing() bool
- func (pin *Pin) Lock()
- func (pin *Pin) MarkAsFailingFor(duration time.Duration)
- func (pin *Pin) NotifyTerminalChange()
- func (pin *Pin) ResetFailingState()
- func (pin *Pin) SetActiveTerminal(pc *PinConnection)
- func (pin *Pin) String() string
- func (pin *Pin) Unlock()
- type PinConnection
- type PinExport
- type PinMatcher
- type PinState
- func (pinState PinState) Add(states PinState) PinState
- func (pinState PinState) Export() []string
- func (pinState PinState) Has(states PinState) bool
- func (pinState PinState) HasAnyOf(states PinState) bool
- func (pinState PinState) HasNoneOf(states PinState) bool
- func (pinState PinState) Name() string
- func (pinState PinState) Remove(states PinState) PinState
- func (pinState PinState) String() string
- type Region
- type Route
- type Routes
- type RoutingProfile
- type StorageInterface
- type SuggestedConnection
- type TransitHubOptions
- type UpdateHook
Constants ¶
const ()
Measurements Configuration.
const ( OptimizePurposeBootstrap = "bootstrap" OptimizePurposeDesegregate = "desegregate" OptimizePurposeWait = "wait" OptimizePurposeTargetStructure = "target-structure" )
Optimization Purposes.
const ( RoutingProfileHomeID = "home" RoutingProfileSingleHopID = "single-hop" RoutingProfileDoubleHopID = "double-hop" RoutingProfileTripleHopID = "triple-hop" )
Routing Profile Names.
Variables ¶
var ( // ErrHomeHubUnset is returned when the Home Hub is required and not set. ErrHomeHubUnset = errors.New("map has no Home Hub set") // ErrEmptyMap is returned when the Map is empty. ErrEmptyMap = errors.New("map is empty") // ErrHubNotFound is returned when the Hub was not found on the Map. ErrHubNotFound = errors.New("hub not found") // ErrAllPinsDisregarded is returned when all pins have been disregarded. ErrAllPinsDisregarded = errors.New("all pins have been disregarded") )
var ( DefaultRoutingProfileID = profile.DefaultRoutingProfileID RoutingProfileHome = &RoutingProfile{ ID: "home", Name: "Plain VPN Mode", MinHops: 1, MaxHops: 1, } RoutingProfileSingleHop = &RoutingProfile{ ID: "single-hop", Name: "Speed Focused", MinHops: 1, MaxHops: 3, MaxExtraHops: 1, MaxExtraCost: 10000, } RoutingProfileDoubleHop = &RoutingProfile{ ID: "double-hop", Name: "Balanced", MinHops: 2, MaxHops: 4, MaxExtraHops: 2, MaxExtraCost: 10000, } RoutingProfileTripleHop = &RoutingProfile{ ID: "triple-hop", Name: "Privacy Focused", MinHops: 3, MaxHops: 5, MaxExtraHops: 3, MaxExtraCost: 10000, } )
Routing Profiles.
var DeriveTunnelOptions func(lp *profile.LayeredProfile, destination *intel.Entity, connEncrypted bool) *Options
DeriveTunnelOptions derives and returns the tunnel options from the connection and profile. This function lives in firewall/tunnel.go and is set here to avoid import loops.
Functions ¶
func CalculateDestinationCost ¶
CalculateDestinationCost calculates the cost of a destination hub to a destination server based on the given proximity. Ranges from 0 to 2500.
func CalculateHubCost ¶
CalculateHubCost calculates the cost of using a Hub based on the given Hub load. Ranges from 100 to 10000.
func CalculateLaneCost ¶
CalculateLaneCost calculates the cost of using a Lane based on the given Lane latency and capacity. Ranges from 0 to 10000.
func HubPoliciesAreSet ¶
HubPoliciesAreSet returns whether any of the given hub policies are set and non-empty.
Types ¶
type AnalysisState ¶
type AnalysisState struct { // Suggested signifies that a direct connection to this Hub is suggested by // the optimization algorithm. Suggested bool // SuggestedHopDistance holds the hop distance to this Hub when only // considering the suggested Hubs as connected. SuggestedHopDistance int // SuggestedHopDistanceInRegion holds the hop distance to this Hub in the // same region when only considering the suggested Hubs as connected. SuggestedHopDistanceInRegion int // CrossRegionalConnections holds the amount of connections a Pin has from // the current region. CrossRegionalConnections int // CrossRegionalLowestCostLane holds the lowest cost of the counted // connections from the current region. CrossRegionalLowestCostLane float32 // CrossRegionalLaneCosts holds all the cross regional lane costs. CrossRegionalLaneCosts []float32 // CrossRegionalHighestCostInHubLimit holds to highest cost of the lowest // cost connections within the maximum allowed lanes on a Hub from the // current region. CrossRegionalHighestCostInHubLimit float32 }
AnalysisState holds state for analyzing the network for optimizations.
type DestinationHubOptions ¶
type DestinationHubOptions HubOptions
DestinationHubOptions holds configuration options for Destination Hub operations with the Map.
func (*DestinationHubOptions) Matcher ¶
func (o *DestinationHubOptions) Matcher(hubIntel *hub.Intel) PinMatcher
Matcher generates a PinMatcher based on the Options.
type HomeHubOptions ¶
type HomeHubOptions HubOptions
HomeHubOptions holds configuration options for Home Hub operations with the Map.
func (*HomeHubOptions) Matcher ¶
func (o *HomeHubOptions) Matcher(hubIntel *hub.Intel) PinMatcher
Matcher generates a PinMatcher based on the Options.
type Hop ¶
type Hop struct { // HubID is the Hub ID. HubID string // Cost is the cost for both Lane to this Hub and the Hub itself. Cost float32 // contains filtered or unexported fields }
Hop is one hop of a route's path.
type HubOptions ¶
type HubOptions struct { // Regard holds required States. Only Hubs where all of these are present // will taken into account for the operation. If NoDefaults is not set, a // basic set of desirable states is added automatically. Regard PinState // Disregard holds disqualifying States. Only Hubs where none of these are // present will be taken into account for the operation. If NoDefaults is not // set, a basic set of undesirable states is added automatically. Disregard PinState // NoDefaults declares whether default and recommended Regard and Disregard states should not be used. NoDefaults bool // HubPolicies is a collection of endpoint lists that Hubs must pass in order // to be taken into account for the operation. HubPolicies []endpoints.Endpoints // RequireVerifiedOwners specifies which verified owners are allowed to be used. // If the list is empty, all owners are allowed. RequireVerifiedOwners []string // CheckHubPolicyWith provides an entity that must match the Hubs entry or exit // policy (depending on type) in order to be taken into account for the operation. CheckHubPolicyWith *intel.Entity }
HubOptions holds configuration options for a specific hub type for operations with the Map.
func (HubOptions) Copy ¶
func (o HubOptions) Copy() HubOptions
Copy returns a shallow copy of the Options.
func (*HubOptions) Matcher ¶
func (o *HubOptions) Matcher(hubType HubType, hubIntel *hub.Intel) PinMatcher
Matcher generates a PinMatcher based on the Options.
type Lane ¶
type Lane struct { // Pin is the Pin/Hub this Lane connects to. Pin *Pin // Capacity designates the available bandwidth between these Hubs. // It is specified in bit/s. Capacity int // Lateny designates the latency between these Hubs. // It is specified in nanoseconds. Latency time.Duration // Cost is the routing cost of this lane. Cost float32 // contains filtered or unexported fields }
Lane is a connection to another Hub.
type LaneExport ¶
type LaneExport struct { HubID string // Capacity designates the available bandwidth between these Hubs. // It is specified in bit/s. Capacity int // Lateny designates the latency between these Hubs. // It is specified in nanoseconds. Latency time.Duration }
LaneExport is the exportable version of a Lane.
type Map ¶
Map represent a collection of Pins and their relationship and status.
var ( // Main is the primary map used. Main *Map )
func (*Map) AddBootstrapHubs ¶
AddBootstrapHubs adds the given bootstrap hubs to the map.
func (*Map) CancelHubUpdateHook ¶
func (m *Map) CancelHubUpdateHook()
CancelHubUpdateHook cancels the map's update hook.
func (*Map) DefaultOptions ¶
DefaultOptions returns the default options for this Map.
func (*Map) FindNearestHubs ¶
func (m *Map) FindNearestHubs(locationV4, locationV6 *geoip.Location, opts *Options, matchFor HubType) ([]*hub.Hub, error)
FindNearestHubs searches for the nearest Hubs to the given IP address. The returned Hubs must not be modified in any way.
func (*Map) FindRouteToHub ¶
FindRouteToHub finds possible routes to the given Hub, with the given options.
func (*Map) FindRoutes ¶
FindRoutes finds possible routes to the given IP, with the given options.
func (*Map) GetAvailableCountries ¶
GetAvailableCountries returns a map of countries including their information where the map has pins suitable for the given type.
func (*Map) GetHome ¶
func (m *Map) GetHome() (*Pin, *docks.CraneTerminal)
GetHome returns the current home and it's accompanying terminal. Both may be nil.
func (*Map) InitializeFromDatabase ¶
InitializeFromDatabase loads all Hubs from the given database prefix and adds them to the Map.
func (*Map) Optimize ¶
func (m *Map) Optimize(opts *HubOptions) (result *OptimizationResult, err error)
Optimize analyzes the map and suggests changes.
func (*Map) PushPinChanges ¶
func (m *Map) PushPinChanges()
PushPinChanges pushes all changed pins to subscribers.
func (*Map) RegisterHubUpdateHook ¶
RegisterHubUpdateHook registers a database pre-put hook that updates all Hubs saved at the given database prefix.
func (*Map) ResetFailingStates ¶
func (m *Map) ResetFailingStates()
ResetFailingStates resets the failing state on all pins.
func (*Map) SaveMeasuredHubs ¶
func (m *Map) SaveMeasuredHubs()
SaveMeasuredHubs saves all Hubs that have unsaved measurements.
func (*Map) SetHome ¶
func (m *Map) SetHome(id string, t *docks.CraneTerminal) (ok bool)
SetHome sets the given hub as the new home. Optionally, a terminal may be supplied to accompany the home hub.
func (*Map) UpdateConfigQuickSettings ¶
UpdateConfigQuickSettings updates config quick settings with available countries.
type Navigator ¶ added in v1.6.19
type Navigator struct {
// contains filtered or unexported fields
}
type OptimizationResult ¶
type OptimizationResult struct { // Purpose holds a semi-human readable constant of the optimization purpose. Purpose string // Approach holds human readable descriptions of how the stated purpose // should be achieved. Approach []string // SuggestedConnections holds the Hubs to which connections are suggested. SuggestedConnections []*SuggestedConnection // MaxConnect specifies how many connections should be created at maximum // based on this optimization. MaxConnect int // StopOthers specifies if other connections than the suggested ones may // be stopped. StopOthers bool // contains filtered or unexported fields }
OptimizationResult holds the result of an optimizaion analysis.
type Options ¶
type Options struct { // Home holds the options for Home Hubs. Home *HomeHubOptions // Transit holds the options for Transit Hubs. Transit *TransitHubOptions // Destination holds the options for Destination Hubs. Destination *DestinationHubOptions // RoutingProfile defines the algorithm to use to find a route. RoutingProfile string }
Options holds configuration options for operations with the Map.
type Pin ¶
type Pin struct { // Hub Information Hub *hub.Hub EntityV4 *intel.Entity EntityV6 *intel.Entity LocationV4 *geoip.Location LocationV6 *geoip.Location // Hub Status State PinState // VerifiedOwner holds the name of the verified owner / operator of the Hub. VerifiedOwner string // HopDistance signifies the needed hops to reach this Hub. // HopDistance is measured from the view of a client. // A Hub itself will have itself at distance 1. // Directly connected Hubs have a distance of 2. HopDistance int // Cost is the routing cost of this Hub. Cost float32 // ConnectedTo holds validated lanes. ConnectedTo map[string]*Lane // Key is Hub ID. // FailingUntil specifies until when this Hub should be regarded as failing. // This is connected to StateFailing. FailingUntil time.Time // Connection holds a information about a connection to the Hub of this Pin. Connection *PinConnection // contains filtered or unexported fields }
Pin represents a Hub on a Map.
func (*Pin) GetActiveTerminal ¶
func (pin *Pin) GetActiveTerminal() *docks.ExpansionTerminal
GetActiveTerminal returns the active terminal of the pin.
func (*Pin) GetLocation ¶
GetLocation returns the geoip location of the Pin, preferring first the given IP, then IPv4.
func (*Pin) HasActiveTerminal ¶
HasActiveTerminal returns whether the Pin has an active terminal.
func (*Pin) IsFailing ¶
IsFailing returns whether the pin should be treated as failing. The Pin is locked for this.
func (*Pin) MarkAsFailingFor ¶
MarkAsFailingFor marks the pin as failing. The Pin is locked for this. Changes are pushed.
func (*Pin) NotifyTerminalChange ¶
func (pin *Pin) NotifyTerminalChange()
NotifyTerminalChange notifies subscribers of the changed terminal.
func (*Pin) ResetFailingState ¶
func (pin *Pin) ResetFailingState()
ResetFailingState resets the failing state. The Pin is locked for this. Changes are not pushed, but Pins are marked.
func (*Pin) SetActiveTerminal ¶
func (pin *Pin) SetActiveTerminal(pc *PinConnection)
SetActiveTerminal sets an active terminal for the pin.
type PinConnection ¶
type PinConnection struct { // Terminal holds the active terminal session. Terminal *docks.ExpansionTerminal // Route is the route built for this terminal. Route *Route }
PinConnection represents a connection to a terminal on the Hub.
type PinExport ¶
type PinExport struct { record.Base sync.Mutex ID string Name string Map string FirstSeen time.Time EntityV4 *intel.Entity EntityV6 *intel.Entity States []string // From pin.State VerifiedOwner string HopDistance int ConnectedTo map[string]*LaneExport // Key is Hub ID. Route []string // Includes Home Hub and this Pin's ID. SessionActive bool Info *hub.Announcement Status *hub.Status }
PinExport is the exportable version of a Pin.
type PinMatcher ¶
PinMatcher is a stateful matching function generated by Options.
type PinState ¶
type PinState uint16
PinState holds a bit-mapped collection of Pin states, or a single state used for assigment and matching.
const ( // StateNone represents an empty state. StateNone PinState = 0 // StateInvalid signifies that there was an error while processing or // handling this Hub. StateInvalid PinState = 1 << (iota - 1) // 1 << 0 => 00000001 => 0x01 // StateSuperseded signifies that this Hub was superseded by another. This is // the case if any other Hub with a matching IP was verified after this one. // Verification timestamp equals Hub.FirstSeen. StateSuperseded // 0x02 // StateFailing signifies that a recent error was encountered while // communicating with this Hub. Pin.FailingUntil specifies when this state is // re-evaluated at earliest. StateFailing // 0x04 // StateOffline signifies that the Hub is offline. StateOffline // 0x08 // StateHasRequiredInfo signifies that the Hub announces the minimum required // information about itself. StateHasRequiredInfo // 0x10 // StateReachable signifies that the Hub is reachable via the network from // the currently connected primary Hub. StateReachable // 0x20 // StateActive signifies that everything seems fine with the Hub and // connections to it should succeed. This is tested by checking if a valid // semi-ephemeral public key is available. StateActive // 0x40 // StateTrusted signifies the Hub has the special trusted status. StateTrusted // 0x0100 // StateUsageDiscouraged signifies that usage of the Hub is discouraged for any task. StateUsageDiscouraged // 0x0200 // StateUsageAsHomeDiscouraged signifies that usage of the Hub as a Home Hub is discouraged. StateUsageAsHomeDiscouraged // 0x0400 // StateUsageAsDestinationDiscouraged signifies that usage of the Hub as a Destination Hub is discouraged. StateUsageAsDestinationDiscouraged // 0x0800 // StateIsHomeHub signifies that the Hub is the current Home Hub. While not // negative in itself, selecting the Home Hub does not make sense in almost // all cases. StateIsHomeHub // 0x1000 // StateConnectivityIssues signifies that the Hub reports connectivity issues. // This might impact all connectivity or just some. // This does not invalidate the Hub for all operations and not in all cases. StateConnectivityIssues // 0x2000 // StateAllowUnencrypted signifies that the Hub is available to handle unencrypted connections. StateAllowUnencrypted // 0x4000 // StateSummaryRegard summarizes all states that must always be set in order to take a Hub into consideration for any task. // TODO: Add StateHasRequiredInfo when we start enforcing Hub information. StateSummaryRegard = StateReachable | StateActive // StateSummaryDisregard summarizes all states that must not be set in order to take a Hub into consideration for any task. StateSummaryDisregard = StateInvalid | StateSuperseded | StateFailing | StateOffline | StateUsageDiscouraged | StateIsHomeHub )
func (PinState) HasNoneOf ¶
HasNoneOf returns whether the state does not have any of the given states.
type Route ¶
type Route struct { // Path is a list of Transit Hubs and the Destination Hub, including the Cost // for each Hop. Path []*Hop // DstCost is the calculated cost between the Destination Hub and the destination IP. DstCost float32 // TotalCost is the sum of all costs of this Route. TotalCost float32 // Algorithm is the ID of the algorithm used to calculate the route. Algorithm string }
Route is a path through the map.
type Routes ¶
type Routes struct { All []*Route // contains filtered or unexported fields }
Routes holds a collection of Routes.
type RoutingProfile ¶
type RoutingProfile struct { ID string // Name is the human readable name of the profile. Name string // MinHops defines how many hops a route must have at minimum. In order to // reduce confusion, the Home Hub is also counted. MinHops int // MaxHops defines the limit on how many hops a route may have. In order to // reduce confusion, the Home Hub is also counted. MaxHops int // MaxExtraHops sets a limit on how many extra hops are allowed in addition // to the amount of Hops in the currently best route. This is an optimization // option and should not interfere with finding the best route, but might // reduce the amount of routes found. MaxExtraHops int // MaxExtraCost sets a limit on the extra cost allowed in addition to the // cost of the currently best route. This is an optimization option and // should not interfere with finding the best route, but might reduce the // amount of routes found. MaxExtraCost float32 }
RoutingProfile defines a routing algorithm with some options.
func GetRoutingProfile ¶
func GetRoutingProfile(id string) *RoutingProfile
GetRoutingProfile returns the routing profile with the given ID.
type StorageInterface ¶
type StorageInterface struct {
storage.InjectBase
}
StorageInterface provices a storage.Interface to the configuration manager.
type SuggestedConnection ¶
type SuggestedConnection struct { // Hub holds the Hub to which a connection is suggested. Hub *hub.Hub // Reason holds a reason why this connection is suggested. Reason string // Duplicate marks duplicate entries. These should be ignored when // connecting, but are helpful for understand the optimization result. Duplicate bool // contains filtered or unexported fields }
SuggestedConnection holds suggestions by the optimization system.
type TransitHubOptions ¶
type TransitHubOptions HubOptions
TransitHubOptions holds configuration options for Transit Hub operations with the Map.
func (*TransitHubOptions) Matcher ¶
func (o *TransitHubOptions) Matcher(hubIntel *hub.Intel) PinMatcher
Matcher generates a PinMatcher based on the Options.
type UpdateHook ¶
UpdateHook updates the a map from database changes.
func (*UpdateHook) UsesPrePut ¶
func (hook *UpdateHook) UsesPrePut() bool
UsesPrePut implements the Hook interface.