net

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2015 License: MIT Imports: 13 Imported by: 0

README

package net

Contains the main components for adding networking functionality to leaps. Currently leaps only supports websockets as a solution for editing documents, this could eventually be accompanied by long polling REST endpoints.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthMiddleware added in v0.1.4

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

AuthMiddleware - A construct designed to take a LeapLocator (a structure for finding and binding to leap documents) and bind it to http clients.

func NewAuthMiddleware added in v0.1.4

func NewAuthMiddleware(
	config AuthMiddlewareConfig,
	logger *log.Logger,
	stats *log.Stats,
) (*AuthMiddleware, error)

NewAuthMiddleware - Create a new leaps AuthMiddleware.

func (*AuthMiddleware) WrapHandler added in v0.1.4

func (a *AuthMiddleware) WrapHandler(handler http.Handler) http.HandlerFunc

WrapHandler - Wrap an http request Handler with the AuthMiddleware authentication.

func (*AuthMiddleware) WrapHandlerFunc added in v0.1.4

func (a *AuthMiddleware) WrapHandlerFunc(handler http.HandlerFunc) http.HandlerFunc

WrapHandlerFunc - Wrap an http request HandlerFunc with the AuthMiddleware authentication.

func (*AuthMiddleware) WrapWSHandler added in v0.1.4

func (a *AuthMiddleware) WrapWSHandler(handler websocket.Handler) websocket.Handler

WrapWSHandler - Wrap a websocket http request handler with the AuthMiddleware authentication.

type AuthMiddlewareConfig added in v0.1.4

type AuthMiddlewareConfig struct {
	Enabled        bool   `json:"enabled" yaml:"enabled"`
	PasswdFilePath string `json:"htpasswd_path" yaml:"htpasswd_path"`
}

AuthMiddlewareConfig - Holds configuration options for the AuthMiddleware

func NewAuthMiddlewareConfig added in v0.1.4

func NewAuthMiddlewareConfig() AuthMiddlewareConfig

NewAuthMiddlewareConfig - Returns an AuthMiddleware configuration with the default values

type HTTPBinderConfig

type HTTPBinderConfig struct {
	BindSendTimeout int `json:"bind_send_timeout_ms" yaml:"bind_send_timeout_ms"`
}

HTTPBinderConfig - Options for individual binders (one for each socket connection)

type HTTPServer

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

HTTPServer - A construct designed to take a LeapLocator (a structure for finding and binding to leap documents) and bind it to http clients.

func CreateHTTPServer

func CreateHTTPServer(
	locator LeapLocator,
	config HTTPServerConfig,
	logger *log.Logger,
	stats *log.Stats,
) (*HTTPServer, error)

CreateHTTPServer - Create a new leaps HTTPServer.

func (*HTTPServer) Listen

func (h *HTTPServer) Listen() error

Listen - Bind to the http endpoint as per configured address, and begin serving requests. This is simply a helper function that calls http.ListenAndServe

func (*HTTPServer) Stop

func (h *HTTPServer) Stop()

Stop - Stop serving web requests and close the HTTPServer.

type HTTPServerConfig

type HTTPServerConfig struct {
	StaticPath     string               `json:"static_path" yaml:"static_path"`
	Path           string               `json:"socket_path" yaml:"socket_path"`
	Address        string               `json:"address" yaml:"address"`
	StaticFilePath string               `json:"www_dir" yaml:"www_dir"`
	Binder         HTTPBinderConfig     `json:"binder" yaml:"binder"`
	SSL            SSLConfig            `json:"ssl" yaml:"ssl"`
	HTTPAuth       AuthMiddlewareConfig `json:"basic_auth" yaml:"basic_auth"`
}

HTTPServerConfig - Holds configuration options for the HTTPServer.

func DefaultHTTPServerConfig

func DefaultHTTPServerConfig() HTTPServerConfig

DefaultHTTPServerConfig - Returns a fully defined HTTPServer configuration with the default values for each field.

type LeapClientMessage

