protocol

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: MIT Imports: 14 Imported by: 5

Documentation

Index

Constants

View Source
const (
	MsgTypeHelo = "HELO"
	MsgTypePing = "PING"
	MsgTypePong = "PONG"
)
View Source
const (
	OptSize       string = "size"
	OptChunk      string = "chunk"
	OptCompressed string = "compressed"
	OptValGZIP    string = "gzip"
)

Variables

This section is empty.

Functions

func GetChunk

func GetChunk(b []byte) (string, error)

GetChunk searches a marshaled message for the "chunk" option value and returns it. The chunk can be used for ack checks without the overhead of unmarshalling. GetChunk returns an error if no value is found.

func ValidatePingDigest

func ValidatePingDigest(p *Ping, key, nonce []byte) error

ValidatePingDigest validates that the digest contained in the PING message is valid for the client hostname (as contained in the PING). Returns a non-nil error if validation fails, nil otherwise.

func ValidatePongDigest

func ValidatePongDigest(p *Pong, key, nonce, salt []byte) error

ValidatePongDigest validates that the digest contained in the PONG message is valid for the server hostname (as contained in the PONG). Returns a non-nil error if validation fails, nil otherwise.

Types

type AckMessage

type AckMessage struct {
	Ack string `msg:"ack"`
}

func (*AckMessage) DecodeMsg

func (z *AckMessage) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (AckMessage) EncodeMsg

func (z AckMessage) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (AckMessage) MarshalMsg

func (z AckMessage) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (AckMessage) Msgsize

func (z AckMessage) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*AckMessage) UnmarshalMsg

func (z *AckMessage) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type ChunkEncoder

type ChunkEncoder interface {
	Chunk() (string, error)
	EncodeMsg(*msgp.Writer) error
}

ChunkEncoder wraps methods to encode a message and generate "chunk" IDs for use with Fluent's chunk-ack protocol. See https://github.com/fluent/fluentd/wiki/Forward-Protocol-Specification-v1#response for more information.

type ChunkReader

type ChunkReader struct {
	R *msgp.Reader
	// contains filtered or unexported fields
}

func (*ChunkReader) Reset

func (cr *ChunkReader) Reset(b []byte)

type Entry

type Entry struct {
	// Timestamp can contain the timestamp in either seconds or nanoseconds
	Timestamp int64
	// Record is the actual event record.
	Record interface{}
}

EntryExt is the basic representation of an individual event. The timestamp is an int64 representing seconds since the epoch (UTC). The initial creator of the entry is responsible for converting to UTC.

func (*Entry) DecodeMsg

func (z *Entry) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Entry) EncodeMsg

func (z Entry) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Entry) MarshalMsg

func (z Entry) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Entry) Msgsize

func (z Entry) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Entry) UnmarshalMsg

func (z *Entry) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type EntryExt

type EntryExt struct {
	// Timestamp can contain the timestamp in either seconds or nanoseconds
	Timestamp EventTime `msg:"eventTime,extension"`
	// Record is the actual event record. The object must be a map or
	// struct. Objects that implement the msgp.Encodable interface will
	// be the most performant.
	Record interface{}
}

EntryExt is the basic representation of an individual event, but using the msgpack extension format for the timestamp.

func (*EntryExt) DecodeMsg

func (z *EntryExt) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (EntryExt) EncodeMsg

func (z EntryExt) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (EntryExt) MarshalMsg

func (z EntryExt) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (EntryExt) Msgsize

func (z EntryExt) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*EntryExt) UnmarshalMsg

func (z *EntryExt) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type EntryList

type EntryList []EntryExt

func (*EntryList) DecodeMsg

func (z *EntryList) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (EntryList) EncodeMsg

func (z EntryList) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (EntryList) Equal

func (el EntryList) Equal(e2 EntryList) bool

Equal compares two EntryList objects and returns true if they have exactly the same elements, false otherwise.

func (EntryList) MarshalMsg

func (z EntryList) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (EntryList) MarshalPacked

func (el EntryList) MarshalPacked() ([]byte, error)

func (EntryList) Msgsize

