tunnel

package
v3.7.8 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package tunnel provides gre network tunnelling

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultAddress is default tunnel bind address
	DefaultAddress = ":0"
	// DefaultToken the shared default token
	DefaultToken = "go.micro.tunnel"
)
View Source
var (
	// DefaultDialTimeout is the dial timeout if none is specified
	DefaultDialTimeout = time.Second * 5
	// ErrDialTimeout is returned by a call to Dial where the timeout occurs
	ErrDialTimeout = errors.New("dial timeout")
	// ErrDiscoverChan is returned when we failed to receive the "announce" back from a discovery
	ErrDiscoverChan = errors.New("failed to discover channel")
	// ErrLinkNotFound is returned when a link is specified at dial time and does not exist
	ErrLinkNotFound = errors.New("link not found")
	// ErrLinkDisconnected is returned when a link we attempt to send to is disconnected
	ErrLinkDisconnected = errors.New("link not connected")
	// ErrLinkLoopback is returned when attempting to send an outbound message over loopback link
	ErrLinkLoopback = errors.New("link is loopback")
	// ErrLinkRemote is returned when attempting to send a loopback message over remote link
	ErrLinkRemote = errors.New("link is remote")
	// ErrReadTimeout is a timeout on session.Recv
	ErrReadTimeout = errors.New("read timeout")
	// ErrDecryptingData is for when theres a nonce error
	ErrDecryptingData = errors.New("error decrypting data")
)

Functions

This section is empty.

Types

type DialOption

type DialOption func(*DialOptions)

DialOption func

func DialLink(id string) DialOption

DialLink specifies the link to pin this connection to. This is not applicable if the multicast option is set.

func DialMode

func DialMode(m Mode) DialOption

DialMode multicast sets the multicast option to send only to those mapped

func DialTimeout

func DialTimeout(t time.Duration) DialOption

DialTimeout sets the dial timeout of the connection

func DialWait

func DialWait(b bool) DialOption

DialWait specifies whether to wait for the connection to be accepted before returning the session

type DialOptions

type DialOptions struct {
	// Link specifies the link to use
	Link string
	// specify mode of the session
	Mode Mode
	// Wait for connection to be accepted
	Wait bool
	// the dial timeout
	Timeout time.Duration
}

DialOptions provides dial options

type Link interface {
	// Id returns the link unique Id
	Id() string
	// Delay is the current load on the link (lower is better)
	Delay() int64
	// Length returns the roundtrip time as nanoseconds (lower is better)
	Length() int64
	// Current transfer rate as bits per second (lower is better)
	Rate() float64
	// Is this a loopback link
	Loopback() bool
	// State of the link: connected/closed/error
	State() string
	// honours transport socket
	transport.Socket
}

Link represents internal links to the tunnel

type ListenOption

type ListenOption func(*ListenOptions)

ListenOption func

func ListenMode

func ListenMode(m Mode) ListenOption

ListenMode option

func ListenTimeout

func ListenTimeout(t time.Duration) ListenOption

ListenTimeout for reads and writes on the listener session

type ListenOptions

type ListenOptions struct {
	// Mode specify mode of the session
	Mode Mode
	// Timeout the read timeout
	Timeout time.Duration
}

ListenOptions provides listen options

type Listener

type Listener interface {
	Accept() (Session, error)
	Channel() string
	Close() error
}

Listener provides similar constructs to the transport.Listener

type Mode

type Mode uint8

Mode of the session

const (
	// Unicast send over one link
	Unicast Mode = iota
	// Multicast send to all channel listeners
	Multicast
	// Broadcast send to all links
	Broadcast
)

type Option

type Option func(*Options)

Option func signature

func Address

func Address(a string) Option

Address sets the tunnel address

func ID added in v3.3.17

func ID(id string) Option

ID sets the tunnel id

func Logger

func Logger(l logger.Logger) Option

Logger sets the logger

func Meter added in v3.1.6

func Meter(m meter.Meter) Option

Meter sets the meter

func Name added in v3.2.1

func Name(n string) Option

Name sets the name

func Nodes

func Nodes(n ...string) Option

Nodes specify remote network nodes

func Token

func Token(t string) Option

Token sets the shared token for auth

func Tracer added in v3.1.6

func Tracer(t tracer.Tracer) Option

Tracer to be used for tracing

func Transport

func Transport(t transport.Transport) Option

Transport listens for incoming connections

type Options

type Options struct {
	// Logger used for logging
	Logger logger.Logger
	// Meter used for metrics
	Meter meter.Meter
	// Tracer used for tracing
	Tracer tracer.Tracer
	// Transport used for communication
	Transport transport.Transport
	// Token the shared auth token
	Token string
	// Name holds the tunnel name
	Name string
	// ID holds the tunnel id
	ID string
	// Address holds the tunnel address
	Address string
	// Nodes holds the tunnel nodes
	Nodes []string
}

Options provides network configuration options

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions returns router default options with filled values

type Session

type Session interface {
	// The unique session id
	Id() string
	// The channel name
	Channel() string
	// The link the session is on
	Link() string
	// a transport socket
	transport.Socket
}

Session is a unique session created when dialling or accepting connections on the tunnel

type Tunnel

type Tunnel interface {
	// Init initializes tunnel with options
	Init(opts ...Option) error
	// Address returns the address the tunnel is listening on
	Address() string
	// Connect connects the tunnel
	Connect(ctx context.Context) error
	// Close closes the tunnel
	Close(ctx context.Context) error
	// Links returns all the links the tunnel is connected to
	Links() []Link
	// Dial allows a client to connect to a channel
	Dial(ctx context.Context, channel string, opts ...DialOption) (Session, error)
	// Listen allows to accept connections on a channel
	Listen(ctx context.Context, channel string, opts ...ListenOption) (Listener, error)
	// String returns the name of the tunnel implementation
	String() string
}

Tunnel creates a gre tunnel on top of the micro/transport. It establishes multiple streams using the Micro-Tunnel-Channel header and Micro-Tunnel-Session header. The tunnel id is a hash of the address being requested.

var DefaultTunnel Tunnel

DefaultTunnel contains default tunnel implementation

Directories

Path Synopsis
Package broker is a tunnel broker
Package broker is a tunnel broker
Package transport provides a tunnel transport
Package transport provides a tunnel transport

Jump to

Keyboard shortcuts

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