buffer

package
v0.0.0-...-00e7cc2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2018 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ErrDisconnectNoDataMessage is a signal that the remote peer terminated the connection and sent no data
	ErrDisconnectNoDataMessage = "peer disconnected prior to sending data"
	// ErrHealthCheckMessage is a signal that the remote peer sent no data but did not terminate the connection
	ErrHealthCheckMessage = "health check errors should be ignored"
	// ErrCipherAuthenticationFailed is returned when the cipher on hand is not valid for the received message.
	ErrCipherAuthenticationFailed = "cipher: message authentication failed"
)
View Source
const BufferSizeBytes = 512

BufferSizeBytes is the number of

Variables

View Source
var LittleEndian littleEndian

LittleEndian encapsulates read methods that assume a LittleEndian byte order for the length prefix.

Functions

func IsCrawler

func IsCrawler(bytes []byte) bool

IsCrawler returns a boolean indicating whether the byte array is from a crawler based on a heuristic looking for patterns

func NewErrDisconnectNoData

func NewErrDisconnectNoData() errors.TracerError

NewErrDisconnectNoData is a signal that the remote peer terminated the connection and sent no data

func NewErrHealthCheck

func NewErrHealthCheck() errors.TracerError

NewErrHealthCheck is a signal that the remote peer sent no data

func NewNetworkError

func NewNetworkError(err error, connectionInfo string) errors.TracerError

NewNetworkError with the passed base error and connection info.

func NewReadOnClosedError

func NewReadOnClosedError() errors.TracerError

NewReadOnClosedError instantiates a ReadOnClosedError with a stack trace

func NewTimeoutError

func NewTimeoutError(operation string, bytes int) error

NewTimeoutError with the passed operation and bytes that were acted upon prior to the timeout.

func NewWriteOnClosedError

func NewWriteOnClosedError() errors.TracerError

NewWriteOnClosedError instantiates a WriteOnClosedError with a stack trace

func Read

func Read(readable io.Reader) ([]byte, error)

Read a readable instance by filling a buffer of constant size until less bytes are read than requested. Returns all byte concatenated together with non-read bytes truncated. NOTE: This function DOES return io.EOF errors which will always terminate the read AFTER the EOF, i.e. read bytes will still be appended when the EOF is returned.

func Write

func Write(writable io.Writer, data []byte) (err error)

Write of the complete contents of data over the passed Writable.

Types

type Connection

type Connection interface {
	// Read and unmarshal into the passed MarshalUnmarshal from the connection.
	Read(mu MarshalUnmarshal) (err errors.TracerError)
	// Write the passed MarshalUnmarshal to the connection.
	Write(mu MarshalUnmarshal) errors.TracerError
	// Close this connection. Once closed this connection cannot be used further.
	Close() errors.TracerError
	// Closed returns a bool indicating that the underlying connection is closed.
	Closed() bool
	// GetConnection that is backing this abstraction.
	GetConnection() net.Conn
	// GetConnectionInfo in string format.
	GetConnectionInfo() string
}

Connection allows for two way exchange of messages.

func NewConnection

func NewConnection(conn net.Conn, prefixRead bool, readTimeout time.Duration, writeTimeout time.Duration) Connection

NewConnection using the passed network connection.

type MarshalError

type MarshalError struct {
	BaseError errors.TracerError
	// contains filtered or unexported fields
}

MarshalError is a marker for triggering logic based upon errors that occur during the marshal/unmarshal routines.

func NewMarshalError

func NewMarshalError(err error) *MarshalError

NewMarshalError with the passed base error

func NewMarshalErrorf

func NewMarshalErrorf(fmt string, arg ...interface{}) *MarshalError

NewMarshalErrorf from the passed format string and arguments

func (*MarshalError) Error

func (err *MarshalError) Error() string

func (*MarshalError) Trace

func (err *MarshalError) Trace() []string

Trace the stack for this errors base error.

type MarshalUnmarshal

type MarshalUnmarshal interface {
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
}

MarshalUnmarshal indicates a struct that can be marshalled to bytes and Unmarshalled from bytes.

type MockConnection

type MockConnection struct {
	ReadMessages  collection.Stack
	ReadFunc      func(mu MarshalUnmarshal) error
	WriteMessages collection.Stack
	WriteError    error
	IsClosed      bool
}

MockConnection is used for testing

func NewMockConnection

func NewMockConnection() *MockConnection

NewMockConnection returns a MockConnection

func (*MockConnection) Close

func (conn *MockConnection) Close() errors.TracerError

Close sets IsClosed to true on the MockConnection

func (*MockConnection) Closed

func (conn *MockConnection) Closed() bool

Closed sets the MockConnection IsClosed to true

func (*MockConnection) GetConnection

func (conn *MockConnection) GetConnection() net.Conn

GetConnection is a no-op

func (*MockConnection) GetConnectionInfo

func (conn *MockConnection) GetConnectionInfo() string

GetConnectionInfo is always blank for the mock connection

func (*MockConnection) Read

Read either uses the ReadFunc or pops a message from the ReadMessages stack

func (*MockConnection) Write

Write pushed the message into a Stack and returns the WriteError on the MockConnection

type NetworkError

type NetworkError struct {
	BaseError      errors.TracerError
	ConnectionInfo string
	// contains filtered or unexported fields
}

NetworkError includes connection info.

func (*NetworkError) Error

func (err *NetworkError) Error() string

func (*NetworkError) Trace

func (err *NetworkError) Trace() []string

Trace the stack for this errors base error.

type ReadOnClosedError

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

ReadOnClosedError is returned when an attempt to read is made on a nil connection.

func (*ReadOnClosedError) Error

func (err *ReadOnClosedError) Error() string

func (*ReadOnClosedError) Trace

func (err *ReadOnClosedError) Trace() []string

Trace returns the stack trace for the error

type TimeoutError

type TimeoutError struct {
	Operation string
	Bytes     int
	// contains filtered or unexported fields
}

TimeoutError is returned when an operation on the connection occurs.

func (*TimeoutError) Error

func (err *TimeoutError) Error() string

Error message string for this error

func (*TimeoutError) Trace

func (err *TimeoutError) Trace() []string

Trace for the error

type WriteOnClosedError

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

WriteOnClosedError is returned when an attempt to write is made on a nil connection.

func (*WriteOnClosedError) Error

func (err *WriteOnClosedError) Error() string

func (*WriteOnClosedError) Trace

func (err *WriteOnClosedError) Trace() []string

Trace returns the stack trace for the error

Jump to

Keyboard shortcuts

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