relay

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package relay is an implementation of relay mechanism. Proxy contains info about nodes which can relaying messages. Relay contains info about nodes of which messages current node have to relay.

Usage:

package relay

relay := NewRelay()
relay.AddClient(node)

if relay.NeedToRelay(node.Address()) {
	//relay message
}

relay.RemoveClient(node)

//-----------------------------------

proxy := NewProxy()
proxy.AddProxyNode(node.Address())

if proxy.ProxyNodesCount > 0 {
	address := proxy.GetNextProxyAddress
	//send message to next proxy
}

proxy.RemoveProxyNode(node.Address)

Index

Constants

View Source
const (
	// Started is relay type means relaying started.
	Started = State(iota + 1)
	// Stopped is relay type means relaying stopped.
	Stopped
	// Error is relay type means error state change.
	Error
	// Unknown unknown relay state.
	Unknown
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Proxy

type Proxy interface {
	// AddProxyNode add an address to proxy list.
	AddProxyNode(address string)
	// RemoveProxyNode removes proxy address from proxy list.
	RemoveProxyNode(address string)
	// GetNextProxyAddress returns a next address to send from proxy list.
	GetNextProxyAddress() string
	// ProxyNodesCount return added proxy count.
	ProxyNodesCount() int
}

Proxy contains proxy addresses.

func NewProxy

func NewProxy() Proxy

NewProxy instantiates proxy struct.

type Relay

type Relay interface {
	// AddClient add client to relay list.
	AddClient(node *node.Node) error
	// RemoveClient removes client from relay list.
	RemoveClient(node *node.Node) error
	// ClientsCount - clients count.
	ClientsCount() int
	// NeedToRelay returns true if origin node is proxy for target node.
	NeedToRelay(targetAddress string) bool
}

Relay Interface for relaying

func NewRelay

func NewRelay() Relay

NewRelay constructs relay list.

type State

type State int

State is alias for relaying state

Jump to

Keyboard shortcuts

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