relay

package
v0.0.0-...-2d91164 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OFF if the relay is created but not used
	OFF = RelayMode("")

	// PassThrough describes the mode in which, requests are accepted and forwarded on to a handler relay
	PassThrough = RelayMode("passthrough")

	// Handler mode is when the relay is accepting requests and processing the requests as if they came in from an HTTP server
	Handler = RelayMode("handle")
)
View Source
const RelayerPing = "Relayer.Ping"

Rpc call handle

View Source
const RelayerRelayRequest = "Relayer.RelayRequest"

Rpc call handle

Variables

This section is empty.

Functions

This section is empty.

Types

type FauxRequest

type FauxRequest struct {
	Method           string
	URL              *url.URL
	Proto            string // "HTTP/1.0"
	ProtoMajor       int    // 1
	ProtoMinor       int    // 0
	Header           http.Header
	Body             []byte // io.ReadCloser
	ContentLength    int64
	TransferEncoding []string
	Host             string
	Form             url.Values
}

FauxRequest is the same as an http.Request, but since we can't send an io.Reader The body is a pre-read byte array

func CreateFauxRequest

func CreateFauxRequest(req *http.Request, body []byte) *FauxRequest

func (*FauxRequest) Request

func (f *FauxRequest) Request() *http.Request

Request turns the FauxRequest into an *http.Request

type Relay

type Relay struct {
	Host      string
	Port      int
	WhiteList *regexp.Regexp
	Mode      RelayMode
	Debug     bool
	// contains filtered or unexported fields
}

Relay

func NewRelay

func NewRelay(host string, port int, whitelist string, mode RelayMode, conf *tls.Config) *Relay

func (*Relay) AddrAllowed

func (r *Relay) AddrAllowed(addr net.Addr) bool

AddrAllowed takes an address and returns whether that address is allowed by Relay's whitelist Only invoked when the relay is in Passthrough mode, and discards the port

func (*Relay) Close

func (r *Relay) Close()

Close

func (*Relay) Connect

func (r *Relay) Connect()

Connect makes an outgoing request to connected to a listening Relay

func (*Relay) HandleFunc

func (r *Relay) HandleFunc(path string, f func(http.ResponseWriter, *http.Request)) *mux.Route

HandleFunc should be used in place of *Router.HandleFunc, to register handlers to accept relayed events.

func (*Relay) Init

func (r *Relay) Init() error

Init is used to initialize the relay

func (*Relay) LastPingTime

func (r *Relay) LastPingTime() time.Time

func (*Relay) Listen

func (r *Relay) Listen() error

Listen opens the configured port and accepts a single tcp connection, if the connection drops this will start listening again for another connection.

func (*Relay) RelayHandler

func (r *Relay) RelayHandler(w http.ResponseWriter, req *http.Request)

RelayHandler takes the place of an actual handler to glue an existing http server to the Relay invoking this handler will forward the request directly to a relay in handle mode

func (*Relay) SetCheckInterval

func (r *Relay) SetCheckInterval(duration time.Duration)

func (*Relay) SetDebug

func (r *Relay) SetDebug(b bool)

func (*Relay) Status

func (r *Relay) Status() RelayStatus

Status create and return a RelayStatus for the current status

type RelayMode

type RelayMode string

RelayMode describes the supported modes a Relay can be in

func (RelayMode) String

func (r RelayMode) String() string

type RelayStatus

type RelayStatus struct {
	Health          health.State `json:"health"`
	Mode            string       `json:"mode"`
	LastPingTime    int64        `json:"lastPingTime,omitempty"`
	Connected       bool         `json:"isConnected"`
	ConnectTime     int64        `json:"connectTime,omitempty"`
	ConnectCount    int64        `json:"connectCount,omitempty"`
	RpcCount        int64        `json:"rpcCount,omitempty"`
	RpcsCounter     interface{}  `json:"rpcsCounter,omitempty"`
	ConnectCounter  interface{}  `json:"connectCounter,omitempty"`
	RpcLatencySecs  interface{}  `json:"rpcLatencySecs,omitempty"`
	PingLatencySecs interface{}  `json:"pingLatencySecs,omitempty"`
}

RelayStatus describes the health of the relay

type Relayer

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

Relayer is an internal object specifically for relaying requests via rpc. it must be exported to enable registering as an rpc

func (*Relayer) Ping

func (r *Relayer) Ping(t time.Time, recv *string) error

Ping is used to check if the Relay is still isConnected

func (*Relayer) RelayRequest

func (r *Relayer) RelayRequest(req FauxRequest, response *Response) error

RelayRequest calls a local handler with a relayed request, this should only be called by the RelayHandler, the method signature should not change as it is required to satisfy the rpc.Register receiver input

type Response

type Response struct {
	Status int
	Body   []byte
}

Response is a container that encapsulates a response from a relayed request

func (*Response) Header

func (r *Response) Header() http.Header

func (*Response) Read

func (r *Response) Read(p []byte) (int, error)

func (*Response) Write

func (r *Response) Write(b []byte) (int, error)

func (*Response) WriteHeader

func (r *Response) WriteHeader(statusCode int)

Jump to

Keyboard shortcuts

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