Documentation ¶
Overview ¶
Package session provides ProtoMsg Session abstraction. A session is a persistent communication channel with it's own set of control packets for opening and closing channels and performing end-to-end health checks. This package provides three levels of abstractions. On top, the Router manages creation and deletion as well as routing of messages to Sessions based on the ProtoMsg 'sid' (SessionID) header. The Session abstraction manages persistent session context such as creating and deleting as well as routing messages to SessionHandlers based on the 'proto' (ProtoType) header. The Session also takes care of session control messages. The SessionHandler is the application specific handler interface that takes care of the application specific messages. The ServeProtoMsg function is called for every inbound message with the associated ProtoType for the registered handler. If the SessionHandler requires persisting resources, Close MUST free these resources when the session shuts down. NOTE: ProtoRoutes that are used to map ProtoTypes to SessionHandlers maps
ProtoTypes to Constructors, since the Router must be able to regenerate new Sessions with independent sets of SessionHandlers.
Index ¶
- Constants
- Variables
- func DeleteSessionById(id string) error
- func GetSessionCount() int
- func GetSessionIds() []string
- func StopSessionById(sessionId string) error
- func StopSessionByUserId(userId string) (count uint, err error)
- func TerminateAllSessions() (shellCount int, sessionCount int, err error)
- func TerminateExpiredSessions() (shellCount int, sessionCount int, totalExpiredLeft int, err error)
- type Config
- type Constructor
- type FileTransferHandler
- func (h *FileTransferHandler) Close() error
- func (h *FileTransferHandler) DownloadHandler(fd *os.File, msg *ws.ProtoMsg, w api.Sender) (err error)
- func (h *FileTransferHandler) Error(code int, msg *ws.ProtoMsg, w api.Sender, err error)
- func (h *FileTransferHandler) FileUploadHandler(msg *ws.ProtoMsg, params model.UploadRequest, dstPath string, w api.Sender) (err error)
- func (h *FileTransferHandler) InitFileDownload(msg *ws.ProtoMsg, w api.Sender) (code int, err error)
- func (h *FileTransferHandler) InitFileUpload(msg *ws.ProtoMsg, w api.Sender) (code int, err error)
- func (h *FileTransferHandler) ServeProtoMsg(msg *ws.ProtoMsg, w api.Sender)
- func (h *FileTransferHandler) StatFile(msg *ws.ProtoMsg, w api.Sender)
- type HandlerFunc
- type PortForwardHandler
- type PortForwarder
- type ProtoRoutes
- type Router
- type Session
- func (sess *Session) Done() <-chan struct{}
- func (sess *Session) Error(msg *ws.ProtoMsg, close bool, errMessage string)
- func (sess *Session) HandleControl(msg *ws.ProtoMsg) (close bool)
- func (sess *Session) ListenAndServe()
- func (sess *Session) MsgChan() chan<- *ws.ProtoMsg
- func (sess *Session) Ping() error
- type SessionHandler
- type SessionStatus
- type TerminalSession
- func (s *TerminalSession) GetActiveAtFmt() string
- func (s *TerminalSession) GetExpiresAtFmt() string
- func (s *TerminalSession) GetId() string
- func (s *TerminalSession) GetShellCommandPath() string
- func (s *TerminalSession) GetShellPid() int
- func (s *TerminalSession) GetStartedAtFmt() string
- func (s *TerminalSession) GetStatus() SessionStatus
- func (s *TerminalSession) HealthcheckPong()
- func (s *TerminalSession) IsExpired(setStatus bool) bool
- func (s *TerminalSession) ResizeShell(height, width uint16)
- func (s *TerminalSession) ShellCommand(m *ws.ProtoMsg) error
- func (s *TerminalSession) StartShell(sock api.Sender, sessionId string, terminal TerminalSettings) error
- func (s *TerminalSession) StopShell() (err error)
- type TerminalSettings
Constants ¶
const ( ACKSlidingWindowSend = 10 ACKSlidingWindowRecv = 20 FileTransferBufSize = 4096 )
const ( NormalMessage int = iota + 1 ErrorMessage )
const MaxTraceback = 32
const (
NoExpirationTimeout = time.Second * 0
)
Variables ¶
var ( ErrNoSession = errors.New("session: does not exist") ErrNoSessionID = errors.New("session: message does not have a session ID") )
var ( ErrSessionShellAlreadyRunning = errors.New("shell is already running") ErrSessionShellNotRunning = errors.New("shell is not running") ErrSessionShellTooManySessionsPerUser = errors.New("user has too many open sessions") ErrSessionNotFound = errors.New("session not found") ErrSessionTooManyShellsAlreadyRunning = errors.New("too many shells spawned") )
var (
MaxUserSessions = 1
)
Functions ¶
func DeleteSessionById ¶
func GetSessionCount ¶
func GetSessionCount() int
func GetSessionIds ¶
func GetSessionIds() []string
func StopSessionById ¶ added in v1.0.2
func StopSessionByUserId ¶
func TerminateAllSessions ¶
Types ¶
type Config ¶
type Config struct { // IdleTimeout is the duration a session can remain inactive before // it shuts down. IdleTimeout time.Duration }
Config is the static configuration for Sessions and Routers.
type Constructor ¶
type Constructor func() SessionHandler
Constructor is a function for SessionHandler initializers. To create a Router, all ProtoType Routes must route to a SessionHandler Constructor (factory).
func FileTransfer ¶
func FileTransfer(root string, limits config.Limits) Constructor
FileTransfer creates a new filetransfer constructor
func MenderClient ¶
func MenderClient() Constructor
func PortForward ¶
func PortForward() Constructor
type FileTransferHandler ¶
type FileTransferHandler struct {
// contains filtered or unexported fields
}
func (*FileTransferHandler) Close ¶
func (h *FileTransferHandler) Close() error
func (*FileTransferHandler) DownloadHandler ¶
func (*FileTransferHandler) FileUploadHandler ¶
func (h *FileTransferHandler) FileUploadHandler( msg *ws.ProtoMsg, params model.UploadRequest, dstPath string, w api.Sender, ) (err error)
func (*FileTransferHandler) InitFileDownload ¶
func (*FileTransferHandler) InitFileUpload ¶
func (*FileTransferHandler) ServeProtoMsg ¶
func (h *FileTransferHandler) ServeProtoMsg(msg *ws.ProtoMsg, w api.Sender)
type HandlerFunc ¶
func (HandlerFunc) Close ¶
func (h HandlerFunc) Close() error
func (HandlerFunc) ServeProtoMsg ¶
func (h HandlerFunc) ServeProtoMsg(msg *ws.ProtoMsg, w api.Sender)
type PortForwardHandler ¶
type PortForwardHandler struct {
// contains filtered or unexported fields
}
func (*PortForwardHandler) Close ¶
func (h *PortForwardHandler) Close() error
func (*PortForwardHandler) ServeProtoMsg ¶
func (h *PortForwardHandler) ServeProtoMsg(msg *ws.ProtoMsg, w api.Sender)
type PortForwarder ¶
type PortForwarder struct { SessionID string ConnectionID string Sender api.Sender // contains filtered or unexported fields }
func (*PortForwarder) Close ¶
func (f *PortForwarder) Close(sendStopMessage bool) error
func (*PortForwarder) Connect ¶
func (f *PortForwarder) Connect(protocol string, host string, portNumber uint16) error
func (*PortForwarder) Read ¶
func (f *PortForwarder) Read()
func (*PortForwarder) Write ¶
func (f *PortForwarder) Write(body []byte) error
type ProtoRoutes ¶
type ProtoRoutes map[ws.ProtoType]Constructor
type Session ¶
type Session struct { Config ID string Routes ProtoRoutes // contains filtered or unexported fields }
func (*Session) ListenAndServe ¶
func (sess *Session) ListenAndServe()
type SessionHandler ¶
type SessionHandler interface { // ServeProtoMsg handles individual messages within the associated // class of ProtoTypes. ServeProtoMsg(msg *ws.ProtoMsg, w api.Sender) // Close frees allocated resources when the session closes. It SHOULD // return an error if the session closes unexpectedly. Close() error }
SessionHandler defines the interface for application specific ProtoMsg handlers.
type SessionStatus ¶
type SessionStatus int
const ( SessionStatusActive SessionStatus = iota SessionStatusExpired SessionStatusIdle SessionStatusHanged SessionStatusEmpty SessionStatusNew )
type TerminalSession ¶
type TerminalSession struct {
// contains filtered or unexported fields
}
func GetSessionById ¶
func GetSessionById(id string) *TerminalSession
func GetSessionsByUserId ¶
func GetSessionsByUserId(userId string) []*TerminalSession
func NewShellSession ¶
func (*TerminalSession) GetActiveAtFmt ¶
func (s *TerminalSession) GetActiveAtFmt() string
func (*TerminalSession) GetExpiresAtFmt ¶
func (s *TerminalSession) GetExpiresAtFmt() string
func (*TerminalSession) GetId ¶
func (s *TerminalSession) GetId() string
func (*TerminalSession) GetShellCommandPath ¶
func (s *TerminalSession) GetShellCommandPath() string
func (*TerminalSession) GetShellPid ¶
func (s *TerminalSession) GetShellPid() int
func (*TerminalSession) GetStartedAtFmt ¶
func (s *TerminalSession) GetStartedAtFmt() string
func (*TerminalSession) GetStatus ¶
func (s *TerminalSession) GetStatus() SessionStatus
func (*TerminalSession) HealthcheckPong ¶
func (s *TerminalSession) HealthcheckPong()
func (*TerminalSession) IsExpired ¶
func (s *TerminalSession) IsExpired(setStatus bool) bool
func (*TerminalSession) ResizeShell ¶
func (s *TerminalSession) ResizeShell(height, width uint16)
func (*TerminalSession) ShellCommand ¶
func (s *TerminalSession) ShellCommand(m *ws.ProtoMsg) error
func (*TerminalSession) StartShell ¶
func (s *TerminalSession) StartShell( sock api.Sender, sessionId string, terminal TerminalSettings, ) error
func (*TerminalSession) StopShell ¶
func (s *TerminalSession) StopShell() (err error)