zmtp

package
v0.0.0-...-5f01694 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OptionServer = "server"
	OptionPubKey = "pubkey"
	OptionSecKey = "seckey"
	OptionSrvKey = "srvkey"
)

Variables

View Source
var ErrInvalidCommandSize invalidCommandSize
View Source
var ErrInvalidFrameHeader invalidFrameHeader
View Source
var ErrInvalidMetadata invalidMetadata

ErrInvalidMetadata is returned when the metadata cannot be parsed into its properties.

View Source
var ErrInvalidNameLength invalidNameLength
View Source
var ErrMechMismatch mechMismatch
View Source
var ErrNameTooLong nameTooLong

ErrNameTooLong is returns when the metadata contains a name specifier which is too long for the metadata length.

Functions

This section is empty.

Types

type ByteReader

type ByteReader byte

func (ByteReader) Read

func (b ByteReader) Read(p []byte) (n int, err error)

type Command

type Command struct {
	Name string
	Body []byte
}

func (Command) BodyLen

func (c Command) BodyLen() int32

BodyLen returns the body length of the given message.

func (*Command) ReadFrom

func (c *Command) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads a command from the given reader.

func (Command) WriteTo

func (c Command) WriteTo(w io.Writer) (int64, error)

WriteTo writes a command to the given writer.

type CommandOrMessage

type CommandOrMessage struct {
	// IsMessage is true iff this contains a message.
	IsMessage bool

	// Command is non nil iff message is nil.
	Command *Command

	// Message is non nil iff IsMessage is true.
	Message *Message
}

CommandOrMessage may either contain a command or a message.

func (*CommandOrMessage) ReadFrom

func (dat *CommandOrMessage) ReadFrom(r io.Reader) (n int64, err error)

type Greeting

type Greeting [64]byte

Greeting defines a zmtp greeting

func NewGreeting

func NewGreeting() Greeting

NewGreeting returns a new zmtp greeting.

func (*Greeting) Mechanism

func (g *Greeting) Mechanism() string

Mechanism returns the mechanism for this Greeting.

func (*Greeting) ReadFrom

func (g *Greeting) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the greeting from a reader.

func (*Greeting) Server

func (g *Greeting) Server() bool

Server returns whether the greeting specifies the sender as a server.

func (*Greeting) SetMechanism

func (g *Greeting) SetMechanism(mech string)

SetMechanism sets the mechanism for this greeting.

func (*Greeting) SetServer

func (g *Greeting) SetServer(server bool)

SetServer sets the server flag in the greeting.

func (*Greeting) SetVersionMajor

func (g *Greeting) SetVersionMajor(major uint8)

SetVersionMajor sets the major version of this zmtp greeting.

func (*Greeting) SetVersionMinor

func (g *Greeting) SetVersionMinor(minor uint8)

SetVersionMinor sets the minor version of this zmtp greeting.

func (*Greeting) String

func (g *Greeting) String() string

String implements Stringer for greeting.

func (*Greeting) VersionMajor

func (g *Greeting) VersionMajor() uint8

VersionMajor returns the major version of this zmtp greeting.

func (*Greeting) VersionMinor

func (g *Greeting) VersionMinor() uint8

VersionMinor returns the minor version of this zmtp greeting.

func (*Greeting) WriteTo

func (g *Greeting) WriteTo(w io.Writer) (int64, error)

WriteTo writes the greeting to a writer.

type Mechanism

type Mechanism interface {
	// Name of the mechanism.
	Name() string

	// ValidateGreeting returns an error if the greeting from another side is invalid for this mechanism.
	ValidateGreeting(*Greeting) (err error)

	// Handshake performs a handshake with the Connection.
	Handshake(net.Conn, Metadata) (s Socket, meta Metadata, err error)

	// Server field for the greeting for this handshake.
	Server() bool

	// SetOption sets an option in the mechanism.
	SetOption(option string, value any) error
}

Mechanism implements the setup of new Connections.

type Message

type Message struct {
	More bool
	Body []byte
}

Message is a zmtp message.

func (*Message) ReadFrom

func (m *Message) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads a message from the given reader.

func (Message) WriteTo

func (m Message) WriteTo(w io.Writer) (int64, error)

WriteTo writes a message to the given writer.

type Metadata

type Metadata []byte

func (*Metadata) AddProperty

func (m *Metadata) AddProperty(name string, value string) error

AddProperty to the Metadata.

func (Metadata) Properties

func (m Metadata) Properties(f func(name string, value string)) error

Properties returns a slice of properties held in this metadata.

type Socket

type Socket interface {
	// Read the next part of traffic.
	Read() (CommandOrMessage, error)

	// Send a message on the socket.
	SendMessage(Message) error

	// SendCommand sends a command on the socket.
	SendCommand(Command) error

	// Access to the underlying conn.
	Net() net.Conn

	// Close the socket.
	Close() error
}

Socket.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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