Documentation
¶
Overview ¶
Package datachannel implements data channel for interactive sessions.
Index ¶
- Variables
- type DataChannel
- func (c *DataChannel) Close() error
- func (c *DataChannel) GetAgentVersion() string
- func (c *DataChannel) GetDisplayMessages() <-chan message.ClientMessage
- func (c *DataChannel) GetExpectedSequenceNumber() int64
- func (c *DataChannel) GetSessionProperties() any
- func (c *DataChannel) GetTargetID() string
- func (c *DataChannel) Open(ctx context.Context, refreshTokenHandler RefreshTokenHandler, ...) (string, error)
- func (c *DataChannel) ProcessIncomingMessageBufferItems(outputMessage message.ClientMessage) error
- func (c *DataChannel) ProcessKMSEncryptionHandshakeAction(ctx context.Context, actionParams json.RawMessage) error
- func (c *DataChannel) ProcessSessionTypeHandshakeAction(actionParams json.RawMessage) error
- func (c *DataChannel) RegisterIncomingMessageHandler(handler IncomingMessageHandler)
- func (c *DataChannel) RegisterOutputStreamHandler(handler OutputStreamDataMessageHandler, isSessionSpecificHandler bool)
- func (c *DataChannel) RegisterStopHandler(handler StopHandler)
- func (c *DataChannel) SendFlag(flagType message.PayloadTypeFlag) error
- func (c *DataChannel) SendInputDataMessage(payloadType message.PayloadType, inputData []byte) error
- func (c *DataChannel) SendMessage(input []byte, inputType int) error
- func (c *DataChannel) SetAgentVersion(agentVersion string)
- type EncryptorBuilder
- type IDataChannel
- type IncomingMessageHandler
- type KMSEncryptorBuilder
- type ListMessageBuffer
- type MapMessageBuffer
- type OutputStreamDataMessageHandler
- type RefreshTokenHandler
- type RoundTripTiming
- type StopHandler
- type StreamingMessage
- type TimeoutHandler
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTimedOut is returned when the session times out. ErrTimedOut = errors.New("timed out") // ErrUnknownSessionType is returned when the session type is unknown. ErrUnknownSessionType = errors.New("unknown session type") // ErrUnsupportedAction is returned when the action is unsupported. ErrUnsupportedAction = errors.New("unsupported action") )
Functions ¶
This section is empty.
Types ¶
type DataChannel ¶
type DataChannel struct {
// contains filtered or unexported fields
}
DataChannel used for communication between the mgs and the cli.
func NewDataChannel ¶
func NewDataChannel(wsChannel communicator.IWebSocketChannel, encryptorBuilder EncryptorBuilder, clientID string, sessionID string, targetID string, logger log.T) (*DataChannel, error)
NewDataChannel creates a DataChannel.
func (*DataChannel) Close ¶
func (c *DataChannel) Close() error
Close closes datachannel - its web socket connection.
func (*DataChannel) GetAgentVersion ¶
func (c *DataChannel) GetAgentVersion() string
GetAgentVersion returns agent version of the target instance.
func (*DataChannel) GetDisplayMessages ¶ added in v0.2.0
func (c *DataChannel) GetDisplayMessages() <-chan message.ClientMessage
GetDisplayMessages returns a channel for messages to be displayed.
func (*DataChannel) GetExpectedSequenceNumber ¶
func (c *DataChannel) GetExpectedSequenceNumber() int64
GetExpectedSequenceNumber returns expected sequence number of the DataChannel.
func (*DataChannel) GetSessionProperties ¶
func (c *DataChannel) GetSessionProperties() any
GetSessionProperties returns SessionProperties of the DataChannel.
func (*DataChannel) GetTargetID ¶
func (c *DataChannel) GetTargetID() string
GetTargetID returns the channel target ID.
func (*DataChannel) Open ¶
func (c *DataChannel) Open(ctx context.Context, refreshTokenHandler RefreshTokenHandler, timeoutHandler TimeoutHandler) (string, error)
Open opens the data channel and registers the message handler.
func (*DataChannel) ProcessIncomingMessageBufferItems ¶
func (c *DataChannel) ProcessIncomingMessageBufferItems( outputMessage message.ClientMessage, ) error
ProcessIncomingMessageBufferItems checks if new expected sequence stream data is present in incomingMessageBuffer. If so, processes it and increments the expected sequence number. Repeats until expected sequence stream data is not found in incomingMessageBuffer.
func (*DataChannel) ProcessKMSEncryptionHandshakeAction ¶
func (c *DataChannel) ProcessKMSEncryptionHandshakeAction(ctx context.Context, actionParams json.RawMessage) error
ProcessKMSEncryptionHandshakeAction sets up the encrypter and calls KMS to generate a new data key. This is triggered when encryption is specified in HandshakeRequest.
func (*DataChannel) ProcessSessionTypeHandshakeAction ¶
func (c *DataChannel) ProcessSessionTypeHandshakeAction(actionParams json.RawMessage) error
ProcessSessionTypeHandshakeAction processes session type action in HandshakeRequest. This sets the session type in the datachannel.
func (*DataChannel) RegisterIncomingMessageHandler ¶ added in v0.2.0
func (c *DataChannel) RegisterIncomingMessageHandler(handler IncomingMessageHandler)
RegisterIncomingMessageHandler sets the message handler for the DataChannel.
func (*DataChannel) RegisterOutputStreamHandler ¶
func (c *DataChannel) RegisterOutputStreamHandler(handler OutputStreamDataMessageHandler, isSessionSpecificHandler bool)
RegisterOutputStreamHandler register a handler for messages of type OutputStream. This is usually called by the plugin.
func (*DataChannel) RegisterStopHandler ¶ added in v0.2.0
func (c *DataChannel) RegisterStopHandler(handler StopHandler)
RegisterStopHandler sets the message handler for the DataChannel.
func (*DataChannel) SendFlag ¶
func (c *DataChannel) SendFlag(flagType message.PayloadTypeFlag) error
SendFlag sends a data message with PayloadType as given flag.
func (*DataChannel) SendInputDataMessage ¶
func (c *DataChannel) SendInputDataMessage(payloadType message.PayloadType, inputData []byte) error
SendInputDataMessage sends a data message in a form of ClientMessage.
func (*DataChannel) SendMessage ¶
func (c *DataChannel) SendMessage(input []byte, inputType int) error
SendMessage sends a message to the service through datachannel.
func (*DataChannel) SetAgentVersion ¶
func (c *DataChannel) SetAgentVersion(agentVersion string)
SetAgentVersion set agent version of the target instance.
type EncryptorBuilder ¶
type EncryptorBuilder interface {
Build(ctx context.Context, kmsKeyID string, sessionID string, targetID string) (encryption.IEncrypter, error)
}
EncryptorBuilder is a function that builds an encryption object.
type IDataChannel ¶
type IDataChannel interface {
Open(ctx context.Context, refreshTokenHandler RefreshTokenHandler, timeoutHandler TimeoutHandler) (string, error)
Close() error
SendFlag(flagType message.PayloadTypeFlag) error
SendInputDataMessage(payloadType message.PayloadType, inputData []byte) error
SendMessage(input []byte, inputType int) error
GetSessionProperties() any
GetAgentVersion() string
GetTargetID() string
RegisterOutputStreamHandler(handler OutputStreamDataMessageHandler, sessionSpecific bool)
RegisterIncomingMessageHandler(handler IncomingMessageHandler)
RegisterStopHandler(handler StopHandler)
GetDisplayMessages() <-chan message.ClientMessage
}
IDataChannel defines the interface for data channel operations.
type IncomingMessageHandler ¶ added in v0.2.0
type IncomingMessageHandler func(input []byte)
IncomingMessageHandler is a function that handles incoming messages.
type KMSEncryptorBuilder ¶
type KMSEncryptorBuilder struct {
// contains filtered or unexported fields
}
KMSEncryptorBuilder builds encryption objects using AWS KMS.
func NewKMSEncryptorBuilder ¶
NewKMSEncryptorBuilder creates a new KMSEncryptorBuilder with the provided KMS client and logger.
func (*KMSEncryptorBuilder) Build ¶
func (b *KMSEncryptorBuilder) Build(ctx context.Context, kmsKeyID string, sessionID string, targetID string) (encryption.IEncrypter, error)
Build creates a new encryption object using the provided KMS key ID, session ID, and target ID.
type ListMessageBuffer ¶
type ListMessageBuffer[T any] struct { // contains filtered or unexported fields }
ListMessageBuffer holds outgoing messages in a linked list, generic over type T.
func NewListMessageBuffer ¶
func NewListMessageBuffer[T any](capacity int) *ListMessageBuffer[T]
NewListMessageBuffer creates a new ListMessageBuffer with the given capacity for type T.
func (*ListMessageBuffer[T]) ForcePushBack ¶
func (b *ListMessageBuffer[T]) ForcePushBack(item T)
ForcePushBack removes first T from if full and adds given T at the end.
func (*ListMessageBuffer[T]) Front ¶
func (b *ListMessageBuffer[T]) Front() (T, bool)
Front returns the first item of type T from the list and true, or the zero value of T and false if the list is empty.
func (*ListMessageBuffer[T]) RemoveIf ¶
func (b *ListMessageBuffer[T]) RemoveIf(predicate func(T) bool) (T, bool)
RemoveIf iterates through the list and removes the first element for which the predicate returns true. It returns the removed item (of type T) and true if an element was removed, otherwise the zero value of T and false.
type MapMessageBuffer ¶
type MapMessageBuffer[K comparable, V any] struct { // contains filtered or unexported fields }
MapMessageBuffer represents a buffer for messages using a map data structure.
func NewMapMessageBuffer ¶
func NewMapMessageBuffer[K comparable, V any](capacity int) *MapMessageBuffer[K, V]
NewMapMessageBuffer creates a new MapMessageBuffer with the given capacity for type T.
func (*MapMessageBuffer[K, V]) Get ¶
func (b *MapMessageBuffer[K, V]) Get(idx K) (V, bool)
Get returns the item of type T at the given index and true, or the zero value of T and false if the index is not found.
func (*MapMessageBuffer[K, V]) IsFull ¶
func (b *MapMessageBuffer[K, V]) IsFull() bool
IsFull checks if the buffer is full.
func (*MapMessageBuffer[K, V]) Remove ¶
func (b *MapMessageBuffer[K, V]) Remove(idx K) (V, bool)
Remove removes the item at the given index and returns it along with a boolean indicating if it was found.
func (*MapMessageBuffer[K, V]) SetUnlessFull ¶
func (b *MapMessageBuffer[K, V]) SetUnlessFull(idx K, item V) bool
SetUnlessFull sets the item at the given index if the buffer is not full.
type OutputStreamDataMessageHandler ¶
type OutputStreamDataMessageHandler func(streamDataMessage message.ClientMessage) (bool, error)
OutputStreamDataMessageHandler is a function type that handles output stream data messages.
type RefreshTokenHandler ¶
RefreshTokenHandler is a function that retrieves a reconnection token.
type RoundTripTiming ¶
RoundTripTiming represents the interface for calculating round trip time.
type StopHandler ¶
type StopHandler func() error
StopHandler is a function type that handles stopping the data channel.
type StreamingMessage ¶
type StreamingMessage struct {
Content []byte
SequenceNumber int64
LastSentTime time.Time
ResendAttempt int
}
StreamingMessage represents a message in the data stream with its metadata.
func (StreamingMessage) GetRoundTripTime ¶
func (m StreamingMessage) GetRoundTripTime() time.Duration
GetRoundTripTime is a function that calculates the round trip time for a streaming message.
type TimeoutHandler ¶
TimeoutHandler is a function that handles timeout events.