Documentation ¶
Overview ¶
Package tunnel defines the a TCP over gRPC transport client and server.
Index ¶
- Variables
- func DialTLSCredsOpts(certFile string) ([]grpc.DialOption, error)
- func DialmTLSCredsOpts(certFile, keyFile, caFile string) ([]grpc.DialOption, error)
- func Listen(ctx context.Context, addr string, cert string, targets map[Target]struct{}) (net.Listener, error)
- func ServerTLSCredsOpts(certFile, keyFile string) ([]grpc.ServerOption, error)
- func ServermTLSCredsOpts(certFile, keyFile, caFile string) ([]grpc.ServerOption, error)
- type Client
- func (c *Client) DeleteTarget(target Target) error
- func (c *Client) Error() error
- func (c *Client) NewSession(target Target) (_ io.ReadWriteCloser, err error)
- func (c *Client) NewTarget(target Target) error
- func (c *Client) PeerTargets(typ string) map[Target]struct{}
- func (c *Client) Register(ctx context.Context) (err error)
- func (c *Client) Run(ctx context.Context) error
- func (c *Client) Start(ctx context.Context)
- func (c *Client) Subscribe(typ string) error
- func (c *Client) Unsubscribe(typ string) error
- type ClientConfig
- type ClientHandlerFunc
- type ClientPeerAddHandlerFunc
- type ClientPeerDelHandlerFunc
- type ClientRegHandlerFunc
- type Conn
- type Listener
- type Server
- type ServerAddTargHandlerFunc
- type ServerConfig
- type ServerDeleteTargHandlerFunc
- type ServerHandlerFunc
- type ServerRegHandlerFunc
- type ServerSession
- type Target
Constants ¶
This section is empty.
Variables ¶
var ( // RetryBaseDelay is the initial retry interval for re-connecting tunnel server/client. RetryBaseDelay = time.Second // RetryMaxDelay caps the retry interval for re-connecting attempts. RetryMaxDelay = time.Minute // RetryRandomization is the randomization factor applied to the retry // interval. RetryRandomization = 0.5 )
Functions ¶
func DialTLSCredsOpts ¶
func DialTLSCredsOpts(certFile string) ([]grpc.DialOption, error)
DialTLSCredsOpts returns a slice of DialOption with TLS credential obtained from certFile.
func DialmTLSCredsOpts ¶
func DialmTLSCredsOpts(certFile, keyFile, caFile string) ([]grpc.DialOption, error)
DialmTLSCredsOpts returns a slice of DialOption with mTLS credential obtained from certFile, keyFile and caFile.
func Listen ¶
func Listen(ctx context.Context, addr string, cert string, targets map[Target]struct{}) (net.Listener, error)
Listen create a tunnel client and returns a Listener.
func ServerTLSCredsOpts ¶
func ServerTLSCredsOpts(certFile, keyFile string) ([]grpc.ServerOption, error)
ServerTLSCredsOpts returns a slice of ServerOption with TLS credential obtained from certFile and keyFile.
func ServermTLSCredsOpts ¶
func ServermTLSCredsOpts(certFile, keyFile, caFile string) ([]grpc.ServerOption, error)
ServermTLSCredsOpts returns a slice of ServerOption with mTLS credential obtained from certFile, keyFile and caFile.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implementation of an endpoint.
func NewClient ¶
func NewClient(tc tpb.TunnelClient, cc ClientConfig, ts map[Target]struct{}) (*Client, error)
NewClient creates a new tunnel client.
func (*Client) DeleteTarget ¶
DeleteTarget sends a target deletion registration via regStream.
func (*Client) NewSession ¶
func (c *Client) NewSession(target Target) (_ io.ReadWriteCloser, err error)
NewSession requests a new stream identified on the server side by target.
func (*Client) PeerTargets ¶
PeerTargets returns all the peer targets matching the given type. If type is an empty string, it will return all targets.
func (*Client) Register ¶
Register initializes the client register stream and determines the capabilities of the tunnel server.
func (*Client) Run ¶
Run initializes the client register stream and determines the capabilities of the tunnel server. Once done, it starts the stream handler responsible for determining what to do with received requests.
func (*Client) Unsubscribe ¶
Unsubscribe send a unsubscription request to the server for stopping receiving targets updates.
type ClientConfig ¶
type ClientConfig struct { RegisterHandler ClientRegHandlerFunc Handler ClientHandlerFunc PeerAddHandler ClientPeerAddHandlerFunc PeerDelHandler ClientPeerDelHandlerFunc Opts []grpc.CallOption Subscriptions []string }
ClientConfig contains the config for the client.
type ClientHandlerFunc ¶
type ClientHandlerFunc func(target Target, rwc io.ReadWriteCloser) error
ClientHandlerFunc handles sessions the client receives from the server.
type ClientPeerAddHandlerFunc ¶
ClientPeerAddHandlerFunc is called when a peer target is registered.
type ClientPeerDelHandlerFunc ¶
ClientPeerDelHandlerFunc is called when a peer target is deleted.
type ClientRegHandlerFunc ¶
ClientRegHandlerFunc defines the targets that the handler function can accept.
type Conn ¶
type Conn struct {
io.ReadWriteCloser
}
Conn is a wraper as a net.Conn interface.
func ClientConn ¶
ClientConn returns a tunnel connection.
func ServerConn ¶
ServerConn returns a tunnel connection.
func (*Conn) RemoteAddr ¶
RemoteAddr is trivial implementation, in order to match interface net.Conn.
func (*Conn) SetDeadline ¶
SetDeadline is trivial implementation, in order to match interface net.Conn.
func (*Conn) SetReadDeadline ¶
SetReadDeadline is trivial implementation, in order to match interface net.Conn.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener wraps a tunnel connection.
type Server ¶
type Server struct { tpb.UnimplementedTunnelServer // contains filtered or unexported fields }
Server is the server implementation of an endpoint.
func NewServer ¶
func NewServer(sc ServerConfig) (*Server, error)
NewServer creates a new tunnel server.
func (*Server) ErrorChan ¶
ErrorChan returns a channel that sends errors from the operations such as Register.
func (*Server) NewSession ¶
func (s *Server) NewSession(ctx context.Context, ss ServerSession) (io.ReadWriteCloser, error)
NewSession requests a new stream identified on the client side by uniqueID.
type ServerAddTargHandlerFunc ¶
ServerAddTargHandlerFunc is called for each target registered by a client. It will be called for target additions.
type ServerConfig ¶
type ServerConfig struct { AddTargetHandler ServerAddTargHandlerFunc DeleteTargetHandler ServerDeleteTargHandlerFunc RegisterHandler ServerRegHandlerFunc Handler ServerHandlerFunc LocalTargets []Target }
ServerConfig contains the config for the server.
type ServerDeleteTargHandlerFunc ¶
ServerDeleteTargHandlerFunc is called for each target registered by a client. It will be called for target additions.
type ServerHandlerFunc ¶
type ServerHandlerFunc func(ss ServerSession, rwc io.ReadWriteCloser) error
ServerHandlerFunc handles sessions the server receives from the client.
type ServerRegHandlerFunc ¶
type ServerRegHandlerFunc func(ss ServerSession) error
ServerRegHandlerFunc defines the targets that the handler function can accept. It is only called when the server accepts new session from the client.
type ServerSession ¶
ServerSession is used by NewSession and the register handler. In the register handler it is used by the client to indicate what it's trying to connect to. In NewSession, ServerSession will indicate what target to connect to, as well as potentially specifying the client to connect to.