zephyr

package module
v0.0.0-...-932a267 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2018 License: Apache-2.0 Imports: 14 Imported by: 5

Documentation

Overview

Package zephyr provides a Go zephyr protocol implementation.

The Session API provides a high-level interface to the protocol and is one most users will likely use. The Dial functions create Sessions with default non-mock parameters and system-default parameters.

More specialized clients can use the lower-level Connection API which allows for more specialized handling of ACKs and message reassembly while implementing server discovery and retransmit schedule. There are also even lower-level notice-parsing functions for even lower-level clients.

Index

Constants

View Source
const (
	ProtocolVersionMajor = 0
	ProtocolVersionMinor = 2
)

ProtocolVersionMajor and ProtocolVersionMinor are the version of the zephyr protocol implemented by this library.

View Source
const MaxMessageBodyLength = 400000

MaxMessageBodyLength is the maximum length of a reassembled message body.

View Source
const MaxPacketLength = 1024

MaxPacketLength is the maximum size of a zephyr notice on the wire.

View Source
const WildcardInstance = "*"

WildcardInstance is the instance value used to subscribe to all instances for a given recipient, class pair.

Variables

View Source
var ErrAuthenticatorLengthMismatch = errors.New("authenticator length mismatch")

ErrAuthenticatorLengthMismatch is returned when processing the authenticator on a RawNotice where the authlen field does not match the length of the decoded authenticator.

View Source
var ErrBadField = errors.New("bad field")

ErrBadField is returned if a field is in the wrong format.

View Source
var ErrBadPacketFieldCount = errors.New("bad field count")

ErrBadPacketFieldCount is returned when parsing a packet with a field count that does not match the content.

View Source
var ErrBadPacketFormat = errors.New("bad packet format")

ErrBadPacketFormat is returned when parsing a malformed packet.

View Source
var ErrBadPacketVersion = errors.New("incompatible packet version")

ErrBadPacketVersion is returned when parsing a packet with an incompatible version field.

View Source
var ErrBadVersionFormat = errors.New("bad version format")

ErrBadVersionFormat is returned when a zephyr version field cannot be parsed.

View Source
var ErrBodyFragmentOutOfBounds = errors.New("message fragment out of bounds")

ErrBodyFragmentOutOfBounds is returned if a notice's body is out of bounds of the reassembled message body.

View Source
var ErrBodyLengthMismatch = errors.New("reassembled body length mismatch")

ErrBodyLengthMismatch is returned if a notice's body length field is incompatible the reassembler being used.

View Source
var ErrBodyTooLong = errors.New("reassembled body too long")

ErrBodyTooLong is returned if the reassembled body is too long.

View Source
var ErrInvalidZcode = errors.New("invalid zcode")

ErrInvalidZcode is returned when decoding invalid zcode input.

View Source
var ErrPacketTooLong = errors.New("packet too long")

ErrPacketTooLong is returned when a notice or packet exceeds the maximum Zephyr packet size.

View Source
var ErrSendTimeout = errors.New("send timeout")

ErrSendTimeout is returned if a send times out without acknowledgement from the server.

View Source
var ErrUnknownEncType = errors.New("unknown enctype")

ErrUnknownEncType is returned when attempting to use a key with an unknown enctype.

View Source
var SystemClock systemClock

SystemClock is the real implementation of the Clock interface.

Functions

func DecodeZAscii

func DecodeZAscii(src []byte) ([]byte, error)

DecodeZAscii decodes zephyrascii and returns the decoded result as a byte slice.

func DecodeZAscii16

func DecodeZAscii16(src []byte) (uint16, error)

DecodeZAscii16 decodes the zephyrascii encoding of a 16-bit integer and returns the result as a uint16.

func DecodeZAscii32

func DecodeZAscii32(src []byte) (uint32, error)

DecodeZAscii32 decodes the zephyrascii encoding of a 32-bit integer and returns the result as a uint32.

func DecodeZAsciiInto

func DecodeZAsciiInto(dst, src []byte) (int, error)

