Documentation ¶
Index ¶
- Constants
- Variables
- func AdaptMsgChToPty(outputCh chan []byte, oscEsc string, output io.Writer) error
- func AdaptOutputChToStream(outputCh chan []byte, output io.Writer) error
- func AdaptStreamToMsgCh(input io.Reader, output chan []byte) error
- func DoShutdown(reason string, exitCode int, quiet bool)
- func EncodeWaveOSCBytes(oscNum string, barr []byte) ([]byte, error)
- func EncodeWaveOSCMessageEx(oscNum string, msg *RpcMessage) ([]byte, error)
- func ExtractUnverifiedRpcContext(tokenStr string) (*wshrpc.RpcContext, error)
- func ExtractUnverifiedSocketName(tokenStr string) (string, error)
- func GetIsCanceledFromContext(ctx context.Context) bool
- func GetRpcSourceFromContext(ctx context.Context) string
- func HandleStdIOClient(logName string, input io.Reader, output io.Writer)
- func MakeClientJWTToken(rpcCtx wshrpc.RpcContext, sockName string) (string, error)
- func MakeConnectionRouteId(connId string) string
- func MakeControllerRouteId(blockId string) string
- func MakeFeBlockRouteId(blockId string) string
- func MakeProcRouteId(procId string) string
- func MakeRouteIdFromCtx(rpcCtx *wshrpc.RpcContext) (string, error)
- func MakeTabRouteId(tabId string) string
- func RestoreTermState()
- func RunWshRpcOverListener(listener net.Listener)
- func SetExtraShutdownFunc(fn func())
- func SetTermRawMode()
- func SetTermRawModeAndInstallShutdownHandlers(quietShutdown bool)
- func StreamToLines(input io.Reader, lineFn func([]byte)) error
- func ValidateAndExtractRpcContextFromToken(tokenStr string) (*wshrpc.RpcContext, error)
- type AbstractRpcClient
- type CommandHandlerFnType
- type EventListener
- type PtyBuffer
- type ResponseFnType
- type RpcMessage
- type RpcRequestHandler
- type RpcResponseHandler
- func (handler *RpcResponseHandler) Context() context.Context
- func (handler *RpcResponseHandler) Finalize()
- func (handler *RpcResponseHandler) GetCommand() string
- func (handler *RpcResponseHandler) GetCommandRawData() any
- func (handler *RpcResponseHandler) GetRpcContext() wshrpc.RpcContext
- func (handler *RpcResponseHandler) GetSource() string
- func (handler *RpcResponseHandler) IsCanceled() bool
- func (handler *RpcResponseHandler) IsDone() bool
- func (handler *RpcResponseHandler) NeedsResponse() bool
- func (handler *RpcResponseHandler) SendMessage(msg string)
- func (handler *RpcResponseHandler) SendResponse(data any, done bool) error
- func (handler *RpcResponseHandler) SendResponseError(err error)
- type ServerImpl
- type WriteFlusher
- type WshRouter
- func (router *WshRouter) GetRpc(routeId string) AbstractRpcClient
- func (router *WshRouter) GetUpstreamClient() AbstractRpcClient
- func (router *WshRouter) HandleProxyAuth(jwtTokenAny any) (*wshrpc.CommandAuthenticateRtnData, error)
- func (router *WshRouter) InjectMessage(msgBytes []byte, fromRouteId string)
- func (router *WshRouter) RegisterRoute(routeId string, rpc AbstractRpcClient, shouldAnnounce bool)
- func (router *WshRouter) RunSimpleRawCommand(ctx context.Context, msg RpcMessage, fromRouteId string) (*RpcMessage, error)
- func (router *WshRouter) SendEvent(routeId string, event wps.WaveEvent)
- func (router *WshRouter) SetUpstreamClient(rpc AbstractRpcClient)
- func (router *WshRouter) UnregisterRoute(routeId string)
- func (router *WshRouter) WaitForRegister(ctx context.Context, routeId string) error
- type WshRpc
- func GetWshRpcFromContext(ctx context.Context) *WshRpc
- func MakeWshRpc(inputCh chan []byte, outputCh chan []byte, rpcCtx wshrpc.RpcContext, ...) *WshRpc
- func SetupConnRpcClient(conn net.Conn, serverImpl ServerImpl) (*WshRpc, chan error, error)
- func SetupDomainSocketRpcClient(sockName string, serverImpl ServerImpl) (*WshRpc, error)
- func SetupPacketRpcClient(input io.Reader, output io.Writer, serverImpl ServerImpl) (*WshRpc, chan []byte)
- func SetupTerminalRpcClient(serverImpl ServerImpl) (*WshRpc, io.Reader)
- func (w *WshRpc) ClientId() string
- func (w *WshRpc) GetAuthToken() string
- func (w *WshRpc) GetRpcContext() wshrpc.RpcContext
- func (w *WshRpc) RecvRpcMessage() ([]byte, bool)
- func (w *WshRpc) SendCommand(command string, data any, opts *wshrpc.RpcOpts) error
- func (w *WshRpc) SendComplexRequest(command string, data any, opts *wshrpc.RpcOpts) (rtnHandler *RpcRequestHandler, rtnErr error)
- func (w *WshRpc) SendRpcMessage(msg []byte)
- func (w *WshRpc) SendRpcRequest(command string, data any, opts *wshrpc.RpcOpts) (any, error)
- func (w *WshRpc) SetAuthToken(token string)
- func (w *WshRpc) SetRpcContext(ctx wshrpc.RpcContext)
- func (w *WshRpc) SetServerImpl(serverImpl ServerImpl)
- type WshRpcMultiProxy
- type WshRpcProxy
- func (p *WshRpcProxy) GetAuthToken() string
- func (p *WshRpcProxy) GetRpcContext() *wshrpc.RpcContext
- func (p *WshRpcProxy) HandleAuthentication() (*wshrpc.RpcContext, error)
- func (p *WshRpcProxy) HandleClientProxyAuth(router *WshRouter) (string, error)
- func (p *WshRpcProxy) RecvRpcMessage() ([]byte, bool)
- func (p *WshRpcProxy) SendRpcMessage(msg []byte)
- func (p *WshRpcProxy) SetAuthToken(authToken string)
- func (p *WshRpcProxy) SetRpcContext(rpcCtx *wshrpc.RpcContext)
Constants ¶
View Source
const ( Mode_Normal = "normal" Mode_Esc = "esc" Mode_WaveEsc = "waveesc" )
View Source
const BEL = 0x07
View Source
const DefaultInputChSize = 32
View Source
const DefaultMessageChSize = 32
View Source
const DefaultOutputChSize = 32
View Source
const DefaultRoute = "wavesrv"
View Source
const DefaultTimeoutMs = 5000
View Source
const ESC = 0x1b
View Source
const ElectronRoute = "electron"
View Source
const HexChars = "0123456789ABCDEF"
View Source
const MaxBufferedDataSize = 256 * 1024
View Source
const RespChSize = 32
View Source
const ST = 0x9c
View Source
const SysRoute = "sys" // this route doesn't exist, just a placeholder for system messages
View Source
const UpstreamRoute = "upstream"
View Source
const WaveJwtTokenVarName = "WAVETERM_JWT"
View Source
const WaveOSC = "23198"
these should both be 5 characters
View Source
const WaveOSCPrefix = "\x1b]" + WaveOSC + ";"
View Source
const WaveOSCPrefixLen = 5 + 3 // \x1b] + WaveOSC + ; + \x07
View Source
const WaveServerOSC = "23199"
View Source
const WaveServerOSCPrefix = "\x1b]" + WaveServerOSC + ";"
Variables ¶
View Source
var DefaultRouter = NewWshRouter()
View Source
var WshCommandDeclMap = wshrpc.GenerateWshCommandDeclMap()
Functions ¶
func AdaptMsgChToPty ¶
func AdaptOutputChToStream ¶
func DoShutdown ¶
func EncodeWaveOSCMessageEx ¶
func EncodeWaveOSCMessageEx(oscNum string, msg *RpcMessage) ([]byte, error)
func ExtractUnverifiedRpcContext ¶
func ExtractUnverifiedRpcContext(tokenStr string) (*wshrpc.RpcContext, error)
only for use on client
func ExtractUnverifiedSocketName ¶
only for use on client
func GetRpcSourceFromContext ¶
func HandleStdIOClient ¶ added in v0.9.0
blocking, returns if there is an error, or on EOF of input
func MakeClientJWTToken ¶
func MakeClientJWTToken(rpcCtx wshrpc.RpcContext, sockName string) (string, error)
func MakeConnectionRouteId ¶
func MakeControllerRouteId ¶
func MakeFeBlockRouteId ¶ added in v0.9.0
func MakeProcRouteId ¶
func MakeRouteIdFromCtx ¶
func MakeRouteIdFromCtx(rpcCtx *wshrpc.RpcContext) (string, error)
func MakeTabRouteId ¶ added in v0.9.0
func RestoreTermState ¶
func RestoreTermState()
func RunWshRpcOverListener ¶
func SetExtraShutdownFunc ¶
func SetExtraShutdownFunc(fn func())
func SetTermRawMode ¶
func SetTermRawMode()
func SetTermRawModeAndInstallShutdownHandlers ¶
func SetTermRawModeAndInstallShutdownHandlers(quietShutdown bool)
func ValidateAndExtractRpcContextFromToken ¶
func ValidateAndExtractRpcContextFromToken(tokenStr string) (*wshrpc.RpcContext, error)
Types ¶
type AbstractRpcClient ¶
type CommandHandlerFnType ¶
type CommandHandlerFnType = func(*RpcResponseHandler) bool
returns true if handler is complete, false for an async handler
type EventListener ¶
func MakeEventListener ¶
func MakeEventListener() *EventListener
func (*EventListener) On ¶
func (el *EventListener) On(eventName string, fn func(*wps.WaveEvent)) string
func (*EventListener) RecvEvent ¶
func (el *EventListener) RecvEvent(e *wps.WaveEvent)
func (*EventListener) Unregister ¶
func (el *EventListener) Unregister(eventName string, id string)
type PtyBuffer ¶
type PtyBuffer struct { CVar *sync.Cond DataBuf *bytes.Buffer EscMode string EscSeqBuf []byte OSCPrefix string InputReader io.Reader MessageCh chan []byte AtEOF bool Err error }
func MakePtyBuffer ¶
closes messageCh when input is closed (or error)
type ResponseFnType ¶
type RpcMessage ¶
type RpcMessage struct { Command string `json:"command,omitempty"` ReqId string `json:"reqid,omitempty"` ResId string `json:"resid,omitempty"` Timeout int `json:"timeout,omitempty"` Route string `json:"route,omitempty"` // to route/forward requests to alternate servers AuthToken string `json:"authtoken,omitempty"` // needed for routing unauthenticated requests (WshRpcMultiProxy) Source string `json:"source,omitempty"` // source route id Cont bool `json:"cont,omitempty"` // flag if additional requests/responses are forthcoming Cancel bool `json:"cancel,omitempty"` // used to cancel a streaming request or response (sent from the side that is not streaming) Error string `json:"error,omitempty"` DataType string `json:"datatype,omitempty"` Data any `json:"data,omitempty"` }
func (*RpcMessage) IsRpcRequest ¶
func (r *RpcMessage) IsRpcRequest() bool
func (*RpcMessage) Validate ¶
func (r *RpcMessage) Validate() error
type RpcRequestHandler ¶
type RpcRequestHandler struct {
// contains filtered or unexported fields
}
func (*RpcRequestHandler) Context ¶
func (handler *RpcRequestHandler) Context() context.Context
func (*RpcRequestHandler) NextResponse ¶
func (handler *RpcRequestHandler) NextResponse() (any, error)
func (*RpcRequestHandler) ResponseDone ¶
func (handler *RpcRequestHandler) ResponseDone() bool
func (*RpcRequestHandler) SendCancel ¶
func (handler *RpcRequestHandler) SendCancel()
type RpcResponseHandler ¶
type RpcResponseHandler struct {
// contains filtered or unexported fields
}
func GetRpcResponseHandlerFromContext ¶
func GetRpcResponseHandlerFromContext(ctx context.Context) *RpcResponseHandler
func (*RpcResponseHandler) Context ¶
func (handler *RpcResponseHandler) Context() context.Context
func (*RpcResponseHandler) Finalize ¶
func (handler *RpcResponseHandler) Finalize()
if async, caller must call finalize
func (*RpcResponseHandler) GetCommand ¶
func (handler *RpcResponseHandler) GetCommand() string
func (*RpcResponseHandler) GetCommandRawData ¶
func (handler *RpcResponseHandler) GetCommandRawData() any
func (*RpcResponseHandler) GetRpcContext ¶
func (handler *RpcResponseHandler) GetRpcContext() wshrpc.RpcContext
func (*RpcResponseHandler) GetSource ¶
func (handler *RpcResponseHandler) GetSource() string
func (*RpcResponseHandler) IsCanceled ¶
func (handler *RpcResponseHandler) IsCanceled() bool
func (*RpcResponseHandler) IsDone ¶
func (handler *RpcResponseHandler) IsDone() bool
func (*RpcResponseHandler) NeedsResponse ¶
func (handler *RpcResponseHandler) NeedsResponse() bool
func (*RpcResponseHandler) SendMessage ¶
func (handler *RpcResponseHandler) SendMessage(msg string)
func (*RpcResponseHandler) SendResponse ¶
func (handler *RpcResponseHandler) SendResponse(data any, done bool) error
func (*RpcResponseHandler) SendResponseError ¶
func (handler *RpcResponseHandler) SendResponseError(err error)
type ServerImpl ¶
type ServerImpl interface {
WshServerImpl()
}
type WriteFlusher ¶ added in v0.9.0
type WshRouter ¶
type WshRouter struct { Lock *sync.Mutex RouteMap map[string]AbstractRpcClient // routeid => client UpstreamClient AbstractRpcClient // upstream client (if we are not the terminal router) AnnouncedRoutes map[string]string // routeid => local routeid RpcMap map[string]*routeInfo // rpcid => routeinfo SimpleRequestMap map[string]chan *RpcMessage // simple reqid => response channel InputCh chan msgAndRoute }
func NewWshRouter ¶
func NewWshRouter() *WshRouter
func (*WshRouter) GetRpc ¶
func (router *WshRouter) GetRpc(routeId string) AbstractRpcClient
this may return nil (returns default only for empty routeId)
func (*WshRouter) GetUpstreamClient ¶
func (router *WshRouter) GetUpstreamClient() AbstractRpcClient
func (*WshRouter) HandleProxyAuth ¶ added in v0.9.0
func (router *WshRouter) HandleProxyAuth(jwtTokenAny any) (*wshrpc.CommandAuthenticateRtnData, error)
func (*WshRouter) InjectMessage ¶ added in v0.9.0
func (*WshRouter) RegisterRoute ¶
func (router *WshRouter) RegisterRoute(routeId string, rpc AbstractRpcClient, shouldAnnounce bool)
this will also consume the output channel of the abstract client
func (*WshRouter) RunSimpleRawCommand ¶ added in v0.9.0
func (router *WshRouter) RunSimpleRawCommand(ctx context.Context, msg RpcMessage, fromRouteId string) (*RpcMessage, error)
func (*WshRouter) SetUpstreamClient ¶
func (router *WshRouter) SetUpstreamClient(rpc AbstractRpcClient)
func (*WshRouter) UnregisterRoute ¶
type WshRpc ¶
type WshRpc struct { Lock *sync.Mutex InputCh chan []byte OutputCh chan []byte RpcContext *atomic.Pointer[wshrpc.RpcContext] AuthToken string RpcMap map[string]*rpcData ServerImpl ServerImpl EventListener *EventListener ResponseHandlerMap map[string]*RpcResponseHandler // reqId => handler Debug bool DebugName string // contains filtered or unexported fields }
func GetWshRpcFromContext ¶
func MakeWshRpc ¶
func MakeWshRpc(inputCh chan []byte, outputCh chan []byte, rpcCtx wshrpc.RpcContext, serverImpl ServerImpl) *WshRpc
closes outputCh when inputCh is closed/done
func SetupConnRpcClient ¶
func SetupDomainSocketRpcClient ¶
func SetupDomainSocketRpcClient(sockName string, serverImpl ServerImpl) (*WshRpc, error)
func SetupPacketRpcClient ¶ added in v0.9.0
func SetupTerminalRpcClient ¶
func SetupTerminalRpcClient(serverImpl ServerImpl) (*WshRpc, io.Reader)
returns (wshRpc, wrappedStdin)
func (*WshRpc) GetAuthToken ¶ added in v0.9.0
func (*WshRpc) GetRpcContext ¶
func (w *WshRpc) GetRpcContext() wshrpc.RpcContext
func (*WshRpc) RecvRpcMessage ¶
func (*WshRpc) SendCommand ¶
no response
func (*WshRpc) SendComplexRequest ¶
func (*WshRpc) SendRpcMessage ¶
func (*WshRpc) SendRpcRequest ¶
single response
func (*WshRpc) SetAuthToken ¶ added in v0.9.0
func (*WshRpc) SetRpcContext ¶
func (w *WshRpc) SetRpcContext(ctx wshrpc.RpcContext)
func (*WshRpc) SetServerImpl ¶
func (w *WshRpc) SetServerImpl(serverImpl ServerImpl)
type WshRpcMultiProxy ¶ added in v0.9.0
type WshRpcMultiProxy struct { Lock *sync.Mutex RouteInfo map[string]*multiProxyRouteInfo // authtoken to info ToRemoteCh chan []byte FromRemoteRawCh chan []byte // raw message from the remote }
handles messages from multiple unauthenitcated clients
func MakeRpcMultiProxy ¶ added in v0.9.0
func MakeRpcMultiProxy() *WshRpcMultiProxy
func (*WshRpcMultiProxy) DisposeRoutes ¶ added in v0.9.0
func (p *WshRpcMultiProxy) DisposeRoutes()
func (*WshRpcMultiProxy) RunUnauthLoop ¶ added in v0.9.0
func (p *WshRpcMultiProxy) RunUnauthLoop()
type WshRpcProxy ¶
type WshRpcProxy struct { Lock *sync.Mutex RpcContext *wshrpc.RpcContext ToRemoteCh chan []byte FromRemoteCh chan []byte AuthToken string }
func MakeRpcProxy ¶
func MakeRpcProxy() *WshRpcProxy
func (*WshRpcProxy) GetAuthToken ¶ added in v0.9.0
func (p *WshRpcProxy) GetAuthToken() string
func (*WshRpcProxy) GetRpcContext ¶
func (p *WshRpcProxy) GetRpcContext() *wshrpc.RpcContext
func (*WshRpcProxy) HandleAuthentication ¶
func (p *WshRpcProxy) HandleAuthentication() (*wshrpc.RpcContext, error)
runs on the server
func (*WshRpcProxy) HandleClientProxyAuth ¶ added in v0.9.0
func (p *WshRpcProxy) HandleClientProxyAuth(router *WshRouter) (string, error)
runs on the client (stdio client)
func (*WshRpcProxy) RecvRpcMessage ¶
func (p *WshRpcProxy) RecvRpcMessage() ([]byte, bool)
func (*WshRpcProxy) SendRpcMessage ¶
func (p *WshRpcProxy) SendRpcMessage(msg []byte)
func (*WshRpcProxy) SetAuthToken ¶ added in v0.9.0
func (p *WshRpcProxy) SetAuthToken(authToken string)
func (*WshRpcProxy) SetRpcContext ¶
func (p *WshRpcProxy) SetRpcContext(rpcCtx *wshrpc.RpcContext)
Click to show internal directories.
Click to hide internal directories.