zyre

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: BSD-3-Clause Imports: 16 Imported by: 1

README

Zyre - Local Area Clustering for Peer-to-Peer Applications

Build Status codecov GoDoc

zyre is a pure-Go implementation of ØMQ/Zyre.

See zeromq.org for more informations.

License

zyre is released under the BSD-3 license.

Documentation

Documentation for zyre is served by GoDoc.

Example

ZSYS_INTERFACE=eth0 go run examples/chat/chat.go -name Foo

Documentation

Overview

Package zyre provides reliable group messaging over local area networks.

For more informations, see https://zeromq.org.

Index

Constants

View Source
const (
	// Signature of the message
	Signature uint16 = 0xAAA0 | 1
	// Version number
	Version byte = 2
)
View Source
const (
	HelloID   uint8 = 1
	WhisperID uint8 = 2
	ShoutID   uint8 = 3
	JoinID    uint8 = 4
	LeaveID   uint8 = 5
	PingID    uint8 = 6
	PingOkID  uint8 = 7
)

Message IDs

Variables

This section is empty.

Functions

func Send

func Send(socket zmq.Socket, msg *ZreMsg) error

Send sends ZreMsg through ZMQ socket.

func SetEvasive

func SetEvasive(evasive time.Duration)

SetEvasive sets evasive.

func SetExpired

func SetExpired(expired time.Duration)

SetExpired sets expired.

Types

type Beacon

type Beacon struct {
	Signals chan *Signal
	Cmds    chan *Cmd
	Replies chan *Cmd
	// contains filtered or unexported fields
}

Beacon defines main structure of the application

func NewBeacon

func NewBeacon() *Beacon

NewBeacon creates a new beacon on a certain UDP port.

func (*Beacon) Close

func (b *Beacon) Close()

Close terminates the beacon.

func (*Beacon) SetBeaconCmd

func (b *Beacon) SetBeaconCmd(req *Cmd) *Cmd

SetBeaconCmd ...

type BeaconMsg

type BeaconMsg struct {
	Protocol [3]byte
	Version  byte
	UUID     []byte
	Port     uint16
}

BeaconMsg frame has this format:

Z R E 3 bytes version 1 byte 0x01 | 0x03 UUID 16 bytes port 2 bytes in network order

type Cmd

type Cmd struct {
	ID      string
	Payload interface{}
	Err     error
}

Cmd type to transfer commands through channels

type ConnData

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

ConnData common data for ipv4 and ipv6

func (*ConnData) Addr

func (conn *ConnData) Addr() string

Addr ...

type Connection

type Connection interface {
	Close() error
	Addr() string
	JoinGroup(ifi *net.Interface) error
	ReadFrom(buff []byte) (n int, src net.IP, err error)
	WriteTo(buff []byte) error
}

Connection defines a common interface for ipv4 and ipv6

func NewConn

func NewConn(port int) (Connection, error)

NewConn returns a new Connection

type Event

type Event struct {
	Type     string            // Event type
	PeerUUID string            // Sender UUID as string
	PeerName string            // Sender public name as string
	PeerAddr string            // Sender ipaddress as string, for an ENTER event
	Headers  map[string]string // Headers, for an ENTER event
	Group    string            // Group name for a SHOUT event
	Msg      []byte            // Message payload for SHOUT or WHISPER
}

Event zyre event

func (*Event) Header

func (e *Event) Header(name string) (string, bool)

Header returns value of a header from the message headers obtained by ENTER.

type Group

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

Group group known to this node

func NewGroup

func NewGroup(name string) *Group

NewGroup creates new group

func (*Group) Join

func (g *Group) Join(peer *Peer)

Join adds peer to group, ignores duplicate joins

func (*Group) Leave

func (g *Group) Leave(peer *Peer)

Leave removes peer from group

func (*Group) Send

func (g *Group) Send(msg *ZreMsg)

Send message to all peers in group

type IPv4Conn

type IPv4Conn struct {
	ConnData
	// contains filtered or unexported fields
}

IPv4Conn IPv4 connection

func NewIPv4Conn

func NewIPv4Conn(port int) (*IPv4Conn, error)

NewIPv4Conn returns a new IPv4Conn

func (*IPv4Conn) Close

func (conn *IPv4Conn) Close() error

Close ...

func (*IPv4Conn) JoinGroup

func (conn *IPv4Conn) JoinGroup(ifi *net.Interface) error

JoinGroup ..

func (*IPv4Conn) ReadFrom

func (conn *IPv4Conn) ReadFrom(buff []byte) (int, net.IP, error)

ReadFrom ...

func (*IPv4Conn) WriteTo

func (conn *IPv4Conn) WriteTo(buff []byte) error

WriteTo ...

type IPv6Conn

type IPv6Conn struct {
	ConnData
	// contains filtered or unexported fields
}

IPv6Conn IPv6 connection

func NewIPv6Conn

func NewIPv6Conn(port int) (*IPv6Conn, error)

NewIPv6Conn returns a new IPv6Conn

func (*IPv6Conn) Close

func (conn *IPv6Conn) Close() error

Close ...

func (*IPv6Conn) JoinGroup

func (conn *IPv6Conn) JoinGroup(ifi *net.Interface) error

JoinGroup ..

func (*IPv6Conn) ReadFrom

func (conn *IPv6Conn) ReadFrom(buff []byte) (int, net.IP, error)

ReadFrom ...

func (*IPv6Conn) WriteTo

func (conn *IPv6Conn) WriteTo(buff []byte) error