DecodeZAsciiInto decodes zephyrascii from src and writes the output into dst. It returns the number of bytes written.

func DecodeZcode

func DecodeZcode(in []byte) ([]byte, error)

DecodeZcode decodes an input byte slice as zcode.

func DecodedZAsciiLength

func DecodedZAsciiLength(n int) int

DecodedZAsciiLength returns the decoded length of a zephyrascii input of length n.

func EncodeMultipart

func EncodeMultipart(part, partof int) string

EncodeMultipart encodes a pair of integers for the multipart field.

func EncodeZAscii

func EncodeZAscii(src []byte) []byte

EncodeZAscii encodes a byte slice as zephyrascii.

func EncodeZAscii16

func EncodeZAscii16(val uint16) []byte

EncodeZAscii16 encodes a 16-bit integer as zephyrascii.

func EncodeZAscii32

func EncodeZAscii32(val uint32) []byte

EncodeZAscii32 encodes a 32-bit integer as zephyrascii.

func EncodeZcode

func EncodeZcode(in []byte) []byte

EncodeZcode encodes an input byte slice as zcode.

func EncodedZAsciiLength

func EncodedZAsciiLength(n int) int

EncodedZAsciiLength returns the length of the zephyrascii encoding of a byte slice of length n.

func ParseMultipart

func ParseMultipart(n *Notice) (int, int)

ParseMultipart parses the multipart field of a notice. It returns the part and partof parts of the field. On parse error, it returns 0 and the length of the body.

func ReadNoticesFromServer

func ReadNoticesFromServer(
	conn net.PacketConn,
	key *krb5.KeyBlock,
) <-chan NoticeReaderResult

ReadNoticesFromServer decodes and authenticates notices sent from the server. Returns a channel containing authenticated notices and errors. The channel is closed on fatal errors. If key is nil, all notices appear as AuthFailed.

func ReadRawNotices

func ReadRawNotices(conn net.PacketConn) <-chan RawReaderResult

ReadRawNotices decodes packets from a PacketConn into RawNotices and returns a stream of them. Non-fatal errors are returned through the stream. On a fatal error or EOF, the channel is closed.

Types

type AuthStatus

type AuthStatus uint32

AuthStatus is the result of authenticating a notice.

const (
	// AuthFailed describes a notice which failed authentication
	// for some reason.
	AuthFailed AuthStatus = 0xffffffff
	// AuthYes describes an authenticated notice.
	AuthYes AuthStatus = 1
	// AuthNo describes a notice which did not claim to be
	// authenticated.
	AuthNo AuthStatus = 0
)

func (AuthStatus) String

func (as AuthStatus) String() string

type Charset

type Charset uint16

A Charset is the value of the "charset" field of a zephyr notice. Note that this field has a number of historical quirks. Only CharsetUTF8 or the byte-swapped version of it are really meaningful.

const (
	CharsetUnknown     Charset = 0x0000
	CharsetISO8859_1   Charset = 0x0004
	CharsetUTF8        Charset = 0x006a
	CharsetUTF8Swapped Charset = 0x6a00
)

The set of Charset values defined as well as one for byte-swapped UTF-8 for compatibility with a zephyr bug.

func (Charset) String

func (cs Charset) String() string

type Clock

type Clock interface {
	Now() time.Time
	After(d time.Duration) <-chan time.Time
}

Clock is a mockable interface for components which involve time.

type Connection

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

A Connection represents a low-level connection to the Zephyr servers. It handles server discovery and sending and receiving Notices. It does not provide high-level constructs like subscribing or message sharding. It also does not automatically send CLIENTACKs.

func NewConnection

func NewConnection(
	conn net.PacketConn,
	server ServerConfig,
	cred *krb5.Credential,
) (*Connection, error)

NewConnection creates a new Connection wrapping a given net.PacketConn. The ServerConfig argument instructs the connection on how to locate the remote servers. The Credential is used to authenticate incoming and outgoing packets. The connection takes ownership of the PacketConn and will close it when Close is called.

