tunnel

package
v1.24.5 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDataChannelSize = 512
	MaxOpenConnectTimeout  = 30 * time.Second
)
View Source
const DefaultEventChannelSize = 1024
View Source
const (
	DefaultRetryInterval = 10 * time.Second
)

Variables

View Source
var DefaultDialTimeout = 30 * time.Second
View Source
var ErrFullChannel = errors.New("channel full")

Functions

func PacketDecode

func PacketDecode[T any](data []byte) T

func PacketEncode

func PacketEncode(data any) []byte

func RandomServerID

func RandomServerID(prefix string) string

func Run

func Run(ctx context.Context, options *Options) error

Types

type Annotations

type Annotations map[string]string

type AuthenticationManager

type AuthenticationManager interface {
	Authentication(ctx context.Context, name string, token string) error
}

type ChannelWithChildren

type ChannelWithChildren struct {
	Channel     *ConnectedTunnel // channel is the direct connected channel
	Annotations map[string]string
	Children    map[string]Annotations // children are channels connected to the direct channel
}

type ConnectedTunnel

type ConnectedTunnel struct {
	Tunnel
	ID              string
	AnnotationsSent Annotations
	Options         TunnelOptions
}

type ConnectionManager

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

func NewConectionManager

func NewConectionManager(s *TunnelServer) *ConnectionManager

func (*ConnectionManager) Open

func (cm *ConnectionManager) Open(network, address string, timeout time.Duration, dest string) (conn net.Conn, err error)

type Connections

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

type Dailer

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

func (Dailer) DialContext

