service

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Watch

func Watch(ws *websocket.Conn, timeout time.Duration, handler func() error) error

Watch watches for broken WebSocket connection. This function periodically sends ping message to the websocket peer and invokes `handler` on first timeout. The caller must continuously read something from `ws` to allow pong messages to be received.

Types

type Binder

type Binder interface {
	Start(ws *websocket.Conn, store *SessionStore) error
}

Binder creates tunnleing session for each client connection.

type BinderAcceptMessage

type BinderAcceptMessage struct {
	Event       string `json:"event"`
	SessionID   string `json:"session_id"`
	PeerAddress string `json:"peer_address"`
}

BinderAcceptMessage is a model of a JSON message sent via websocket on client connection.

type Service

type Service interface {
	GetBinder(key string, port int) (Binder, error)
}

Service is an abstraction of a tunneling service.

type Session

type Session interface {
	// PeerAddr returns the network address of a connected peer. This must be
	// invariant throughout the entire lifetime of a session.
	PeerAddr() net.Addr

	// Start starts a tunneling session through given websocket channel.
	Start(ws *websocket.Conn) error

	// Close closes client connection. This cancels tunneling session.
	Close() error
}

Session is an abstraction of a tunneling session.

type SessionStore

type SessionStore struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SessionStore is a concurrent storage of sessions.

func (*SessionStore) Add

func (store *SessionStore) Add(sess Session) string

Add adds a new session to store and returns a token ID for the session. The session can later be retrieved using the token for only a single time.

func (*SessionStore) Get

func (store *SessionStore) Get(peer net.Addr) Session

Get returns the session connected with given peer. Nil is returned if no such session in store.

func (*SessionStore) Remove

func (store *SessionStore) Remove(sess Session)

Remove removes sess from store.

func (*SessionStore) Resolve

func (store *SessionStore) Resolve(id string) Session

Resolve returns a session associated to given token ID. Nil is returned if the token is invalid. Token is invalidated after calling this function.

Jump to

Keyboard shortcuts

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