client

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package client implements client for Policy Information Point (PIP) server.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConnected occurs if method connect is called after connection has been
	// established.
	ErrConnected = errors.New("connection has been already established")

	// ErrNotConnected occurs if method get is called before connection has been
	// established.
	ErrNotConnected = errors.New("connection hasn't been established yet")
)

Functions

This section is empty.

Types

type CacheHitHandler

type CacheHitHandler func(path string, args []pdp.AttributeValue, v pdp.AttributeValue, err error)

CacheHitHandler defines a function prototype to call on each cache hit if cache has been enabled.

type Client

type Client interface {
	// Connect establishes connection to given PIP server.
	Connect() error

	// Close terminates previously established connection if any. Close silently
	// returns if connection hasn't been established yet or if it has been
	// already closed.
	Close()

	// Get requests information from PIP.
	Get(path string, args []pdp.AttributeValue) (pdp.AttributeValue, error)
}

Client defines abstract PIP service client interface.

func NewClient

func NewClient(opts ...Option) Client

NewClient creates client instance.

type ConnErrHandler

type ConnErrHandler func(net.Addr, error)

ConnErrHandler is a function to process errors within a connection.

type Option

type Option func(*options)

An Option allows to set such options as address, balancer and so on.

func WithAddress

func WithAddress(a string) Option

WithAddress returns an Option which sets destination address.

func WithBufferSize

func WithBufferSize(n int) Option

WithBufferSize returns an Option which sets size of input and output buffers. By default it is 1 MB.

func WithCacheHitHandler

func WithCacheHitHandler(h CacheHitHandler) Option

WithCacheHitHandler returns an Option which sets handler for cache hits.

func WithCacheTTL

func WithCacheTTL(d time.Duration) Option

WithCacheTTL returns an Option which adds cache with given TTL for cached requests. Cache size isn't limited in the case and can consume all available memory on machine.

func WithCacheTTLAndMaxSize

func WithCacheTTLAndMaxSize(d time.Duration, size int) Option

WithCacheTTLAndMaxSize returns an Option which adds cache with given TTL and size limit for entire cache in MB. When the limit is reached then new requests override the oldest ones.

func WithConnErrHandler

func WithConnErrHandler(f ConnErrHandler) Option

WithConnErrHandler returns an Option which sets custom handler for transport errors.

func WithConnTimeout

func WithConnTimeout(d time.Duration) Option

WithConnTimeout returns an Option which sets connection timeout.

func WithDNSRadar

func WithDNSRadar() Option

WithDNSRadar returns an Option which turns on DNS discovery (DNS radar). The radar periodicaly looks up for IP addresses using system resolver (works only for TCP networks). It uses an address given by WithAddress option as host name for DNS qurey. If the query gives several IP addresses, PIP client balances load using balancer given by With*Balancer option. Addresses which come from With*Balancer option are used only as initial set of addresses to connect to. If further DNS queries don't return those addresses client stops using them.

func WithHotSpotBalancer

func WithHotSpotBalancer(addrs ...string) Option

WithHotSpotBalancer returns an Option which sets hot spot balancer. The balancer puts requests to the same connection until its queue is full and then goes to the next connection. If no addresses provided with the option client connects to all IP addresses it can get by host name from WithAddress option. For "unix" network the option is ignored.

func WithK8sRadar

func WithK8sRadar() Option

WithK8sRadar returns an Option which turns on kubernetes discovery. The discovery works only inside kubernetes cluster and requires "get", "watch" and "list" access to "pods" resource. It treats address from WithAddress option as selector encoded in following form "<valueN>.<keyN>. ... .<value2>.<key2>.<value1>.<key1>.<namespacea>" (it should contain at least one key value pair and namespace). Similarly to DNS in case of several pods given balancer is used and addresses coming with balancer options become initiall addresses. However the discovery drops connection to an initiall address only if kubernetes tells that the pod with the IP goes down.

func WithMaxQueue

func WithMaxQueue(n int) Option

WithMaxQueue returns an Option which limits number of requests client can send in parallel.

func WithMaxRequestSize

func WithMaxRequestSize(n int) Option

WithMaxRequestSize returns an Option which limits request size in bytes to given value. Default 10KB.

func WithNetwork

func WithNetwork(n string) Option

WithNetwork returns an Option which sets destination network. The client supports "tcp", "tcp4", "tcp6" and "unix" netwroks.

func WithResponseCheckInterval

func WithResponseCheckInterval(d time.Duration) Option

WithResponseCheckInterval returns an Option which sets inteval of timeout checks.

func WithResponseTimeout

func WithResponseTimeout(d time.Duration) Option

WithResponseTimeout returns an Option which sets timeout for a response. If client gets no response within the interval it drops connection.

func WithRoundRobinBalancer

func WithRoundRobinBalancer(addrs ...string) Option

WithRoundRobinBalancer returns an Option which sets round robin balancer. If no addresses provided with the option client connects to all IP addresses it can get by host name from WithAddress option. For "unix" network the option is ignored.

func WithWriteInterval

func WithWriteInterval(d time.Duration) Option

WithWriteInterval returns an Option which sets duration after which data from write buffer are sent to network even if write buffer isn't full. Default 50 us.

Jump to

Keyboard shortcuts

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