Documentation ¶
Overview ¶
Package tunnel is fast and secure client/server package that enables proxying public connections to your local machine over a tunnel connection from the local machine to the public server.
Index ¶
- Variables
- type Auth
- type Backoff
- type Client
- type ClientConfig
- type ConnDiscoNotifier
- type ConnPool
- func (p *ConnPool) AddConn(conn net.Conn, identifier id.ID) error
- func (p *ConnPool) AddrToIdentifier(addr string) id.ID
- func (p *ConnPool) DeleteConn(identifier id.ID)
- func (p *ConnPool) GetClientConn(req *http.Request, addr string) (*http2.ClientConn, error)
- func (p *ConnPool) MarkDead(c *http2.ClientConn)
- func (p *ConnPool) URL(identifier id.ID) string
- type DiscoNotifier
- type HTTPProxy
- type HostAuth
- type ProxyFunc
- type ProxyFuncs
- type RegChecker
- type RegistryItem
- type Server
- func (s *Server) Addr() string
- func (s *Server) DiscoNotify(identifier id.ID)
- func (r Server) IsSubscribed(identifier id.ID) bool
- func (r Server) Item(identifier id.ID) *RegistryItem
- func (s *Server) RoundTrip(r *http.Request) (*http.Response, error)
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) Start()
- func (s *Server) Stop()
- func (r Server) Subscribe(identifier id.ID)
- func (r Server) Subscriber(hostPort string) (id.ID, *Auth, bool)
- func (s *Server) Unsubscribe(identifier id.ID) *RegistryItem
- type ServerConfig
- type TCPProxy
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultTimeout specifies general purpose timeout. DefaultTimeout = 10 * time.Second )
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
type Backoff interface { // Next returns the duration to sleep before retrying to reconnect. // If the returned value is negative, the retry is aborted. NextBackOff() time.Duration // Reset is used to signal a reconnection was successful and next // call to Next should return desired time duration for 1st reconnection // attempt. Reset() }
Backoff defines behavior of staggering reconnection retries.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is responsible for creating connection to the server, handling control messages. It uses ProxyFunc for transferring data between server and local services.
func NewClient ¶
func NewClient(config *ClientConfig) *Client
NewClient creates a new unconnected Client based on configuration. Caller must invoke Start() on returned instance in order to connect server.
type ClientConfig ¶
type ClientConfig struct { // ServerAddr specifies TCP address of the tunnel server. ServerAddr string // TLSClientConfig specifies the tls configuration to use with // tls.Client. TLSClientConfig *tls.Config // DialTLS specifies an optional dial function that creates a tls // connection to the server. If DialTLS is nil, tls.Dial is used. DialTLS func(network, addr string, config *tls.Config) (net.Conn, error) // Backoff specifies backoff policy on server connection retry. If nil // when dial fails it will not be retried. Backoff Backoff // Tunnels specifies the tunnels client requests to be opened on server. Tunnels map[string]*proto.Tunnel // p is ProxyFunc responsible for transferring data between server // and local services. Proxy ProxyFunc // Logger is optional logger. If nil logging is disabled. Logger log.Logger }
ClientConfig is configuration of the Client.
type ConnDiscoNotifier ¶
type ConnDiscoNotifier interface { DiscoNotifier // ConnNotify is called on client connect. ConnNotify(tunnels map[string]*proto.Tunnel, identifier id.ID) }
ConnDiscoNotifier - this interfaces implements the DiscoNotifier interface, as well as providing a ConnNotify method.
type ConnPool ¶
type ConnPool struct {
// contains filtered or unexported fields
}
ConnPool - describes a connection pool
func (*ConnPool) AddrToIdentifier ¶
AddrToIdentifier - Converts an address, as generated from URL, back into an ID
func (*ConnPool) DeleteConn ¶
DeleteConn - This deletes a connection from the pool, sending a notification.
func (*ConnPool) GetClientConn ¶
GetClientConn - this implements http2.ClientConnPool
func (*ConnPool) MarkDead ¶
func (p *ConnPool) MarkDead(c *http2.ClientConn)
MarkDead - this implements http2.ClientConnPool
type DiscoNotifier ¶
type DiscoNotifier interface { // DiscoNotify is called on client disconnect. DiscoNotify(identifier id.ID) }
DiscoNotifier - this interface provides a DiscoNotify method
type HTTPProxy ¶
type HTTPProxy struct { httputil.ReverseProxy // contains filtered or unexported fields }
HTTPProxy forwards HTTP traffic.
func NewHTTPProxy ¶
NewHTTPProxy creates a new direct HTTPProxy, everything will be proxied to localURL.
func NewMultiHTTPProxy ¶
NewMultiHTTPProxy creates a new dispatching HTTPProxy, requests may go to different backends based on localURLMap.
func (*HTTPProxy) Director ¶
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)
p is a ProxyFunc.
type ProxyFunc ¶
type ProxyFunc func(w io.Writer, r io.ReadCloser, msg *proto.ControlMessage)
ProxyFunc is responsible for forwarding a remote connection to local server and writing the response.
func Proxy ¶
func Proxy(p ProxyFuncs) ProxyFunc
p returns a ProxyFunc that uses custom function if provided.
type ProxyFuncs ¶
type ProxyFuncs struct { // HTTP is custom implementation of HTTP proxing. HTTP ProxyFunc // TCP is custom implementation of TCP proxing. TCP ProxyFunc }
ProxyFuncs is a collection of ProxyFunc.
type RegChecker ¶
type RegChecker interface { // CheckRegistration - if returns true, it will auto-register. // a client. This allows us to hook into a registration database // instead of keeping all possible registrations in memory. CheckRegistration(id.ID) bool }
RegChecker - this interface allows us to plug in an external checker for a registry on client connect.
type RegistryItem ¶
RegistryItem holds information about hosts and listeners associated with a client.
type Server ¶
type Server struct { ConnPool *ConnPool // 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.
func (*Server) DiscoNotify ¶
DiscoNotify clears resources used by client, it's invoked by connection pool when client goes away. This is the default DiscoNotifier, and is called in the absence of one. If you set DiscoNotifier to something other than this method, you will need to have that method call this DiscoNotify or cleanup will not occur.
func (Server) IsSubscribed ¶
IsSubscribed returns true if client is subscribed.
func (Server) Item ¶
func (r Server) Item(identifier id.ID) *RegistryItem
Item - fetch RegistryItem by ID. If it doesn't exist, or has a void registration, return nil
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) Subscriber ¶
Subscriber returns client identifier assigned to given host.
func (*Server) Unsubscribe ¶
func (s *Server) Unsubscribe(identifier id.ID) *RegistryItem
Unsubscribe removes client from registry, disconnects client if already connected and returns it's RegistryItem.
type ServerConfig ¶
type ServerConfig struct { // Addr is TCP address to listen for client connections. If empty ":0" // is used. Addr string // TLSConfig specifies the tls configuration to use with tls.Listener. TLSConfig *tls.Config // Listener specifies optional listener for client connections. If nil // tls.Listen("tcp", Addr, TLSConfig) is used. Listener net.Listener // Logger is optional logger. If nil logging is disabled. Logger log.Logger // Notifier is optional notification on disconnects. If it additionally // implements ConnDiscoNotifier interface, ConnNotify will be called // when a client connects. Notifier DiscoNotifier // Optional RegChecker implementation, for doing dynamic registrations. RegChecker RegChecker }
ServerConfig defines configuration for the Server.
type TCPProxy ¶
type TCPProxy struct {
// contains filtered or unexported fields
}
TCPProxy forwards TCP streams.
func NewMultiTCPProxy ¶
NewMultiTCPProxy creates a new dispatching TCPProxy, connections may go to different backends based on localAddrMap.
func NewTCPProxy ¶
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)
p is a ProxyFunc.