protocol

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 11 Imported by: 5

Documentation

Overview

Package protocol implements the VelocyStream protocol (it is not intended to be used directly).

Index

Constants

View Source
const (
	DefaultIdleConnTimeout = time.Minute
	DefaultConnLimit       = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

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

Connection is a single socket connection to a server.

func (*Connection) Close

func (c *Connection) Close() error

Close the connection to the server

func (*Connection) IsClosed

func (c *Connection) IsClosed() bool

IsClosed returns true when the connection is closed, false otherwise.

func (*Connection) IsConfigured

func (c *Connection) IsConfigured() bool

IsConfigured returns true when the configuration callback has finished on this connection, without errors.

func (*Connection) IsIdle

func (c *Connection) IsIdle(idleTimeout time.Duration) bool

IsIdle returns true when the last activity was more than the given timeout ago.

func (*Connection) Send

func (c *Connection) Send(ctx context.Context, messageParts ...[]byte) (<-chan Message, error)

Send sends a message (consisting of given parts) to the server and returns a channel on which the response will be delivered. When the connection is closed before a response was received, the returned channel will be closed.

type Message

type Message struct {
	ID   uint64
	Data []byte
	// contains filtered or unexported fields
}

Message is what is send back to the client in response to a request.

type Transport

type Transport struct {
	TransportConfig
	// contains filtered or unexported fields
}

Transport manages client-server connections using the VST protocol to a specific host.

func NewTransport

func NewTransport(hostAddr string, tlsConfig *tls.Config, config TransportConfig) *Transport

NewTransport creates a new Transport for given address & tls settings.

func (*Transport) CloseAllConnections

func (c *Transport) CloseAllConnections()

CloseAllConnections closes all connections.

func (*Transport) CloseIdleConnections

func (c *Transport) CloseIdleConnections() (closed, remaining int)

CloseIdleConnections closes all connections which are closed or have been idle for more than the configured idle timeout.

func (*Transport) Send

func (c *Transport) Send(ctx context.Context, messageParts ...[]byte) (<-chan Message, error)

Send sends a message (consisting of given parts) to the server and returns a channel on which the response will be delivered. When the connection is closed before a response was received, the returned channel will be closed.

func (*Transport) SetOnConnectionCreated

func (c *Transport) SetOnConnectionCreated(handler func(context.Context, *Connection) error)

SetOnConnectionCreated stores a callback function that is called every time a new connection has been created.

type TransportConfig

type TransportConfig struct {
	// IdleConnTimeout is the maximum amount of time an idle
	// (keep-alive) connection will remain idle before closing
	// itself.
	// Zero means no limit.
	IdleConnTimeout time.Duration

	// ConnLimit is the upper limit to the number of connections to a single server.
	// Due to the nature of the VST protocol, this value does not have to be high.
	// The default is 3 (DefaultConnLimit).
	ConnLimit int

	// Version specifies the version of the Velocystream protocol
	Version Version
}

TransportConfig contains configuration options for Transport.

type Version

type Version int

Version indicates the version of the Velocystream protocol

const (
	Version1_0 Version = iota // VST 1.0
	Version1_1                // VST 1.1
)

Jump to

Keyboard shortcuts

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