tunserver

package
v16.9.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// RoutingAgentIDMetadataKey is used to pass destination agent id in request metadata
	// from the routing kas instance, that is handling the incoming request, to the gateway kas instance,
	// that is forwarding the request to an agentk.
	RoutingAgentIDMetadataKey = routingHopPrefix + "routing-agent-id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DataCallback

type DataCallback interface {
	Header(map[string]*prototool.Values) error
	Message([]byte) error
	Trailer(map[string]*prototool.Values) error
	Error(*statuspb.Status) error
}

type FindHandle

type FindHandle interface {
	// Get finds a tunnel to an agentk.
	// It waits for a matching tunnel to proxy a connection through. When a matching tunnel is found, it is returned.
	// It returns gRPC status errors only, ready to return from RPC handler.
	Get(ctx context.Context) (Tunnel, error)
	// Done must be called to free resources of this FindHandle instance.
	// ctx is used for tracing only.
	Done(ctx context.Context)
}

type GatewayFinder

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

func NewGatewayFinder

func NewGatewayFinder(log *zap.Logger, gatewayPool grpctool.PoolInterface, tunnelQuerier PollingQuerier,
	rpcApi modshared.RPCAPI, fullMethod string, ownPrivateApiUrl string, agentId int64, outgoingCtx context.Context,
	pollConfig retry.PollConfigFactory, tryNewGatewayInterval time.Duration) *GatewayFinder

func (*GatewayFinder) Find

type PollKasUrlsByAgentIdCallback

type PollKasUrlsByAgentIdCallback func(kasUrls []string)

PollKasUrlsByAgentIdCallback is called periodically with found kas URLs for a particular agent id.

type PollingQuerier

type PollingQuerier interface {
	PollKasUrlsByAgentId(ctx context.Context, agentId int64, cb PollKasUrlsByAgentIdCallback)
	CachedKasUrlsByAgentId(agentId int64) []string
}

type ReadyGateway

type ReadyGateway struct {
	URL          string
	Stream       grpc.ClientStream
	Conn         grpctool.PoolConn
	StreamCancel context.CancelFunc
}

func (ReadyGateway) Done

func (g ReadyGateway) Done()

type Router

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

Router routes traffic from kas to another kas to agentk. routing kas -> gateway kas -> agentk

func NewRouter

func NewRouter(kasPool grpctool.PoolInterface, tunnelQuerier PollingQuerier, tunnelFinder TunnelFinder, ownPrivateApiUrl string,
	internalServer, privateApiServer grpc.ServiceRegistrar, pollConfig retry.PollConfigFactory,
	tunnelFindTimeout, tryNewKasInterval time.Duration,
	tp trace.TracerProvider, dm otelmetric.Meter) (*Router, error)

func (*Router) RegisterTunclientAPI

func (r *Router) RegisterTunclientAPI(desc *grpc.ServiceDesc)

type StateType

type StateType int
const (

	// StateReady - tunnel is owned by the registry and is ready to be found and used for forwarding.
	StateReady StateType
	// StateFound - tunnel is not owned by registry, was found and about to be used for forwarding.
	StateFound
	// StateForwarding - tunnel is not owned by registry, is being used for forwarding.
	StateForwarding
	// StateDone - tunnel is not owned by anyone, it has been used for forwarding, Done() has been called.
	StateDone
	// StateContextDone - tunnel is not owned by anyone, reverse tunnel's context signalled done in HandleTunnel().
	StateContextDone
)

type Tunnel

type Tunnel interface {
	// ForwardStream performs bi-directional message forwarding between incomingStream and the tunnel.
	// cb is called with header, messages and trailer coming from the tunnel. It's the callers
	// responsibility to forward them into the incomingStream.
	ForwardStream(log *zap.Logger, rpcApi modshared.RPCAPI, incomingStream grpc.ServerStream, cb DataCallback) error
	// Done must be called when the caller is done with the Tunnel.
	// ctx is used for tracing only.
	Done(ctx context.Context)
}

type TunnelFinder

type TunnelFinder interface {
	// FindTunnel starts searching for a tunnel to a matching agentk.
	// Found tunnel is:
	// - to an agent with provided id.
	// - supports handling provided gRPC service and method.
	// Tunnel found boolean indicates whether a suitable tunnel is immediately available from the
	// returned FindHandle object.
	FindTunnel(ctx context.Context, agentId int64, service, method string) (bool, FindHandle)
}

type TunnelImpl

type TunnelImpl struct {
	Tunnel       rpc.ReverseTunnel_ConnectServer
	TunnelRetErr chan<- error
	AgentID      int64
	Descriptor   *info.APIDescriptor
	State        StateType

	OnForward func(*TunnelImpl) error
	OnDone    func(context.Context, *TunnelImpl)
}

func (*TunnelImpl) Done

func (t *TunnelImpl) Done(ctx context.Context)

func (*TunnelImpl) ForwardStream

func (t *TunnelImpl) ForwardStream(log *zap.Logger, rpcApi modshared.RPCAPI, incomingStream grpc.ServerStream, cb DataCallback) error

Jump to

Keyboard shortcuts

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