wsp

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Timeout     time.Duration
	IdleTimeout time.Duration
	SecretKey   string
}

type Connection

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

Connection manages a single websocket connection from the peer. wsp supports multiple connections from a single peer at the same time.

func NewConnection

func NewConnection(pool *Pool, ws *websocket.Conn) *Connection

NewConnection returns a new Connection.

func (*Connection) Close

func (c *Connection) Close()

Close the connection

func (*Connection) Release

func (c *Connection) Release()

Release notifies that this connection is ready to use again

func (*Connection) Take

func (c *Connection) Take() bool

Take notifies that this connection is going to be used

func (*Connection) WritePump added in v0.13.1

func (c *Connection) WritePump()

type ConnectionRequest

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

ConnectionRequest is used to request a proxy connection from the dispatcher

func NewConnectionRequest

func NewConnectionRequest(timeout time.Duration, serverId PoolID) (cr *ConnectionRequest)

NewConnectionRequest creates a new connection request

type ConnectionStatus

type ConnectionStatus int

ConnectionStatus is an enumeration type which represents the status of WebSocket connection.

const (
	// Idle state means it is opened but not working now.
	// The default value for Connection is Idle, so it is ok to use zero-value(int: 0) for Idle status.
	Idle ConnectionStatus = iota
	Busy
	Closed
)

type Message added in v0.13.1

type Message struct {
	Type  int
	Value []byte
}

type Pool

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

Pool handles all connections from the peer.

func NewPool

func NewPool(server *Server, id PoolID) *Pool

NewPool creates a new Pool

func (*Pool) Clean

func (p *Pool) Clean()

Clean removes dead connection from the pool Look for dead connection in the pool This MUST be surrounded by pool.lock.Lock()

func (*Pool) IsEmpty

func (p *Pool) IsEmpty() bool

IsEmpty clean the pool and return true if the pool is empty

func (*Pool) Offer

func (p *Pool) Offer(connection *Connection)

Offer offers an idle connection to the server.

func (*Pool) Register

func (p *Pool) Register(ws *websocket.Conn)

Register creates a new Connection and adds it to the pool

func (*Pool) Shutdown

func (p *Pool) Shutdown()

Shutdown closes every connections in the pool and cleans it

func (*Pool) Size

func (p *Pool) Size() (ps *PoolSize)

Size return the number of connection in each state in the pool

type PoolID

type PoolID string

PoolID represents the identifier of the connected WebSocket client.

type PoolSize

type PoolSize struct {
	Idle   int
	Busy   int
	Closed int
}

PoolSize is the number of connection in each state in the pool

type Server

type Server struct {
	Config *Config
	// contains filtered or unexported fields
}

Server is a Reverse HTTP Proxy over WebSocket This is the Server part, Clients will offer websocket connections, those will be pooled to transfer HTTP Request and response

func NewServer

func NewServer(config *Config) (server *Server)

NewServer return a new Server instance

func (*Server) GetServerID

func (s *Server) GetServerID(r *http.Request) (serverID string, err error)

func (*Server) Register

func (s *Server) Register(w http.ResponseWriter, r *http.Request)

Request receives the WebSocket upgrade handshake request from wsp_client.

func (*Server) Request

func (s *Server) Request(w http.ResponseWriter, r *http.Request)

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown stop the Server

func (*Server) Start

func (s *Server) Start()

Start Server HTTP server

func (*Server) Ws

func (s *Server) Ws(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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