Documentation

Index

Constants

View Source
const (
	ListenerAcceptDeadline = 500 * time.Millisecond
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	ClientLookup(context.Context, *tls.CertificateRequestInfo) (*tls.Certificate, error)
	ServerName() string
	CACert(ctx context.Context) *x509.Certificate
}

    Client is used to lookup a client certificate.

    type ClusterHook

    type ClusterHook interface {
    	AddClient(alpn string, client Client)
    	RemoveClient(alpn string)
    	AddHandler(alpn string, handler Handler)
    	StopHandler(alpn string)
    	TLSConfig(ctx context.Context) (*tls.Config, error)
    	Addr() net.Addr
    	GetDialerFunc(ctx context.Context, alpnProto string) func(string, time.Duration) (net.Conn, error)
    }

    type ConnectionInfo

    type ConnectionInfo struct {
    	Node     string
    	Remote   string
    	IsServer bool
    	ALPN     string
    }

    type Handler

    type Handler interface {
    	ServerLookup(context.Context, *tls.ClientHelloInfo) (*tls.Certificate, error)
    	CALookup(context.Context) ([]*x509.Certificate, error)
    
    	// Handoff is used to pass the connection lifetime off to
    	// the handler
    	Handoff(context.Context, *sync.WaitGroup, chan struct{}, *tls.Conn) error
    	Stop() error
    }

      Handler exposes functions for looking up TLS configuration and handing off a connection for a cluster listener application.

      type InmemLayer

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

        InmemLayer is an in-memory implementation of NetworkLayer. This is primarially useful for tests.

        func NewInmemLayer

        func NewInmemLayer(addr string, logger log.Logger) *InmemLayer

          NewInmemLayer returns a new in-memory layer configured to listen on the provided address.

          func (*InmemLayer) Addrs

          func (l *InmemLayer) Addrs() []net.Addr

            Addrs implements NetworkLayer.

            func (*InmemLayer) Close

            func (l *InmemLayer) Close() error

              Close is used to permanently disable the transport

              func (*InmemLayer) Connect

              func (l *InmemLayer) Connect(remote *InmemLayer)

                Connect is used to connect this transport to another transport for a given peer name. This allows for local routing.

                func (*InmemLayer) Dial

                func (l *InmemLayer) Dial(addr string, timeout time.Duration, tlsConfig *tls.Config) (*tls.Conn, error)

                  Dial implements NetworkLayer.

                  func (*InmemLayer) Disconnect

                  func (l *InmemLayer) Disconnect(peer string)

                    Disconnect is used to remove the ability to route to a given peer.

                    func (*InmemLayer) DisconnectAll

                    func (l *InmemLayer) DisconnectAll()

                      DisconnectAll is used to remove all routes to peers.

                      func (*InmemLayer) Listeners

                      func (l *InmemLayer) Listeners() []NetworkListener

                        Listeners implements NetworkLayer.

                        func (*InmemLayer) SetConnectionCh

                        func (l *InmemLayer) SetConnectionCh(ch chan *ConnectionInfo)

                        func (*InmemLayer) SetReaderDelay

                        func (l *InmemLayer) SetReaderDelay(delay time.Duration)

                        type InmemLayerCluster

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

                          InmemLayerCluster composes a set of layers and handles connecting them all together. It also satisfies the NetworkLayerSet interface.

                          func NewInmemLayerCluster

                          func NewInmemLayerCluster(clusterName string, nodes int, logger log.Logger) (*InmemLayerCluster, error)

                            NewInmemLayerCluster returns a new in-memory layer set that builds n nodes and connects them all together.

                            func (*InmemLayerCluster) ConnectCluster

                            func (ic *InmemLayerCluster) ConnectCluster(remote *InmemLayerCluster)

                              ConnectCluster connects this cluster with the provided remote cluster, connecting all nodes to each other.

                              func (*InmemLayerCluster) Layers

                              func (ic *InmemLayerCluster) Layers() []NetworkLayer

                                Layers implements the NetworkLayerSet interface.

                                func (*InmemLayerCluster) SetConnectionCh

                                func (ic *InmemLayerCluster) SetConnectionCh(ch chan *ConnectionInfo)

                                func (*InmemLayerCluster) SetReaderDelay

                                func (ic *InmemLayerCluster) SetReaderDelay(delay time.Duration)

                                type Listener

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

                                  Listener is the source of truth for cluster handlers and connection clients. It dynamically builds the cluster TLS information. It's also responsible for starting tcp listeners and accepting new cluster connections.

                                  func NewListener

                                  func NewListener(networkLayer NetworkLayer, cipherSuites []uint16, logger log.Logger, idleTimeout time.Duration) *Listener

                                  func (*Listener) AddClient

                                  func (cl *Listener) AddClient(alpn string, client Client)

                                    AddClient adds a new client for an ALPN name

                                    func (*Listener) AddHandler

                                    func (cl *Listener) AddHandler(alpn string, handler Handler)

                                      AddHandler registers a new cluster handler for the provided ALPN name.

                                      func (*Listener) Addr

                                      func (cl *Listener) Addr() net.Addr

                                      func (*Listener) Addrs

                                      func (cl *Listener) Addrs() []net.Addr

                                      func (*Listener) GetDialerFunc

                                      func (cl *Listener) GetDialerFunc(ctx context.Context, alpn string) func(string, time.Duration) (net.Conn, error)

                                        GetDialerFunc returns a function that looks up the TLS information for the provided alpn name and calls the network layer's dial function.

                                        func (*Listener) Handler

                                        func (cl *Listener) Handler(alpn string) (Handler, bool)

                                          Handler returns the handler for the provided ALPN name

                                          func (*Listener) RemoveClient

                                          func (cl *Listener) RemoveClient(alpn string)

                                            RemoveClient removes the client for the specified ALPN name

                                            func (*Listener) Run

                                            func (cl *Listener) Run(ctx context.Context) error

                                              Run starts the tcp listeners and will accept connections until stop is called. This function blocks so should be called in a goroutine.

                                              func (*Listener) Server

                                              func (cl *Listener) Server() *http2.Server

                                                Server returns the http2 server that the cluster listener is using

                                                func (*Listener) SetAdvertiseAddr

                                                func (cl *Listener) SetAdvertiseAddr(addr string) error

                                                func (*Listener) Stop

                                                func (cl *Listener) Stop()

                                                  Stop stops the cluster listener

                                                  func (*Listener) StopHandler

                                                  func (cl *Listener) StopHandler(alpn string)

                                                    StopHandler stops the cluster handler for the provided ALPN name, it also calls stop on the handler.

                                                    func (*Listener) TLSConfig

                                                    func (cl *Listener) TLSConfig(ctx context.Context) (*tls.Config, error)

                                                      TLSConfig returns a tls config object that uses dynamic lookups to correctly authenticate registered handlers/clients

                                                      type NetAddr

                                                      type NetAddr struct {
                                                      	Host string
                                                      }

                                                      func (*NetAddr) Network

                                                      func (*NetAddr) Network() string

                                                      func (*NetAddr) String

                                                      func (c *NetAddr) String() string

                                                      type NetworkLayer

                                                      type NetworkLayer interface {
                                                      	Addrs() []net.Addr
                                                      	Listeners() []NetworkListener
                                                      	Dial(address string, timeout time.Duration, tlsConfig *tls.Config) (*tls.Conn, error)
                                                      	Close() error
                                                      }

                                                        NetworkLayer is the network abstraction used in the cluster listener. Abstracting the network layer out allows us to swap the underlying implementations for tests.

                                                        type NetworkLayerSet

                                                        type NetworkLayerSet interface {
                                                        	Layers() []NetworkLayer
                                                        }

                                                          NetworkLayerSet is used for returning a slice of layers to a caller.

                                                          type NetworkListener

                                                          type NetworkListener interface {
                                                          	net.Listener
                                                          
                                                          	SetDeadline(t time.Time) error
                                                          }

                                                            NetworkListener is used by the network layer to define a net.Listener for use in the cluster listener.

                                                            type TCPLayer

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

                                                              TCPLayer implements the NetworkLayer interface and uses TCP as the underlying network.

                                                              func NewTCPLayer

                                                              func NewTCPLayer(addrs []*net.TCPAddr, logger log.Logger) *TCPLayer

                                                                NewTCPLayer returns a TCPLayer.

                                                                func (*TCPLayer) Addrs

                                                                func (l *TCPLayer) Addrs() []net.Addr

                                                                  Addrs implements NetworkLayer.

                                                                  func (*TCPLayer) Close

                                                                  func (l *TCPLayer) Close() error

                                                                    Close implements the NetworkLayer interface.

                                                                    func (*TCPLayer) Dial

                                                                    func (l *TCPLayer) Dial(address string, timeout time.Duration, tlsConfig *tls.Config) (*tls.Conn, error)

                                                                      Dial implements the NetworkLayer interface.

                                                                      func (*TCPLayer) Listeners

                                                                      func (l *TCPLayer) Listeners() []NetworkListener

                                                                        Listeners implements NetworkLayer. It starts a new TCP listener for each configured address.