Documentation ¶
Index ¶
- Constants
- func IPProto(network string) int
- func WithPool(ctx context.Context, pool *Pool) context.Context
- type BidiStream
- type ConnID
- func (id ConnID) Destination() net.IP
- func (id ConnID) DestinationAddr() net.Addr
- func (id ConnID) DestinationPort() uint16
- func (id ConnID) IsIPv4() bool
- func (id ConnID) Network() string
- func (id ConnID) Protocol() int
- func (id ConnID) ProtocolString() (proto string)
- func (id ConnID) Reply() ConnID
- func (id ConnID) ReplyString() string
- func (id ConnID) Source() net.IP
- func (id ConnID) SourceAddr() net.Addr
- func (id ConnID) SourcePort() uint16
- func (id ConnID) String() string
- type Control
- type ControlCode
- type Handler
- type HandlerCreator
- type Message
- type Pool
- type Tunnel
Constants ¶
const ( SessionInfo = ControlCode(iota) Connect ConnectOK ConnectReject Disconnect DisconnectOK ReadClosed // deprecated, treat as Disconnect WriteClosed // deprecated, treat as Disconnect KeepAlive )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BidiStream ¶ added in v2.4.3
type BidiStream interface { Send(*rpc.ConnMessage) error Recv() (*rpc.ConnMessage, error) }
type ConnID ¶
type ConnID string
A ConnID is a compact and immutable representation of protocol, source IP, source port, destination IP and destination port which is suitable as a map key.
func (ConnID) Destination ¶
Destination returns the destination IP
func (ConnID) DestinationAddr ¶
DestinationAddr returns the *net.TCPAddr or *net.UDPAddr that corresponds to the destination IP and port of this instance.
func (ConnID) DestinationPort ¶
DestinationPort returns the destination port
func (ConnID) ProtocolString ¶
ProtocolString returns the protocol string, e.g. "tcp4"
func (ConnID) Reply ¶ added in v2.3.2
Reply returns a copy of this ConnID with swapped source and destination properties
func (ConnID) ReplyString ¶
ReplyString returns a formatted string suitable for logging showing the destination:destinationPort -> source:sourcePort
func (ConnID) SourceAddr ¶
SourceAddr returns the *net.TCPAddr or *net.UDPAddr that corresponds to the source IP and port of this instance.
type Control ¶
type Control interface { Message Code() ControlCode SessionInfo() *manager.SessionInfo // contains filtered or unexported methods }
func NewControl ¶
func NewControl(id ConnID, code ControlCode, payload []byte) Control
func SessionInfoControl ¶
func SessionInfoControl(sessionInfo *manager.SessionInfo) Control
func SyncRequestControl ¶ added in v2.4.3
func SyncResponseControl ¶ added in v2.4.3
func VersionControl ¶ added in v2.4.3
func VersionControl() Control
type ControlCode ¶
type ControlCode byte
func (ControlCode) String ¶
func (c ControlCode) String() string
type Handler ¶
type Handler interface { // Close closes the handle Close(context.Context) HandleMessage(ctx context.Context, message Message) Start(ctx context.Context) }
func HandlerFromConn ¶
HandlerFromConn is like NewHandler but initializes the handler with an already existing connection.
func NewDialer ¶
NewDialer creates a new handler that dispatches messages in both directions between the given gRPC server and the destination identified by the given connID.
The handler remains active until it's been idle for idleDuration, at which time it will automatically close and call the release function it got from the connpool.Pool to ensure that it gets properly released.
type HandlerCreator ¶
HandlerCreator describes the function signature for the function that creates a handler
type Message ¶
type Message interface { ID() ConnID Payload() []byte TunnelMessage() *manager.ConnMessage }
func FromConnMessage ¶
func FromConnMessage(cm *manager.ConnMessage) Message
func NewMessage ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
func (*Pool) Get ¶
Get finds a handler for the given id from the pool and returns it. Nil is returned if no such handler exists
func (*Pool) GetOrCreate ¶ added in v2.4.3
func (p *Pool) GetOrCreate(ctx context.Context, id ConnID, createHandler HandlerCreator) (Handler, bool, error)
GetOrCreate finds a handler for the given id from the pool, or creates a new handler using the given createHandler func when no handler was found. The handler is returned together with a boolean flag which is set to true if the handler was found or false if it was created.
type Tunnel ¶ added in v2.4.3
type Tunnel interface { DialLoop(ctx context.Context, pool *Pool) error ReadLoop(ctx context.Context) (<-chan Message, <-chan error) Send(context.Context, Message) error Receive(context.Context) (Message, error) CloseSend() error }
The Tunnel interface represents a bidirectional, synchronized Tunnel that sends TCP or UDP traffic over gRPC using manager.ConnMessage messages.
A Tunnel is closed by one of six things happening at either end (or at both ends).
- Read from local connection fails (typically EOF)
- Write to local connection fails (connection peer closed)
- Idle timer timed out.
- Context is cancelled.
- Disconnect request received from Tunnel peer.
- DisconnectOK received from Tunnel peer.
When #1 or #2 happens, the Tunnel will send a Disconnect request to its Tunnel peer, shorten the Idle timer, and then continue to serve incoming data from the Tunnel peer until a DisconnectOK is received. Once that happens, it's guaranteed that the Tunnel peer will send no more messages and the Tunnel is closed.
When #3, #4, or #5 happens, the Tunnel will send a DisconnectOK to its Tunnel peer and close.
When #6 happens, the Tunnel will simply close.
func NewTunnel ¶ added in v2.4.3
func NewTunnel(stream BidiStream) Tunnel