cache

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assertion

type Assertion interface {
	//Add adds an assertion together with an expiration time (number of seconds since 01.01.1970) to
	//the cache. It returns false if the cache is full and a non internal element has been removed
	//according to some strategy. It also adds assertion to the consistency cache.
	Add(assertion *section.Assertion, expiration int64, isInternal bool) bool
	//Get returns true and a set of assertions matching the given key if there exist some. Otherwise
	//nil and false is returned. If strict is set only an exact match for the provided FQDN is returned
	// otherwise a search up the domain name hiearchy is performed.
	Get(fqdn, context string, objType object.Type, strict bool) ([]*section.Assertion, bool)
	//RemoveExpiredValues goes through the cache and removes all expired assertions from the
	//assertionCache and the consistency cache.
	RemoveExpiredValues()
	//RemoveZone deletes all assertions in the assertionCache and consistencyCache of the given
	//zone.
	RemoveZone(zone string)
	//Checkpoint returns all cached assertions
	Checkpoint() []section.Section
	//Len returns the number of elements in the cache.
	Len() int
}

Assertion is used to store and efficiently lookup assertions

type AssertionImpl

type AssertionImpl struct {
	// contains filtered or unexported fields
}

* assertion cache implementation * It keeps track of all assertionCacheValues of a zone in zoneMap (besides the cache) * such that we can remove all entries of a zone in case of misbehavior or inconsistencies. * It does not support any context

func NewAssertion

func NewAssertion(maxSize int) *AssertionImpl

func (*AssertionImpl) Add

func (c *AssertionImpl) Add(a *section.Assertion, expiration int64, isInternal bool) bool

Add adds an assertion together with an expiration time (number of seconds since 01.01.1970) to the cache. It returns false if the cache is full and an element was removed according to least recently used strategy. It also adds the shard to the consistency cache.

func (*AssertionImpl) Checkpoint

func (c *AssertionImpl) Checkpoint() (assertions []section.Section)

Checkpoint returns all cached assertions

func (*AssertionImpl) Get

func (c *AssertionImpl) Get(fqdn, context string, objType object.Type, strict bool) ([]*section.Assertion, bool)

Get returns true and a set of assertions matching the given key if there exist some. Otherwise nil and false is returned. If strict is true then only a direct match for the provided FQDN is looked up. Otherwise, a search up the domain name hierarchy is performed to get the topmost match.

func (*AssertionImpl) Len

func (c *AssertionImpl) Len() int

Len returns the number of elements in the cache.

func (*AssertionImpl) RemoveExpiredValues

func (c *AssertionImpl) RemoveExpiredValues()

RemoveExpiredValues goes through the cache and removes all expired assertions from the assertionCache and the consistency cache.

func (*AssertionImpl) RemoveZone

func (c *AssertionImpl) RemoveZone(zone string)

RemoveZone deletes all assertions in the assertionCache and consistencyCache of the given zone.

type Capability

type Capability interface {
	//Add normalizes and serializes capabilities and then calculates a sha256 hash over it. It then
	//stores the mapping from the hash to a pointer of the list.
	//If the cache is full it removes a capability according to some metric
	Add(capabilities []message.Capability)
	//Get returns true and a pointer to the capability list from which the hash was taken if
	//present, otherwise false and nil.
	Get(hash []byte) ([]message.Capability, bool)
	//Len returns the number of elements currently in the cache.
	Len() int
}

Capability stores a mapping from a hash of a capability list to a pointer of the list.

type CapabilityImpl

type CapabilityImpl struct {
	// contains filtered or unexported fields
}

* Capability cache implementation

func NewCapability

func NewCapability(maxSize int) *CapabilityImpl

func (*CapabilityImpl) Add

func (c *CapabilityImpl) Add(capabilities []message.Capability)

func (*CapabilityImpl) Get

func (c *CapabilityImpl) Get(hash []byte) ([]message.Capability, bool)

func (*CapabilityImpl) Len

func (c *CapabilityImpl) Len() int

type Connection

