Movatterモバイル変換


[0]ホーム

URL:


revdial

package
v0.0.0-...-35ef07fLatest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License:BSD-3-ClauseImports:14Imported by:2

Details

Repository

cs.opensource.google/go/x/build

Links

README

Go Reference

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.

Documentation

Overview

Package revdial implements a Dialer and Listener which work togetherto turn an accepted connection (for instance, a Hijacked HTTP request) intoa Dialer which can then create net.Conns connecting back to the originaldialer, 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 amachine deep inside a NAT. Rather than connecting to the machinedirectly (which you can't, because of the NAT), you have thesequestered machine connect out to a public machine. Both sidesthen use revdial and the public machine can become a client for theNATed machine.

Index

Constants

This section is empty.

Variables

View Source
var ErrListenerClosed =errors.New("revdial: Listener closed")

ErrListenerClosed is returned by Accept after Close has been called.

Functions

funcConnHandler

func ConnHandler()http.Handler

ConnHandler returns the HTTP handler that needs to be mounted somewherethat the Listeners can dial out and get to. A dialer to connect to itis given to NewListener and the path to reach it is given to NewDialerto use in messages to the listener.

funcReadProtoSwitchOrRedirect

func ReadProtoSwitchOrRedirect(r *bufio.Reader, req *http.Request) (locationstring, errerror)

ReadProtoSwitchOrRedirect is a helper for completing revdial protocol switchrequests. If the response indicates successful switch, nothing is returned.If the response indicates a redirect, the new location is returned.

Types

typeDialer

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

The Dialer can create new connections.

funcNewDialer

func NewDialer(cnet.Conn, connPathstring) *Dialer

NewDialer returns the side of the connection which will initiatenew connections. This will typically be the side which did the HTTPHijack. The connection is (typically) the hijacked HTTP clientconnection. The connPath is the HTTP path and optional query (butwithout scheme or host) on the dialer where the ConnHandler ismounted.

func (*Dialer)Close

func (d *Dialer) Close()error

Close closes the Dialer.

func (*Dialer)Dial

func (d *Dialer) Dial(ctxcontext.Context) (net.Conn,error)

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 bythis process on purpose, by a local error, or close or error fromthe peer).

typeListener

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

Listener is a net.Listener, returning new connections which arrivefrom a corresponding Dialer.

funcNewListener

func NewListener(serverConnnet.Conn, dialServer func(context.Context) (net.Conn,error)) *Listener

NewListener returns a new Listener, accepting connections whicharrive from the provided server connection, which should be afterany necessary authentication (usually after an HTTP exchange).

The provided dialServer func is responsible for connecting back tothe server and doing TLS setup.

func (*Listener)Accept

func (ln *Listener) Accept() (net.Conn,error)

Accept blocks and returns a new connection, or an error.

func (*Listener)Addr

func (ln *Listener) Addr()net.Addr

Addr returns a dummy address. This exists only to conform to thenet.Listener interface.

func (*Listener)Close

func (ln *Listener) Close()error

Close closes the Listener, making future Accept calls return anerror.

func (*Listener)Closed

func (ln *Listener) Closed()bool

Closed reports whether the listener has been closed.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp