router

package
v2.0.3+incompatible Latest Latest
Warning

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

Go to latest
Published: May 15, 2018 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package router provides a WAMP router implementation that supports most of the WAMP advanced profile, offers multiple transports and TLS, and extends publication filtering functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authorizer

type Authorizer interface {
	// Authorize returns true if the sending session is authorized to send the
	// message.  Otherwise, it returns or false if not authorized.  An error is
	// returned if there is a failure to determine authorization.  This error
	// is included in the ERROR response to the client.
	//
	// Since the Authorizer accesses both the sending session and the message
	// through a pointer, the authorizer can alter the content of both the
	// sending session and the message.  This allows the authorizer to also
	// work as an interceptor of messages that can change their content and/or
	// change the sending session based on the intercepted message.  This
	// functionality may be used to set values in the session upon encountering
	// certain messages sent by that session.
	Authorize(*wamp.Session, wamp.Message) (bool, error)
}

Authorizer is the interface implemented by a type that provides the ability to authorize sending messages.

type Broker

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

func NewBroker

func NewBroker(logger stdlog.StdLog, strictURI, allowDisclose, debug bool) *Broker

NewBroker returns a new default broker implementation instance.

func (*Broker) Close

func (b *Broker) Close()

Close stops the broker, letting already queued actions finish.

func (*Broker) Publish

func (b *Broker) Publish(pub *wamp.Session, msg *wamp.Publish)

Publish finds all subscriptions for the topic being published to, including those matching the topic by pattern, and sends an event to the subscribers of that topic.

When a single event matches more than one of a Subscriber's subscriptions, the event will be delivered for each subscription.

The Subscriber can detect the delivery of that same event on multiple subscriptions via EVENT.PUBLISHED.Publication, which will be identical.

func (*Broker) RemoveSession

func (b *Broker) RemoveSession(sess *wamp.Session)

RemoveSession removes all subscriptions of the subscriber. This is called when a client leaves the realm by sending a GOODBYE message or by disconnecting from the router. If there are any subscriptions for this session a wamp.subscription.on_delete meta event is published for each.

func (*Broker) Role

func (b *Broker) Role() wamp.Dict

Role returns the role information for the "broker" role. The data returned is suitable for use as broker role info in a WELCOME message.

func (*Broker) Subscribe

func (b *Broker) Subscribe(sub *wamp.Session, msg *wamp.Subscribe)

Subscribe subscribes the client to the given topic.

In case of receiving a SUBSCRIBE message from the same Subscriber and to already subscribed topic, Broker should answer with SUBSCRIBED message, containing the existing Subscription|id.

By default, Subscribers subscribe to topics with exact matching policy. A Subscriber might want to subscribe to topics based on a pattern. If the Broker and the Subscriber support pattern-based subscriptions, this matching can happen by prefix-matching policy or wildcard-matching policy.

func (*Broker) Unsubscribe

func (b *Broker) Unsubscribe(sub *wamp.Session, msg *wamp.Unsubscribe)

Unsubscribe removes the requested subscription.

type Dealer

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

func NewDealer

func NewDealer(logger stdlog.StdLog, strictURI, allowDisclose, debug bool) *Dealer

NewDealer creates the default Dealer implementation.

Messages are routed serially by the dealer's message handling goroutine. This serialization is limited to the work of determining the message's destination, and then the message is handed off to the next goroutine, typically the receiving client's send handler.

func (*Dealer) Call

func (d *Dealer) Call(caller *wamp.Session, msg *wamp.Call)

Call invokes a registered remote procedure.

func (*Dealer) Cancel

func (d *Dealer) Cancel(caller *wamp.Session, msg *wamp.Cancel)

Cancel actively cancels a call that is in progress.

Cancellation behaves differently depending on the mode:

"skip": The pending call is canceled and ERROR is send immediately back to the caller. No INTERRUPT is sent to the callee and the result is discarded when received.

"kill": INTERRUPT is sent to the client, but ERROR is not returned to the caller until after the callee has responded to the canceled call. In this case the caller may receive RESULT or ERROR depending whether the callee finishes processing the invocation or the interrupt first.

"killnowait": The pending call is canceled and ERROR is send immediately back to the caller. INTERRUPT is sent to the callee and any response to the invocation or interrupt from the callee is discarded when received.

If the callee does not support call canceling, then behavior is "skip".

func (*Dealer) Close

func (d *Dealer) Close()

Close stops the dealer, letting already queued actions finish.

func (*Dealer) Error

func (d *Dealer) Error(msg *wamp.Error)

Error handles an invocation error returned by the callee.

func (*Dealer) RegCountCallees

func (d *Dealer) RegCountCallees(msg *wamp.Invocation) wamp.Message

regCountCallees obtains the number of sessions currently attached to the registration.

