guacamole

package module
v0.0.0-...-72ec28a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

README

Guacamole

Go port of Guacamole common. This package is used in TRASA RDP access proxy which works with guacd.

Documentation

Overview

package guacamole implements a HTTP client and a WebSocket client that connects to an Apache Guacamole server.

Index

Constants

View Source
const (
	SocketTimeout  = 15 * time.Second
	MaxGuacMessage = 8192
)
View Source
const InternalDataOpcode = ""

The Guacamole protocol instruction Opcode reserved for arbitrary internal use by tunnel implementations. The value of this Opcode is guaranteed to be the empty string (""). Tunnel implementations may use this Opcode for any purpose. It is currently used by the HTTP tunnel to mark the end of the HTTP response, and by the WebSocket tunnel to transmit the tunnel UUID.

View Source
const TfaOpcode = "tfa"

Variables

View Source
var InternalOpcodeIns = []byte(fmt.Sprint(len(InternalDataOpcode), ".", InternalDataOpcode))

Functions

This section is empty.

Types

type Config

type Config struct {
	// ConnectionID is used to reconnect to an existing session, otherwise leave blank for a new session.
	ConnectionID string
	// Protocol is the protocol of the connection from guacd to the remote (rdp, ssh, etc).
	Protocol string
	// Parameters are used to configure protocol specific options like sla for rdp or terminal color schemes.
	Parameters map[string]string

	// OptimalScreenWidth is the desired width of the screen
	OptimalScreenWidth int
	// OptimalScreenHeight is the desired height of the screen
	OptimalScreenHeight int
	// OptimalResolution is the desired resolution of the screen
	OptimalResolution int
	// AudioMimetypes is an array of the supported audio types
	AudioMimetypes []string
	// VideoMimetypes is an array of the supported video types
	VideoMimetypes []string
	// ImageMimetypes is an array of the supported image types
	ImageMimetypes []string
}

Config is the data sent to guacd to configure the session during the handshake.

func NewGuacamoleConfiguration

func NewGuacamoleConfiguration() *Config

NewGuacamoleConfiguration returns a Config with sane defaults

type CountedLock

type CountedLock struct {
	// contains filtered or unexported fields
}

CountedLock counts how many goroutines are waiting on the lock

func (*CountedLock) HasQueued

func (r *CountedLock) HasQueued() bool

HasQueued returns true if a goroutine is waiting on the lock

func (*CountedLock) Lock

func (r *CountedLock) Lock()

Lock locks the mutex

func (*CountedLock) Unlock

func (r *CountedLock) Unlock()

Unlock unlocks the mutex

type ErrGuac

type ErrGuac struct {
	Status Status
	Kind   ErrKind
	// contains filtered or unexported fields
}

type ErrKind

type ErrKind int
const (
	ErrClientBadType ErrKind = iota
	ErrClient
	ErrClientOverrun
	ErrClientTimeout
	ErrClientTooMany
	ErrConnectionClosed
	ErrOther
	ErrResourceClosed
	ErrResourceConflict
	ErrResourceNotFound
	ErrSecurity
	ErrServerBusy
	ErrServer
	ErrSessionClosed
	ErrSessionConflict
	ErrSessionTimeout
	ErrUnauthorized
	ErrUnsupported
	ErrUpstream
	ErrUpstreamNotFound
	ErrUpstreamTimeout
	ErrUpstreamUnavailable
)

func (ErrKind) NewError

func (e ErrKind) NewError(args ...string) error

NewError creates a new error struct instance with Kind and included message

func (ErrKind) Status

func (e ErrKind) Status() (state Status)

Status convert ErrKind to Status

type Instruction

type Instruction struct {
	Opcode string
	Args   []string
	// contains filtered or unexported fields
}

Instruction represents a Guacamole instruction

func NewInstruction

func NewInstruction(opcode string, args ...string) *Instruction

NewInstruction creates an instruction

