network

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2019 License: Apache-2.0 Imports: 22 Imported by: 11

Documentation

Overview

Package network is for creating internetworks

Index

Constants

This section is empty.

Variables

View Source
var (
	// NetworkChannel is the name of the tunnel channel for passing network messages
	NetworkChannel = "network"
	// ControlChannel is the name of the tunnel channel for passing control message
	ControlChannel = "control"
	// DefaultLink is default network link
	DefaultLink = "network"
)
View Source
var (
	// DefaultName is default network name
	DefaultName = "go.micro"
	// DefaultAddress is default network address
	DefaultAddress = ":0"
	// ResolveTime defines time interval to periodically resolve network nodes
	ResolveTime = 1 * time.Minute
	// AnnounceTime defines time interval to periodically announce node neighbours
	AnnounceTime = 30 * time.Second
	// PruneTime defines time interval to periodically check nodes that need to be pruned
	// due to their not announcing their presence within this time interval
	PruneTime = 90 * time.Second
)
View Source
var (
	// ErrPeerExists is returned when adding a peer which already exists
	ErrPeerExists = errors.New("peer already exists")
	// ErrPeerNotFound is returned when a peer could not be found in node topology
	ErrPeerNotFound = errors.New("peer not found")
)
View Source
var (
	// ErrClientNotFound is returned when client for tunnel channel could not be found
	ErrClientNotFound = errors.New("client not found")
)
View Source
var (
	// MaxDepth defines max depth of peer topology
	MaxDepth uint = 3
)

Functions

func PeersToProto added in v1.11.0

func PeersToProto(node Node, depth uint) *pb.Peer

PeersToProto returns node peers graph encoded into protobuf

func UnpackPeerTopology added in v1.11.0

func UnpackPeerTopology(pbPeer *pb.Peer, lastSeen time.Time, depth uint) *node

UnpackPeerTopology unpacks pb.Peer into node topology of given depth

Types

type Network

type Network interface {
	// Node is network node
	Node
	// Options returns the network options
	Options() Options
	// Name of the network
	Name() string
	// Connect starts the resolver and tunnel server
	Connect() error
	// Close stops the tunnel and resolving
	Close() error
	// Client is micro client
	Client() client.Client
	// Server is micro server
	Server() server.Server
}

Network is micro network

func NewNetwork added in v1.10.0

func NewNetwork(opts ...Option) Network

NewNetwork returns a new network interface

type Node

type Node interface {
	// Id is node id
	Id() string
	// Address is node bind address
	Address() string
	// Peers returns node peers
	Peers() []Node
	// Network is the network node is in
	Network() Network
}

Node is network node

type Option added in v1.10.0

type Option func(*Options)

func Address added in v1.10.0

func Address(a string) Option

Address sets the network address

func Advertise(a string) Option

Advertise sets the address to advertise

func Id added in v1.10.0

func Id(id string) Option

Id sets the id of the network node

func Name added in v1.10.0

func Name(n string) Option

Name sets the network name

func Peers added in v1.11.0

func Peers(n ...string) Option

Peers is a list of peers to connect to

func Proxy added in v1.10.0

func Proxy(p proxy.Proxy) Option

Proxy sets the network proxy

func Resolver added in v1.10.0

func Resolver(r resolver.Resolver) Option

Resolver is the network resolver

func Router added in v1.10.0

func Router(r router.Router) Option

Router sets the network router

func Tunnel added in v1.10.0

func Tunnel(t tunnel.Tunnel) Option

Tunnel sets the network tunnel

type Options added in v1.10.0

type Options struct {
	// Id of the node
	Id string
	// Name of the network
	Name string
	// Address to bind to
	Address string
	// Advertise sets the address to advertise
	Advertise string
	// Peers is a list of peers to connect to
	Peers []string
	// Tunnel is network tunnel
	Tunnel tunnel.Tunnel
	// Router is network router
	Router router.Router
	// Proxy is network proxy
	Proxy proxy.Proxy
	// Resolver is network resolver
	Resolver resolver.Resolver
}

Options configure network

func DefaultOptions added in v1.10.0

func DefaultOptions() Options

DefaultOptions returns network default options

Directories

Path Synopsis
Package handler implements network RPC handler
Package handler implements network RPC handler
Package resolver resolves network names to addresses
Package resolver resolves network names to addresses
dns
Package dns resolves names to dns srv records
Package dns resolves names to dns srv records
http
Package http resolves names to network addresses using a http request
Package http resolves names to network addresses using a http request
registry
Package registry resolves names using the go-micro registry
Package registry resolves names using the go-micro registry
static
Package static is a static resolver
Package static is a static resolver

Jump to

Keyboard shortcuts

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