wsconncache

package
v0.0.0-...-560f09a Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package wsconncache caches workspace agent connections by UUID.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func New

func New(params CacheParams) (*Cache, error)

New creates a new workspace connection cache that closes connections after the inactive timeout provided.

Agent connections are cached due to WebRTC negotiation taking a few hundred milliseconds.

func (*Cache) Acquire

func (c *Cache) Acquire(r *http.Request, id int64) (*Conn, func(), error)

Acquire gets or establishes a connection with the dialer using the ID provided. If a connection is in-progress, that connection or error will be returned.

The returned function is used to release a lock on the connection. Once zero locks exist on a connection, the inactive timeout will begin to tick down. After the time expires, the connection will be cleared from the cache.

func (*Cache) Close

func (c *Cache) Close() error

func (*Cache) ForgetAndClose

func (c *Cache) ForgetAndClose(id int64)

ForgetAndClose closes the connection and removes it from the cache.

type CacheParams

type CacheParams struct {
	// Dialer creates a new agent connection by ID.
	Dialer          Dialer
	InactiveTimeout time.Duration
	Logger          logging.Logger
	Js              *mq.JetstreamClient
}

type Conn

type Conn struct {
	*agentsdk.AgentConn
	// contains filtered or unexported fields
}

Conn wraps an agent connection with a reusable HTTP transport.

func (*Conn) CloseWithError

func (c *Conn) CloseWithError(err error) error

CloseWithError ends the HTTP transport if exists, and closes the agent.

func (*Conn) HTTPTransport

func (c *Conn) HTTPTransport() *http.Transport

type Dialer

type Dialer func(r *http.Request, id int64) (*agentsdk.AgentConn, error)

Dialer creates a new agent connection by ID.

Jump to

Keyboard shortcuts

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