type LeapClientMessage struct {
	Command  string        `json:"command" yaml:"command"`
	Token    string        `json:"token" yaml:"token"`
	DocID    string        `json:"document_id,omitempty" yaml:"document_id,omitempty"`
	UserID   string        `json:"user_id,omitempty" yaml:"user_id,omitempty"`
	Document *lib.Document `json:"leap_document,omitempty" yaml:"leap_document,omitempty"`
}

LeapClientMessage - A structure that defines a message format to expect from clients. Commands can be 'create' (init with new document) or 'find' (init with existing document).

type LeapLocator

type LeapLocator interface {
	// FindDocument - Find and return a binder portal to an existing document
	FindDocument(string, string) (lib.BinderPortal, error)

	// CreateDocument - Create and return a binder portal to a new document
	CreateDocument(string, string, lib.Document) (lib.BinderPortal, error)

	// Close - Close the LeapLocator
	Close()
}

LeapLocator - An interface capable of locating and creating leaps documents. This can either be a curator, which deals with documents on the local service, or a TBD, which load balances between servers of curators.

type LeapServerMessage

type LeapServerMessage struct {
	Type     string        `json:"response_type" yaml:"response_type"`
	Document *lib.Document `json:"leap_document,omitempty" yaml:"leap_document,omitempty"`
	Version  *int          `json:"version,omitempty" yaml:"version,omitempty"`
	Error    string        `json:"error,omitempty" yaml:"error,omitempty"`
}

LeapServerMessage - A structure that defines a response message from the server to a client. Type can be 'document' (init response) or 'error' (an error message to display to the client).

type LeapSocketClientMessage added in v0.1.0

type LeapSocketClientMessage struct {
	Command   string          `json:"command" yaml:"command"`
	Transform *lib.OTransform `json:"transform,omitempty" yaml:"transform,omitempty"`
	Position  *int64          `json:"position,omitempty" yaml:"position,omitempty"`
	Message   string          `json:"message,omitempty" yaml:"message,omitempty"`
}

LeapSocketClientMessage - A structure that defines a message format to expect from clients connected to a text model. Commands can currently be 'submit' (submit a transform to a bound document), or 'update' (submit an update to the users cursor position).

type LeapSocketServerMessage added in v0.1.0

type LeapSocketServerMessage struct {
	Type       string              `json:"response_type" yaml:"response_type"`
	Transforms []lib.OTransform    `json:"transforms,omitempty" yaml:"transforms,omitempty"`
	Updates    []lib.ClientMessage `json:"user_updates,omitempty" yaml:"user_updates,omitempty"`
	Version    int                 `json:"version,omitempty" yaml:"version,omitempty"`
	Error      string              `json:"error,omitempty" yaml:"error,omitempty"`
}

LeapSocketServerMessage - A structure that defines a response message from a text model to a client. Type can be 'transforms' (continuous delivery), 'correction' (actual version of a submitted transform), 'update' (an update to a users status) or 'error' (an error message to display to the client).

type SSLConfig added in v0.1.4

type SSLConfig struct {
	Enabled         bool   `json:"enabled" yaml:"enabled"`
	CertificatePath string `json:"certificate_path" yaml:"certificate_path"`
	PrivateKeyPath  string `json:"private_key_path" yaml:"private_key_path"`
}

SSLConfig - Options for setting an SSL certificate

func NewSSLConfig added in v0.1.4

func NewSSLConfig() SSLConfig

NewSSLConfig - Creates a new SSLConfig object with default values

type WebsocketServer added in v0.1.0

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

WebsocketServer - A websocket client that connects a binder of a document to a websocket client.

func NewWebsocketServer added in v0.1.0

func NewWebsocketServer(
	config HTTPBinderConfig,
	socket *websocket.Conn,
	binder lib.BinderPortal,
	closeChan <-chan bool,
	logger *log.Logger,
	stats *log.Stats,
) *WebsocketServer

NewWebsocketServer - Creates a new HTTP websocket client.

func (*WebsocketServer) Launch added in v0.1.0

func (w *WebsocketServer) Launch()

Launch - Launches the client, wrapping two goroutines around a connected websocket and a BinderPortal. This call spawns two goroutines and blocks until both are closed. One goroutine manages incoming messages routing through to the binder, the other manages outgoing messages routing back through the websocket.

Jump to

Keyboard shortcuts

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