func (d Dailer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

func (Dailer) DialTimeout

func (d Dailer) DialTimeout(network, address string, timeout time.Duration) (net.Conn, error)

type EventKind

type EventKind string
const (
	EventKindConnected    EventKind = "connected"
	EventKindKeepalive    EventKind = "alive"
	EventKindDisConnected EventKind = "disconnected"
)

type EventWatcher

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

func (*EventWatcher) Close

func (t *EventWatcher) Close()

func (EventWatcher) Result

func (r EventWatcher) Result() <-chan TunnelEvent

type GRPCTunnel

type GRPCTunnel[T grpcstream] struct {
	// contains filtered or unexported fields
}

func (*GRPCTunnel[T]) Close

func (t *GRPCTunnel[T]) Close() error

func (*GRPCTunnel[T]) Recv

func (t *GRPCTunnel[T]) Recv(into *Packet) error

func (*GRPCTunnel[T]) Send

func (t *GRPCTunnel[T]) Send(from *Packet) error

type GrpcTunnelServer

type GrpcTunnelServer struct {
	TunnelServer      *TunnelServer
	ClientAnnotations Annotations // annotations send to downstream clients
	proto.UnimplementedPeerServiceServer
}

func (GrpcTunnelServer) Connect

func (s GrpcTunnelServer) Connect(connectServer proto.PeerService_ConnectServer) error

func (GrpcTunnelServer) ConnectUpstream

func (s GrpcTunnelServer) ConnectUpstream(ctx context.Context, addr string, tlsConfig *tls.Config, token string, annotations Annotations) error

func (GrpcTunnelServer) ConnectUpstreamWithRetry

func (s GrpcTunnelServer) ConnectUpstreamWithRetry(ctx context.Context, addr string, tlsConfig *tls.Config, token string, annotations Annotations) error

func (GrpcTunnelServer) GrpcServer

func (s GrpcTunnelServer) GrpcServer(tlsConfig *tls.Config) *grpc.Server

func (GrpcTunnelServer) ServeGrpc

func (s GrpcTunnelServer) ServeGrpc(ctx context.Context, listen string, tlsConfig *tls.Config) error

type NonAuthManager

type NonAuthManager struct{}

func (*NonAuthManager) Authentication

func (m *NonAuthManager) Authentication(ctx context.Context, name string, token string) error

type Options

type Options struct {
	PeerID          string `json:"peerID,omitempty"`
	Listen          string `json:"listen,omitempty"`
	UpstreamAddr    string `json:"upstreamAddr,omitempty"`
	EnableClientTLS bool   `json:"enableClientTLS,omitempty"`
	Token           string `json:"token,omitempty"`
	TLS             *TLS   `json:"tls,omitempty"`
}

func NewDefaultOptions

func NewDefaultOptions() *Options

type Packet

type Packet struct {
	Kind    PacketKind
	Src     string
	Dest    string
	SrcCID  int64
	DestCID int64
	Data    []byte
	Error   string
}

type PacketDataConnect

type PacketDataConnect struct {
	Token string `json:"token,omitempty"`
}

type PacketDataOpen

type PacketDataOpen struct {
	Network string        `json:"network,omitempty"`
	Address string        `json:"address,omitempty"`
	Timeout time.Duration `json:"timeout,omitempty"`
}

type PacketDataRoute

type PacketDataRoute struct {
	Kind        RouteUpdateKind        `json:"kind,omitempty"`
	Annotations Annotations            `json:"annotations,omitempty"`
	Peers       map[string]Annotations `json:"peers,omitempty"`
}

type PacketKind

type PacketKind int
const (
	PacketKindData    PacketKind = iota // data or as a ack
	PacketKindConnect                   // handshake and auth
	PacketKindOpen                      // open connection
	PacketKindClose                     // close connect/stream
	PacketKindRoute                     // route update
)

type RouteTable

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

func NewEmptyRouteTable

func NewEmptyRouteTable(s *TunnelServer) *RouteTable

func (*RouteTable) Connect

func (t *RouteTable) Connect(tun *ConnectedTunnel, data PacketDataRoute)

func (*RouteTable) Disconnect

func (t *RouteTable) Disconnect(stream *ConnectedTunnel)

func (*RouteTable) Exists

func (t *RouteTable) Exists(id string) bool

func (*RouteTable) OnChange

func (t *RouteTable) OnChange(from *ConnectedTunnel, data PacketDataRoute)

func (*RouteTable) RouteExchange

func (t *RouteTable) RouteExchange(idchannel *ConnectedTunnel, annotationsToSend Annotations) (*PacketDataRoute, error)

func (*RouteTable) Select

func (t *RouteTable) Select(dest string) (*ConnectedTunnel, error)

func (*RouteTable) SendKeepAlive

func (t *RouteTable) SendKeepAlive(annotationsToSend Annotations) error

type RouteUpdateKind

type RouteUpdateKind int
const (
	RouteUpdateKindInvalid RouteUpdateKind = iota
	RouteUpdateKindReferesh
	RouteUpdateKindOnline
	RouteUpdateKindOffline
	RouteUpdateKindKeepAlive
)

type TLS

type TLS struct {
	CertFile string `json:"certFile,omitempty"`
	KeyFile  string `json:"keyFile,omitempty"`
	CAFile   string `json:"caFile,omitempty"`
}

func NewDefaultTLS

func NewDefaultTLS() *TLS

func (TLS) ToTLSConfig

func (o TLS) ToTLSConfig() (*tls.Config, error)

type Tunnel

type Tunnel interface {
	Recv(*Packet) error
	Send(*Packet) error
	Close() error
}

type TunnelConn

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

func (*TunnelConn) Close

func (c *TunnelConn) Close() error

Close tunnel connection and close raw connection,remove self from connection manager

func (*TunnelConn) LocalAddr

func (c *TunnelConn) LocalAddr() net.Addr

func (*TunnelConn) Read

func (c *TunnelConn) Read(b []byte) (n int, err error)

func (*TunnelConn) RemoteAddr

func (c *TunnelConn) RemoteAddr() net.Addr

func (*TunnelConn) SetDeadline

func (c *TunnelConn) SetDeadline(t time.Time) error

func (*TunnelConn) SetReadDeadline

func (c *TunnelConn) SetReadDeadline(t time.Time) error

func (*TunnelConn) SetWriteDeadline

func (c *TunnelConn) SetWriteDeadline(t time.Time) error

func (*TunnelConn) Write

func (c *TunnelConn) Write(b []byte) (n int, err error)

type TunnelEvent

type TunnelEvent struct {
	From            string
	FromAnnotations map[string]string
	Kind            EventKind
	Peers           map[string]Annotations
}

type TunnelEventer

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

func NewTunnelEventer

func NewTunnelEventer(s *TunnelServer) *TunnelEventer

func (*TunnelEventer) Watch

func (t *TunnelEventer) Watch(ctx context.Context) EventWatcher

type TunnelOptions

type TunnelOptions struct {
	SendRouteChange bool
	IsDefaultOut    bool // send to this channel if no route
}

type TunnelServer

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

func NewTunnelServer

func NewTunnelServer(id string, auth AuthenticationManager) *TunnelServer

func (*TunnelServer) Connect

func (s *TunnelServer) Connect(ctx context.Context, channel Tunnel, token string, annotations Annotations, options TunnelOptions) error

func (*TunnelServer) DialerOn

func (s *TunnelServer) DialerOn(dest string) Dailer

func (*TunnelServer) SendKeepAlive

func (s *TunnelServer) SendKeepAlive(ctx context.Context, annotationsToSend Annotations) error

func (*TunnelServer) TransportOnTunnel

func (s *TunnelServer) TransportOnTunnel(dest string) http.RoundTripper

nolint: gomnd same with http.DefaultTransport use http2 rr to reuse http(tcp) connection

func (*TunnelServer) Wacth

func (s *TunnelServer) Wacth(ctx context.Context) EventWatcher

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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