router

package
v0.0.21-r1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: Apache-2.0 Imports: 11 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
	// DefaultServerBufferBytes is the default buffer size to exchange between connections.
	DefaultServerBufferBytes = 4096
)
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,
	ChannelBufferBytes:        DefaultServerBufferBytes,
}

DefaultRouterOption is a set of parameters in default value.

Functions

func DialOnConn added in v0.0.22

func DialOnConn(RouterAddress string, TargetChannel string, Conn net.Conn) error

DialOnConn initiaites a dial protocol with the router on `RouterAddress`. It is caller's resposibility to close the connection on error.

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 {
	// Returns if the permission check is passed for `frame`.
	CheckPermission(*Frame, net.Conn) error

	// Returns the expiration time of the key. Router will use this to set a connection deadline.
	GetExpirationTime(*Frame, net.Conn) time.Time
}

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.

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 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
	// ChannelBufferBytes specifies the size of the buffer while bridging the channel.
	ChannelBufferBytes uint64
}

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

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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