transport

package
v5.10.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT, MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MessageTypeKeepalive is the message type sent for keepalives--which are just an
	// event without a Check or Metrics section.
	MessageTypeKeepalive = "keepalive"

	// MessageTypeEvent is the message type string for events.
	MessageTypeEvent = "event"

	// HeaderKeyAgentName is the HTTP request header specifying the Agent name
	HeaderKeyAgentName = "Sensu-AgentName"

	// HeaderKeyNamespace is the HTTP request header specifying the Agent Namespace
	HeaderKeyNamespace = "Sensu-Namespace"

	// HeaderKeyUser is the HTTP request header specifying the Agent User
	HeaderKeyUser = "Sensu-User"

	// HeaderKeySubscriptions is the HTTP request header specifying the Agent Subscriptions
	HeaderKeySubscriptions = "Sensu-Subscriptions"
)

Variables

This section is empty.

Functions

func Decode

func Decode(payload []byte) (string, []byte, error)

Decode a message received from a websocket channel.

func Encode

func Encode(msgType string, payload []byte) []byte

Encode a message to be sent over a websocket channel

Types

type ClosedError

type ClosedError struct {
	Message string
}

A ClosedError is returned when Receive or Send is called on a closed Transport.

func (ClosedError) Error

func (e ClosedError) Error() string

type ConnectionError

type ConnectionError struct {
	Message string
}

A ConnectionError is returned when a Transport receives any unexpected error connecting to, sending to, or receiving from a backend.

func (ConnectionError) Error

func (e ConnectionError) Error() string

type Message

type Message struct {
	// Type is the type of the message (event, etc)
	Type string

	// Payload is the serialized message.
	Payload []byte

	// SendCallback is a callback that is executed after a Send operation.
	// The error value of Send is passed to the callback.
	SendCallback func(error)
}

A Message is a tuple of a message type (i.e. channel) and a byte-array payload to be sent across the transport.

func NewMessage

func NewMessage(msgType string, payload []byte) *Message

NewMessage creates a new Message.

type Server

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

Server ...

func NewServer

func NewServer() *Server

NewServer is used to initialize a new Server and return a pointer to it.

func (*Server) Serve

func (s *Server) Serve(w http.ResponseWriter, r *http.Request) (Transport, error)

Serve is used to initialize a websocket connection and returns an pointer to a Transport used to communicate with that client.

type Transport

type Transport interface {
	// Close will cleanly shutdown a sensu transport connection.
	Close() error

	// Closed returns true if the underlying connection is closed.
	Closed() bool

	// Receive is used to receive a message from the transport. It takes a context
	// and blocks until the next message is received from the transport.
	Receive() (*Message, error)

	// Send is used to send a message over the transport. It takes a message type
	// hint and a serialized payload. Send will block until the message has been
	// sent. Send is synchronous, returning nil if the write to the underlying
	// socket was successful and an error otherwise.
	Send(*Message) error
}

The Transport interface defines the set of methods available to a connection between the Sensu backend and agent.

func Connect

func Connect(wsServerURL string, tlsOpts *types.TLSOptions, requestHeader http.Header) (Transport, error)

Connect causes the transport Client to connect to a given websocket backend. This is a thin wrapper around a websocket connection that makes the connection safe for concurrent use by multiple goroutines.

func NewTransport

func NewTransport(conn *websocket.Conn) Transport

NewTransport creates an initialized Transport and return its pointer.

type WebSocketTransport

type WebSocketTransport struct {
	Connection *websocket.Conn
	// contains filtered or unexported fields
}

A WebSocketTransport is a connection between sensu Agents and Backends over WebSocket.

func (*WebSocketTransport) Close

func (t *WebSocketTransport) Close() error

Close attempts to send a "going away" message over the websocket connection. This will cause a Write over the websocket transport, which can cause a panic. We rescue potential panics and consider the connection closed, returning nil, because the connection _will_ be closed. Hay!

func (*WebSocketTransport) Closed

func (t *WebSocketTransport) Closed() bool

Closed returns true if the underlying websocket connection has been closed.

func (*WebSocketTransport) Receive

func (t *WebSocketTransport) Receive() (*Message, error)

Receive a message over the websocket connection. Like Send, returns either a ClosedError or a ConnectionError if unable to receive a message. Receive blocks until the connection has a message ready or a timeout is reached.

func (*WebSocketTransport) Send

func (t *WebSocketTransport) Send(m *Message) (err error)

Send a message over the websocket connection. If the connection has been closed, returns a ClosedError. Returns a ConnectionError if the websocket connection returns an error while sending, but the connection is still open.

Jump to

Keyboard shortcuts

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