turms

package module
v0.0.0-...-592acc0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2016 License: MIT Imports: 11 Imported by: 0

README

turms

Build Status Coverage Status Go Report Card GoDoc

The Go implementation of WAMP (Web Application Messaging Protocol) v2.

Spec implementation:

Transports:

All message-based, reliable, ordered, bidirectional (full-duplex) connections which implement turms.Conn or net.Conn.

Codec:

Implemented:

  • JSON Missing:
  • MsgPack 5+
Basic Profile:

Implemented, test coverage low:

  • Sessions
  • Publisher
  • Subscriber
  • Caller
  • Callee
Advanced Profile:

Missing:

  • Progressive Call Results
  • Progressive Calls
  • Call Timeouts
  • Call Canceling
  • Caller Identification
  • Call Trust Levels
  • Registration Meta API
  • Pattern-based Registrations
  • Shared Registration
  • Sharded Registration
  • Registration Revocation
  • Procedure Reflection
  • Subscriber Black- and Whitelisting
  • Publisher Exclusion
  • Publisher Identification
  • Publication Trust Levels
  • Subscription Meta API
  • Pattern-based Subscriptions
  • Sharded Subscriptions
  • Event History
  • Registration Revocation
  • Topic Reflection
  • Session Meta API
  • Authentication

Documentation

Overview

+build generate

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSession = errors.New("session does not exist in context")
	ErrNoSub     = errors.New("subscription does not exist")
)
View Source
var (
	ErrNotWS       = errors.New("not a websocket schema")
	ErrNoProcedure = errors.New("procedure does not exist")
)
View Source
var (
	EvOnCreate       = URI("wamp.registration.on_create")
	EvOnRegister     = URI("wamp.registration.on_register")
	EvOnUnregister   = URI("wamp.registration.on_unregister")
	EvOnDelete       = URI("wamp.registration.on_delete")
	ProcList         = URI("wamp.registration.list")
	ProcLookUp       = URI("wamp.registration.lookup")
	ProcMatch        = URI("wamp.registration.match")
	ProcGet          = URI("wamp.registration.get")
	ProcListCallees  = URI("wamp.registration.list_callees")
	ProcCountCallees = URI("wamp.registration.count_callees")

	ErrNoCaller = errors.New("caller does not exist")
	ErrNoCall   = errors.New("call does not exist")
)
View Source
var (
	ErrRoleExist         = errors.New("role already exists")
	ErrRoleNotExist      = errors.New("role does not exist")
	ErrProtocolViolation = errors.New("protocol violation")
	ErrRealmExist        = errors.New("realm already exists")
	ErrRealmNoExist      = errors.New("realm doesn not exist")
)
View Source
var (
	InvalidURI             = URI("wamp.error.invalid_uri")                   // The provided URI is not valid.
	NoSuchProcedure        = URI("wamp.error.no_such_procedure")             // No procedure registered under the given URL.
	ProcedureAlreadyExists = URI("wamp.error.procedure_already_exists")      // A procedure with the given URI is already registered.
	NoSuchRegistration     = URI("wamp.error.no_such_registration")          // A Dealer could not perform an unregister, since the given registration is not active.
	NoSuchSubscription     = URI("wamp.error.no_such_subscription")          // A Broker could not perform an unsubscribe, since the given subscription is not active.
	InvalidArument         = URI("wamp.error.invalid_argument")              // A Call failed since the given argument types or values are not acceptable to the called procedure.
	SystemShutdown         = URI("wamp.error.system_shutdown")               // Used as a GOODBYE or ABORT reason.
	CloseRealm             = URI("wamp.error.close_realm")                   // Used as a GOODBYE reason when a Peer wants to leave the realm.
	GoodbyeAndOut          = URI("wamp.error.goodbye_and_out")               // Used as a GOODBYE reply reason to acknowledge the end of a Peers session.
	NotAuthorized          = URI("wamp.error.not_authorized")                // Peer is not authorized to perform the operation.
	AuthorizationFailed    = URI("wamp.error.authorization_failed")          // Dealer or Broker could not determine if the Peer is authorized to perform the operation.
	NoSuchRealm            = URI("wamp.error.no_such_realm")                 // Peer wanted to join non-exsisting realm.
	NoSuchRole             = URI("wamp.error.no_such_role")                  // Authenticated Role does not or no longer exists.
	Canceled               = URI("wamp.error.canceled")                      // Previously issued call is canceled.
	OptionNotAllowed       = URI("wamp.error.option_not_allowed")            // Requested interaction with an option was disallowed by the Router.
	NoEligibleCallee       = URI("wamp.error.no_eligible_callee")            // Callee black list or Caller exclusion lead to an exclusion of any Callee providing the procedure.
	DiscloseMe             = URI("wamp.error.option_disallowed.disclose_me") // A Router rejected client request to disclose its identity.
	NetworkFailure         = URI("wamp.error.network_failure")               // A Router encountered a network failure.
)
View Source
var ErrInvalidURI = errors.New("invalid uri")
View Source
var (
	ErrWrongSubprotocol = errors.New("wrong subprotocol")
)