func NewConnectionFull

func NewConnectionFull(
	conn net.PacketConn,
	server ServerConfig,
	cred *krb5.Credential,
	clock Clock,
) (*Connection, error)

NewConnectionFull does the same as NewConnection but takes an additional Clock argument for testing.

func (*Connection) Close

func (c *Connection) Close() error

Close closes the underlying connection.

func (*Connection) Credential

func (c *Connection) Credential() *krb5.Credential

Credential returns the credential for this connection.

func (*Connection) LocalAddr

func (c *Connection) LocalAddr() *net.UDPAddr

LocalAddr returns the local UDP address for the client when communicating with the Zephyr servers.

func (*Connection) Notices

func (c *Connection) Notices() <-chan NoticeReaderResult

Notices returns the incoming notices from the connection.

func (*Connection) RefreshServer

func (c *Connection) RefreshServer() ([]*net.UDPAddr, error)

RefreshServer forces a manual refresh of the server schedule from the ServerConfig. This will be called periodically and when outgoing messages time out, so there should be little need to call this manually.

func (*Connection) SendNotice

func (c *Connection) SendNotice(ctx *krb5.Context, n *Notice) (*Notice, error)

SendNotice sends an authenticated notice to the servers. If the notice expects an acknowledgement, it returns the SERVACK or SERVNAK notice from the server on success.

func (*Connection) SendNoticeUnackedTo

func (c *Connection) SendNoticeUnackedTo(n *Notice, addr net.Addr) error

SendNoticeUnackedTo sends an unauthenticated and unacked notice to a given destination. This is used to send a CLIENTACK to a received notice.

func (*Connection) SendNoticeUnauth

func (c *Connection) SendNoticeUnauth(n *Notice) (*Notice, error)

SendNoticeUnauth sends an unauthenticated notice to the servers. If the notice expects an acknowledgement, it returns the SERVACK or SERVNAK notice from the server on success.

func (*Connection) SendPacket

func (c *Connection) SendPacket(pkt []byte, kind Kind, uid UID) (*Notice, error)

SendPacket sends a raw packet to the Zephyr servers. Based on kind and uid, it may wait for an acknowledgement. In that case, the SERVACK or SERVNAK notice will be returned. SendPacket rotates between the server instances and refreshes server list as necessary.

func (*Connection) SendPacketUnackedTo

func (c *Connection) SendPacketUnackedTo(pkt []byte, addr net.Addr) error

SendPacketUnackedTo sends a raw packet to a given destination.

type Header struct {
	Kind          Kind
	UID           UID
	Port          uint16
	Class         string
	Instance      string
	OpCode        string
	Sender        string
	Recipient     string
	DefaultFormat string
	SenderAddress net.IP
	Charset       Charset
	OtherFields   [][]byte
}

A Header is the set of common metadata between a Notice and a reassembled Message.

type Kind

type Kind uint32

A Kind is the first field a zephyr notice.

const (
	// UNSAFE notices are acknowledged by neither the server nor
	// the zhm (in implementations which use one).
	UNSAFE Kind = 0
	// UNACKED notices are not acknowledged by the server.
	UNACKED Kind = 1
	// ACKED notices are acknowledged by the server with a
	// SERVACK.
	ACKED Kind = 2
	// HMACK notices are zhm acknowledgements.
	HMACK Kind = 3
	// HMCTL notices are used in communications between the server
	// and the zhm.
	HMCTL Kind = 4
	// SERVACK notices are acknowledgements from the server that a
	// notice was accepted for delivery.
	SERVACK Kind = 5
	// SERVNAK notices are acknowledgements from the server that a
	// notice was received but not delivered for some reason.
	SERVNAK Kind = 6
	// CLIENTACK notices are sent by the client to acknowledgement
	// a notice from the server.
	CLIENTACK Kind = 7
	// STAT notices are used to request statistics from the zhm.
	STAT Kind = 8
)

func (Kind) ExpectsClientACK

func (k Kind) ExpectsClientACK() bool

