Documentation
¶
Overview ¶
Package transport implements various HTTP transport utilities based on Go net package.
Package transport provides network utility functions, complementing the more common ones in the net package.
Index ¶
- Variables
- func IsClosedConnError(err error) bool
- func LimitListener(l net.Listener, n int) net.Listener
- func NewKeepAliveListener(l net.Listener, scheme string, tlscfg *tls.Config) (net.Listener, error)
- func NewListener(addr, scheme string, tlsinfo *TLSInfo) (l net.Listener, err error)
- func NewTLSListener(l net.Listener, tlsinfo *TLSInfo) (net.Listener, error)
- func NewTimeoutListener(addr string, scheme string, tlsinfo *TLSInfo, ...) (net.Listener, error)
- func NewTimeoutTransport(info TLSInfo, dialtimeoutd, rdtimeoutd, wtimeoutd time.Duration) (*http.Transport, error)
- func NewTransport(info TLSInfo, dialtimeoutd time.Duration) (*http.Transport, error)
- func NewUnixListener(addr string) (net.Listener, error)
- func ValidateSecureEndpoints(tlsInfo TLSInfo, eps []string) ([]string, error)
- type Proxy
- type ProxyConfig
- type TLSInfo
Constants ¶
This section is empty.
Variables ¶
var (
ErrNotTCP = errors.New("only tcp connections have keepalive")
)
Functions ¶
func IsClosedConnError ¶
IsClosedConnError returns true if the error is from closing listener, cmux. copied from golang.org/x/net/http2/http2.go
func LimitListener ¶
LimitListener returns a Listener that accepts at most n simultaneous connections from the provided Listener.
func NewKeepAliveListener ¶
NewKeepAliveListener returns a listener that listens on the given address. Be careful when wrap around KeepAliveListener with another Listener if TLSInfo is not nil. Some pkgs (like go/http) might expect Listener to return TLSConn type to start TLS handshake. http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html
func NewListener ¶
func NewTLSListener ¶
NewTLSListener handshakes TLS connections and performs optional CRL checking.
func NewTimeoutListener ¶
func NewTimeoutListener(addr string, scheme string, tlsinfo *TLSInfo, rdtimeoutd, wtimeoutd time.Duration) (net.Listener, error)
NewTimeoutListener returns a listener that listens on the given address. If read/write on the accepted connection blocks longer than its time limit, it will return timeout error.
func NewTimeoutTransport ¶
func NewTimeoutTransport(info TLSInfo, dialtimeoutd, rdtimeoutd, wtimeoutd time.Duration) (*http.Transport, error)
NewTimeoutTransport returns a transport created using the given TLS info. If read/write on the created connection blocks longer than its time limit, it will return timeout error. If read/write timeout is set, transport will not be able to reuse connection.
func NewTransport ¶
Types ¶
type Proxy ¶
type Proxy interface {
// From returns proxy source address in "scheme://host:port" format.
From() string
// To returns proxy destination address in "scheme://host:port" format.
To() string
// Ready returns when proxy is ready to serve.
Ready() <-chan struct{}
// Done returns when proxy has been closed.
Done() <-chan struct{}
// Error sends errors while serving proxy.
Error() <-chan error
// Close closes listener and transport.
Close() error
// DelayAccept adds latency ± random variable to accepting new incoming connections.
DelayAccept(latency, rv time.Duration)
// UndelayAccept removes sending latencies.
UndelayAccept()
// LatencyAccept returns current latency on accepting new incoming connections.
LatencyAccept() time.Duration
// DelayTx adds latency ± random variable to "sending" layer.
DelayTx(latency, rv time.Duration)
// UndelayTx removes sending latencies.
UndelayTx()
// LatencyTx returns current send latency.
LatencyTx() time.Duration
// DelayRx adds latency ± random variable to "receiving" layer.
DelayRx(latency, rv time.Duration)
// UndelayRx removes "receiving" latencies.
UndelayRx()
// LatencyRx returns current receive latency.
LatencyRx() time.Duration
// PauseAccept stops accepting new connections.
PauseAccept()
// UnpauseAccept removes pause operation on accepting new connections.
UnpauseAccept()
// PauseTx stops "forwarding" packets.
PauseTx()
// UnpauseTx removes "forwarding" pause operation.
UnpauseTx()
// PauseRx stops "receiving" packets to client.
PauseRx()
// UnpauseRx removes "receiving" pause operation.
UnpauseRx()
// BlackholeTx drops all incoming packets before "forwarding".
BlackholeTx()
// UnblackholeTx removes blackhole operation on "sending".
UnblackholeTx()
// BlackholeRx drops all incoming packets to client.
BlackholeRx()
// UnblackholeRx removes blackhole operation on "receiving".
UnblackholeRx()
// CorruptTx corrupts incoming packets from the listener.
CorruptTx(f func(data []byte) []byte)
// UncorruptTx removes corrupt operation on "forwarding".
UncorruptTx()
// CorruptRx corrupts incoming packets to client.
CorruptRx(f func(data []byte) []byte)
// UncorruptRx removes corrupt operation on "receiving".
UncorruptRx()
// ResetListener closes and restarts listener.
ResetListener() error
}
Proxy defines proxy layer that simulates common network faults, such as latency spikes, packet drop/corruption, etc..
func NewProxy ¶
func NewProxy(cfg ProxyConfig) Proxy
NewProxy returns a proxy implementation with no iptables/tc dependencies. The proxy layer overhead is <1ms.
type ProxyConfig ¶
type ProxyConfig struct {
From url.URL
To url.URL
TLSInfo TLSInfo
DialTimeout time.Duration
BufferSize int
RetryInterval time.Duration
Logger grpclog.LoggerV2
}
ProxyConfig defines proxy configuration.
type TLSInfo ¶
type TLSInfo struct {
CertFile string
KeyFile string
CAFile string // TODO: deprecate this in v4
TrustedCAFile string
ClientCertAuth bool
CRLFile string
InsecureSkipVerify bool
// ServerName ensures the cert matches the given host in case of discovery / virtual hosting
ServerName string
// HandshakeFailure is optionally called when a connection fails to handshake. The
// connection will be closed immediately afterwards.
HandshakeFailure func(*tls.Conn, error)
// AllowedCN is a CN which must be provided by a client.
AllowedCN string
// contains filtered or unexported fields
}
func (TLSInfo) ClientConfig ¶
ClientConfig generates a tls.Config object for use by an HTTP client.
func (TLSInfo) ServerConfig ¶
ServerConfig generates a tls.Config object for use by an HTTP server.