func (z EntryList) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*EntryList) UnmarshalMsg

func (z *EntryList) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*EntryList) UnmarshalPacked

func (el *EntryList) UnmarshalPacked(bits []byte) ([]byte, error)

type EventTime

type EventTime struct {
	time.Time
}

EventTime is the fluent-forward representation of a timestamp

func EventTimeNow

func EventTimeNow() EventTime

EventTimeNow returns an EventTime set to time.Now().UTC().

func (*EventTime) DecodeMsg

func (z *EventTime) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (EventTime) EncodeMsg

func (z EventTime) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*EventTime) ExtensionType

func (et *EventTime) ExtensionType() int8

func (*EventTime) Len

func (et *EventTime) Len() int

func (*EventTime) MarshalBinaryTo

func (et *EventTime) MarshalBinaryTo(b []byte) error

MarshalBinaryTo implements the Extension interface for marshaling an EventTime into a byte slice.

func (EventTime) MarshalMsg

func (z EventTime) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (EventTime) Msgsize

func (z EventTime) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*EventTime) UnmarshalBinary

func (et *EventTime) UnmarshalBinary(timeBytes []byte) error

UnmarshalBinary implements the Extension interface for unmarshaling into an EventTime object.

func (*EventTime) UnmarshalMsg

func (z *EventTime) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type ForwardMessage

type ForwardMessage struct {
	// Tag is a dot-delimted string used to categorize events
	Tag string
	// Entries is the set of event objects to be carried in this message
	Entries EntryList
	// Options - used to control server behavior.  Same as above, may need to
	// switch to interface{} or similar at some point.
	Options *MessageOptions
}

ForwardMessage is used in Forward mode to send multiple events in a single msgpack array within a single request.

func NewForwardMessage

func NewForwardMessage(
	tag string,
	entries EntryList,
) *ForwardMessage

NewForwardMessage creates a ForwardMessage from the supplied tag, EntryList, and MessageOptions. this function will set Options.Size to the length of the entry list.

func (*ForwardMessage) Chunk

func (fm *ForwardMessage) Chunk() (string, error)

func (*ForwardMessage) DecodeMsg

func (fm *ForwardMessage) DecodeMsg(dc *msgp.Reader) error

func (*ForwardMessage) EncodeMsg

func (fm *ForwardMessage) EncodeMsg(dc *msgp.Writer) error

func (*ForwardMessage) MarshalMsg

func (fm *ForwardMessage) MarshalMsg(bits []byte) ([]byte, error)

func (*ForwardMessage) Msgsize

func (fm *ForwardMessage) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*ForwardMessage) UnmarshalMsg

func (fm *ForwardMessage) UnmarshalMsg(bits []byte) ([]byte, error)

type GzipCompressor

type GzipCompressor struct {
	Buffer     *bytes.Buffer
	GzipWriter *gzip.Writer
}

func (*GzipCompressor) Bytes

func (mc *GzipCompressor) Bytes() []byte

Bytes returns the gzip-compressed byte stream.

func (*GzipCompressor) Reset

func (mc *GzipCompressor) Reset()

Reset resets the buffer to be empty, but it retains the underlying storage for use by future writes.

func (*GzipCompressor) Write

func (mc *GzipCompressor) Write(bits []byte) error

Write writes to the compression stream.

type Helo

type Helo struct {
	MessageType string
	Options     *HeloOpts
}

Helo is the initial handshake message, sent by the server and received by the client. Client will respond with a Ping.

func NewHelo

func NewHelo(opts *HeloOpts) *Helo

NewHelo returns a Helo message with the specified options. if opts is nil, then a nonce is generated, auth is left empty, and keepalive is true.

func (*Helo) DecodeMsg

func (z *Helo) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Helo) EncodeMsg

func (z *Helo) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Helo) MarshalMsg

func (z *Helo) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Helo) Msgsize

func (z *Helo) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Helo) UnmarshalMsg

func (z *Helo) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type HeloOpts

type HeloOpts struct {
	Nonce     []byte `msg:"nonce"`
	Auth      []byte `msg:"auth"`
	Keepalive bool   `msg:"keepalive"`
}

