router

package
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultDialConnectionTimeout is the default timeout for a dial operation.
	DefaultDialConnectionTimeout = 2 * time.Second
	// DefaultListenConnectionKeepAlive is the default keep alive checking interval for listening threads.
	DefaultListenConnectionKeepAlive = 20 * time.Second
)
View Source
const ListenerWaitTimeout = 5 * time.Minute

ListenerWaitTimeout specifies the duration for the listener to close the connection without receiving heartbeat from router.

View Source
const MaxChannelNameLength = 256

MaxChannelNameLength limits the maxmimum length of a channel name.

Variables

View Source
var DefaultRouterOption = Option{
	TokenAuthority:            &noPermissionCheckAuthority{},
	DialConnectionTimeout:     DefaultDialConnectionTimeout,
	ListenConnectionKeepAlive: DefaultListenConnectionKeepAlive,
}

DefaultRouterOption is a set of parameters in default value.

Functions

func ReadFrame added in v0.0.15

func ReadFrame(frame *Frame, reader io.Reader) error

ReadFrame decodes a frame from the reader, the data will be override.

func WriteFrame added in v0.0.15

func WriteFrame(frame *Frame, writer io.Writer) error

WriteFrame writes a frame to the writer.

Types

type Address

type Address struct {
	Channel string
}

Address represents an address in Router network.

func (*Address) Network

func (*Address) Network() string

Network returns the network type.

func (*Address) String

func (address *Address) String() string

String return the channel name of this address.

type Authority

type Authority interface {
	// Only returns a PeerInfo when the connection has the access permission.
	ValidatePeerInfo(*Frame, net.Conn) (*PeerInfo, error)
}

Authority will be used by the router for ACL control.

type Client

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

Client implements a Dial method to join the Router network.

func NewClient

func NewClient(RouterAddress string, TLSConfig *tls.Config) *Client

NewClient creates a RouterClient with TLS settings.

func NewClientWithoutAuth

func NewClientWithoutAuth(RouterAddress string) *Client

NewClientWithoutAuth creates a RouterClient structure.

func (*Client) Dial

func (client *Client) Dial(TargetChannel string) (net.Conn, error)

Dial initiaites a dial request into the Route network.

func (*Client) ScanChannel added in v0.0.38

func (client *Client) ScanChannel(ChannelRegexp string) (*ListenerScanResult, error)

ScanChannel returns the list of acessible channels.

type Frame

type Frame struct {
	Type         byte
	ConnectionID uint64
	Payload      string
}

Frame is the packet using between Router.

type Listener

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

Listener implements a net.Listener interface on Router network.

func NewListener

func NewListener(RouterAddress string, Channel string, TLSConfig *tls.Config) (*Listener, error)

NewListener creates a RouterListener.

func NewListenerWithoutAuth

func NewListenerWithoutAuth(RouterAddress string, Channel string) (*Listener, error)

NewListenerWithoutAuth creates a RouterListener structure and try to handshake with Router in `RouterAddress`.

func NewRouterListenerWithConn

func NewRouterListenerWithConn(
	RouterAddress string, Channel string, RouterAddressDialer func(string) (net.Conn, error)) (*Listener, error)

NewRouterListenerWithConn creates a RouterListener structure. Conn here can be a just initialized connectiono from TLS.

func (*Listener) Accept

func (listener *Listener) Accept() (net.Conn, error)

Accept returns a bridged connection from a dial request.

func (*Listener) Addr

func (listener *Listener) Addr() net.Addr

Addr returns the listener's address.

func (*Listener) Close

func (listener *Listener) Close() error

Close closes the listener.

func (*Listener) IsClosed

func (listener *Listener) IsClosed() bool

IsClosed returns whether the listener is closed.

type ListenerScanResult added in v0.0.38

type ListenerScanResult struct {
	ActiveChannels []string `json:"active_channels"`
}

ListenerScanResult returns a snapshot of accessible channels at the moment.

type Option

type Option struct {
	// TokenAuthority is the authority used for checking permissions.
	TokenAuthority Authority
	// DialConnectionTimeout specifies the timeout when a dialer connects to a listener.
	DialConnectionTimeout time.Duration
	// ListenConnectionKeepAlive specfies the health check interval.
	ListenConnectionKeepAlive time.Duration
}

Option specifies a set of options being used by the router.

type PeerInfo added in v0.0.29

type PeerInfo struct {
	Name          string `json:"name"`
	RemoteAddress string `json:"remote-address"`
	Expiration    time.Time
}

PeerInfo provides the necessary information to identify a peer.

type Router

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

Router proxies requests.

func NewDefaultRouter

func NewDefaultRouter() *Router

NewDefaultRouter creates a router with default option.

func NewRouter

func NewRouter(option Option) *Router

NewRouter creates a Router structure.

func (*Router) Serve

func (router *Router) Serve(listener net.Listener) error

Serve starts the serving process, this is a blocking call.

type TrackerConnection added in v0.0.29

type TrackerConnection struct {
	net.Conn
	// contains filtered or unexported fields
}

TrackerConnection keeps the track of the wrapped connection.

func (*TrackerConnection) Close added in v0.0.29

func (conn *TrackerConnection) Close() error

Close implements the net.Conn Close interface as well as finish the tracking.

func (*TrackerConnection) ErrorF added in v0.0.35

func (conn *TrackerConnection) ErrorF(format string, args ...interface{})

ErrorF prints a message to the according tracker and marks it as error status.

func (*TrackerConnection) PrintF added in v0.0.29

func (conn *TrackerConnection) PrintF(format string, args ...interface{})

PrintF prints a message to the according tracker.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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