func (*Dealer) RegGet

func (d *Dealer) RegGet(msg *wamp.Invocation) wamp.Message

RegGet retrieves information on a particular registration.

func (*Dealer) RegList

func (d *Dealer) RegList(msg *wamp.Invocation) wamp.Message

RegList retrieves registration IDs listed according to match policies.

func (*Dealer) RegListCallees

func (d *Dealer) RegListCallees(msg *wamp.Invocation) wamp.Message

RegListCallees retrieves a list of session IDs for sessions currently attached to the registration.

func (*Dealer) RegLookup

func (d *Dealer) RegLookup(msg *wamp.Invocation) wamp.Message

RegLookup retrieves registration IDs listed according to match policies.

func (*Dealer) RegMatch

func (d *Dealer) RegMatch(msg *wamp.Invocation) wamp.Message

RegMatch obtains the registration best matching a given procedure URI.

func (*Dealer) Register

func (d *Dealer) Register(callee *wamp.Session, msg *wamp.Register)

Register registers a callee to handle calls to a procedure.

If the shared_registration feature is supported, and if allowed by the invocation policy, multiple callees may register to handle the same procedure.

func (*Dealer) RemoveSession

func (d *Dealer) RemoveSession(sess *wamp.Session)

Remove a callee's registrations. This is called when a client leaves the realm by sending a GOODBYE message or by disconnecting from the router. If there are any registrations for this session wamp.registration.on_unregister and wamp.registration.on_delete meta events are published for each.

func (*Dealer) Role

func (d *Dealer) Role() wamp.Dict

Role returns the role information for the "dealer" role. The data returned is suitable for use as broker role info in a WELCOME message.

func (*Dealer) SetMetaPeer

func (d *Dealer) SetMetaPeer(metaPeer wamp.Peer)

SetMetaPeer sets the client that the dealer uses to publish meta events.

func (*Dealer) Unregister

func (d *Dealer) Unregister(callee *wamp.Session, msg *wamp.Unregister)

Unregister removes a remote procedure previously registered by the callee.

func (*Dealer) Yield

func (d *Dealer) Yield(callee *wamp.Session, msg *wamp.Yield)

Yield handles the result of successfully processing and finishing the execution of a call, send from callee to dealer.

type RawSocketServer

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

RawSocketServer handles socket connections.

func NewRawSocketServer

func NewRawSocketServer(r Router, recvLimit int, keepAlive time.Duration) *RawSocketServer

NewRawSocketServer takes a router instance and creates a new socket server.

func (*RawSocketServer) ListenAndServe

func (s *RawSocketServer) ListenAndServe(network, address string) (io.Closer, error)

ListenAndServe listens on the specified endpoint and starts a goroutine that accepts new client connections until the returned io.closer is closed.

func (*RawSocketServer) ListenAndServeTLS

func (s *RawSocketServer) ListenAndServeTLS(network, address string, tlscfg *tls.Config, certFile, keyFile string) (io.Closer, error)

ListenAndServeTLS listens on the specified endpoint and starts a goroutine that accepts new TLS client connections until the returned io.closer is closed. If tls.Config does not already contain a certificate, then certFile and keyFile, if specified, are used to load an X509 certificate.

type RealmConfig

type RealmConfig struct {
	// URI that identifies the realm.
	URI wamp.URI
	// Enforce strict URI format validation.
	StrictURI bool `json:"strict_uri"`
	// Allow anonymous authentication.  Does not require any Authenticators.
	AnonymousAuth bool `json:"anonymous_auth"`
	// Allow publisher and caller identity disclosure when requested.
	AllowDisclose bool `json:"allow_disclose"`
	// Slice of Authenticator interfaces.
	Authenticators []auth.Authenticator
	// Authorizer called for each message.
	Authorizer Authorizer
	// Require authentication for local clients.  Normally local clients are
	// always trusted.  Setting this treats local clients same as others.
	RequireLocalAuth bool `json:"require_local_auth"`
}

RealmConfig configures a single realm in the router. The router configuration may specify a list of realms to configure.

type Router

type Router interface {
	// Attach connects a client to the router and to the requested realm.
	Attach(wamp.Peer) error

	// AttachClient connects a client to the router and to the requested realm.
	// It provides additional transport information details.
	AttachClient(wamp.Peer, wamp.Dict) error

	// Close stops the router and waits message processing to stop.
	Close()

	// Logger returns the logger the router is using.
	Logger() stdlog.StdLog

	// AddRealm will append a realm to this router
	AddRealm(*RealmConfig) error

	// RemoveRealm will attempt to remove a realm from this router
	RemoveRealm(wamp.URI)
}

A Router handles new Peers and routes requests to the requested Realm.

func NewRouter

