{"modulePath":"github.phpd.cn/openshift/origin","version":"v1.5.1","isLatest":false,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package userspace\n\n## Variables\n\n```go\nvar (\n\tErrMissingServiceEntry = errors.New(\"missing service entry\")\n\tErrMissingEndpoints    = errors.New(\"missing endpoints\")\n)\n```\n\n```go\nvar EndpointDialTimeout = []time.Duration{250 * time.Millisecond, 500 * time.Millisecond, 1 * time.Second, 2 * time.Second}\n```\nHow long we wait for a connection to a backend in seconds\n\n```go\nvar (\n\t// ErrProxyOnLocalhost is returned by NewProxier if the user requests a proxier on\n\t// the loopback address. May be checked for by callers of NewProxier to know whether\n\t// the caller provided invalid input.\n\tErrProxyOnLocalhost = fmt.Errorf(\"cannot proxy on localhost\")\n)\n```\n\n## Functions\n\n```go\nfunc CleanupLeftovers(ipt iptables.Interface) (encounteredError bool)\n```\nCleanupLeftovers removes all iptables rules and chains created by the Proxier It returns true if an error was encountered. Errors are logged.\n\n```go\nfunc IsProxyLocked(err error) bool\n```\nIsProxyLocked returns true if the proxy could not acquire the lock on iptables.\n\n```go\nfunc ProxyTCP(in, out *net.TCPConn)\n```\nproxyTCP proxies data bi-directionally between in and out.\n\n```go\nfunc TryConnectEndpoints(service proxy.ServicePortName, srcAddr net.Addr, protocol string, loadBalancer LoadBalancer) (net.Conn, error)\n```\nTryConnectEndpoints attempts to connect to the next available endpoint for the given service, cycling through until it is able to successfully connect, or it has tried with all timeouts in EndpointsDialTimeout.\n\n## Types\n\n```go\ntype ClientCache struct {\n\tsync.Mutex\n\tClients map[string]net.Conn // addr string -\u003e connection\n}\n```\nHolds all the known UDP clients that have not timed out.\n\n```go\ntype LoadBalancer interface {\n\t// NextEndpoint returns the endpoint to handle a request for the given\n\t// service-port and source address.\n\tNextEndpoint(service proxy.ServicePortName, srcAddr net.Addr, sessionAffinityReset bool) (string, error)\n\tNewService(service proxy.ServicePortName, sessionAffinityType api.ServiceAffinity, stickyMaxAgeMinutes int) error\n\tCleanupStaleStickySessions(service proxy.ServicePortName)\n\tServiceHasEndpoints(service proxy.ServicePortName) bool\n}\n```\nLoadBalancer is an interface for distributing incoming requests to service endpoints.\n\n```go\ntype LoadBalancerRR struct {\n\t// contains filtered or unexported fields\n}\n```\nLoadBalancerRR is a round-robin load balancer.\n\n```go\nfunc NewLoadBalancerRR() *LoadBalancerRR\n```\nNewLoadBalancerRR returns a new LoadBalancerRR.\n\n```go\nfunc (lb *LoadBalancerRR) CleanupStaleStickySessions(svcPort proxy.ServicePortName)\n```\n\n```go\nfunc (lb *LoadBalancerRR) NewService(svcPort proxy.ServicePortName, affinityType api.ServiceAffinity, ttlMinutes int) error\n```\n\n```go\nfunc (lb *LoadBalancerRR) NextEndpoint(svcPort proxy.ServicePortName, srcAddr net.Addr, sessionAffinityReset bool) (string, error)\n```\nNextEndpoint returns a service endpoint. The service endpoint is chosen using the round-robin algorithm.\n\n```go\nfunc (lb *LoadBalancerRR) OnEndpointsUpdate(allEndpoints []api.Endpoints)\n```\nOnEndpointsUpdate manages the registered service endpoints. Registered endpoints are updated if found in the update set or unregistered if missing from the update set.\n\n```go\nfunc (lb *LoadBalancerRR) ServiceHasEndpoints(svcPort proxy.ServicePortName) bool\n```\nServiceHasEndpoints checks whether a service entry has endpoints.\n\n```go\ntype PortAllocator interface {\n\tAllocateNext() (int, error)\n\tRelease(int)\n}\n```\n\n```go\ntype Proxier struct {\n\t// contains filtered or unexported fields\n}\n```\nProxier is a simple proxy for TCP connections between a localhost:lport and services that provide the actual implementations.\n\n```go\nfunc NewCustomProxier(loadBalancer LoadBalancer, listenIP net.IP, iptables iptables.Interface, exec utilexec.Interface, pr utilnet.PortRange, syncPeriod, udpIdleTimeout time.Duration, makeProxySocket ProxySocketFunc) (*Proxier, error)\n```\nNewCustomProxier functions similarly to NewProxier, returing a new Proxier for the given LadBalancer and address.  The new proxier is constructed using the ProxySocket constructor provided, however, instead of constructing the default ProxySockets.\n\n```go\nfunc NewProxier(loadBalancer LoadBalancer, listenIP net.IP, iptables iptables.Interface, exec utilexec.Interface, pr utilnet.PortRange, syncPeriod, udpIdleTimeout time.Duration) (*Proxier, error)\n```\nNewProxier returns a new Proxier given a LoadBalancer and an address on which to listen.  Because of the iptables logic, It is assumed that there is only a single Proxier active on a machine. An error will be returned if the proxier cannot be started due to an invalid ListenIP (loopback) or if iptables fails to update or acquire the initial lock. Once a proxier is created, it will keep iptables up to date in the background and will not terminate if a particular iptables call fails.\n\n```go\nfunc (proxier *Proxier) OnServiceUpdate(services []api.Service)\n```\nOnServiceUpdate manages the active set of service proxies. Active service proxies are reinitialized if found in the update set or shutdown if missing from the update set.\n\n```go\nfunc (proxier *Proxier) Sync()\n```\nSync is called to immediately synchronize the proxier state to iptables\n\n```go\nfunc (proxier *Proxier) SyncLoop()\n```\nSyncLoop runs periodic work.  This is expected to run as a goroutine or as the main loop of the app.  It does not return.\n\n```go\ntype ProxySocket interface {\n\t// Addr gets the net.Addr for a ProxySocket.\n\tAddr() net.Addr\n\t// Close stops the ProxySocket from accepting incoming connections.\n\t// Each implementation should comment on the impact of calling Close\n\t// while sessions are active.\n\tClose() error\n\t// ProxyLoop proxies incoming connections for the specified service to the service endpoints.\n\tProxyLoop(service proxy.ServicePortName, info *ServiceInfo, loadBalancer LoadBalancer)\n\t// ListenPort returns the host port that the ProxySocket is listening on\n\tListenPort() int\n}\n```\nAbstraction over TCP/UDP sockets which are proxied.\n\n```go\nfunc NewProxySocket(protocol api.Protocol, ip net.IP, port int) (ProxySocket, error)\n```\n\n```go\ntype ProxySocketFunc func(protocol api.Protocol, ip net.IP, port int) (ProxySocket, error)\n```\nProxySocketFunc is a function which constructs a ProxySocket from a protocol, ip, and port\n\n```go\ntype ServiceInfo struct {\n\tTimeout       time.Duration\n\tActiveClients *ClientCache\n\tServiceRef    api.ObjectReference\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (info *ServiceInfo) IsAlive() bool\n```\n\n","path":"github.phpd.cn/openshift/origin/pkg/proxy/userspace","name":"userspace","synopsis":"","isRedistributable":true}
