Documentation ¶
Index ¶
- Constants
- func IPProto(network string) int
- func WithPool(ctx context.Context, pool *Pool) context.Context
- 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 Stream
- type TunnelStream
Constants ¶
const ( SessionInfo = ControlCode(iota) Connect ConnectOK ConnectReject Disconnect DisconnectOK ReadClosed WriteClosed KeepAlive )
Variables ¶
This section is empty.
Functions ¶
Types ¶
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 }
func NewControl ¶
func NewControl(id ConnID, code ControlCode, payload []byte) Control
func SessionInfoControl ¶
func SessionInfoControl(sessionInfo *manager.SessionInfo) 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 ¶
func HandlerFromConn(connID ConnID, bidiStream TunnelStream, release func(), conn net.Conn) Handler
HandlerFromConn is like NewHandler but initializes the handler with an already existing connection.
func NewDialer ¶
func NewDialer(connID ConnID, bidiStream TunnelStream, release func()) Handler
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 ¶
func (p *Pool) Get(ctx context.Context, id ConnID, createHandler HandlerCreator) (Handler, bool, error)
Get 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 Stream ¶
type Stream struct {
TunnelStream
}
func NewStream ¶
func NewStream(bidiStream TunnelStream) *Stream
type TunnelStream ¶
type TunnelStream interface { Send(*rpc.ConnMessage) error Recv() (*rpc.ConnMessage, error) }