zedcloud

package
v0.0.0-...-7f3d85a Latest Latest
Warning

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

Go to latest
Published: May 2, 2019 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package httpproxy provides support for HTTP proxy determination based on environment variables, as provided by net/http's ProxyFromEnvironment function.

The API is not subject to the Go 1 compatibility promise and may change at any time. package httpproxy

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDeferred

func AddDeferred(key string, buf *bytes.Buffer, size int64, url string,
	zedcloudCtx ZedCloudContext, return400 bool)

Add to slice for this key

func Append

func Append(cms metricsMap, cms1 metricsMap) metricsMap

Concatenate different interfaces and URLs into a union map

func CastCloudMetrics

func CastCloudMetrics(in interface{}) metricsMap

XXX this works but ugly as ... Alternative seems to be a deep walk with type assertions in order to produce the map of map of map with the correct type.

func GetCloudMetrics

func GetCloudMetrics() metricsMap

func GetTlsConfig

func GetTlsConfig(serverName string, clientCert *tls.Certificate) (*tls.Config, error)

If a server arg is specified it overrides the serverFilename content. If a clientCert is specified it overrides the device*Name files.

func HandleDeferred

func HandleDeferred(event time.Time, spacing time.Duration) bool

Try to send all deferred items. Give up if any one fails Stop timer if map becomes empty Returns true when there are no more deferred items

func HasDeferred

func HasDeferred(key string) bool

Check if there are any deferred items for this key

func InitDeferred

func InitDeferred() <-chan time.Time

Create and return a channel to the caller

func LookupProxy

func LookupProxy(status *types.DeviceNetworkStatus, ifname string,
	rawUrl string) (*url.URL, error)

func RemoveDeferred

func RemoveDeferred(key string)

Remove any item for the specific key. If no items left then stop timer.

func SendOnAllIntf

func SendOnAllIntf(ctx ZedCloudContext, url string, reqlen int64, b *bytes.Buffer, iteration int, return400 bool) (*http.Response, []byte, error)

Tries all interfaces (free first) until one succeeds. interation arg ensure load spreading across multiple interfaces. Returns response for first success. Caller can not use resp.Body but can use []byte contents return.

func SendOnIntf

func SendOnIntf(ctx ZedCloudContext, destUrl string, intf string, reqlen int64, b *bytes.Buffer, allowProxy bool, timeout int) (*http.Response, []byte, error)

Tries all source addresses on interface until one succeeds. Returns response for first success. Caller can not use resp.Body but can use []byte contents return. If we get a http response, we return that even if it was an error to allow the caller to look at StatusCode

func SetDeferred

func SetDeferred(key string, buf *bytes.Buffer, size int64, url string,
	zedcloudCtx ZedCloudContext, return400 bool)

Replace any item for the specified key. If timer not running start it

func VerifyAllIntf

func VerifyAllIntf(ctx ZedCloudContext,
	url string, successCount int, iteration int) (bool, error)

We try with free interfaces first. If we find enough free interfaces through which cloud connectivity can be achieved, we won't test non-free interfaces. Otherwise we test non-free interfaces also.

func ZedCloudFailure

func ZedCloudFailure(ifname string, url string, reqLen int64, respLen int64)

func ZedCloudSuccess

func ZedCloudSuccess(ifname string, url string, reqLen int64, respLen int64)

Types

type Config

type Config struct {
	// HTTPProxy represents the value of the HTTP_PROXY or
	// http_proxy environment variable. It will be used as the proxy
	// URL for HTTP requests and HTTPS requests unless overridden by
	// HTTPSProxy or NoProxy.
	HTTPProxy string

	// HTTPSProxy represents the HTTPS_PROXY or https_proxy
	// environment variable. It will be used as the proxy URL for
	// HTTPS requests unless overridden by NoProxy.
	HTTPSProxy string

	// NoProxy represents the NO_PROXY or no_proxy environment
	// variable. It specifies a string that contains comma-separated values
	// specifying hosts that should be excluded from proxying. Each value is
	// represented by an IP address prefix (1.2.3.4), an IP address prefix in
	// CIDR notation (1.2.3.4/8), a domain name, or a special DNS label (*).
	// An IP address prefix and domain name can also include a literal port
	// number (1.2.3.4:80).
	// A domain name matches that name and all subdomains. A domain name with
	// a leading "." matches subdomains only. For example "foo.com" matches
	// "foo.com" and "bar.foo.com"; ".y.com" matches "x.y.com" but not "y.com".
	// A single asterisk (*) indicates that no proxying should be done.
	// A best effort is made to parse the string and errors are
	// ignored.
	NoProxy string

	// CGI holds whether the current process is running
	// as a CGI handler (FromEnvironment infers this from the
	// presence of a REQUEST_METHOD environment variable).
	// When this is set, ProxyForURL will return an error
	// when HTTPProxy applies, because a client could be
	// setting HTTP_PROXY maliciously. See https://golang.org/s/cgihttpproxy.
	CGI bool
}

Config holds configuration for HTTP proxy settings. See FromEnvironment for details.

func (*Config) ProxyFunc

func (cfg *Config) ProxyFunc() func(reqURL *url.URL) (*url.URL, error)

ProxyFunc returns a function that determines the proxy URL to use for a given request URL. Changing the contents of cfg will not affect proxy functions created earlier.

A nil URL and nil error are returned if no proxy is defined in the environment, or a proxy should not be used for the given request, as defined by NO_PROXY.

As a special case, if req.URL.Host is "localhost" (with or without a port number), then a nil URL and nil error will be returned.

type DeferredContext

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

Some day we might return this; right now only for the defaultCtx

type WSConnection

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

WSConnection represents a single websocket connection

type WSTunnelClient

type WSTunnelClient struct {
	TunnelServerName string            // hostname[:port] string representation of remote tunnel server
	Tunnel           string            // websocket server to connect to (ws[s]://hostname[:port])
	DestURL          string            // formatted websocket endpoint URL
	LocalRelayServer string            // local server to send received requests to
	Timeout          time.Duration     // timeout on websocket
	Connected        bool              // true when we have an active connection to remote server
	Dialer           *websocket.Dialer // dialer connection initialized & tested for success
	// contains filtered or unexported fields
}

WSTunnelClient represents a persistent tunnel that can cycle through many websockets. The conn field points to the latest websocket, but it's important to realize that there may be goroutines handling older websockets that are not fully closed yet running at any point in time

func InitializeTunnelClient

func InitializeTunnelClient(serverName string, localRelay string) *WSTunnelClient

InitializeTunnelClient returns a websocket tunnel client configured with the requested remote and local servers.

func (*WSTunnelClient) Start

func (t *WSTunnelClient) Start()

Start triggers workflow to establish the websocket session with remote tunnel server

func (*WSTunnelClient) Stop

func (t *WSTunnelClient) Stop()

Stop tunnel client

func (*WSTunnelClient) TestConnection

func (t *WSTunnelClient) TestConnection(proxyURL *url.URL, localAddr net.IP) error

TestConnection validates the configured parameters for correctness and further attempts an actual connection request to confirm if the client can successfully connect to remote backend server.

type ZedCloudContext

type ZedCloudContext struct {
	DeviceNetworkStatus *types.DeviceNetworkStatus
	TlsConfig           *tls.Config
	FailureFunc         func(intf string, url string, reqLen int64, respLen int64)
	SuccessFunc         func(intf string, url string, reqLen int64, respLen int64)
	NoLedManager        bool // Don't call UpdateLedManagerConfig
}

XXX should we add some Init() function to create this? Currently caller fills it in.

Jump to

Keyboard shortcuts

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