Functions

func Broker

func Broker() *broker

Broker returns a handler that handles messages by routing incoming events from Publishers to Subscribers that are subscribed to respective topics. Requires a Realm handler chained before the Broker.

func Dealer

func Dealer() *dealer

Dealer returns a handler that handles messages by routing calls from incoming Callers to Callees implementing the procedure called, and route call results back from Callees to Callers. Requires a Realm handler chained before the Dealer.

func ErrorFromContext

func ErrorFromContext(ctx context.Context) (error, bool)

ErrorFromContext extracts the error value from the context.

func NewErrorContext

func NewErrorContext(ctx context.Context, err error) context.Context

NewErrorContext returns a child context with the error value stored in it.

func NewRealm

func NewRealm() *realmHandler

NewRealm returns a realm handler that handles realm specific messages.

func NewSessionContext

func NewSessionContext(ctx context.Context, session *Session) context.Context

NewSessionContext returns a child context with the session value stored in it.

func Pipe

func Pipe() (Conn, Conn)

Types

type Abort

type Abort struct {
	T       MessageType
	Details map[string]interface{}
	Reason  URI
}

func (*Abort) Type

func (msg *Abort) Type() MessageType

type Call

type Call struct {
	T         MessageType
	Request   ID
	Options   map[string]interface{}
	Procedure URI
	Args      []interface{}
	ArgsKW    map[string]interface{}
}

func (*Call) Type

func (msg *Call) Type() MessageType

type Chain

type Chain []Handler

A Chain is a chain of Handlers. It implements a Handler.

func (*Chain) Handle

func (c *Chain) Handle(ctx context.Context, conn Conn, msg Message) context.Context

Handle calls each chain element Handle function subsequently.

type Client

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

A Client is a Peer which connects to a Router.

func Dial

func Dial(url string) (*Client, error)

func DialWithInfo

func DialWithInfo(info *DialInfo) (*Client, error)

func NewClient

func NewClient(c Conn, timeout time.Duration) *Client

func (*Client) Call

func (c *Client) Call(ctx context.Context, procedure URI, args []interface{}, argsKW map[string]interface{}) (*Result, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) JoinRealm

func (c *Client) JoinRealm(ctx context.Context, realm URI, details Details) error

func (*Client) Publish

func (c *Client) Publish(ctx context.Context, options Options, topic URI, args []interface{}, argsKW map[string]interface{}) error

func (*Client) Register

func (c *Client) Register(ctx context.Context, name URI, h InvocationHandler) error

func (*Client) Send

func (c *Client) Send(ctx context.Context, message Message) error

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, topic URI) (<-chan *Event, error)

func (*Client) Unregister

func (c *Client) Unregister(ctx context.Context, name URI) error

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(ctx context.Context, topic URI) error

type ClientDetails

type ClientDetails struct {
	Callee     bool
	Caller     bool
	Publisher  bool
	Subscriber bool
}

func (*ClientDetails) Details

func (d *ClientDetails) Details() map[string]interface{}

type Conn

type Conn interface {
	Read(context.Context) (Message, error)
	Send(context.Context, Message) error
	Close() error
}

A Conn represents a connection between two Peers.

func NewWebsocketConn

func NewWebsocketConn(c *websocket.Conn) (Conn, error)

type Details

type Details interface {
	Details() map[string]interface{}
}

type DialInfo

type DialInfo struct {
	URL      string
	Origin   string
	Protocol string
	Timeout  time.Duration
}