ExpectsClientACK returns whether the server expects a client acknowledgement in response to this packet.

func (Kind) ExpectsServerACK

func (k Kind) ExpectsServerACK() bool

ExpectsServerACK returns whether the client expects a server acknowledgement in response to this packet.

func (Kind) IsACK

func (k Kind) IsACK() bool

IsACK returns whether this is a server or client acknowledgement.

func (Kind) IsServerACK

func (k Kind) IsServerACK() bool

IsServerACK returns whether this is a SERVACK or SERVNAK.

func (Kind) String

func (k Kind) String() string

type Message

type Message struct {
	Header
	Body []string
}

A Message is a high-level reassembled zepyr message. This is the final stage of the messaging pipeline.

type MessageReaderResult

type MessageReaderResult struct {
	Message    *Message
	AuthStatus AuthStatus
}

A MessageReaderResult is an output of a Session's incoming Message channel. It either contains a Message with accompanying AuthStatus or an error.

type Notice

type Notice struct {
	Header
	Multipart string
	MultiUID  UID
	RawBody   []byte
}

A Notice is a raw message sent and received over zephyr.

func DecodeRawNotice

func DecodeRawNotice(r *RawNotice) (*Notice, error)

DecodeRawNotice decodes a RawNotice into a Notice. The underlying byte slices on the result do not share backing stores with the RawNotice.

func SendCancelSubscriptions

func SendCancelSubscriptions(
	ctx *krb5.Context,
	conn *Connection,
	port uint16,
) (*Notice, error)

SendCancelSubscriptions uses a connection to close a session. The passed krb5 context is used to authenticate the request. The port number is the port to subscribe, or 0 to use the port of the connection.

func SendMessage

func SendMessage(ctx *krb5.Context, conn *Connection, msg *Message) (*Notice, error)

SendMessage sends an authenticated message across a connection, sharding into multiple notices as needed. It returns the ACK from the server if the message is ACKED.

func SendMessageUnauth

func SendMessageUnauth(conn *Connection, msg *Message) (*Notice, error)

SendMessageUnauth sends an unauthenticated message across a connection, sharding into multiple notices as needed. It returns the ACK from the server if the message is ACKED.

func SendSubscribe

func SendSubscribe(
	ctx *krb5.Context,
	conn *Connection,
	port uint16,
	subs []Subscription,
) (*Notice, error)

SendSubscribe uses a connection to subscribe to a list of subscriptions, along with any defaults configured on the server. The passed krb5 context is used to authenticate the request. The port number is the port to subscribe, or 0 to use the port of the connection.

func SendSubscribeNoDefaults

func SendSubscribeNoDefaults(
	ctx *krb5.Context,
	conn *Connection,
	port uint16,
	subs []Subscription,
) (*Notice, error)

SendSubscribeNoDefaults uses a connection to subscribe to a list of subscriptions. The passed krb5 context is used to authenticate the request. The port number is the port to subscribe, or 0 to use the port of the connection.

func SendUnsubscribe

func SendUnsubscribe(
	ctx *krb5.Context,
	conn *Connection,
	port uint16,
	subs []Subscription,
) (*Notice, error)

SendUnsubscribe uses a connection to unsubscribe from a list of subscriptions. The passed krb5 context is used to authenticate the request. The port number is the port to subscribe, or 0 to use the port of the connection.

func (*Notice) EncodePacketForClient

func (n *Notice) EncodePacketForClient(
	ctx *krb5.Context, authstatus AuthStatus, key *krb5.KeyBlock) ([]byte, error)

EncodePacketForClient encodes and authenticates a Notice to be sent to a client. Returns a packet.

func (*Notice) EncodePacketForServer

func (n *Notice) EncodePacketForServer(
	ctx *krb5.Context, cred *krb5.Credential) ([]byte, error)

EncodePacketForServer encodes and authenticates a Notice to be sent to a server. Returns a packet.

func (*Notice) EncodePacketUnauth

func (n *Notice) EncodePacketUnauth() []byte

EncodePacketUnauth encodes a Notice into an unauthenticated packet.

func (*Notice) EncodeRawNoticeForClient

func (n *Notice) EncodeRawNoticeForClient(
	ctx *krb5.Context, authstatus AuthStatus, key *krb5.KeyBlock) (*RawNotice, error)

EncodeRawNoticeForClient encodes and authenticates a Notice to send to a client using a pre-negotiated session key. Returns a RawNotice.

func (*Notice) EncodeRawNoticeForServer

func (n *Notice) EncodeRawNoticeForServer(
	ctx *krb5.Context, cred *krb5.Credential) (*RawNotice, error)

EncodeRawNoticeForServer encodes a Notice into an authenticated RawNotice to send to the server. Returns the RawNotice. The authenticator always negotiates the key in the credential.

TODO(davidben): Go back to returning the krb5.KeyBlock output from the API? Unless we negotiate a subkey, it's guaranteed to be the key in the credential anyway, and shared subscriptions require this to be true.

func (*Notice) EncodeRawNoticeUnauth

func (n *Notice) EncodeRawNoticeUnauth() *RawNotice

EncodeRawNoticeUnauth encodes a Notice into an unauthenticated RawNotice.

func (*Notice) MakeACK

func (n *Notice) MakeACK(kind Kind, body string) *Notice

MakeACK creates an acknowledgement notice for this message. Like libzephyr, this preserves the non-body header fields in the notice. This is not necessary for a CLIENTACK but is necessary for a SERVACK; clients like BarnOwl don't bother associating SERVACKs with outgoing messages and just trust the values in the SERVACK.

TODO(davidben): Unlike libzephyr, this doesn't preserve the checksum and authenticator. This should be fine. In fact, we can even authenticate ACKs without breaking anything.

type NoticeReaderResult

type NoticeReaderResult struct {
	Notice     *Notice
	AuthStatus AuthStatus
	Addr       net.Addr
}

A NoticeReaderResult is an output of a ReadNoticesFromServer call. It either contains a notice with authentication status and source address or an error.

type RawNotice

type RawNotice struct {
	HeaderFields [][]byte
	Body         []byte
}

A RawNotice is the first stage of processing a packet. The individual header fields are parsed out to extract a checksum and authenticator. The other fields are uninterpreted.

func DecodePacket

func DecodePacket(packet []byte) (*RawNotice, error)

DecodePacket records a packet into a RawNotice.

func (*RawNotice) CheckAuthFromClient

func (r *RawNotice) CheckAuthFromClient(
	ctx *krb5.Context,
	service *krb5.Principal,
	keytab *krb5.KeyTab,
) (AuthStatus, *krb5.KeyBlock, error)

CheckAuthFromClient is called by a server to check a packet from a client using a server KeyTab. If successful, the session key from the client's authenticator is returned.

func (*RawNotice) CheckAuthFromServer

func (r *RawNotice) CheckAuthFromServer(
	ctx *krb5.Context,
	key *krb5.KeyBlock,
) (AuthStatus, error)

CheckAuthFromServer is called by a client to check a packet from the server using a previously negotiated key.

func (*RawNotice) ChecksumPayload

func (r *RawNotice) ChecksumPayload() []byte

ChecksumPayload returns the portion of the packet that is checksumed. (The checksum itself is removed and the remainder is concatenated.)

func (*RawNotice) DecodeAuthStatus

func (r *RawNotice) DecodeAuthStatus() (AuthStatus, error)

DecodeAuthStatus decodes the authstate field of a RawNotice.

func (*RawNotice) DecodeAuthenticator

func (r *RawNotice) DecodeAuthenticator() ([]byte, error)

DecodeAuthenticator decodes the authenticator field of a RawNotice.

func (*RawNotice) DecodeChecksum

func (r *RawNotice) DecodeChecksum() ([]byte, error)

DecodeChecksum decodes the checksum field of a RawNotice.

func (*RawNotice) EncodePacket

