relay

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2019 License: Apache-2.0, BSD-3-Clause-Clear Imports: 3 Imported by: 0

Documentation

Overview

Package relay is an implementation of relay mechanism. Proxy contains info about hosts which can relaying packets. Relay contains info about hosts of which packets current host have to relay.

Usage:

package relay

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

if relay.NeedToRelay(host.Address()) {
	//relay packet
}

relay.RemoveClient(host)

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

proxy := NewProxy()
proxy.AddProxyHost(host.Address())

if proxy.ProxyHostsCount > 0 {
	address := proxy.GetNextProxyAddress
	//send packet to next proxy
}

proxy.RemoveProxyHost(host.Address)

Index

Constants

View Source
const (
	// Unknown unknown relay state.
	Unknown = State(iota + 1)
	// Started is relay type means relaying started.
	Started
	// Stopped is relay type means relaying stopped.
	Stopped
	// Error is relay type means error state change.
	Error
	// NoAuth - this error returns if host tries to send relay request but not authenticated.
	NoAuth
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Proxy

type Proxy interface {
	// AddProxyHost add an address to proxy list.
	AddProxyHost(address string)
	// RemoveProxyHost removes proxy address from proxy list.
	RemoveProxyHost(address string)
	// GetNextProxyAddress returns a next address to send from proxy list.
	GetNextProxyAddress() string
	// ProxyHostsCount return added proxy count.
	ProxyHostsCount() 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(host *host.Host) error
	// RemoveClient removes client from relay list.
	RemoveClient(host *host.Host) error
	// ClientsCount - clients count.
	ClientsCount() int
	// NeedToRelay returns true if origin host is proxy for target host.
	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