type Error

type Error struct {
	T       MessageType
	ErrCode MessageType
	Request ID
	Details map[string]interface{}
	Error   URI
	Args    []interface{}
	ArgsKW  map[string]interface{}
}

func (*Error) Response

func (err *Error) Response() ID

func (*Error) Type

func (msg *Error) Type() MessageType

type Event

type Event struct {
	T            MessageType
	Subscription ID
	Publication  ID
	Details      map[string]interface{}
	Args         []interface{}
	ArgsKW       map[string]interface{}
}

func (*Event) Type

func (msg *Event) Type() MessageType

type Goodbye

type Goodbye struct {
	T       MessageType
	Details map[string]interface{}
	Reason  URI
}

func (*Goodbye) Type

func (msg *Goodbye) Type() MessageType

type Handler

type Handler interface {
	Handle(context.Context, Conn, Message) context.Context
}

A Handler manages messages.

type Hello

type Hello struct {
	T       MessageType
	Realm   URI
	Details map[string]interface{}
}

func (*Hello) Type

func (msg *Hello) Type() MessageType

type ID

type ID uint64

func NewGlobalID

func NewGlobalID() ID

NewGlobalID draws a randomly, uniformly distributed ID from the complete range of [0, 2^53]. The drawn ID is allowed to be used in the global scope.

type Invocation

type Invocation struct {
	T            MessageType
	Request      ID
	Registration ID
	Details      map[string]interface{}
	Args         []interface{}
	ArgsKW       map[string]interface{}
}

func (*Invocation) Type

func (msg *Invocation) Type() MessageType

type InvocationHandler

type InvocationHandler func(context.Context, *Invocation) ([]interface{}, map[string]interface{}, error)

type Message

type Message interface {
	Type() MessageType
}

func NewMessage

func NewMessage(t MessageType) Message

type MessageType

type MessageType uint32
const (
	HelloCode   MessageType = 1
	WelcomeCode MessageType = 2
	AbortCode   MessageType = 3
	GoodbyeCode MessageType = 6

	ErrorCode MessageType = 8

	PublishCode   MessageType = 16
	PublishedCode MessageType = 17

	SubscribeCode    MessageType = 32
	SubscribedCode   MessageType = 33
	UnsubscribeCode  MessageType = 34
	UnsubscribedCode MessageType = 35
	EventCode        MessageType = 36

	CallCode   MessageType = 48
	ResultCode MessageType = 50

	RegisterCode     MessageType = 64
	RegisteredCode   MessageType = 65
	UnregisterCode   MessageType = 66
	UnregisteredCode MessageType = 67
	InvocationCode   MessageType = 68
	YieldCode        MessageType = 70

	ChallengeCode    MessageType = 4
	AuthenticateCode MessageType = 5
	CancelCode       MessageType = 49
	InterruptCode    MessageType = 69
)

type Options

type Options interface {
	Options() map[string]interface{}
}

type Publish

type Publish struct {
	T       MessageType
	Request ID
	Options map[string]interface{}
	Topic   URI
	Args    []interface{}
	ArgsKW  map[string]interface{}
}

func (*Publish) Type

func (msg *Publish) Type() MessageType

type PublishOption

type PublishOption struct {
	AcknowledgePublish bool
}

func (*PublishOption) Options

func (opt *PublishOption) Options() map[string]interface{}

type Published

type Published struct {
	T           MessageType
	Request     ID
	Publication ID
}

func (*Published) Response

func (p *Published) Response() ID

func (*Published) Type

func (msg *Published) Type() MessageType

type Realm

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

func (*Realm) Details

func (r *Realm) Details() map[string]interface{}

func (*Realm) Name

func (r *Realm) Name() URI

func (*Realm) RegisterFeatures

func (r *Realm) RegisterFeatures(name string, features ...string) error

func (*Realm) RegisterRole

func (r *Realm) RegisterRole(name string) error

func (*Realm) SetValue

func (r *Realm) SetValue(key interface{}, value interface{})

func (*Realm) Value

func (r *Realm) Value(key interface{}) (interface{}, bool)

type Register

type Register struct {
	T         MessageType
	Request   ID
	Options   map[string]interface{}
	Procedure URI
}

func (*Register) Type