type Connection interface {
	//AddConnection adds conn to the cache. If the cache capacity is reached, a connection from the cache will be
	//chosen by some metric, closed and removed.
	AddConnection(conn net.Conn)
	//AddCapability adds capabilities to the destAddr entry. It returns false if there is no entry
	//in the cache for dstAddr. If there is already a capability list associated with destAddr, it
	//will be overwritten.
	AddCapabilityList(dstAddr net.Addr, capabilities []message.Capability) bool
	//GetConnection returns true and all cached connections to dstAddr.
	//GetConnection returns false if there is no cached connection to dstAddr.
	GetConnection(dstAddr net.Addr) ([]net.Conn, bool)
	//Get returns true and the capability list of dstAddr.
	//Get returns false if there is no capability list of dstAddr.
	GetCapabilityList(dstAddr net.Addr) ([]message.Capability, bool)
	//CloseAndRemoveConnection closes conn and removes it from the cache.
	CloseAndRemoveConnection(conn net.Conn)
	//CloseAndRemoveConnections closes and removes all cached connections to addr
	CloseAndRemoveConnections(addr net.Addr)
	//CloseAndRemoveAllConnections closes and removes all cached connections
	CloseAndRemoveAllConnections()
	//Len returns the number of connections currently in the cache.
	Len() int
}

Connection stores persistent stream-oriented network connections.

type ConnectionImpl

type ConnectionImpl struct {
	// contains filtered or unexported fields
}

* Connection cache implementation

func NewConnection

func NewConnection(maxSize int) *ConnectionImpl

func (*ConnectionImpl) AddCapabilityList

func (c *ConnectionImpl) AddCapabilityList(dstAddr net.Addr, capabilities []message.Capability) bool

AddCapability adds capabilities to the destAddr entry. It returns false if there is no entry in the cache for dstAddr. If there is already a capability list associated with destAddr, it will be overwritten.

func (*ConnectionImpl) AddConnection

func (c *ConnectionImpl) AddConnection(conn net.Conn)

AddConnection adds conn to the cache. If the cache is full the least recently used connection is removed.

func (*ConnectionImpl) CloseAndRemoveAllConnections

func (c *ConnectionImpl) CloseAndRemoveAllConnections()

CloseAndRemoveAllConnections closes all cached connections and removes them from the cache

func (*ConnectionImpl) CloseAndRemoveConnection

func (c *ConnectionImpl) CloseAndRemoveConnection(conn net.Conn)

CloseAndRemoveConnection closes conn and removes it from the cache

func (*ConnectionImpl) CloseAndRemoveConnections

func (c *ConnectionImpl) CloseAndRemoveConnections(addr net.Addr)

CloseAndRemoveConnections closes all cached connections to addr and removes them from the cache

func (*ConnectionImpl) GetCapabilityList

func (c *ConnectionImpl) GetCapabilityList(dstAddr net.Addr) ([]message.Capability, bool)

Get returns true and the capability list of dstAddr. Get returns false if there is no capability list of dstAddr.

func (*ConnectionImpl) GetConnection

func (c *ConnectionImpl) GetConnection(dstAddr net.Addr) ([]net.Conn, bool)

GetConnection returns true and all cached connection objects to dstAddr. GetConnection returns false if there is no cached connection to dstAddr.

func (*ConnectionImpl) Len

func (c *ConnectionImpl) Len() int

type NegAssertionImpl

type NegAssertionImpl struct {
	// contains filtered or unexported fields
}

* negative assertion cache implementation * It keeps track of all assertionCacheValues of a zone in zoneMap (besides the cache) * such that we can remove all entries of a zone in case of misbehavior or inconsistencies. * It does not support any context

func NewNegAssertion

func NewNegAssertion(maxSize int) *NegAssertionImpl

func (*NegAssertionImpl) AddPshard

func (c *NegAssertionImpl) AddPshard(pshard *section.Pshard, expiration int64, isInternal bool) bool

Add adds a pshard together with an expiration time (number of seconds since 01.01.1970) to the cache. It returns false if the cache is full and an element was removed according to least recently used strategy. It also adds shard to the consistency cache.

func (*NegAssertionImpl) AddShard

func (c *NegAssertionImpl) AddShard(shard *section.Shard, expiration int64, isInternal bool) bool

Add adds a shard together with an expiration time (number of seconds since 01.01.1970) to the cache. It returns false if the cache is full and an element was removed according to least recently used strategy. It also adds shard to the consistency cache.

func (*NegAssertionImpl) AddZone

func (c *NegAssertionImpl) AddZone(zone *section.Zone, expiration int64, isInternal bool) bool

Add adds a zone together with an expiration time (number of seconds since 01.01.1970) to the cache. It returns false if the cache is full and an element was removed according to least recently used strategy. It also adds zone to the consistency cache.

func (*NegAssertionImpl) Checkpoint

func (c *NegAssertionImpl) Checkpoint() (sections []section.Section)

Checkpoint returns all cached assertions

func (*NegAssertionImpl) Get

