Documentation ¶
Overview ¶
Package store provides an interface for keeping routes and neighbor information without querying a route server. The refresh happens in a configurable interval.
There a currently two implementations: A postgres and and in-memory backend.
Index ¶
- Constants
- Variables
- func ContainsCi(s, substr string) bool
- func SerializeReasons(reasons map[int]string) map[string]string
- func StartHousekeeping(ctx context.Context, cfg *config.Config)
- type NeighborsStore
- func (s *NeighborsStore) CacheTTL(ctx context.Context) time.Time
- func (s *NeighborsStore) CachedAt(ctx context.Context) time.Time
- func (s *NeighborsStore) FilterNeighbors(ctx context.Context, filter *api.NeighborFilter) (api.Neighbors, error)
- func (s *NeighborsStore) GetNeighborsAt(ctx context.Context, sourceID string) (api.Neighbors, error)
- func (s *NeighborsStore) GetNeighborsMapAt(ctx context.Context, sourceID string) (map[string]*api.Neighbor, error)
- func (s *NeighborsStore) GetStatus(sourceID string) (*Status, error)
- func (s *NeighborsStore) IsInitialized(sourceID string) bool
- func (s *NeighborsStore) LookupNeighbors(ctx context.Context, query string) (api.NeighborsLookupResults, error)
- func (s *NeighborsStore) SourceCacheTTL(ctx context.Context, sourceID string) time.Time
- func (s *NeighborsStore) SourceCachedAt(sourceID string) time.Time
- func (s *NeighborsStore) Start(ctx context.Context)
- func (s *NeighborsStore) Stats(ctx context.Context) *api.NeighborsStoreStats
- func (s *NeighborsStore) Status(ctx context.Context) *api.StoreStatus
- type NeighborsStoreBackend
- type RoutesStore
- func (s *RoutesStore) CacheTTL(ctx context.Context) time.Time
- func (s *RoutesStore) CachedAt(ctx context.Context) time.Time
- func (s *RoutesStore) LookupPrefix(ctx context.Context, prefix string, filters *api.SearchFilters) (api.LookupRoutes, error)
- func (s *RoutesStore) LookupPrefixForNeighbors(ctx context.Context, neighbors api.NeighborsLookupResults, ...) (api.LookupRoutes, error)
- func (s *RoutesStore) Start(ctx context.Context)
- func (s *RoutesStore) Stats(ctx context.Context) *api.RoutesStoreStats
- func (s *RoutesStore) Status(ctx context.Context) *api.StoreStatus
- type RoutesStoreBackend
- type SourceStatusList
- type SourcesStore
- func (s *SourcesStore) CachedAt(ctx context.Context) time.Time
- func (s *SourcesStore) Get(sourceID string) *config.SourceConfig
- func (s *SourcesStore) GetInstance(sourceID string) sources.Source
- func (s *SourcesStore) GetName(sourceID string) string
- func (s *SourcesStore) GetSourceIDs() []string
- func (s *SourcesStore) GetSourceIDsForRefresh() []string
- func (s *SourcesStore) GetSourcesStatus() []*Status
- func (s *SourcesStore) GetStatus(sourceID string) (*Status, error)
- func (s *SourcesStore) IsInitialized(sourceID string) (bool, error)
- func (s *SourcesStore) LockSource(sourceID string) error
- func (s *SourcesStore) NextRefresh(ctx context.Context) time.Time
- func (s *SourcesStore) RefreshError(sourceID string, sourceErr interface{})
- func (s *SourcesStore) RefreshSuccess(sourceID string) error
- func (s *SourcesStore) ShouldRefresh(sourceID string) bool
- type State
- type Status
Constants ¶
const ( StateInit = iota StateReady StateBusy StateError )
Store State Constants
Variables ¶
var ErrSourceNotInitialized = errors.New(
"source is not initialized")
ErrSourceNotInitialized is returned if a source is known but not yet initialized
var ReMatchASLookup = regexp.MustCompile(`(?i)^AS(\d+)`)
ReMatchASLookup matches lookups with an 'AS' prefix
Functions ¶
func ContainsCi ¶
ContainsCi is like `strings.Contains` but case insensitive
func SerializeReasons ¶
SerializeReasons asserts the bgp communitiy parts are actually strings, because there are no such things as integers as keys in json. Serialization of this is undefined behaviour, so we keep these interallybut provide a string as a key for serialization
Types ¶
type NeighborsStore ¶
type NeighborsStore struct {
// contains filtered or unexported fields
}
NeighborsStore is queryable for neighbor information
func NewNeighborsStore ¶
func NewNeighborsStore( cfg *config.Config, backend NeighborsStoreBackend, ) *NeighborsStore
NewNeighborsStore creates a new store for neighbors
func (*NeighborsStore) CacheTTL ¶
func (s *NeighborsStore) CacheTTL( ctx context.Context, ) time.Time
CacheTTL returns the TTL time
func (*NeighborsStore) CachedAt ¶
func (s *NeighborsStore) CachedAt( ctx context.Context, ) time.Time
CachedAt returns the time of the oldest partial refresh of the dataset.
func (*NeighborsStore) FilterNeighbors ¶
func (s *NeighborsStore) FilterNeighbors( ctx context.Context, filter *api.NeighborFilter, ) (api.Neighbors, error)
FilterNeighbors retrieves neighbors by name or by ASN from all route servers.
func (*NeighborsStore) GetNeighborsAt ¶
func (s *NeighborsStore) GetNeighborsAt( ctx context.Context, sourceID string, ) (api.Neighbors, error)
GetNeighborsAt gets all neighbors from a routeserver
func (*NeighborsStore) GetNeighborsMapAt ¶
func (s *NeighborsStore) GetNeighborsMapAt( ctx context.Context, sourceID string, ) (map[string]*api.Neighbor, error)
GetNeighborsMapAt looks up a neighbor on a RS by ID.
func (*NeighborsStore) GetStatus ¶
func (s *NeighborsStore) GetStatus(sourceID string) (*Status, error)
GetStatus retrievs the status for a route server identified by sourceID.
func (*NeighborsStore) IsInitialized ¶
func (s *NeighborsStore) IsInitialized(sourceID string) bool
IsInitialized retrieves the status for a route server and checks if it is ready.
func (*NeighborsStore) LookupNeighbors ¶
func (s *NeighborsStore) LookupNeighbors( ctx context.Context, query string, ) (api.NeighborsLookupResults, error)
LookupNeighbors filters for neighbors matching a query on all route servers.
func (*NeighborsStore) SourceCacheTTL ¶
SourceCacheTTL returns the next time when a refresh will be started.
func (*NeighborsStore) SourceCachedAt ¶
func (s *NeighborsStore) SourceCachedAt(sourceID string) time.Time
SourceCachedAt returns the last time the store content was refreshed.
func (*NeighborsStore) Start ¶
func (s *NeighborsStore) Start(ctx context.Context)
Start the store's housekeeping.
func (*NeighborsStore) Stats ¶
func (s *NeighborsStore) Stats( ctx context.Context, ) *api.NeighborsStoreStats
Stats exports some statistics for monitoring.
func (*NeighborsStore) Status ¶
func (s *NeighborsStore) Status(ctx context.Context) *api.StoreStatus
Status returns the stores current status
type NeighborsStoreBackend ¶
type NeighborsStoreBackend interface { // SetNeighbors replaces all neighbors for a given // route server identified by sourceID. SetNeighbors( ctx context.Context, sourceID string, neighbors api.Neighbors, ) error // GetNeighborsAt retrieves all neighbors associated // with a route server (source). GetNeighborsAt( ctx context.Context, sourceID string, ) (api.Neighbors, error) // GetNeighborsMapAt retrieve a map of neighbor ids // to the neighbor for a given route server for quick // consecutive lookup. GetNeighborsMapAt( ctx context.Context, sourceID string, ) (map[string]*api.Neighbor, error) // CountNeighborsAt retrieves the current number of // stored neighbors. CountNeighborsAt( ctx context.Context, sourceID string, ) (int, error) }
NeighborsStoreBackend interface
type RoutesStore ¶
type RoutesStore struct {
// contains filtered or unexported fields
}
The RoutesStore holds a mapping of routes, status and cfgs and will be queried instead of a backend by the API
func NewRoutesStore ¶
func NewRoutesStore( neighbors *NeighborsStore, cfg *config.Config, backend RoutesStoreBackend, ) *RoutesStore
NewRoutesStore makes a new store instance with a cfg.
func (*RoutesStore) CacheTTL ¶
func (s *RoutesStore) CacheTTL( ctx context.Context, ) time.Time
CacheTTL returns the TTL time
func (*RoutesStore) CachedAt ¶
func (s *RoutesStore) CachedAt( ctx context.Context, ) time.Time
CachedAt returns the time of the oldest partial refresh of the dataset.
func (*RoutesStore) LookupPrefix ¶
func (s *RoutesStore) LookupPrefix( ctx context.Context, prefix string, filters *api.SearchFilters, ) (api.LookupRoutes, error)
LookupPrefix performs a lookup over all route servers
func (*RoutesStore) LookupPrefixForNeighbors ¶
func (s *RoutesStore) LookupPrefixForNeighbors( ctx context.Context, neighbors api.NeighborsLookupResults, filters *api.SearchFilters, ) (api.LookupRoutes, error)
LookupPrefixForNeighbors returns all routes for a set of neighbors.
func (*RoutesStore) Start ¶
func (s *RoutesStore) Start(ctx context.Context)
Start starts the routes store
func (*RoutesStore) Stats ¶
func (s *RoutesStore) Stats(ctx context.Context) *api.RoutesStoreStats
Stats calculates some store insights
func (*RoutesStore) Status ¶
func (s *RoutesStore) Status(ctx context.Context) *api.StoreStatus
Status returns the store status meta
type RoutesStoreBackend ¶
type RoutesStoreBackend interface { // SetRoutes updates the routes in the store after a refresh. SetRoutes( ctx context.Context, sourceID string, routes api.LookupRoutes, ) error // CountRoutesAt returns the number of imported // and filtered routes for a given route server. // Example: (imported, filtered, error) CountRoutesAt( ctx context.Context, sourceID string, ) (uint, uint, error) // FindByNeighbors retrieves the prefixes // announced by the neighbor at a given source FindByNeighbors( ctx context.Context, neighbors []*api.NeighborQuery, filters *api.SearchFilters, ) (api.LookupRoutes, error) // FindByPrefix FindByPrefix( ctx context.Context, prefix string, filters *api.SearchFilters, limit uint, ) (api.LookupRoutes, error) }
RoutesStoreBackend interface
type SourceStatusList ¶
type SourceStatusList []*Status
SourceStatusList is a sortable list of source status
func (SourceStatusList) Less ¶
func (l SourceStatusList) Less(i, j int) bool
Less implements the sort interface
func (SourceStatusList) Swap ¶
func (l SourceStatusList) Swap(i, j int)
Swap implements the sort interface
type SourcesStore ¶
SourcesStore provides methods for retrieving the current status of a source.
func NewSourcesStore ¶
func NewSourcesStore( cfg *config.Config, refreshInterval time.Duration, refreshParallelism int, ) *SourcesStore
NewSourcesStore initializes a new source store
func (*SourcesStore) CachedAt ¶
func (s *SourcesStore) CachedAt(ctx context.Context) time.Time
CachedAt retrievs the oldest refresh time from all sources. All data is then guaranteed to be older than the CachedAt date.
func (*SourcesStore) Get ¶
func (s *SourcesStore) Get(sourceID string) *config.SourceConfig
Get retrieves the source
func (*SourcesStore) GetInstance ¶
func (s *SourcesStore) GetInstance(sourceID string) sources.Source
GetInstance retrieves a source instance by ID
func (*SourcesStore) GetName ¶
func (s *SourcesStore) GetName(sourceID string) string
GetName retrieves a source name by ID
func (*SourcesStore) GetSourceIDs ¶
func (s *SourcesStore) GetSourceIDs() []string
GetSourceIDs returns a list of registered source ids.
func (*SourcesStore) GetSourceIDsForRefresh ¶
func (s *SourcesStore) GetSourceIDsForRefresh() []string
GetSourceIDsForRefresh will retrieve a list of source IDs, which are currently not locked, sorted by least refreshed. The number of sources returned is limited through the refresh parallelism parameter.
func (*SourcesStore) GetSourcesStatus ¶
func (s *SourcesStore) GetSourcesStatus() []*Status
GetSourcesStatus will retrieve the status for all sources as a list.
func (*SourcesStore) GetStatus ¶
func (s *SourcesStore) GetStatus(sourceID string) (*Status, error)
GetStatus will retrieve the status of a source
func (*SourcesStore) IsInitialized ¶
func (s *SourcesStore) IsInitialized(sourceID string) (bool, error)
IsInitialized will retrieve the status of the source and check if a successful refresh happened at least once.
func (*SourcesStore) LockSource ¶
func (s *SourcesStore) LockSource(sourceID string) error
LockSource indicates the start of a refresh
func (*SourcesStore) NextRefresh ¶
func (s *SourcesStore) NextRefresh( ctx context.Context, ) time.Time
NextRefresh calculates the next refresh time
func (*SourcesStore) RefreshError ¶
func (s *SourcesStore) RefreshError( sourceID string, sourceErr interface{}, )
RefreshError indicates that the refresh has failed
func (*SourcesStore) RefreshSuccess ¶
func (s *SourcesStore) RefreshSuccess(sourceID string) error
RefreshSuccess indicates a successful update of the store's content.
func (*SourcesStore) ShouldRefresh ¶
func (s *SourcesStore) ShouldRefresh( sourceID string, ) bool
ShouldRefresh checks if the source needs a new refresh according to the provided refreshInterval.
type Status ¶
type Status struct { RefreshInterval time.Duration `json:"refresh_interval"` RefreshParallelism int `json:"-"` LastRefresh time.Time `json:"last_refresh"` LastRefreshDuration time.Duration `json:"-"` LastError interface{} `json:"-"` State State `json:"state"` Initialized bool `json:"initialized"` SourceID string `json:"source_id"` // contains filtered or unexported fields }
Status defines a status the store can be in.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
backends
|
|
memory
Package memory provides in-memory backends for neighbor and route stores.
|
Package memory provides in-memory backends for neighbor and route stores. |
postgres
Package postgres is an implementation of a routes and neighbors store using the postgres database.
|
Package postgres is an implementation of a routes and neighbors store using the postgres database. |