client

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTLSDialFuncNotProvided = errors.New("a TLSDialFunc must be provided in secure mode")

ErrTLSDailFuncNotProvided is returned by NewClient if secure is True but no TLSDailFunc is provided.

Functions

func AsyncSubscription added in v0.2.0

func AsyncSubscription(ctx context.Context, broker *Client, hm EventHandler, eh ErrorHandler)

AsyncSubscription runs the message handling loop given an EventHandler and optional ErrorHandler.

func IsNormalWebsocketClose

func IsNormalWebsocketClose(err error) bool

IsNormalWebsocketClose returns true if err indicates a normal EOF close of the websocket.

Types

type Client

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

Client is a basic websocket client for publishing/subscribing to events via the Zeek broker websocket API.

func NewClient

func NewClient(ctx context.Context, hostPort string, secure bool,
	tlsDialFunc TLSDialFunc, topics []string) (*Client, error)

NewClient constructs a new websocket client to connect to the endpoint specified, subscribing to topics (which may be an empty list). If secure is False, then TLS must be turned off for the broker websocket server in zeek (using "redef Broker::disable_ssl = T;"). If secure is True, then a TLS dial function agument (tlsDialFunc) must be provided. For the default broker configuration (which disables TLS verification), use weirdtls.BrokerDefaultTLSDialer. When broker is configured with certificates, the securetls.MakeSecureDialer() function returns a dialer function that uses a provided CA and client certificate/key that is loaded from PEM files. The dial function may be nil if secure is False (if not nil, it will be ignored).

func (*Client) Close

func (c *Client) Close() error

Close closes the underlying websocket connection.

func (*Client) PublishEvent

func (c *Client) PublishEvent(topic string, evt encoding.Event) error

PublishEvent publishes an event to the topic provided.

func (*Client) ReadEvent

func (c *Client) ReadEvent() (topic string, evt encoding.Event, retErr error)

ReadEvent reads a single event from broker, and returns the topic and event, or an error (including errors received from broker itself). The Client instance must be created with the list topic subscriptions.

func (*Client) RemoteEndpointInfo

func (c *Client) RemoteEndpointInfo() (uuid string, version string)

RemoteEndpointInfo returns the broker remote endpoint UUID and version received in the initial handshake when the websocket connection is established.

type ErrorHandler added in v0.2.0

type ErrorHandler func(err error)

type EventHandler added in v0.2.0

type EventHandler func(topic string, event encoding.Event)

type TLSDialFunc added in v0.2.0

type TLSDialFunc func(ctx context.Context, network, addr string) (net.Conn, error)

TLSDialFunc is a type alias for the function that us used by NewClient to make a TLS connection when connecting to an HTTPS websocket (wss scheme) broker server.

Jump to

Keyboard shortcuts

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