func (c *NegAssertionImpl) Get(zone, context string, interval section.Interval) ([]section.WithSigForward, bool)

Get returns true and a set of assertions matching the given key if there exist some. Otherwise nil and false is returned.

func (*NegAssertionImpl) Len

func (c *NegAssertionImpl) Len() int

Len returns the number of elements in the cache.

func (*NegAssertionImpl) RemoveExpiredValues

func (c *NegAssertionImpl) RemoveExpiredValues()

RemoveExpiredValues goes through the cache and removes all expired shards and zones.

func (*NegAssertionImpl) RemoveZone

func (c *NegAssertionImpl) RemoveZone(zone string)

RemoveZone deletes all shards and zones in the assertionCache and consistencyCache of the given subjectZone.

type NegativeAssertion

type NegativeAssertion interface {
	//Add adds shard together with an expiration time (number of seconds since 01.01.1970) to
	//the cache. It returns false if the cache is full and a non internal element has been removed
	//according to some strategy. It also adds shard to the consistency cache.
	AddShard(shard *section.Shard, expiration int64, isInternal bool) bool
	//Add adds pshard together with an expiration time (number of seconds since 01.01.1970) to
	//the cache. It returns false if the cache is full and a non internal element has been removed
	//according to some strategy. It also adds shard to the consistency cache.
	AddPshard(pshard *section.Pshard, expiration int64, isInternal bool) bool
	//Add adds zone together with an expiration time (number of seconds since 01.01.1970) to
	//the cache. It returns false if the cache is full and a non internal element has been removed
	//according to some strategy. It also adds zone to the consistency cache.
	AddZone(zone *section.Zone, expiration int64, isInternal bool) bool
	//Get returns true and a set of shards and zones matching subjectZone and context and overlap
	//with interval if there exist some. When context is the empty string, a random context is
	//chosen. Otherwise nil and false is returned.
	Get(subjectZone, context string, interval section.Interval) ([]section.WithSigForward, bool)
	//RemoveExpiredValues goes through the cache and removes all expired shards and zones from the
	//assertionCache and the consistency cache.
	RemoveExpiredValues()
	//RemoveZone deletes all shards and zones in the assertionCache and consistencyCache of the
	//given subjectZone.
	RemoveZone(subjectZone string)
	//Checkpoint returns all cached negative assertions
	Checkpoint() []section.Section
	//Len returns the number of elements in the cache.
	Len() int
}

type PendingKey

type PendingKey interface {
	//Add adds ss to the cache together with the token and expiration time of the query sent to the
	//host with the addr defined in ss.
	Add(ss util.MsgSectionSender, t token.Token, expiration int64)
	//GetAndRemove returns util.MsgSectionSender which corresponds to token and true, and deletes it from
	//the cache. False is returned if no util.MsgSectionSender matched token.
	GetAndRemove(t token.Token) (util.MsgSectionSender, bool)
	//ContainsToken returns true if t is cached
	ContainsToken(t token.Token) bool
	//RemoveExpiredValues deletes all expired entries. It logs the host's addr which was not able to
	//respond in time.
	RemoveExpiredValues()
	//Len returns the number of sections in the cache
	Len() int
}

type PendingKeyImpl

type PendingKeyImpl struct {
	// contains filtered or unexported fields
}

func NewPendingKey

func NewPendingKey(maxSize int) *PendingKeyImpl

func (*PendingKeyImpl) Add

func (c *PendingKeyImpl) Add(ss util.MsgSectionSender, t token.Token, expiration int64)

Add adds ss to the cache together with the token and expiration time of the query sent to the host with the addr defined in ss.

func (*PendingKeyImpl) ContainsToken

func (c *PendingKeyImpl) ContainsToken(t token.Token) bool

ContainsToken returns true if t is cached

func (*PendingKeyImpl) GetAndRemove

func (c *PendingKeyImpl) GetAndRemove(t token.Token) (util.MsgSectionSender, bool)

GetAndRemove returns util.MsgSectionSender which corresponds to token and true, and deletes it from the cache. False is returned if no util.MsgSectionSender matched token.

func (*PendingKeyImpl) Len

func (c *PendingKeyImpl) Len() int

Len returns the number of sections in the cache

func (*PendingKeyImpl) RemoveExpiredValues

func (c *PendingKeyImpl) RemoveExpiredValues()

RemoveExpiredValues deletes all expired entries. It logs the host's addr which was not able to respond in time.

type PendingQuery

