Documentation ¶
Index ¶
Constants ¶
View Source
const ( TypeHTTP = iota TypeTCP )
Variables ¶
This section is empty.
Functions ¶
func UsableAddrs ¶
UsableAddrs returns all tcp addresses that we can bind a listener to.
Types ¶
type StateRecorder ¶
type StateRecorder struct {
// contains filtered or unexported fields
}
StateRecorder saves state changes pushed to StateRecorder.C().
func NewStateRecorder ¶
func NewStateRecorder() *StateRecorder
func (*StateRecorder) C ¶
func (rec *StateRecorder) C() chan<- *tunnel.ClientStateChange
func (*StateRecorder) States ¶
func (rec *StateRecorder) States() []*tunnel.ClientStateChange
func (*StateRecorder) WaitTransition ¶
func (rec *StateRecorder) WaitTransition(from, to tunnel.ClientState) error
func (*StateRecorder) WaitTransitions ¶
func (rec *StateRecorder) WaitTransitions(states ...tunnel.ClientState) error
type Tunnel ¶
type Tunnel struct { // Type specifies a tunnel type - either TypeHTTP (default) or TypeTCP. Type int // Handler is a handler to use for serving tunneled connections on // local server. The value of this field is required to be of type: // // - http.Handler or http.HandlerFunc for HTTP tunnels // - func(net.Conn) for TCP tunnels // // Required field. Handler interface{} // LocalAddr is a network address of local server that handles // connections/requests with Handler. // // Optional field, takes value of "127.0.0.1:0" when empty. LocalAddr string // ClientIdent is an identifier of a client that have already // registered a HTTP tunnel and have established control connection. // // If the Type is TypeTCP, instead of creating new client // for this TCP tunnel, we add it to an existing client // specified by the field. // // Optional field for TCP tunnels. // Ignored field for HTTP tunnels. ClientIdent string // RemoteAddr is a network address of remote server, which accepts // connections on a tunnel server side. // // Required field for TCP tunnels. // Ignored field for HTTP tunnels. RemoteAddr string // RemoteAddrIdent an identifier of an already existing listener, // that listens on multiple interfaces; if the RemoteAddrIdent is valid // identifier the IP field is required to be non-nil and RemoteAddr // is ignored. // // Optional field for TCP tunnels. // Ignored field for HTTP tunnels. RemoteAddrIdent string // IP specifies an IP address value for IP-based routing for TCP tunnels. // For more details see inline documentation for (*tunnel.Server).AddAddr. // // Optional field for TCP tunnels. // Ignored field for HTTP tunnels. IP net.IP // StateChanges listens on state transitions. // // If ClientIdent field is empty, the StateChanges will receive // state transition events for the newly created client. // Otherwise setting this field is a nop. StateChanges chan<- *tunnel.ClientStateChange }
Tunnel represents a single HTTP or TCP tunnel that can be served by TunnelTest.
type TunnelTest ¶
type TunnelTest struct { Server *tunnel.Server ServerStateRecorder *StateRecorder Clients map[string]*tunnel.Client Listeners map[string][2]net.Listener // [0] is local listener, [1] is remote one (for TCP tunnels) Addrs []*net.TCPAddr Tunnels map[string]*Tunnel DebugNet bool // for debugging network communication // contains filtered or unexported fields }
func NewTunnelTest ¶
func NewTunnelTest() (*TunnelTest, error)
func Serve ¶
func Serve(tunnels map[string]*Tunnel) (*TunnelTest, error)
Serve creates new TunnelTest that serves the given tunnels.
If tunnels is nil, DefaultTunnels() are used instead.
func (*TunnelTest) Addr ¶
func (tt *TunnelTest) Addr(ident string) net.Addr
Addr gives server endpoint of the TCP tunnel for the given ident.
If the tunnel does not exist or is a HTTP one, TunnelAddr return nil.
func (*TunnelTest) Close ¶
func (tt *TunnelTest) Close() (err error)
func (*TunnelTest) Request ¶
Request creates a HTTP request to a server endpoint of the HTTP tunnel for the given ident.
If the tunnel does not exist, Request returns nil.
func (*TunnelTest) ServerAddr ¶
func (tt *TunnelTest) ServerAddr() net.Addr
Click to show internal directories.
Click to hide internal directories.