server

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddrPool

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

func (*AddrPool) Acquire

func (ap *AddrPool) Acquire(cname string, pname string) (int, error)

func (*AddrPool) GetHTTPPort added in v0.3.0

func (ap *AddrPool) GetHTTPPort(id string) (int, error)

GetHTTPPort retrieves port for given node id http tunnel

func (*AddrPool) GetWSPort added in v0.3.0

func (ap *AddrPool) GetWSPort(id string) (int, error)

GetWSPort retrieves port for given node id websocket tunel

func (*AddrPool) Init

func (ap *AddrPool) Init(rang string) error

func (*AddrPool) Release

func (ap *AddrPool) Release(id string) error

type Auth

type Auth struct {
	Token string
}

func NewAuth

func NewAuth(token string) *Auth

NewAuth creates new auth from string.

type HTTPProxy

type HTTPProxy struct {
	httputil.ReverseProxy
	// contains filtered or unexported fields
}

HTTPProxy forwards HTTP traffic.

func NewHTTPProxy

func NewHTTPProxy(localURL *url.URL, logger *log.Entry) *HTTPProxy

NewHTTPProxy creates a new direct HTTPProxy, everything will be proxied to localURL.

func NewMultiHTTPProxy

func NewMultiHTTPProxy(localURLMap map[string]*url.URL, logger *log.Entry) *HTTPProxy

NewMultiHTTPProxy creates a new dispatching HTTPProxy, requests may go to different backends based on localURLMap.

func (*HTTPProxy) Director

func (p *HTTPProxy) Director(req *http.Request)

Director is ReverseProxy Director it changes request URL so that the request is correctly routed based on localURL and localURLMap. If no URL can be found the request is canceled.

func (*HTTPProxy) Proxy

func (p *HTTPProxy) Proxy(w io.Writer, r io.ReadCloser, msg *proto.ControlMessage)

Proxy is a ProxyFunc.

type HostAuth

type HostAuth struct {
	Host string
	Auth *Auth
}

HostAuth holds host and authentication info.

type Pooler

type Pooler interface {
	Init(rang string) error
	Acquire(cname string, pname string) (int, error)
	Release(id string) error
	GetHTTPPort(id string) (int, error)
	GetWSPort(id string) (int, error)
}

type RegistryItem

type RegistryItem struct {
	Hosts         []*HostAuth
	Listeners     []net.Listener
	ListenerNames []string
	ClientName    string
	ClientID      string
}

RegistryItem holds information about hosts and listeners associated with a client.

type RemoteID

type RemoteID struct {
	ClientID string
	PortName string
	Port     int
}

type Server

type Server struct {
	PortPool Pooler
	// contains filtered or unexported fields
}

Server is responsible for proxying public connections to the client over a tunnel connection.

func NewServer

func NewServer(config *ServerConfig) (*Server, error)

NewServer creates a new Server based on configuration. Caller must invoke Start() on returned instance in order to start server

func (*Server) Addr

func (s *Server) Addr() string

Addr returns network address clients connect to.

func (Server) GetID

func (r Server) GetID(cname string) string

GetID returns the ID for this client

func (*Server) Ping

func (s *Server) Ping(identifier string) (time.Duration, error)

Ping measures the RTT response time.

func (Server) PreSubscribe

func (r Server) PreSubscribe(origaddr string)

func (*Server) RoundTrip

func (s *Server) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip is http.RoundTriper implementation.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP proxies http connection to the client.

func (*Server) Start

func (s *Server) Start()

Start starts accepting connections form clients. For accepting http traffic from end users server must be run as handler on http server.

func (*Server) Stop

func (s *Server) Stop()

Stop closes the server.

func (Server) Subscribe

func (r Server) Subscribe(cname string, origaddr string)

Subscribe allows to connect client with a given identifier.

func (Server) Subscriber

func (r Server) Subscriber(hostPort string) (string, *Auth, bool)

Subscriber returns client identifier assigned to given host.

func (*Server) Unsubscribe

func (s *Server) Unsubscribe(identifier string, idname string) *RegistryItem

Unsubscribe removes client from registry, disconnects client if already connected and returns it's RegistryItem.

type ServerConfig

type ServerConfig struct {
	// Address is TCP address to listen for client connections. If empty ":0" is used.
	Address string
	// PortPool assigns and release ports
	PortPool Pooler
	// AuthHandler is function validates provided auth token
	AuthHandler func(string) bool
	// Logger is optional logger. If nil logging is disabled.
	Logger *log.Entry
}

ServerConfig defines all data needed for running the Server.

type TCPProxy

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

TCPProxy forwards TCP streams.

func NewMultiTCPProxy

func NewMultiTCPProxy(localAddrMap map[string]string, logger *log.Entry) *TCPProxy

NewMultiTCPProxy creates a new dispatching TCPProxy, connections may go to different backends based on localAddrMap.

func NewTCPProxy

func NewTCPProxy(localAddr string, logger *log.Entry) *TCPProxy

NewTCPProxy creates new direct TCPProxy, everything will be proxied to localAddr.

func (*TCPProxy) Proxy

func (p *TCPProxy) Proxy(w io.Writer, r io.ReadCloser, msg *proto.ControlMessage)

Proxy is a ProxyFunc.

type TunnelExt

type TunnelExt struct {
	IdName  string
	Tunnels map[string]*proto.Tunnel
}

Jump to

Keyboard shortcuts

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