type PendingQuery interface {
	//Add checks if this server has already forwarded a msg containing the same queries as ss. If
	//this is the case, ss is added to the cache and false is returned. If not, ss is added together
	//with t and expiration to the cache and true is returned.
	Add(ss util.MsgSectionSender, t token.Token, expiration int64) bool
	//GetAndRemove returns all util.MsgSectionSenders which correspond to token and delete them from the
	//cache.
	GetAndRemove(t token.Token) []util.MsgSectionSender
	//RemoveExpiredValues deletes all expired entries.
	RemoveExpiredValues()
	//Len returns the number of sections in the cache
	Len() int
}

type PendingQueryImpl

type PendingQueryImpl struct {
	// contains filtered or unexported fields
}

func NewPendingQuery

func NewPendingQuery(maxSize int) *PendingQueryImpl

func (*PendingQueryImpl) Add

func (c *PendingQueryImpl) Add(ss util.MsgSectionSender, t token.Token, expiration int64) bool

Add checks if this server has already forwarded a msg containing the same queries as ss. If this is the case, ss is added to the cache and false is returned. If not, ss is added together with t and expiration to the cache and true is returned.

func (*PendingQueryImpl) GetAndRemove

func (c *PendingQueryImpl) GetAndRemove(t token.Token) []util.MsgSectionSender

GetAndRemove returns all util.MsgSectionSenders which correspond to token and delete them from the cache.

func (*PendingQueryImpl) Len

func (c *PendingQueryImpl) Len() int

Len returns the number of sections in the cache

func (*PendingQueryImpl) RemoveExpiredValues

func (c *PendingQueryImpl) RemoveExpiredValues()

RemoveExpiredValues deletes all expired entries.

type ZoneKeyImpl

type ZoneKeyImpl struct {
	// contains filtered or unexported fields
}

* Zone key cache implementation

func NewZoneKey

func NewZoneKey(maxSize, warnSize, maxKeysPerZone int) *ZoneKeyImpl

func (*ZoneKeyImpl) Add

func (c *ZoneKeyImpl) Add(assertion *section.Assertion, publicKey keys.PublicKey, internal bool) bool

Add adds publicKey together with the assertion containing it to the cache. Returns false if the cache exceeds a configured (during initialization of the cache) amount of entries. If the cache is full it removes a public key according to some metric. The cache logs a message when a zone has more than a certain (configurable) amount of public keys. (An external service can then decide if it wants to blacklist a given zone). If the internal flag is set, the publicKey will only be removed after it expired.

func (*ZoneKeyImpl) Checkpoint

func (c *ZoneKeyImpl) Checkpoint() (assertions []section.Section)

Checkpoint returns all cached assertions

func (*ZoneKeyImpl) Get

func (c *ZoneKeyImpl) Get(zone, context string, sigMetaData signature.MetaData) (
	keys.PublicKey, *section.Assertion, bool)

Get returns true and a valid public key matching zone and publicKeyID. It returns false if there exists no valid public key in the cache.

func (*ZoneKeyImpl) Len

func (c *ZoneKeyImpl) Len() int

Len returns the number of public keys currently in the cache.

func (*ZoneKeyImpl) RemoveExpiredKeys

func (c *ZoneKeyImpl) RemoveExpiredKeys()

RemoveExpiredKeys deletes all expired public keys from the cache.

type ZonePublicKey

type ZonePublicKey interface {
	//Add adds publicKey together with the assertion containing it to the cache. Returns false if
	//the cache exceeds a configured (during initialization of the cache) amount of entries. If the
	//cache is full it removes a public key according to some metric. The cache logs a message when
	//a zone has more than a certain (configurable) amount of public keys. (An external service can
	//then decide if it wants to blacklist a given zone). If the internal flag is set, the publicKey
	//will only be removed after it expired.
	Add(assertion *section.Assertion, publicKey keys.PublicKey, internal bool) bool
	//Get returns true, the assertion holding the returned public key, and a non expired public key
	//which can be used to verify a signature with sigMetaData. It returns false if there is no
	//valid matching public key in the cache.
	Get(zone, context string, sigMetaData signature.MetaData) (
		keys.PublicKey, *section.Assertion, bool)
	//RemoveExpiredKeys deletes all expired public keys from the cache.
	RemoveExpiredKeys()
	//Checkpoint returns all cached assertions
	Checkpoint() []section.Section
	//Len returns the number of public keys currently in the cache.
	Len() int
}

ZonePublicKey is used to store public keys of zones and a pointer to delegation assertions containing them.

Jump to

Keyboard shortcuts

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