func Parse

func Parse(data []byte) (*Instruction, error)

func ReadOne

func ReadOne(stream *Stream) (instruction *Instruction, err error)

ReadOne takes an instruction from the stream and parses it into an Instruction

func (*Instruction) Byte

func (i *Instruction) Byte() []byte

func (*Instruction) String

func (i *Instruction) String() string

String returns the on-wire representation of the instruction

type InstructionReader

type InstructionReader interface {
	// ReadSome returns the next complete guacd message from the stream
	ReadSome() ([]byte, error)
	// Available returns true if there are bytes buffered in the stream
	Available() bool
	// Flush resets the internal buffer for reuse
	Flush()
}

InstructionReader provides reading functionality to a Stream

type SimpleTunnel

type SimpleTunnel struct {
	// contains filtered or unexported fields
}

Base Tunnel implementation which synchronizes access to the underlying reader and writer with locks

func NewSimpleTunnel

func NewSimpleTunnel(stream *Stream, uuid string) *SimpleTunnel

NewSimpleTunnel creates a new tunnel

func (*SimpleTunnel) AcquireReader

func (t *SimpleTunnel) AcquireReader() InstructionReader

AcquireReader acquires the reader lock

func (*SimpleTunnel) AcquireWriter

func (t *SimpleTunnel) AcquireWriter() io.Writer

AcquireWriter locks the writer lock

func (*SimpleTunnel) Close

func (t *SimpleTunnel) Close() (err error)

Close closes the underlying stream

func (*SimpleTunnel) ConnectionID

func (t *SimpleTunnel) ConnectionID() string

ConnectionID returns the underlying Guacamole connection ID

func (*SimpleTunnel) GetUUID

func (t *SimpleTunnel) GetUUID() string

GetUUID returns the tunnel's UUID

func (*SimpleTunnel) HasQueuedReaderThreads

func (t *SimpleTunnel) HasQueuedReaderThreads() bool

HasQueuedReaderThreads returns true if more than one goroutine is trying to read

func (*SimpleTunnel) HasQueuedWriterThreads

func (t *SimpleTunnel) HasQueuedWriterThreads() bool

HasQueuedWriterThreads returns true if more than one goroutine is trying to write

func (*SimpleTunnel) ReleaseReader

func (t *SimpleTunnel) ReleaseReader()

ReleaseReader releases the reader

func (*SimpleTunnel) ReleaseWriter

func (t *SimpleTunnel) ReleaseWriter()

ReleaseWriter releases the writer lock

type Status

type Status int
const (
	// Undefined Add to instead null
	Undefined Status = -1

	// Success indicates the operation succeeded.
	Success Status = iota

	// Unsupported indicates the requested operation is unsupported.
	Unsupported

	// ServerError indicates the operation could not be performed due to an internal failure.
	ServerError

	// ServerBusy indicates the operation could not be performed as the server is busy.
	ServerBusy

	// UpstreamTimeout indicates the operation could not be performed because the upstream server is not responding.
	UpstreamTimeout

	// UpstreamError indicates the operation was unsuccessful due to an error or otherwise unexpected
	// condition of the upstream server.
	UpstreamError

	// ResourceNotFound indicates the operation could not be performed as the requested resource does not exist.
	ResourceNotFound

	// ResourceConflict indicates the operation could not be performed as the requested resource is already in use.
	ResourceConflict

	// ResourceClosed indicates the operation could not be performed as the requested resource is now closed.
	ResourceClosed

	// UpstreamNotFound indicates the operation could not be performed because the upstream server does
	// not appear to exist.
	UpstreamNotFound

	// UpstreamUnavailable indicates the operation could not be performed because the upstream server is not
	// available to service the request.
	UpstreamUnavailable

	// SessionConflict indicates the session within the upstream server has ended because it conflicted
	// with another session.
	SessionConflict

	// SessionTimeout indicates the session within the upstream server has ended because it appeared to be inactive.
	SessionTimeout

	// SessionClosed indicates the session within the upstream server has been forcibly terminated.
	SessionClosed

	// ClientBadRequest indicates the operation could not be performed because bad parameters were given.
	ClientBadRequest

	// ClientUnauthorized indicates the user is not authorized.
	ClientUnauthorized

	// ClientForbidden indicates the user is not allowed to do the operation.
	ClientForbidden

	// ClientTimeout indicates the client took too long to respond.
	ClientTimeout

	// ClientOverrun indicates the client sent too much data.
	ClientOverrun

	// ClientBadType indicates the client sent data of an unsupported or unexpected type.
	ClientBadType

	// ClientTooMany indivates the operation failed because the current client is already using too many resources.
	ClientTooMany
)

