navigator

package
v0.3.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2021 License: AGPL-3.0 Imports: 27 Imported by: 2

Documentation

Index

Constants

View Source
const (
	RoutingProfileDefaultName  = "default"
	RoutingProfileShortestName = "shortest"
	RoutingProfileHomeName     = "home"
)

Variables

View Source
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")
)
View Source
var (
	RoutingProfileDefault = &RoutingProfile{
		ID:           RoutingProfileDefaultName,
		MinHops:      3,
		MaxHops:      5,
		MaxExtraHops: 2,
		MaxExtraCost: 100,
	}

	RoutingProfileShortest = &RoutingProfile{
		ID:           RoutingProfileShortestName,
		MinHops:      1,
		MaxHops:      5,
		MaxExtraHops: 1,
		MaxExtraCost: 100,
	}
)

Functions

This section is empty.

Types

type Hop added in v0.3.0

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 int
	// contains filtered or unexported fields
}

func (*Hop) Pin added in v0.3.0

func (hop *Hop) Pin() *Pin

type HubType added in v0.3.0

type HubType uint8
const (
	HomeHub HubType = iota
	TransitHub
	DestinationHub
)

type Lane added in v0.3.0

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
	// contains filtered or unexported fields
}

Lane is a connection to another Hub.

type LaneExport added in v0.3.7

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

type Map struct {
	sync.RWMutex
	Name string
	// contains filtered or unexported fields
}

Map represent a collection of Pins and their relationship and status.

var (
	Main *Map
)

func NewMap

func NewMap(name string) *Map

NewMap returns a new and empty Map.

func (*Map) AddBootstrapHubs added in v0.3.0

func (m *Map) AddBootstrapHubs(bootstrapTransports []string) error

AddBootstrapHubs adds the given bootstrap hubs to the map

func (*Map) Close added in v0.3.0

func (m *Map) Close()

func (*Map) DefaultOptions added in v0.3.0

func (m *Map) DefaultOptions() *Options

DefaultOptions returns the default options for this Map.

func (*Map) FindNearestHubs added in v0.3.0

func (m *Map) FindNearestHubs(locationV4, locationV6 *geoip.Location, opts *Options, matchFor HubType, maxMatches int) ([]*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) FindRoutes added in v0.3.0

func (m *Map) FindRoutes(ip net.IP, opts *Options, maxRoutes int) (*Routes, error)

func (*Map) GetHome added in v0.3.0

func (m *Map) GetHome() (*Pin, *docks.CraneTerminal)

GetHome returns the current home and it's accompanying terminal. Both may be nil.

func (*Map) GetPin added in v0.3.7

func (m *Map) GetPin(hubID string) (pin *Pin, ok bool)

GetPin returns the Pin of the Hub with the given ID.

func (*Map) InitializeFromDatabase added in v0.3.0

func (m *Map) InitializeFromDatabase()

InitializeFromDatabase loads all Hubs from the given database prefix and adds them to the Map.

func (*Map) Optimize added in v0.3.0

func (m *Map) Optimize(opts *Options) (connectTo *hub.Hub, err error)

FindNearestHubs searches for the nearest Hubs to the given IP address. The returned Hubs must not be modified in any way.

func (*Map) PushPinChanges added in v0.3.7

func (m *Map) PushPinChanges()

func (*Map) RegisterHubUpdateHook added in v0.3.0

func (m *Map) RegisterHubUpdateHook() error

RegisterHubUpdateHook registers a database pre-put hook that updates all Hubs saved at the given database prefix.

func (*Map) RemoveHub added in v0.3.0

func (m *Map) RemoveHub(id string)

RemoveHub removes a Hub from the Map.

func (*Map) SetHome added in v0.3.0

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) Stats added in v0.3.0

func (m *Map) Stats() *MapStats

Stats collects and returns statistics from the map.

func (*Map) UpdateHub added in v0.3.0

func (m *Map) UpdateHub(h *hub.Hub)

UpdateHub updates a Hub on the Map.

func (*Map) UpdateIntel added in v0.3.0

func (m *Map) UpdateIntel(update *hub.Intel) error

UpdateIntel supplies the map with new intel data. The data is not copied, so it must not be modified after being supplied. If the map is empty, the bootstrap hubs will be added to the map.

type MapStats added in v0.3.0

type MapStats struct {
	Name   string
	States map[PinState]int
	Lanes  map[int]int
}

func (*MapStats) String added in v0.3.0

func (ms *MapStats) String() string

type Options added in v0.3.0

type Options 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 undesireable states is added automatically.
	Disregard PinState

	// HubPolicy is an endpoint list that all Hubs must pass in order to be taken into account for the operation.
	HubPolicy endpoints.Endpoints

	// HomeHubPolicy is an endpoint list that Home Hubs must pass in order to be taken into account for the operation.
	HomeHubPolicy endpoints.Endpoints

	// DestinationHubPolicy is an endpoint list that Destination Hubs must pass in order to be taken into account for the operation.
	DestinationHubPolicy endpoints.Endpoints

	// FIXME
	CheckHubEntryPolicy bool

	// FIXME
	CheckHubExitPolicy bool

	// NoDefaults declares whether default and recommended Regard and Disregard states should not be used.
	NoDefaults bool

	// RequireTrustedDestinationHubs declares whether only Destination Hubs that have the Trusted state should be used.
	RequireTrustedDestinationHubs bool

	// RoutingProfile defines the algorithm to use to find a route.
	RoutingProfile string
}

Options holds configuration options for operations with the Map.

func (*Options) Copy added in v0.3.0

func (o *Options) Copy() *Options

func (*Options) Matcher added in v0.3.0

func (o *Options) Matcher(hubType HubType) PinMatcher

type Pin added in v0.3.0

type Pin struct {
	// Hub Information
	Hub        *hub.Hub
	EntityV4   *intel.Entity
	EntityV6   *intel.Entity
	LocationV4 *geoip.Location
	LocationV6 *geoip.Location

	// Hub Status
	State       PinState
	HopDistance int
	Load        int              // estimated in microseconds this port adds to latency
	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) Export added in v0.3.7

func (pin *Pin) Export() *PinExport

func (*Pin) GetActiveTerminal added in v0.3.7

func (pin *Pin) GetActiveTerminal() *docks.ExpansionTerminal

func (*Pin) HasActiveTerminal added in v0.3.0

func (pin *Pin) HasActiveTerminal() bool

func (*Pin) Lock added in v0.3.0

func (pin *Pin) Lock()

func (*Pin) NotifyTerminalChange added in v0.3.7

func (pin *Pin) NotifyTerminalChange()

func (*Pin) SetActiveTerminal added in v0.3.7

func (pin *Pin) SetActiveTerminal(pc *PinConnection)

func (*Pin) String added in v0.3.0

func (pin *Pin) String() string

String returns a human-readable representation of the Pin.

func (*Pin) Unlock added in v0.3.0

func (pin *Pin) Unlock()

type PinConnection added in v0.3.0

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 added in v0.3.7

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
	HopDistance int

	ConnectedTo   map[string]*LaneExport // Key is Hub ID.
	Route         []string               // Includes Home Hub and this Pin's ID.
	SessionActive bool
}

PinExport is the exportable version of a Pin.

type PinMatcher added in v0.3.0

type PinMatcher func(pin *Pin) bool

type PinState added in v0.3.0

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.IgnoreUntil specifies when this state is
	// re-evaluated at earliest.
	StateFailing // 0x04

	// 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

	// 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 | StateUsageDiscouraged | StateIsHomeHub
)

func (PinState) Export added in v0.3.7

func (pinState PinState) Export() []string

Export returns a list of all state names.

func (PinState) Name added in v0.3.0

func (pinState PinState) Name() string

Name returns the name of a single state flag.

func (PinState) String added in v0.3.0

func (pinState PinState) String() string

String returns the states as a human readable string.

type Route

type Route struct {
	// DstCost is the calculated cost between the Destination Hub and the destination IP.
	DstCost int

	// Path is a list of Transit Hubs and the Destination Hub, including the Cost
	// for each Hop.
	Path []*Hop

	// TotalCost is the sum of all costs of this Route.
	TotalCost int

	// Algorithm is the ID of the algorithm used to calculate the route.
	Algorithm string
}

func (*Route) CopyUpTo added in v0.3.0

func (r *Route) CopyUpTo(n int) *Route

CopyUpTo makes a somewhat deep copy of the Route up to the specified amount and returns it. Hops themselves are not copied, because their data does not change. Therefore, returned Hops may not be edited. Specify an amount of 0 to copy all.

func (*Route) String

func (r *Route) String() string

type Routes added in v0.3.0

type Routes struct {
	All []*Route
	// contains filtered or unexported fields
}

func (*Routes) Len added in v0.3.0

func (r *Routes) Len() int

Len is the number of elements in the collection.

func (*Routes) Less added in v0.3.0

func (r *Routes) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (*Routes) Swap added in v0.3.0

func (r *Routes) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type RoutingProfile added in v0.3.0

type RoutingProfile struct {
	ID 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 int
}

type StorageInterface added in v0.3.7

type StorageInterface struct {
	storage.InjectBase
}

StorageInterface provices a storage.Interface to the configuration manager.

func (*StorageInterface) Get added in v0.3.7

func (s *StorageInterface) Get(key string) (record.Record, error)

Get returns a database record.

func (*StorageInterface) Query added in v0.3.7

func (s *StorageInterface) Query(q *query.Query, local, internal bool) (*iterator.Iterator, error)

Query returns a an iterator for the supplied query.

type UpdateHook added in v0.3.0

type UpdateHook struct {
	database.HookBase
	// contains filtered or unexported fields
}

func (*UpdateHook) PrePut added in v0.3.0

func (hook *UpdateHook) PrePut(r record.Record) (record.Record, error)

PrePut implements the Hook interface.

func (*UpdateHook) UsesPrePut added in v0.3.0

func (hook *UpdateHook) UsesPrePut() bool

UsesPrePut implements the Hook interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL