Documentation ¶
Index ¶
- type Config
- type Connection
- type ConnectionRequest
- type ConnectionStatus
- type Pool
- type PoolID
- type PoolSize
- type Server
- func (s *Server) DispatchConnections()
- func (s *Server) GetDestinationURL(subdomain string) string
- func (s *Server) GetOrCreatePoolForUser(subdomain, localServer, userIdentifier string, id PoolID) (*Pool, error)
- func (s *Server) GetSubdomainFromHost(host string) (string, error)
- func (s *Server) Shutdown()
- func (s *Server) Start()
- type UserConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Host string Port int Domain string Secure bool Timeout int IdleTimeout int Users []UserConfig }
Config configures an Server
func LoadConfiguration ¶
LoadConfiguration loads configuration from a YAML file
func (Config) GetTimeout ¶
GetTimeout returns the time.Duration converted to millisecond
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) ProxyRequest ¶
func (connection *Connection) ProxyRequest(c echo.Context) (err error)
Proxy a HTTP request through the Proxy over the websocket connection
func (*Connection) Release ¶
func (connection *Connection) Release()
Release notifies that this connection is ready to use again
func (*Connection) Take ¶
func (connection *Connection) Take() bool
Take notifies that this connection is going to be used
type ConnectionRequest ¶
type ConnectionRequest struct { // Pick the connection for this subdomain Subdomain string Connection chan *Connection }
ConnectionRequest is used to request a proxy connection from the dispatcher
func NewConnectionRequest ¶
func NewConnectionRequest(timeout time.Duration, connectionFor string) (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 Pool ¶
type Pool struct { ID PoolID Subdomain string LocalServer string UserIdentifier string // contains filtered or unexported fields }
Pool handles all connections from the peer.
func (*Pool) Clean ¶
func (pool *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) Offer ¶
func (pool *Pool) Offer(connection *Connection)
Offer offers an idle connection to the server.
type PoolID ¶
type PoolID string
PoolID represents the identifier of the connected WebSocket client.
type Server ¶
type Server struct { Config *Config Upgrader websocket.Upgrader // In Pools, keep connections with WebSocket peers. Pools map[string]*Pool // A RWMutex is a reader/writer mutual exclusion Lock, // and it is for exclusive control with pools operation. // // This is locked when reading and writing pools, the timing is when: // 1. (rw) registering websocket clients in /register endpoint // 2. (rw) remove empty pools which has no connections // 3. (r) dispatching connection from available pools to clients requests // // And then it is released after each process is completed. Lock sync.RWMutex // Through Dispatcher channel it communicates between "server" thread and "Dispatcher" thread. // "server" thread sends the value to this channel when accepting requests in the endpoint /requests, // and "Dispatcher" thread reads this channel. Dispatcher chan *ConnectionRequest // DB connection DB *gorm.DB // 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 (*Server) DispatchConnections ¶
func (s *Server) DispatchConnections()
Dispatch connection from available pools to clients requests