func (r *RawNotice) EncodePacket() []byte

EncodePacket encodes a RawNotice as a packet. If it is to be authenticated, the checksum and (if a client) authenticator fields must be already populated.

type RawReaderResult

type RawReaderResult struct {
	RawNotice *RawNotice
	Addr      net.Addr
}

A RawReaderResult is an output of a ReadRawNotices call. It either contains a RawNotice and a source address or an error.

type Reassembler

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

Reassembler maintains state for a reassembled notice.

func NewReassembler

func NewReassembler(length int) *Reassembler

NewReassembler creates a Reassembler for a message with a given body length.

func NewReassemblerFromMultipartField

func NewReassemblerFromMultipartField(n *Notice) (*Reassembler, error)

NewReassemblerFromMultipartField creates a Reassembler for a given notice's multipart field. Note that this does not call AddNotice.

func (*Reassembler) AddNotice

func (r *Reassembler) AddNotice(n *Notice, authStatus AuthStatus) error

AddNotice adds a notice into the reassembler state. If the notice is incompatible and discarded, it returns an error.

func (*Reassembler) Done

func (r *Reassembler) Done() bool

Done returns true when the message body has been reassembled.

func (*Reassembler) Message

func (r *Reassembler) Message() (*Message, AuthStatus)

Message returns the reassembled message once it is done.

type ServerConfig

type ServerConfig interface {
	// ResolveServer returns a list of zephyrd addresses to
	// round-robin connect to. This may be repeatedly to refresh
	// this list. ResolveServer cannot return a list of length 0.
	ResolveServer() ([]*net.UDPAddr, error)
}

A ServerConfig describes how to connect to a given zephyrd instance.

func NewServerFromHesiod

func NewServerFromHesiod(hs *hesiod.Hesiod) (ServerConfig, error)

NewServerFromHesiod creates the server configuration for a zephyr installation at a Hesiod realm.

func NewStaticServer

func NewStaticServer(addrs []*net.UDPAddr) ServerConfig

NewStaticServer returns a ServerConfig which returns a static list of zephyr server addresses.

type Session

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

A Session is a high-level connection to the zephyr servers. It handles reassembly of sharded messages, ACKs, and deduplicating notices by UID. This API should be used by most zephyr clients.

func Dial

func Dial(
	hesiod *hesiod.Hesiod,
	cred *krb5.Credential,
) (*Session, error)

Dial creates a new Session using the given Hesiod object and credential.

func DialSystemDefault

func DialSystemDefault() (*Session, error)

DialSystemDefault opens a new Session using credentials from the default ccache and using the system-wide Hesiod config to find the zephyrds.

func NewSession

func NewSession(
	conn net.PacketConn,
	server ServerConfig,
	cred *krb5.Credential,
) (*Session, error)

NewSession creates a new Session attached to a given connection with server configuration and credential.

func NewSessionFull

func NewSessionFull(
	conn net.PacketConn,
	server ServerConfig,
	cred *krb5.Credential,
	clock Clock,
) (*Session, error)

NewSessionFull creates a new Session attached to a given connection with server configuration and credential. This variant allows passing a custom clock for testing.

func (*Session) Close

func (s *Session) Close() error

Close closes the session.

func (*Session) Credential

func (s *Session) Credential() *krb5.Credential

Credential returns the credential for this session.

func (*Session) LocalAddr

func (s *Session) LocalAddr() *net.UDPAddr

LocalAddr returns the local UDP address for the client when communicating with the Zephyr servers.

func (*Session) MakeUID

func (s *Session) MakeUID(t time.Time) UID

MakeUID creates a new UID for a given time and this sessions local IP address.

func (*Session) Messages

func (s *Session) Messages() <-chan MessageReaderResult

Messages returns the incoming messages from the session.

func (*Session) Port

func (s *Session) Port() uint16

Port returns the local UDP port for the client.

func (*Session) Realm

func (s *Session) Realm() string

Realm returns the realm of the server being connected to.

func (*Session) SendCancelSubscriptions

func (s *Session) SendCancelSubscriptions(ctx *krb5.Context) (*Notice, error)

SendCancelSubscriptions closes the session. This should be called before exit to release the port on the zephyrd. It returns the ACK from the server.

func (*Session) SendMessage

func (s *Session) SendMessage(ctx *krb5.Context, msg *Message) (*Notice, error)

SendMessage sends an authenticated message over the session, sharding into multiple notices as needed. It returns the ACK from the server if the message is ACKED.

func (*Session) SendMessageUnauth

func (s *Session) SendMessageUnauth(msg *Message) (*Notice, error)

SendMessageUnauth sends an unauthenticated message over the session, sharding into multiple notices as needed. It returns the ACK from the server if the message is ACKED.

func (*Session) SendSubscribe

func (s *Session) SendSubscribe(
	ctx *krb5.Context,
	subs []Subscription,
) (*Notice, error)

SendSubscribe sends a subscription notice for a list of triples, along with any defaults configured on the server.

func (*Session) SendSubscribeNoDefaults

func (s *Session) SendSubscribeNoDefaults(
	ctx *krb5.Context,
	subs []Subscription,
) (*Notice, error)

SendSubscribeNoDefaults sends a subscription notice for a list of triples. It returns the ACK from the server.

func (*Session) SendUnsubscribe

func (s *Session) SendUnsubscribe(
	ctx *krb5.Context,
	subs []Subscription,
) (*Notice, error)

SendUnsubscribe unsubscribes from a list of triples. It returns the ACK from the server.

func (*Session) Sender

func (s *Session) Sender() string

Sender returns the user the session is authenticated as.

type Subscription

type Subscription struct {
	Recipient string
	Class     string
	Instance  string
}

A Subscription represents a triple to subscribe to.

type UID

type UID [12]byte

A UID is the identifier of a zephyr notice. It includes the sender's IP address and the send time.

func MakeUID

func MakeUID(ip net.IP, time time.Time) UID

MakeUID creates a uid out of an IP address and time. If ip is not an IPv4 address, the last four bytes are taken.

func (UID) Equal

func (uid UID) Equal(x UID) bool

Equal returns true iff two uids are equal.

func (UID) IP

func (uid UID) IP() net.IP

IP returns the IP address portion of the uid.

func (UID) Time

func (uid UID) Time() time.Time

Time returns the time portion of the uid.

type WindowedMap

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

A WindowedMap is a map from UID to some value type where keys expire if not accessed for some time.

func NewWindowedMap

func NewWindowedMap(lifetime time.Duration) *WindowedMap

NewWindowedMap creates a new WindowedMap with the specified lifetime for key entries.

func NewWindowedMapFull

func NewWindowedMapFull(lifetime time.Duration, clock Clock) *WindowedMap

NewWindowedMapFull creates a new WindowedMap with the specified lifetime for key entries. It allows passing a custom Clock implementation for testing purposes.

func (*WindowedMap) ExpireOldEntries

func (w *WindowedMap) ExpireOldEntries()

ExpireOldEntries removes entries from the windowed map which have since expired.

func (*WindowedMap) Len

func (w *WindowedMap) Len() int

Len returns the number of entries in the windowed map. Note that this does not get updated for any entries that map have expired since the last lookup or modification.

func (*WindowedMap) Lookup

func (w *WindowedMap) Lookup(uid UID) (interface{}, bool)

Lookup looks up the value for a given UID. The second return value is false if the key is not in the map. Looking up a UID updates the access time for that key.

func (*WindowedMap) Put

func (w *WindowedMap) Put(uid UID, value interface{})

Put inserts a new value into the windowed map, overriding the existing value for UID if it already exists.

func (*WindowedMap) Remove

func (w *WindowedMap) Remove(uid UID) (interface{}, bool)

Remove removes the entry for a given UID and returns the value associated with it. The second return value is false if the key is not in the map.

Directories

Path Synopsis
cmd
subscriber command
zwrite command

Jump to

Keyboard shortcuts

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