sniproxy

package
v0.0.0-...-c9163c1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2022 License: AGPL-3.0 Imports: 24 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultReadBufferSize  = 64 * 1024
	DefaultWriteBufferSize = 64 * 1024
)

Default buffer sizes for sniproxy.

Variables

This section is empty.

Functions

func IsClosedConnError

func IsClosedConnError(err error) bool

IsClosedConnError checks if the error is a Closed connection error.

Types

type Dest

type Dest struct {
	Name       string
	Home       bool // Use DialHome.
	ForwardTCP string
}

Dest specifies a destination.

type DialOption

type DialOption struct {
	// Path is the path of the WebSocket endpoint.
	Path string

	// Dialer is an optional WebSocket dialer to use.
	Dialer *websocket.Dialer

	// TunnelOptions fine tunes the behavior of a tunnel.
	TunnelOptions *Options

	// WithoutTLS uses the "ws://" scheme rather than the "wss://" scheme.
	WithoutTLS bool
}

DialOption provides addition option for dialing.

type Endpoint

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

Endpoint is an endpoint that implements the listener.

func Dial

func Dial(
	ctx context.Context, r Router, opt *DialOption,
) (*Endpoint, error)

Dial connects to fabrics server, establishes a tunnel and returns an endpoint.

func (*Endpoint) Accept

func (p *Endpoint) Accept() (net.Conn, error)

Accept accepts a connection from the tunnel.

func (*Endpoint) Addr

func (p *Endpoint) Addr() net.Addr

Addr returns the network address of the endpoint.

func (*Endpoint) Close

func (p *Endpoint) Close() error

Close closes the endpoint. It closes the tunnel, so all accepted, unclosed connections are also lost.

type Options

type Options struct {
	// Using a new websocket connection for each new incoming
	// new connection.
	Siding bool `json:",omitempty"`

	// Remote enables sending remote address.
	DialWithAddr bool `json:",omitempty"`
}

Options is a the JSON marshalable options for dialing an endpoint.

type Router

type Router interface {
	Route(ctx context.Context) (host string, token string, err error)
}

Router provides a host to connect with a token.

type Server

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

Server is an SNI based TCP proxy server that can serve over websocket.

func NewServer

func NewServer(config *ServerConfig) *Server

NewServer creates a new server that can accept endpoint providing websocket connections.

func (*Server) ServeBack

func (s *Server) ServeBack(c *aries.C) error

ServeBack serves an incoming proxy connection via websocket. It uses c.User as the endpoint name

func (*Server) ServeBackName

func (s *Server) ServeBackName(c *aries.C, name string) error

ServeBackName serves an incoming proxy connection via websocket using the given endpoint name.

func (*Server) ServeFront

func (s *Server) ServeFront(ctx context.Context, lis net.Listener) error

ServeFront starts accepting connections from the configured net.Listener and route incoming connections to connected endpoints.

type ServerConfig

type ServerConfig struct {
	// Lookup looks for the user ID for a particular domain.
	Lookup func(domain string) (*Dest, error)

	// DialHome provides a dialer for dialing home for endpoint name "~".
	DialHome func(ctx context.Context) (net.Conn, error)

	// DialForward provides a dialer for dialing a domain for endpoint
	// that is fowarding to a TCP. If this is not provided,
	// a default network TCP dailing will be used.
	DialForward func(ctx context.Context, fwd string) (net.Conn, error)

	// SideToken gets a token for side connections.
	SideToken func(user string) (string, error)

	// OnConnect is called when a new endpoint connects. It returns
	// a session ID. This callback function is optional.
	OnConnect func(user string) int64

	// OnDisconnect is called when a new endpoint disconnects. It is
	// called with the user's name and the session ID got from
	// OnConnect. If OnConnect is not set, session is always 0.
	OnDisconnect func(user string, session int64)
}

ServerConfig contains configuration of an SNI based proxy server.

type StaticRouter

type StaticRouter struct {
	Host  string
	Token string
}

StaticRouter routes to the given host with the given token.

func (*StaticRouter) Route

func (r *StaticRouter) Route(ctx context.Context) (string, string, error)

Route returns the given static host and token.

type TLSHelloConn

type TLSHelloConn struct {
	net.Conn
	// contains filtered or unexported fields
}

TLSHelloConn wraps a connection and peeks the hello info.

func NewTLSHelloConn

func NewTLSHelloConn(conn net.Conn) *TLSHelloConn

NewTLSHelloConn wraps conn and reads the TLS ClientHello inforamtion.

func (*TLSHelloConn) HelloInfo

func (c *TLSHelloConn) HelloInfo() (*TLSHelloInfo, error)

HelloInfo returns the SNI information extracted from the TLS ClientHello, without consuming any bytes from br. On any error, the empty string is returned.

func (*TLSHelloConn) Read

func (c *TLSHelloConn) Read(buf []byte) (int, error)

Read implements io.Reader

type TLSHelloInfo

type TLSHelloInfo struct {
	ServerName string
	ProtoCount int
	FirstProto string
}

TLSHelloInfo contains the brief information about at TLS ClientHello message.

Jump to

Keyboard shortcuts

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