package revdial
import "golang.org/x/build/revdial/v2"
Package revdial implements a Dialer and Listener which work together to turn an accepted connection (for instance, a Hijacked HTTP request) into a Dialer which can then create net.Conns connecting back to the original dialer, which then gets a net.Listener accepting those conns.
This is basically a very minimal SOCKS5 client & server.
The motivation is that sometimes you want to run a server on a machine deep inside a NAT. Rather than connecting to the machine directly (which you can't, because of the NAT), you have the sequestered machine connect out to a public machine. Both sides then use revdial and the public machine can become a client for the NATed machine.
Index ¶
- Variables
- func ConnHandler() http.Handler
- func ReadProtoSwitchOrRedirect(r *bufio.Reader, req *http.Request) (location string, err error)
- type Dialer
- func NewDialer(c net.Conn, connPath string) *Dialer
- func (d *Dialer) Close() error
- func (d *Dialer) Dial(ctx context.Context) (net.Conn, error)
- func (d *Dialer) Done() <-chan struct{}
- type Listener
Variables ¶
ErrListenerClosed is returned by Accept after Close has been called.
Functions ¶
func ConnHandler ¶
ConnHandler returns the HTTP handler that needs to be mounted somewhere that the Listeners can dial out and get to. A dialer to connect to it is given to NewListener and the path to reach it is given to NewDialer to use in messages to the listener.
func ReadProtoSwitchOrRedirect ¶
ReadProtoSwitchOrRedirect is a helper for completing revdial protocol switch requests. If the response indicates successful switch, nothing is returned. If the response indicates a redirect, the new location is returned.
Types ¶
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
The Dialer can create new connections.
func NewDialer ¶
NewDialer returns the side of the connection which will initiate new connections. This will typically be the side which did the HTTP Hijack. The connection is (typically) the hijacked HTTP client connection. The connPath is the HTTP path and optional query (but without scheme or host) on the dialer where the ConnHandler is mounted.
func (*Dialer) Close ¶
Close closes the Dialer.
func (*Dialer) Dial ¶
Dial creates a new connection back to the Listener.
func (*Dialer) Done ¶
func (d *Dialer) Done() <-chan struct{}
Done returns a channel which is closed when d is closed (either by this process on purpose, by a local error, or close or error from the peer).
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener is a net.Listener, returning new connections which arrive from a corresponding Dialer.
func NewListener ¶
NewListener returns a new Listener, accepting connections which arrive from the provided server connection, which should be after any necessary authentication (usually after an HTTP exchange).
The provided dialServer func is responsible for connecting back to the server and doing TLS setup.
func (*Listener) Accept ¶
Accept blocks and returns a new connection, or an error.
func (*Listener) Addr ¶
Addr returns a dummy address. This exists only to conform to the net.Listener interface.
func (*Listener) Close ¶
Close closes the Listener, making future Accept calls return an error.
func (*Listener) Closed ¶
Closed reports whether the listener has been closed.
Source Files ¶
revdial.go
- Version
- v0.0.0-20250421191922-3619c213cff3 (latest)
- Published
- Apr 21, 2025
- Platform
- linux/amd64
- Imports
- 14 packages
- Last checked
- 2 months ago –
Tools for package owners.