backend

package
v0.0.0-...-4bb11d9 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2018 License: Apache-2.0, MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HostWithoutPort

func HostWithoutPort(s string) string

HostWithoutPort extracts a hostname from an request, omitting any ":PORT" portion, if present. This is the value from the "Host:" header in HTTP1, or the ":authority" header in HTTP2.

func MatchHeaders

func MatchHeaders(fromReq, fromDB map[string]string) bool

MatchHeaders compares headers from an HTTP2 request to values in our database.

func RetrieveServerKeys

func RetrieveServerKeys(db *storm.DB) (curvetls.Pubkey, curvetls.Privkey, error)

RetrieveServerKeys gets the curvetls public key for our co-chair instance's api. Clients will need to know the server's public key.

Types

type BackendData

type BackendData struct {
	ID     int    `storm:"id,increment"`
	Domain string `storm:"unique"`
	IPs    []string
	// An optional endpoint we can call, expecting HTTP 200
	HealthCheck string
	// one of HTTP1, HTTP2, GRPC
	Protocol server.Backend_Protocol
	// Our TLS certs and keys.
	BackendCert, BackendKey []byte
	// Headers to match on during backend selection when we first
	// get a connection.
	MatchHeaders map[string]string
}

BackendData is our type for the storm ORM. We can define field-level constraints and indexes on struct tags. It is unfortunate that we need an intermediary type, but it seems better than going in and adding storm struct tags to protobuf-generated code.

See issue: https://github.com/golang/protobuf/issues/52

func (BackendData) AsBackend

func (bd BackendData) AsBackend() *server.Backend

AsBackend is a conversion method to a grpc-sendable type.

type KeyPair

type KeyPair struct {
	Name string `storm:"unique,id"`
	// Pub and Priv are base64 strings that represent curvetls keys
	// for servers or clients.
	Pub  string
	Priv string
}

KeyPair is a database type that represents curvetls key pairs. A KeyPair must be in the database for each pure grpc client that wants to connect. Not used for grpc websocket clients. We rely on HTTPS for those.

type Opt

type Opt func(*TCPForwarder)

An Opt lets us set values on a TCPForwarder.

func WithAddr

func WithAddr(addr string) Opt

WithAddr sets the ip:port our TCPForwarder will listen on. Has no effect if used in conjunction with WithListener.

func WithDB

func WithDB(db *storm.DB) Opt

WithDB sets a *storm.DB directly on our TCPForwarder.

func WithDBPath

func WithDBPath(path string) Opt

WithDBPath opens a DB at path and sets it on our TCPForwarder.

func WithListener

func WithListener(l net.Listener) Opt

WithListener sets our TCPForwarder's net.Listener.

func WithLogger

func WithLogger(logger *logrus.Logger) Opt

WithLogger sets our logger.

func WithProxyClient

func WithProxyClient(pc server.ProxyClient) Opt

WithProxyClient sets our grpc server.ProxyClient.

type Proxy

type Proxy struct {
	DB *storm.DB
	// contains filtered or unexported fields
}

Proxy is our server.ProxyServer implementation.

func NewProxy

func NewProxy(path string) (*Proxy, error)

NewProxy is our constructor for the server.ProxyServer implementation.

func (*Proxy) GetKVStream

func (p *Proxy) GetKVStream(key *server.Key, stream server.Proxy_GetKVStreamServer) error

GetKVStream scans a keyspace.

func (*Proxy) Put

func (p *Proxy) Put(ctx context.Context, b *server.Backend) (*server.OpResult, error)

Put adds a backend to our pool of proxied Backends.

func (*Proxy) PutKVStream

func (p *Proxy) PutKVStream(stream server.Proxy_PutKVStreamServer) error

PutKVStream lets us stream key-value pairs into our db.

func (*Proxy) Remove

func (p *Proxy) Remove(_ context.Context, b *server.Backend) (*server.OpResult, error)

Remove ...

func (*Proxy) State

State returns the state of the proxy. The number of backends returned is controlled by the domain field of the request. A blank domain returns all.

type StormKeystore

type StormKeystore struct {
	DB *storm.DB
}

func (*StormKeystore) Allowed

func (sk *StormKeystore) Allowed(pubkey curvetls.Pubkey) bool

type TCPForwarder

type TCPForwarder struct {
	C server.ProxyClient
	L net.Listener

	DB   *storm.DB
	Addr string
	// contains filtered or unexported fields
}

TCPForwarder is our actual listener type that clients will connect to. This implementation then inspects the requests that come in on connections, and selects an appropriate backend by talking gRPC to a Proxy instance via C, its embedded server.ProxyClient.

func NewTCPForwarder

func NewTCPForwarder(opts ...Opt) (*TCPForwarder, error)

NewTCPForwarder constructs a TCPForwarder from a variable list of options. Passing a database (either by pass or by reference) is required or the TCPForwarder will fail at runtime.

func NewTCPForwarderFromGRPCClient

func NewTCPForwarderFromGRPCClient(l net.Listener, pc server.ProxyClient, db *storm.DB, logger *logrus.Logger) *TCPForwarder

NewTCPForwarderFromGRPCClient ...

func (*TCPForwarder) DialAndTunnel

func (f *TCPForwarder) DialAndTunnel(bd *BackendData, buffered *bytes.Buffer, conn net.Conn) error

DialAndTunnel connects to the passed in backend, and tunnels traffic to it and from it.

func (*TCPForwarder) GetCertificate

func (f *TCPForwarder) GetCertificate(hi *tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificate fetches tls.Certificate from the database for each connection. This lets us dynamically fetch certs.

func (*TCPForwarder) Start

func (f *TCPForwarder) Start() error

Start accepts TCP connections.

func (*TCPForwarder) Stop

func (f *TCPForwarder) Stop() error

Stop ...

type TimedRecord

type TimedRecord struct {
	TS   []byte
	Data trace.Record
}

type Tunnel

type Tunnel struct {
	ErrorState error
	ErrorSig   chan error
}

A Tunnel streams data between two conns.

Jump to

Keyboard shortcuts

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