protocol

package
v0.20.9 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: Apache-2.0 Imports: 17 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SendJSONMessage

func SendJSONMessage(msgType MessageType, msg string, ws Connection) error

SendJSONMessage writes a single NDT message in JSON format.

func SendMetrics

func SendMetrics(metrics interface{}, m Messager, prefix string) error

SendMetrics sends all the required properties out along the NDT control channel.

func UUIDToFile

func UUIDToFile(dir, uuid string) (*os.File, error)

UUIDToFile converts a UUID into a newly-created open file with the extension '.json'.

func WriteTLVMessage

func WriteTLVMessage(ws Connection, msgType MessageType, message string) error

WriteTLVMessage write a single NDT message to the connection.

Types

type Connection

type Connection interface {
	ReadMessage() (_ int, p []byte, err error) // The first value in the returned tuple should be ignored. It is included in the API for websocket.Conn compatibility.
	ReadBytes() (count int64, err error)
	WriteMessage(messageType int, data []byte) error
	FillUntil(t time.Time, buffer []byte) (bytesWritten int64, err error)
	ServerIPAndPort() (string, int)
	ClientIPAndPort() (string, int)
	Close() error
	UUID() string
	String() string
	Messager() Messager
}

Connection is a general system over which we might be able to read an NDT message. It contains a subset of the methods of websocket.Conn, in order to allow non-websocket-based NDT tests in support of plain TCP clients.

type Encoding

type Encoding int

Encoding encodes the communication methods we support.

const (
	Unknown Encoding = iota // Unknown is the zero-value for Encoding
	JSON
	TLV
)

The different message types we support. This is initially Unknown for plain ndt5 connections and becomes JSON or TLV depending on the whether we receive MsgLogin or MsgExtendedLogin, but is always JSON for WS and WSS.

func (Encoding) Messager

func (e Encoding) Messager(conn Connection) Messager

Messager creates an object that can encode and decode messages in the corresponding format and send them along the passed-in connection.

func (Encoding) String

func (e Encoding) String() string

type JSONMessage

type JSONMessage struct {
	Msg   string `json:"msg"`
	Tests string `json:"tests,omitempty"`
}

JSONMessage holds the JSON messages we can receive from the server. We only support the subset of the NDT JSON protocol that has two fields: msg, and tests.

func ReceiveJSONMessage

func ReceiveJSONMessage(ws Connection, expectedType MessageType) (*JSONMessage, error)

ReceiveJSONMessage reads a single NDT message in JSON format.

func (*JSONMessage) String

func (n *JSONMessage) String() string

String serializes the message to a string.

type Measurable

type Measurable interface {
	StartMeasuring(ctx context.Context)
	StopMeasuring() (*web100.Metrics, error)
}

Measurable things can be measured over a given timeframe.

type MeasuredConnection

type MeasuredConnection interface {
	Connection
	Measurable
}

MeasuredConnection is a connection which can also be measured.

func AdaptWsConn

func AdaptWsConn(ws *websocket.Conn) MeasuredConnection

AdaptWsConn turns a websocket Connection into a struct which implements both Measurer and Connection

type MeasuredFlexibleConnection

type MeasuredFlexibleConnection interface {
	MeasuredConnection
	SetEncoding(Encoding)
}

MeasuredFlexibleConnection allows a MeasuredConnection to switch between TLV or JSON encoding.

func AdaptNetConn

func AdaptNetConn(conn net.Conn, input io.Reader) MeasuredFlexibleConnection

AdaptNetConn turns a non-WS-based TCP connection into a protocol.MeasuredConnection that can have its encoding set on the fly.

type MessageType

type MessageType byte

MessageType is the full set opf NDT protocol messages we understand.

const (
	// MsgUnknown is the zero-value of MessageType and it is the message type to
	// return under error conditions or when the message is malformed.
	MsgUnknown MessageType = iota
	// SrvQueue signals how long a client should wait.
	SrvQueue
	// MsgLogin is used for signalling capabilities.
	MsgLogin
	// TestPrepare indicates that the server is getting ready to run a test.
	TestPrepare
	// TestStart indicates prepapartion is complete and the test is about to run.
	TestStart
	// TestMsg is used for communication during a test.
	TestMsg
	// TestFinalize is the last message a test sends.
	TestFinalize
	// MsgError is sent when an error occurs.
	MsgError
	// MsgResults sends test results.
	MsgResults
	// MsgLogout is used to logout.
	MsgLogout
	// MsgWaiting is used for queue management.
	MsgWaiting
	// MsgExtendedLogin is used to signal advanced capabilities.
	MsgExtendedLogin
)

func ReadTLVMessage

func ReadTLVMessage(ws Connection, expectedTypes ...MessageType) ([]byte, MessageType, error)

ReadTLVMessage reads a single NDT message out of the connection.

func (MessageType) String

func (m MessageType) String() string

type Messager

type Messager interface {
	SendMessage(MessageType, []byte) error
	SendS2CResults(throughputKbps, unsentBytes, totalSentBytes int64) error
	ReceiveMessage(MessageType) ([]byte, error)
	Encoding() Encoding
}

Messager allows us to send JSON and non-JSON messages using a single unified interface.

Jump to

Keyboard shortcuts

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