gyre

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: LGPL-3.0 Imports: 19 Imported by: 1

README

Gyre GoDoc Build Status

This is a Golang port of Zyre 2.0, an open-source framework for proximity-based peer-to-peer applications, implementing the same ZeroMQ Realtime Exchange Protocol.

Description

Gyre does local area discovery and clustering. A Gyre node broadcasts UDP beacons, and connects to peers that it finds. This class wraps a Gyre node with a message-based API.

All incoming events are delivered via the recv call of a Gyre instance. The first frame defines the type of the message, and following frames provide further values:

ENTER fromnode headers ipaddress
    a new peer has entered the network
EXIT fromnode
    a peer has left the network
JOIN fromnode groupname
    a peer has joined a specific group
LEAVE fromnode groupname
    a peer has left a specific group
WHISPER fromnode message
    a peer has sent this node a message
SHOUT fromnode groupname message
    a peer has sent one of our groups a message

In SHOUT and WHISPER the message is a single frame in this version. In ENTER, the headers frame contains a packed dictionary.

To join or leave a group, use the Join and Leave methods. To set a header value, use the SetHeader method. To send a message to a single peer, use Whisper method. To send a message to a group, use Shout.

Example (docker)

Run following command in a terminal:

docker run --rm -i --tty -t armen/gyre chat -name yourname

And repeat the above command in another terminal, the chat instances will discover eachother. Happy chatting!

Api

View the API docs GoDoc

Project Organization

Gyre is owned by all its authors and contributors. This is an open source project licensed under the LGPLv3. To contribute to Gyre please read the C4.1 process that we use.

To report an issue, use the Gyre issue tracker at github.com.

Documentation

Overview

Package gyre is Golang port of Zyre, an open-source framework for proximity-based peer-to-peer applications. Gyre does local area discovery and clustering. A Gyre node broadcasts UDP beacons, and connects to peers that it finds. This class wraps a Gyre node with a message-based API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetEvasive

func SetEvasive(evasive time.Duration)

SetEvasive sets evasive.

func SetExpired

func SetExpired(expired time.Duration)

SetExpired sets expired.

func SetLoopInterval

func SetLoopInterval(interval time.Duration)

SetLoopInterval sets interval of checking health of other peers

Types

type Event

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

Event represents an event which contains information about the sender and the group it belongs.

func (*Event) Addr

func (e *Event) Addr() string

Addr returns the sending peer's ipaddress as a string.

func (*Event) Group

func (e *Event) Group() string

Group returns the group name that a SHOUT event was sent to.

func (*Event) Header

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

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

func (*Event) Headers

func (e *Event) Headers() map[string]string

Headers returns the event headers, or nil if there are none

func (*Event) Msg

func (e *Event) Msg() []byte

Msg returns the incoming message payload (currently one frame).

func (*Event) Name

func (e *Event) Name() string

Name returns the sending peer's public name as a string.

func (*Event) Sender

func (e *Event) Sender() string

Sender returns the sending peer's id as a string.

func (*Event) Type

func (e *Event) Type() EventType

Type returns event type, which is a EventType.

type EventType

type EventType int

EventType defines event type

const (
	EventEnter EventType = iota + 1
	EventJoin
	EventLeave
	EventExit
	EventWhisper
	EventShout
)

Event types

func (EventType) String

func (e EventType) String() string

Converts EventType to string.

type Gyre

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

Gyre structure

func New

func New() (g *Gyre, err error)

New creates a new Gyre node. Note that until you start the node it is silent and invisible to other nodes on the network.

func (*Gyre) Addr

func (g *Gyre) Addr() (string, error)

Addr returns our address. Note that it will return empty string if called before Start() method.

func (*Gyre) Dump

func (g *Gyre) Dump() error

Dump prints Gyre node information.

func (*Gyre) Events

func (g *Gyre) 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 (*Gyre) GossipBind

func (g *Gyre) GossipBind(endpoint string) error

GossipBind Sets up gossip discovery of other nodes. At least one node in the cluster must bind to a well-known gossip endpoint, so other nodes can connect to it. Note that gossip endpoints are completely distinct from Gyre node endpoints, and should not overlap (they can use the same transport).

func (*Gyre) GossipConnect

func (g *Gyre) GossipConnect(endpoint string) error

GossipConnect Sets up gossip discovery of other nodes. A node may connect to multiple other nodes, for redundancy paths.

