remotedialer

package module
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: May 8, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

README

Reverse Tunneling Dialer

Client makes an outbound connection to a server. The server can now do net.Dial from the server that will actually do a net.Dial on the client and pipe all bytes back and forth.

Fun times!

Refer to server/ and client/ how to use. Or don't.... This framework can hurt your head trying to conceptualize.

See also:

  • inlets.dev which uses the client and server components to form a tunnel for clients behind NAT or firewalls.

Documentation

Index

Constants

View Source
const (
	Data messageType = iota + 1
	Connect
	Error
	AddClient
	RemoveClient
)
View Source
const (
	PingWaitDuration  = 60 * time.Second
	PingWriteInterval = 5 * time.Second
	MaxRead           = 8192
	HandshakeTimeOut  = 10 * time.Second
)
View Source
const (
	MaxBuffer = 1 << 20
)

Variables

View Source
var (
	Token = "X-API-Tunnel-Token"
	ID    = "X-API-Tunnel-ID"
)
View Source
var PrintTunnelData bool

PrintTunnelData No tunnel logging by default

Functions

func ClientConnect

func ClientConnect(ctx context.Context, wsURL string, headers http.Header, dialer *websocket.Dialer,
	auth ConnectAuthorizer, onConnect func(context.Context, *Session) error) error

ClientConnect connect to WS and wait 5 seconds when error

func ConnectToProxy added in v0.2.8

func ConnectToProxy(rootCtx context.Context, proxyURL string, headers http.Header, auth ConnectAuthorizer, dialer *websocket.Dialer, onConnect func(context.Context, *Session) error) error

ConnectToProxy connect to websocket server

func DefaultErrorWriter

func DefaultErrorWriter(rw http.ResponseWriter, req *http.Request, code int, err error)

func SetLogger added in v0.2.9

func SetLogger(logger Logger)

SetLogger ...

Types

type Authorizer

type Authorizer func(req *http.Request) (clientKey string, authed bool, err error)

type ConnectAuthorizer

type ConnectAuthorizer func(proto, address string) bool

ConnectAuthorizer custom for authorization

type Dialer

type Dialer func(ctx context.Context, network, address string) (net.Conn, error)

type ErrorWriter

type ErrorWriter func(rw http.ResponseWriter, req *http.Request, code int, err error)

type Logger added in v0.2.9

type Logger interface {

	// Debugf uses fmt.Sprintf to log a templated message.
	Debugf(template string, args ...interface{})
	// Infof uses fmt.Sprintf to log a templated message.
	Infof(template string, args ...interface{})
	// Warnf uses fmt.Sprintf to log a templated message.
	Warnf(template string, args ...interface{})
	// Errorf uses fmt.Sprintf to log a templated message.
	Errorf(template string, args ...interface{})
}

Logger like zap.Sugar

func GetLogger added in v0.2.9

func GetLogger() Logger

GetLogger ...

type Server

type Server struct {
	PeerID                  string
	PeerToken               string
	ClientConnectAuthorizer ConnectAuthorizer
	// contains filtered or unexported fields
}

func New

func New(auth Authorizer, errorWriter ErrorWriter) *Server

func (*Server) AddPeer

func (s *Server) AddPeer(url, id, token string)

func (*Server) Dialer

func (s *Server) Dialer(clientKey string) Dialer

func (*Server) HasSession

func (s *Server) HasSession(clientKey string) bool

func (*Server) RemovePeer

func (s *Server) RemovePeer(id string)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type Session

type Session struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewClientSession

func NewClientSession(auth ConnectAuthorizer, conn *websocket.Conn) *Session

func NewClientSessionWithDialer added in v0.2.12

func NewClientSessionWithDialer(auth ConnectAuthorizer, conn *websocket.Conn, dialer Dialer) *Session

func (*Session) Close

func (s *Session) Close()

func (*Session) Dial added in v0.2.12

func (s *Session) Dial(ctx context.Context, proto, address string) (net.Conn, error)

func (*Session) Serve

func (s *Session) Serve(ctx context.Context) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL