Documentation
¶
Index ¶
- Constants
- Variables
- func PacketDecode[T any](data []byte) T
- func PacketEncode(data any) []byte
- func RandomServerID(prefix string) string
- func Run(ctx context.Context, options *Options) error
- type Annotations
- type AuthenticationManager
- type ChannelWithChildren
- type ConnectedTunnel
- type ConnectionManager
- type Connections
- type Dailer
- type EventKind
- type EventWatcher
- type GRPCTunnel
- type GrpcTunnelServer
- func (s GrpcTunnelServer) Connect(connectServer proto.PeerService_ConnectServer) error
- func (s GrpcTunnelServer) ConnectUpstream(ctx context.Context, addr string, tlsConfig *tls.Config, token string, ...) error
- func (s GrpcTunnelServer) ConnectUpstreamWithRetry(ctx context.Context, addr string, tlsConfig *tls.Config, token string, ...) error
- func (s GrpcTunnelServer) GrpcServer(tlsConfig *tls.Config) *grpc.Server
- func (s GrpcTunnelServer) ServeGrpc(ctx context.Context, listen string, tlsConfig *tls.Config) error
- type NonAuthManager
- type Options
- type Packet
- type PacketDataConnect
- type PacketDataOpen
- type PacketDataRoute
- type PacketKind
- type RouteTable
- func (t *RouteTable) Connect(tun *ConnectedTunnel, data PacketDataRoute)
- func (t *RouteTable) Disconnect(stream *ConnectedTunnel)
- func (t *RouteTable) Exists(id string) bool
- func (t *RouteTable) OnChange(from *ConnectedTunnel, data PacketDataRoute)
- func (t *RouteTable) RouteExchange(idchannel *ConnectedTunnel, annotationsToSend Annotations) (*PacketDataRoute, error)
- func (t *RouteTable) Select(dest string) (*ConnectedTunnel, error)
- func (t *RouteTable) SendKeepAlive(annotationsToSend Annotations) error
- type RouteUpdateKind
- type TLS
- type Tunnel
- type TunnelConn
- func (c *TunnelConn) Close() error
- func (c *TunnelConn) LocalAddr() net.Addr
- func (c *TunnelConn) Read(b []byte) (n int, err error)
- func (c *TunnelConn) RemoteAddr() net.Addr
- func (c *TunnelConn) SetDeadline(t time.Time) error
- func (c *TunnelConn) SetReadDeadline(t time.Time) error
- func (c *TunnelConn) SetWriteDeadline(t time.Time) error
- func (c *TunnelConn) Write(b []byte) (n int, err error)
- type TunnelEvent
- type TunnelEventer
- type TunnelOptions
- type TunnelServer
- func (s *TunnelServer) Connect(ctx context.Context, channel Tunnel, token string, annotations Annotations, ...) error
- func (s *TunnelServer) DialerOn(dest string) Dailer
- func (s *TunnelServer) SendKeepAlive(ctx context.Context, annotationsToSend Annotations) error
- func (s *TunnelServer) TransportOnTunnel(dest string) http.RoundTripper
- func (s *TunnelServer) Wacth(ctx context.Context) EventWatcher
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
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
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
}
type GRPCTunnel ¶
type GRPCTunnel[T grpcstream] struct {
// contains filtered or unexported fields
}
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
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) OnChange ¶
func (t *RouteTable) OnChange(from *ConnectedTunnel, data PacketDataRoute)
func (*RouteTable) RouteExchange ¶
func (t *RouteTable) RouteExchange(idchannel *ConnectedTunnel, annotationsToSend Annotations) (*PacketDataRoute, 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 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) 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
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
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) 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
Source Files
¶
Click to show internal directories.
Click to hide internal directories.