func (*HeloOpts) DecodeMsg

func (z *HeloOpts) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*HeloOpts) EncodeMsg

func (z *HeloOpts) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*HeloOpts) MarshalMsg

func (z *HeloOpts) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*HeloOpts) Msgsize

func (z *HeloOpts) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*HeloOpts) UnmarshalMsg

func (z *HeloOpts) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Message

type Message struct {
	// Tag is a dot-delimited string used to categorize events
	Tag       string
	Timestamp int64
	Record    interface{}
	// Options - used to control server behavior.
	Options *MessageOptions
}

Message is used to send a single event at a time

func NewMessage

func NewMessage(
	tag string,
	record interface{},
) *Message

NewMessage creates a Message from the supplied tag and record. The record object must be a map or struct. Objects that implement the msgp.Encodable interface will be the most performant. Timestamp is set to time.Now().UTC() and marshaled with second precision.

func (*Message) Chunk

func (msg *Message) Chunk() (string, error)

func (*Message) DecodeMsg

func (msg *Message) DecodeMsg(dc *msgp.Reader) error

func (*Message) EncodeMsg

func (z *Message) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Message) MarshalMsg

func (z *Message) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Message) Msgsize

func (msg *Message) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Message) UnmarshalMsg

func (msg *Message) UnmarshalMsg(bits []byte) ([]byte, error)

type MessageExt

type MessageExt struct {
	Tag       string
	Timestamp EventTime `msg:"eventTime,extension"`
	Record    interface{}
	Options   *MessageOptions
}

MessageExt

func NewMessageExt

func NewMessageExt(
	tag string,
	record interface{},
) *MessageExt

NewMessageExt creates a MessageExt from the supplied tag and record. The record object must be a map or struct. Objects that implement the msgp.Encodable interface will be the most performant. Timestamp is set to time.Now().UTC() and marshaled with subsecond precision.

func (*MessageExt) Chunk

func (msg *MessageExt) Chunk() (string, error)

func (*MessageExt) DecodeMsg

func (msg *MessageExt) DecodeMsg(dc *msgp.Reader) error

func (*MessageExt) EncodeMsg

func (z *MessageExt) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*MessageExt) MarshalMsg

func (z *MessageExt) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*MessageExt) Msgsize

func (msg *MessageExt) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*MessageExt) UnmarshalMsg

func (msg *MessageExt) UnmarshalMsg(bits []byte) ([]byte, error)

type MessageOptions

type MessageOptions struct {
	Size       *int   `msg:"size,omitempty"`
	Chunk      string `msg:"chunk,omitempty"`
	Compressed string `msg:"compressed,omitempty"`
}

func (*MessageOptions) DecodeMsg

func (z *MessageOptions) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*MessageOptions) EncodeMsg

func (z *MessageOptions) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*MessageOptions) MarshalMsg

func (z *MessageOptions) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*MessageOptions) Msgsize

func (z *MessageOptions) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*MessageOptions) UnmarshalMsg

func (z *MessageOptions) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type PackedForwardMessage

type PackedForwardMessage struct {
	// Tag is a dot-delimited string used to categorize events
	Tag string
	// EventStream is the set of events (entries in Fluent-speak) serialized
	// into a msgpack byte stream
	EventStream []byte
	// Options - used to control server behavior.  Same as above, may need to
	// switch to interface{} or similar at some point.
	Options *MessageOptions
}

PackedForwardMessage is just like ForwardMessage, except that the events are carried as a msgpack binary stream

func NewCompressedPackedForwardMessage

func NewCompressedPackedForwardMessage(
	tag string, entries []EntryExt,
) (*PackedForwardMessage, error)

NewCompressedPackedForwardMessage returns a PackedForwardMessage with a gzip-compressed byte stream.

func NewCompressedPackedForwardMessageFromBytes

func NewCompressedPackedForwardMessageFromBytes(
	tag string, entries []byte,
) (*PackedForwardMessage, error)

NewCompressedPackedForwardMessageFromBytes returns a PackedForwardMessage with a gzip-compressed byte stream.

func NewPackedForwardMessage

func NewPackedForwardMessage(
	tag string,
	entries EntryList,
) (*PackedForwardMessage, error)

NewPackedForwardMessage creates a PackedForwardMessage from the supplied tag, EntryList, and MessageOptions. Regardless of the options supplied, this function will set Options.Size to the length of the entry list.

func NewPackedForwardMessageFromBytes

func NewPackedForwardMessageFromBytes(
	tag string,
	entries []byte,
) *PackedForwardMessage

NewPackedForwardMessageFromBytes creates a PackedForwardMessage from the supplied tag, bytes, and MessageOptions. This function does not set Options.Size to the length of the entry list.

func (*PackedForwardMessage) Chunk

func (msg *PackedForwardMessage) Chunk() (string, error)

func (*PackedForwardMessage) DecodeMsg

func (msg *PackedForwardMessage) DecodeMsg(dc *msgp.Reader) error

func (*PackedForwardMessage) EncodeMsg

func (z *PackedForwardMessage) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*PackedForwardMessage) MarshalMsg

func (z *PackedForwardMessage) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*PackedForwardMessage) Msgsize

func (msg *PackedForwardMessage) Msgsize() (s int)

func (*PackedForwardMessage) UnmarshalMsg

func (msg *PackedForwardMessage) UnmarshalMsg(bits []byte) ([]byte, error)

type Ping

type Ping struct {
	MessageType        string
	ClientHostname     string
	SharedKeySalt      []byte
	SharedKeyHexDigest string
	Username           string
	Password           string
}

Ping is the response message sent by the client after receiving a Helo from the server. Server will respond with a Pong.

func NewPing

func NewPing(hostname string, sharedKey, salt, nonce []byte) (*Ping, error)

NewPing returns a PING message. The digest is computed from the hostname, key, salt, and nonce using SHA512.

func NewPingWithAuth

func NewPingWithAuth(hostname string, sharedKey, salt, nonce []byte, username, password string) (*Ping, error)

NewPingWithAuth returns a PING message containing the username and password to be used for authentication. The digest is computed from the hostname, key, salt, and nonce using SHA512.

func (*Ping) DecodeMsg

func (z *Ping) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Ping) EncodeMsg

func (z *Ping) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Ping) MarshalMsg

func (z *Ping) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Ping) Msgsize

func (z *Ping) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Ping) UnmarshalMsg

func (z *Ping) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Pong

type Pong struct {
	MessageType        string
	AuthResult         bool
	Reason             string
	ServerHostname     string
	SharedKeyHexDigest string
}

Pong is the response message sent by the server after receiving a Ping from the client. A Pong concludes the handshake.

func NewPong

func NewPong(authResult bool, reason string, hostname string, sharedKey []byte,
	helo *Helo, ping *Ping) (*Pong, error)

NewPong returns a PONG message. AuthResult indicates whether the credentials presented by the client were accepted and therefore whether the client can continue using the connection, switching from handshake mode to sending events. As with the PING, the digest is computed from the hostname, key, salt, and nonce using SHA512. Server implementations must use the nonce created for the initial Helo and the salt sent by the client in the Ping.

func (*Pong) DecodeMsg

func (z *Pong) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Pong) EncodeMsg

func (z *Pong) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Pong) MarshalMsg

func (z *Pong) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Pong) Msgsize

func (z *Pong) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Pong) UnmarshalMsg

func (z *Pong) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type RawMessage

type RawMessage []byte

RawMessage is a ChunkEncoder wrapper for []byte.

func (RawMessage) Chunk

func (rm RawMessage) Chunk() (string, error)

Chunk searches the message for the chunk ID. In the case of RawMessage, Chunk is read-only. It returns an error if the chunk is not found.

func (*RawMessage) DecodeMsg

func (z *RawMessage) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (RawMessage) EncodeMsg

func (rm RawMessage) EncodeMsg(w *msgp.Writer) error

func (RawMessage) MarshalMsg

func (z RawMessage) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (RawMessage) Msgsize

func (z RawMessage) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*RawMessage) UnmarshalMsg

func (z *RawMessage) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

Jump to

Keyboard shortcuts

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