func NewRouter(config *RouterConfig, logger stdlog.StdLog) (Router, error)

NewRouter creates a WAMP router instance.

type RouterConfig

type RouterConfig struct {
	// RealmConfigs defines the configurations for realms within the router.
	RealmConfigs []*RealmConfig `json:"realms"`

	// RealmTemplate, if defined, is used by the router to create new realms
	// when a client requests to join a realm that does not yet exist.  If
	// RealmTemplate is nil (the default), then clients must join existing
	// realms.
	//
	// Caution, enabling a realm template that allows anonymous authentication
	// allows unauthenticated clients to create new realms.
	RealmTemplate *RealmConfig `json:"realm_template"`

	// Enable debug logging for router, realm, broker, dealer
	Debug bool
}

RouterConfig configures the router with realms, and optionally a template for creating new realms.

type WebsocketServer

type WebsocketServer struct {
	// Upgrader specifies parameters for upgrading an HTTP connection to a
	// WebSocket connection.  See:
	// https://godoc.org/github.com/gorilla/websocket#Upgrader
	Upgrader *websocket.Upgrader

	// Serializer for text frames.  Defaults to JSONSerializer.
	TextSerializer serialize.Serializer
	// Serializer for binary frames.  Defaults to MessagePackSerializer.
	BinarySerializer serialize.Serializer

	// EnableTrackingCookie tells the server to send a random-value cookie to
	// the websocket client.  A returning client may identify itself by sending
	// a previously issued tracking cookie in a websocket request.  If a
	// request header received by the server contains the tracking cookie, then
	// the cookie is included in the HELLO and session details.  The new
	// tracking cookie that gets sent to the client (the cookie to expect for
	// subsequent connections) is also stored in HELLO and session details.
	//
	// The cookie from the request, and the next cookie to expect, are
	// stored in the HELLO and session details, respectively, as:
	//
	//     Details.transport.auth.cookie|*http.Cookie
	//     Details.transport.auth.nextcookie|*http.Cookie
	//
	// This information is available to auth/authz logic, and can be retrieved
	// from details as follows:
	//
	//     req *http.Request
	//     path := []string{"transport", "auth", "request"}
	//     v, err := wamp.DictValue(details, path)
	//     if err == nil {
	//         req = v.(*http.Request)
	//     }
	//
	// The "cookie" and "nextcookie" values are retrieved similarly.
	EnableTrackingCookie bool
	// EnableRequestCapture tells the server to include the upgrade HTTP
	// request in the HELLO and session details.  It is stored in
	// Details.transport.auth.request|*http.Request and is available to
	// auth/authz logic.
	EnableRequestCapture bool

	// KeepAlive is the time passed to TCPConn.SetKeepAlivePeriod().  If not
	// specified, default system keep-alive settings are used.
	KeepAlive time.Duration
	// contains filtered or unexported fields
}

WebsocketServer handles websocket connections.

func NewWebsocketServer

func NewWebsocketServer(r Router) *WebsocketServer

NewWebsocketServer takes a router instance and creates a new websocket server.

Optional websocket server configuration can be set, after creating the server instance, by setting WebsocketServer.Upgrader and WebsocketServer members directly.

To run the websocket server, call one of the server's ListenAndServe methods:

s := NewWebsocketServer(r)
closer, err := s.ListenAndServe(address)

Or, use the various ListenAndServe functions provided by net/http. This works because WebsocketServer implements the http.Handler interface:

s := NewWebsocketServer(r)
server := &http.Server{
    Handler: s,
    Addr:    address,
}
server.ListenAndServe()

func (*WebsocketServer) ListenAndServe

func (s *WebsocketServer) ListenAndServe(address string) (io.Closer, error)

ListenAndServe listens on the specified TCP address and starts a goroutine that accepts new client connections until the returned io.closer is closed.

func (*WebsocketServer) ListenAndServeTLS

func (s *WebsocketServer) ListenAndServeTLS(address string, tlscfg *tls.Config, certFile, keyFile string) (io.Closer, error)

ListenAndServeTLS listens on the specified TCP address and starts a goroutine that accepts new TLS client connections until the returned io.closer is closed. If tls.Config does not already contain a certificate, then certFile and keyFile, if specified, are used to load an X509 certificate.

func (*WebsocketServer) ServeHTTP

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

ServeHTTP handles HTTP connections.

func (*WebsocketServer) SetConfig

func (s *WebsocketServer) SetConfig(wsCfg transport.WebsocketConfig)

DEPRICATED - Set WebsocketServer.Upgrader and WebsockServer.Xxx members directly.

Directories

Path Synopsis
Package auth provides interfaces for implementing authentication logic that the WAMP router can use.
Package auth provides interfaces for implementing authentication logic that the WAMP router can use.

Jump to

Keyboard shortcuts

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