func (msg *Register) Type() MessageType

type Registered

type Registered struct {
	T            MessageType
	Request      ID
	Registration ID
}

func (*Registered) Response

func (reg *Registered) Response() ID

func (*Registered) Type

func (msg *Registered) Type() MessageType

type RegistrationDetails

type RegistrationDetails struct {
	ID               ID
	Created          time.Time
	Procedure        URI
	MatchPolicy      string
	InvocationPolicy string
}

type Response

type Response interface {
	Message
	Response() ID
}

type Result

type Result struct {
	T       MessageType
	Request ID
	Details map[string]interface{}
	Args    []interface{}
	ArgsKW  map[string]interface{}
}

func (*Result) Response

func (res *Result) Response() ID

func (*Result) Type

func (msg *Result) Type() MessageType

type Router

type Router struct {

	// TODO Router.Handler provides a potential data race
	Handler Handler
	// contains filtered or unexported fields
}

A Router performs message routing between components and may handle either or both the roles of Dealer or Broker.

func NewRouter

func NewRouter() *Router

NewRouter creates a new router ready to accept new connections.

func (*Router) AcceptConn

func (r *Router) AcceptConn(conn Conn)

AcceptConn starts the routing process for the connection.

func (*Router) Client

func (r *Router) Client() *Client

Client creates an in-memory Client.

func (*Router) Close

func (r *Router) Close() error

Close sends Goodbye messages to all clients, closes the connections and stops routing.

type Session

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

func SessionFromContext

func SessionFromContext(ctx context.Context) (*Session, bool)

SessionFromContext extracts the session value from the context.

func (*Session) ID

func (s *Session) ID() ID

func (*Session) Realm

func (s *Session) Realm() *Realm

func (*Session) RouterID

func (s *Session) RouterID() ID

func (*Session) SessionID

func (s *Session) SessionID() ID

type Subscribe

type Subscribe struct {
	T       MessageType
	Request ID
	Options map[string]interface{}
	Topic   URI
}

func (*Subscribe) Type

func (msg *Subscribe) Type() MessageType

type Subscribed

type Subscribed struct {
	T            MessageType
	Request      ID
	Subscription ID
}

func (*Subscribed) Response

func (sub *Subscribed) Response() ID

func (*Subscribed) Type

func (msg *Subscribed) Type() MessageType

type Subscription

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

type URI

type URI string

func (*URI) Error

func (u *URI) Error() string

func (URI) Valid

func (u URI) Valid() bool

Valid checks the URI for invalid patterns. Pattern: ^([0-9a-z_]+\.)*([0-9a-z_]+)$

type Unregister

type Unregister struct {
	T            MessageType
	Request      ID
	Registration ID
}

func (*Unregister) Type

func (msg *Unregister) Type() MessageType

type Unregistered

type Unregistered struct {
	T       MessageType
	Request ID
}

func (*Unregistered) Response

func (unreg *Unregistered) Response() ID

func (*Unregistered) Type

func (msg *Unregistered) Type() MessageType

type Unsubscribe

type Unsubscribe struct {
	T            MessageType
	Request      ID
	Subscription ID
}

func (*Unsubscribe) Type

func (msg *Unsubscribe) Type() MessageType

type Unsubscribed

type Unsubscribed struct {
	T       MessageType
	Request ID
}

func (*Unsubscribed) Response

func (unsub *Unsubscribed) Response() ID

func (*Unsubscribed) Type

func (msg *Unsubscribed) Type() MessageType

type WebsocketConn

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

func (*WebsocketConn) Close

func (c *WebsocketConn) Close() error

func (*WebsocketConn) Read

func (c *WebsocketConn) Read(ctx context.Context) (Message, error)

func (*WebsocketConn) Send

func (c *WebsocketConn) Send(ctx context.Context, msg Message) error

type Welcome

type Welcome struct {
	T       MessageType
	Session ID
	Details map[string]interface{}
}

func (*Welcome) Type

func (msg *Welcome) Type() MessageType

type Yield

type Yield struct {
	T       MessageType
	Request ID
	Options map[string]interface{}
	Args    []interface{}
	ArgsKW  map[string]interface{}
}

func (*Yield) Response

func (y *Yield) Response() ID

func (*Yield) Type

func (msg *Yield) Type() MessageType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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