Documentation ¶
Index ¶
- Constants
- Variables
- func IsCrawler(bytes []byte) bool
- func NewErrDisconnectNoData() errors.TracerError
- func NewErrHealthCheck() errors.TracerError
- func NewNetworkError(err error, connectionInfo string) errors.TracerError
- func NewReadOnClosedError() errors.TracerError
- func NewTimeoutError(operation string, bytes int) error
- func NewWriteOnClosedError() errors.TracerError
- func Read(readable io.Reader) ([]byte, error)
- func Write(writable io.Writer, data []byte) (err error)
- type Connection
- type MarshalError
- type MarshalUnmarshal
- type MockConnection
- func (conn *MockConnection) Close() errors.TracerError
- func (conn *MockConnection) Closed() bool
- func (conn *MockConnection) GetConnection() net.Conn
- func (conn *MockConnection) GetConnectionInfo() string
- func (conn *MockConnection) Read(mu MarshalUnmarshal) errors.TracerError
- func (conn *MockConnection) Write(mu MarshalUnmarshal) errors.TracerError
- type NetworkError
- type ReadOnClosedError
- type TimeoutError
- type WriteOnClosedError
Constants ¶
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" )
const BufferSizeBytes = 512
BufferSizeBytes is the number of
Variables ¶
var LittleEndian littleEndian
LittleEndian encapsulates read methods that assume a LittleEndian byte order for the length prefix.
Functions ¶
func IsCrawler ¶
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 ¶
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 ¶
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.
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 ¶
func (conn *MockConnection) Read(mu MarshalUnmarshal) errors.TracerError
Read either uses the ReadFunc or pops a message from the ReadMessages stack
func (*MockConnection) Write ¶
func (conn *MockConnection) Write(mu MarshalUnmarshal) errors.TracerError
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 ¶
TimeoutError is returned when an operation on the connection occurs.
func (*TimeoutError) Error ¶
func (err *TimeoutError) Error() string
Error message string for this 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