tunnel

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "TUNNEL"

Variables

View Source
var EmptyMetadata = Metadata{
	Command: Empty,
	Address: &Address{
		DomainName:  "-",
		AddressType: InvalidType,
	},
}

Functions

func Log

func Log(conn TunnelConn, isRelay bool)

func NewAccessLog

func NewAccessLog(ctx context.Context) error

func RegisterTunnel

func RegisterTunnel(name string, tunnel Tunnel)

RegisterTunnel register a tunnel by tunnel name

Types

type Address

type Address struct {
	DomainName  string
	Port        int
	NetworkType string
	net.IP
	AddressType
	SrcAddress *Address
}

func NewAddressFromAddr

func NewAddressFromAddr(network string, addr string) (*Address, error)

func NewAddressFromBytes

func NewAddressFromBytes(addressType byte, addr []byte, port int) (*Address, error)

func NewAddressFromHostPort

func NewAddressFromHostPort(network string, host string, port int) *Address

func (*Address) Copy

func (a *Address) Copy() *Address

func (*Address) Msg

func (a *Address) Msg() []byte

func (*Address) Network

func (a *Address) Network() string

func (*Address) ReadFrom

func (a *Address) ReadFrom(r io.Reader) error

func (*Address) ResolveIP

func (a *Address) ResolveIP() (net.IP, error)

func (*Address) String

func (a *Address) String() string

func (*Address) WriteTo

func (a *Address) WriteTo(w io.Writer) error

type AddressType

type AddressType byte
const (
	IPv4        AddressType = 1
	DomainName  AddressType = 3
	IPv6        AddressType = 4
	InvalidType AddressType = 0
)

func (AddressType) String

func (a AddressType) String() string

type Client

type Client interface {
	Dialer
	io.Closer
}

Client is the tunnel client based on stream connections

type Command

type Command byte
const (
	Connect   Command = 1
	Associate Command = 3
	Mux       Command = 0x7f
	Empty     Command = 0
)

func (Command) String

func (c Command) String() string

type Config

type Config struct {
	AccessLog string `json:"access_log" yaml:"access-log"`
}

type Conn

type Conn interface {
	net.Conn
	Name() string
	Metadata() *Metadata
	User() statistic.User
	Tunnels() *Tunnels
	Epoch() time.Time
	Sent() uint64
	Recv() uint64
}

Conn is the TCP connection in the tunnel

type ConnDialer

type ConnDialer interface {
	DialConn(*Address, statistic.User, *Metadata, Tunnel) (Conn, error)
}

ConnDialer creates TCP connections from the tunnel

type ConnListener

type ConnListener interface {
	AcceptConn(Tunnel) (Conn, error)
}

ConnListener accept TCP connections

type Dialer

type Dialer interface {
	ConnDialer
	PacketDialer
}

Dialer can dial to original server with a tunnel

type Listener

type Listener interface {
	ConnListener
	PacketListener
}

Listener can accept TCP and UDP streams from a tunnel

type Logger

type Logger struct {
	*golog.Logger
}

type Metadata

type Metadata struct {
	Command
	*Address
	SourceName  string
	RouterName  string
	ProcessName string
	IsTouch     bool
}

func (*Metadata) Network

func (r *Metadata) Network() string

func (*Metadata) ReadFrom

func (r *Metadata) ReadFrom(rr io.Reader) error

func (*Metadata) String

func (r *Metadata) String() string

func (*Metadata) WriteTo

func (r *Metadata) WriteTo(w io.Writer) error

type PacketConn

type PacketConn interface {
	net.PacketConn
	Name() string
	WriteWithMetadata([]byte, *Metadata) (int, error)
	ReadWithMetadata([]byte) (int, *Metadata, error)
	User() statistic.User
	Tunnels() *Tunnels
	Epoch() time.Time
	Sent() uint64
	Recv() uint64
}

PacketConn is the UDP packet stream in the tunnel

type PacketDialer

type PacketDialer interface {
	DialPacket(statistic.User, Tunnel) (PacketConn, error)
}

PacketDialer creates UDP packet stream from the tunnel

type PacketListener

type PacketListener interface {
	AcceptPacket(Tunnel) (PacketConn, error)
}

PacketListener accept UDP packet stream We don't have any tunnel based on packet streams, so AcceptPacket will always receive a real PacketConn

type Server

type Server interface {
	Listener
	io.Closer
}

Server is the tunnel server based on stream connections

type Tunnel

type Tunnel interface {
	Name() string
	NewClient(context.Context, Client) (Client, error)
	NewServer(context.Context, Server) (Server, error)
}

Tunnel describes a tunnel, allowing creating a tunnel from another tunnel We assume that the lower tunnels know exatly how upper tunnels work, and lower tunnels is transparent for the upper tunnels

func GetTunnel

func GetTunnel(name string) (Tunnel, error)

type TunnelConn

type TunnelConn interface {
	Name() string
	Epoch() time.Time
}

type Tunnels

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

func NewTunnels

func NewTunnels() *Tunnels

func (*Tunnels) Append

func (pts *Tunnels) Append(conn TunnelConn) *Tunnels

func (*Tunnels) Get

func (ts *Tunnels) Get(name string) TunnelConn

func (*Tunnels) Root

func (ts *Tunnels) Root() TunnelConn

func (*Tunnels) String

func (ts *Tunnels) String() string

Jump to

Keyboard shortcuts

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