Documentation ¶
Overview ¶
Package tun2 tunnels HTTP requests over existing, long-lived connections using smux1 and optionally kcp2 to enable more reliable transport.
Currently this only works on a per-domain basis, but it is designed to be flexible enough to support path-based routing as an addition in the future.
Index ¶
- Variables
- type Auth
- type Backend
- type Client
- type ClientConfig
- type Connection
- type Server
- func (s *Server) Close()
- func (s *Server) GetAllBackends() []Backend
- func (s *Server) GetBackendsForDomain(domain string) []Backend
- func (s *Server) GetBackendsForUser(uname string) []Backend
- func (s *Server) HandleConn(ctx context.Context, c net.Conn)
- func (s *Server) KillBackend(id string) error
- func (s *Server) Listen(l net.Listener)
- func (s *Server) RoundTrip(req *http.Request) (*http.Response, error)
- func (s *Server) Wait()
- type ServerConfig
- type Storage
Constants ¶
This section is empty.
Variables ¶
var ( ErrCantOpenSessionStream = errors.New("tun2: connection can't open session stream") ErrCantWriteRequest = errors.New("tun2: connection stream can't write request") ErrCantReadResponse = errors.New("tun2: connection stream can't read response") )
Connection-specific errors
var ( ErrNoSuchBackend = errors.New("tun2: there is no such backend") ErrAuthMismatch = errors.New("tun2: authenication doesn't match database records") ErrCantRemoveWhatDoesntExist = errors.New("tun2: this connection does not exist, cannot remove it") )
Error values
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct { ID string Proto string User string Domain string Phi float32 Host string Usable bool }
Backend is the public state of an individual Connection.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client connects to a remote tun2 server and sets up authentication before routing individual HTTP requests to discrete streams that are reverse proxied to the eventual backend.
func NewClient ¶
func NewClient(cfg *ClientConfig) (*Client, error)
NewClient constructs an instance of Client with a given ClientConfig.
type ClientConfig ¶
type ClientConfig struct { TLSConfig *tls.Config ConnType string ServerAddr string Token string Domain string BackendURL string // contains filtered or unexported fields }
ClientConfig configures client with settings that the user provides.
type Connection ¶
Connection is a single active client -> server connection and session containing many streams over TCP+TLS or KCP+TLS. Every stream beyond the control stream is assumed to be passed to the underlying backend server.
All Connection methods assume this is locked externally.
func (*Connection) Close ¶
func (c *Connection) Close() error
Close destroys resouces specific to the connection.
func (*Connection) OpenStream ¶
OpenStream creates a new stream (connection) to the backend server.
func (*Connection) Ping ¶
func (c *Connection) Ping() error
Ping ends a "ping" to the client. If the client doesn't respond or the connection dies, then the connection needs to be cleaned up.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server routes frontend HTTP traffic to backend TCP traffic.
func NewServer ¶
func NewServer(cfg *ServerConfig) (*Server, error)
NewServer creates a new Server instance with a given config, acquiring all relevant resources.
func (*Server) GetAllBackends ¶
GetAllBackends fetches every backend connected to this server.
func (*Server) GetBackendsForDomain ¶
GetBackendsForDomain fetches all backends connected to this server associated to a single public domain name.
func (*Server) GetBackendsForUser ¶
GetBackendsForUser fetches all backends connected to this server owned by a given user by username.
func (*Server) HandleConn ¶
HandleConn starts up the needed mechanisms to relay HTTP traffic to/from the currently connected backend.
func (*Server) KillBackend ¶
KillBackend forcibly disconnects a given backend but doesn't offer a way to "ban" it from reconnecting.
func (*Server) Listen ¶
Listen passes this Server a given net.Listener to accept backend connections.
type ServerConfig ¶
ServerConfig ...