WriteTo ...

type Peer

type Peer struct {
	Identity string            // Identity UUID
	Name     string            // Peer's public name
	Headers  map[string]string // Peer headers
	// contains filtered or unexported fields
}

Peer one of our peers in a ZRE network

func NewPeer

func NewPeer(ctx context.Context, identity string) (p *Peer)

NewPeer creates new peer

func (*Peer) Connect

func (p *Peer) Connect(from []byte, endpoint string) (err error)

Connect peer mailbox Configures mailbox and connects to peer's router endpoint

func (*Peer) Destroy

func (p *Peer) Destroy()

Destroy and disconnect peer

func (*Peer) Disconnect

func (p *Peer) Disconnect()

Disconnect peer mailbox No more messages will be sent to peer until connected again

func (*Peer) Header

func (p *Peer) Header(key string) (string, bool)

Header gets peer header value

func (*Peer) MessagesLost

func (p *Peer) MessagesLost(msg *ZreMsg) bool

MessagesLost check if messages were lost from peer, returns true if they were FIXME not same implementation as zyre or pyre

func (*Peer) Refresh

func (p *Peer) Refresh()

Refresh registers activity at peer

func (*Peer) Send

func (p *Peer) Send(msg *ZreMsg) error

Send message to peer

type Signal

type Signal struct {
	Addr     string
	Transmit []byte
}

Signal contains the body of the beacon (Transmit) and the source address

type ZreMsg

type ZreMsg struct {
	Endpoint string            //  Sender connect endpoint
	Groups   []string          //  List of groups sender is in
	Status   byte              //  Sender groups status value
	Name     string            //  Sender public name
	Headers  map[string]string //  Sender header properties
	Content  []byte            //  Wrapped message content
	Group    string            //  Name of Group
	// contains filtered or unexported fields
}

ZreMsg work with ZRE messages

func NewZreMsg

func NewZreMsg(id uint8) *ZreMsg

NewZreMsg creates new ZreMsg message with messageID

func Recv

func Recv(socket zmq.Socket) (*ZreMsg, error)

Recv reads ZreMsg from ZMQ Socket

type Zyre

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

Zyre structure

func NewZyre

func NewZyre(ctx context.Context) *Zyre

NewZyre creates a new Zyre node. Note that until you start the node it is silent and invisible to other nodes on the network. The node name is provided to other nodes during discovery.

func (*Zyre) Events

func (zyre *Zyre) Events() chan *Event

Events returns a channel of events. The events may be a control event (ENTER, EXIT, JOIN, LEAVE) or data (WHISPER, SHOUT).

func (*Zyre) Join

func (zyre *Zyre) Join(group string)

Join a named group; after joining a group you can send messages to the group and all Zyre nodes in that group will receive them.

func (*Zyre) Leave

func (zyre *Zyre) Leave(group string)

Leave a group.

func (*Zyre) Name

func (zyre *Zyre) Name() string

Name returns our node name, after successful initialization. By default is taken from the UUID and shortened.

func (*Zyre) Peers

func (zyre *Zyre) Peers() []string

Peers returns a list of current peer IDs.

func (*Zyre) SetHeader

func (zyre *Zyre) SetHeader(name string, format string, args ...interface{}) *Zyre

SetHeader sets node header; these are provided to other nodes during discovery and come in each ENTER message.

func (*Zyre) SetInterface

func (zyre *Zyre) SetInterface(iface string) *Zyre

SetInterface sets network interface for UDP beacons. If you do not set this, CZMQ will choose an interface for you. On boxes with several interfaces you should specify which one you want to use, or strange things can happen.

func (*Zyre) SetInterval

func (zyre *Zyre) SetInterval(interval time.Duration) *Zyre

SetInterval sets UDP beacon discovery interval. Default is instant beacon exploration followed by pinging every 1000 msecs.

func (*Zyre) SetName

func (zyre *Zyre) SetName(name string) *Zyre

SetName sets node name.

func (*Zyre) SetPort

func (zyre *Zyre) SetPort(port int) *Zyre

SetPort sets UDP beacon discovery port; defaults to 5670, this call overrides that so you can create independent clusters on the same network, for e.zyre. development vs. production. Has no effect after zyre.Start(). FIXME make sure it has no effect after zyre.Start()

func (*Zyre) SetVerbose

func (zyre *Zyre) SetVerbose() *Zyre

SetVerbose sets verbose mode; this tells the node to log all traffic as well as all major events.

func (*Zyre) Shout

func (zyre *Zyre) Shout(group string, payload []byte)

Shout sends message to a named group.

func (*Zyre) Shouts

func (zyre *Zyre) Shouts(group string, format string, args ...interface{})

Shouts sends formatted string to a named group

func (*Zyre) Start

func (zyre *Zyre) Start() error

Start node, after setting header values. When you start a node it begins discovery and connection. Returns nil if OK, error if it wasn't possible to start the node.

func (*Zyre) Stop

func (zyre *Zyre) Stop()

Stop node; this signals to other peers that this node will go away. This is polite; however you can also just destroy the node without stopping it.

func (*Zyre) UUID

func (zyre *Zyre) UUID() string

UUID returns our node UUID, after successful initialization

func (*Zyre) Whisper

func (zyre *Zyre) Whisper(peer string, payload []byte)

Whisper sends message to single peer, specified as a UUID string

func (*Zyre) Whispers

func (zyre *Zyre) Whispers(peer string, format string, args ...interface{})

Whispers sends formatted string to a single peer specified as UUID string

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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