func (*Gyre) GossipPort

func (g *Gyre) GossipPort() (string, error)

GossipPort returns the port number that gossip engine is bound to

func (*Gyre) Header

func (g *Gyre) Header(key string) (string, bool)

Header returns specified header

func (*Gyre) Headers

func (g *Gyre) Headers() (map[string]string, error)

Headers returns headers

func (*Gyre) Join

func (g *Gyre) Join(group string) error

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

func (*Gyre) Leave

func (g *Gyre) Leave(group string) error

Leave a group.

func (*Gyre) Name

func (g *Gyre) Name() string

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

func (*Gyre) SetEndpoint

func (g *Gyre) SetEndpoint(endpoint string) error

SetEndpoint sets the endpoint. By default, Gyre binds to an ephemeral TCP port and broadcasts the local host name using UDP beaconing. When you call this method, Gyre will use gossip discovery instead of UDP beaconing. You MUST set-up the gossip service separately using GossipBind() and GossipConnect(). Note that the endpoint MUST be valid for both bind and connect operations. You can use inproc://, ipc://, or tcp:// transports (for tcp://, use an IP address that is meaningful to remote as well as local nodes).

func (*Gyre) SetHeader

func (g *Gyre) SetHeader(name string, format string, args ...interface{}) error

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

func (*Gyre) SetInterface

func (g *Gyre) SetInterface(iface string) error

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

func (*Gyre) SetInterval

func (g *Gyre) SetInterval(interval time.Duration) error

SetInterval sets ZRE discovery interval. Default is instant beacon exploration followed by pinging every 1,000 msecs.

func (*Gyre) SetName

func (g *Gyre) SetName(name string) error

SetName sets node name; this is provided to other nodes during discovery. If you do not set this, the UUID is used as a basis.

func (*Gyre) SetPort

func (g *Gyre) SetPort(port int) error

SetPort sets ZRE discovery port; defaults to 5670, this call overrides that so you can create independent clusters on the same network, for e.g development vs production.

func (*Gyre) SetVerbose

func (g *Gyre) SetVerbose() error

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

func (*Gyre) Shout

func (g *Gyre) Shout(group string, payload []byte) error

Shout sends a message to a named group.

func (*Gyre) Shouts

func (g *Gyre) Shouts(group string, format string, args ...interface{}) error

Shouts sends a message to a named group.

func (*Gyre) Start

func (g *Gyre) Start() error

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

func (*Gyre) Stop

func (g *Gyre) Stop() error

Stop stops a 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 (*Gyre) UUID

func (g *Gyre) UUID() string

UUID returns our node UUID, after successful initialization

func (*Gyre) Whisper

func (g *Gyre) Whisper(peer string, payload []byte) error

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

func (*Gyre) Whispers

func (g *Gyre) Whispers(peer string, format string, args ...interface{}) error

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

Directories

Path Synopsis
Package beacon implements a peer-to-peer discovery service for local networks.
Package beacon implements a peer-to-peer discovery service for local networks.
cmd
monitor
Monitors ZRE network traffic Usage: monitor [Options] Examples: monitor -group GROUP_NAME Options: Usage of monitor: -group="*": The group we are going to join.
Monitors ZRE network traffic Usage: monitor [Options] Examples: monitor -group GROUP_NAME Options: Usage of monitor: -group="*": The group we are going to join.
Examples directory contains example applications written with Gyre framework.
Examples directory contains example applications written with Gyre framework.
chat
Chat example is a simple chat application to demonstrate the Gyre API.
Chat example is a simple chat application to demonstrate the Gyre API.
chat-gossip
Chat example is a simple chat application to demonstrate the Gyre API.
Chat example is a simple chat application to demonstrate the Gyre API.
ping
Ping other peers in a ZRE network Usage: ping [Options] Examples: ping -group GRP Options: Usage of ping: -group="GLOBAL": The group we are going to join -verbose=false: Set verbose flag
Ping other peers in a ZRE network Usage: ping [Options] Examples: ping -group GRP Options: Usage of ping: -group="GLOBAL": The group we are going to join -verbose=false: Set verbose flag
Package shm provides a neat way of storing key-val data.
Package shm provides a neat way of storing key-val data.
zre
msg
Package msg is 100% generated.
Package msg is 100% generated.

Jump to

Keyboard shortcuts

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