func FromGuacamoleStatusCode

func FromGuacamoleStatusCode(code int) (ret Status)

FromGuacamoleStatusCode returns the Status corresponding to the given Guacamole protocol Status code.

func (Status) GetGuacamoleStatusCode

func (s Status) GetGuacamoleStatusCode() int

GetGuacamoleStatusCode returns the corresponding Guacamole protocol Status code.

func (Status) GetHTTPStatusCode

func (s Status) GetHTTPStatusCode() int

GetHTTPStatusCode returns the most applicable HTTP error code.

func (Status) GetWebSocketCode

func (s Status) GetWebSocketCode() int

GetWebSocketCode returns the most applicable HTTP error code.

func (Status) String

func (s Status) String() string

String returns the name of the status.

type Stream

type Stream struct {

	// ConnectionID is the ID Guacamole gives and can be used to reconnect or share sessions
	ConnectionID string
	// contains filtered or unexported fields
}

Stream wraps the connection to Guacamole providing timeouts and reading a single instruction at a time (since returning partial instructions would be an error)

func NewStream

func NewStream(conn net.Conn, timeout time.Duration) (ret *Stream)

NewStream creates a new stream

func (*Stream) AssertOpcode

func (s *Stream) AssertOpcode(opcode string) (instruction *Instruction, err error)

AssertOpcode checks the next opcode in the stream matches what is expected. Useful during handshake.

func (*Stream) Available

func (s *Stream) Available() bool

Available returns true if there are messages buffered

func (*Stream) Close

func (s *Stream) Close() error

Close closes the underlying network connection

func (*Stream) Flush

func (s *Stream) Flush()

Flush resets the internal buffer

func (*Stream) Handshake

func (s *Stream) Handshake(config *Config) error

Handshake configures the guacd session

func (*Stream) ReadSome

func (s *Stream) ReadSome() (instruction []byte, err error)

ReadSome takes the next instruction (from the network or from the buffer) and returns it. io.Reader is not implemented because this seems like the right place to maintain a buffer.

func (*Stream) Write

func (s *Stream) Write(data []byte) (n int, err error)

Write sends messages to Guacamole with a timeout

type Tunnel

type Tunnel interface {
	// AcquireReader returns a reader to the tunnel if it isn't locked
	AcquireReader() InstructionReader
	// ReleaseReader releases the lock on the reader
	ReleaseReader()
	// HasQueuedReaderThreads returns true if there is a reader locked
	HasQueuedReaderThreads() bool
	// AcquireWriter returns a writer to the tunnel if it isn't locked
	AcquireWriter() io.Writer
	// ReleaseWriter releases the lock on the writer
	ReleaseWriter()
	// HasQueuedWriterThreads returns true if there is a writer locked
	HasQueuedWriterThreads() bool
	// GetUUID returns the uuid of the tunnel
	GetUUID() string
	// ConnectionId returns the guacd Connection ID of the tunnel
	ConnectionID() string
	// Close closes the tunnel
	Close() error
}

Tunnel provides a unique identifier and synchronized access to the InstructionReader and Writer associated with a Stream.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL