Documentation ¶
Overview ¶
package rabric implements the WAMPv2 protocol.
See the official WAMP documentation at http://wamp.ws for more details on the protocol.
Index ¶
- Constants
- func Debug()
- func NewDefaultAuthorizer() *defaultAuthorizer
- func NewDefaultInterceptor() *defaultInterceptor
- func SetLogger(l Logger)
- type Abort
- type AuthFunc
- type Authenticate
- type AuthenticationError
- type Authenticator
- type Authorizer
- type BasicMethodHandler
- type BinaryData
- type Broker
- type CRAuthenticator
- type Call
- type CallResult
- type Cancel
- type Challenge
- type Client
- func (c *Client) BasicRegister(procedure string, fn BasicMethodHandler) error
- func (c *Client) Call(procedure string, args []interface{}, kwargs map[string]interface{}) (*Result, error)
- func (c *Client) Close() error
- func (c *Client) JoinRealm(realm string, details map[string]interface{}) (map[string]interface{}, error)
- func (c *Client) LeaveRealm() error
- func (c *Client) Publish(topic string, args []interface{}, kwargs map[string]interface{}) error
- func (c *Client) Receive()
- func (c *Client) Register(procedure string, fn MethodHandler, options map[string]interface{}) error
- func (c *Client) Subscribe(topic string, fn EventHandler) error
- func (c *Client) Unregister(procedure string) error
- func (c *Client) Unsubscribe(topic string) error
- type Dealer
- type Error
- type Event
- type EventHandler
- type Goodbye
- type Heartbeat
- type Hello
- type ID
- type Interceptor
- type Interrupt
- type Invocation
- type JSONSerializer
- type Logger
- type Message
- type MessagePackSerializer
- type MessageType
- type MethodHandler
- type NoSuchRealmError
- type Peer
- type Publish
- type Published
- type Realm
- type RealmExistsError
- type Register
- type Registered
- type RemoteProcedure
- type Result
- type Router
- type Sender
- type Serialization
- type Serializer
- type Session
- type Subscribe
- type Subscribed
- type URI
- type Unregister
- type Unregistered
- type Unsubscribe
- type Unsubscribed
- type WebsocketServer
- type Welcome
- type Yield
Constants ¶
const ( // Peer provided an incorrect URI for any URI-based attribute of WAMP message, // such as realm, topic or procedure. ErrInvalidUri = URI("wamp.error.invalid_uri") // A Dealer could not perform a call, since no procedure is currently // registered under the given URI. ErrNoSuchProcedure = URI("wamp.error.no_such_procedure") // A procedure could not be registered, since a procedure with the given URI // is already registered. ErrProcedureAlreadyExists = URI("wamp.error.procedure_already_exists") // A Dealer could not perform an unregister, since the given registration is // not active. ErrNoSuchRegistration = URI("wamp.error.no_such_registration") // A Broker could not perform an unsubscribe, since the given subscription is // not active. ErrNoSuchSubscription = URI("wamp.error.no_such_subscription") // A call failed, since the given argument types or values are not acceptable // to the called procedure - in which case the Callee may throw this error. Or // a Router performing payload validation checked the payload (args / kwargs) // of a call, call result, call error or publish, and the payload did not // conform - in which case the Router may throw this error. ErrInvalidArgument = URI("wamp.error.invalid_argument") // The Peer is shutting down completely - used as a GOODBYE (or ABORT) reason. ErrSystemShutdown = URI("wamp.error.system_shutdown") // The Peer wants to leave the realm - used as a GOODBYE reason. ErrCloseRealm = URI("wamp.error.close_realm") // A Peer acknowledges ending of a session - used as a GOOBYE reply reason. ErrGoodbyeAndOut = URI("wamp.error.goodbye_and_out") // A join, call, register, publish or subscribe failed, since the Peer is not // authorized to perform the operation. ErrNotAuthorized = URI("wamp.error.not_authorized") // A Dealer or Broker could not determine if the Peer is authorized to perform // a join, call, register, publish or subscribe, since the authorization // operation itself failed. E.g. a custom authorizer ran into an error. ErrAuthorizationFailed = URI("wamp.error.authorization_failed") // Peer wanted to join a non-existing realm (and the Router did not allow to // auto-create the realm) ErrNoSuchRealm = URI("wamp.error.no_such_realm") // A Peer was to be authenticated under a Role that does not (or no longer) // exists on the Router. For example, the Peer was successfully authenticated, // but the Role configured does not exists - hence there is some // misconfiguration in the Router. ErrNoSuchRole = URI("wamp.error.no_such_role") )
Variables ¶
This section is empty.
Functions ¶
func NewDefaultAuthorizer ¶
func NewDefaultAuthorizer() *defaultAuthorizer
func NewDefaultInterceptor ¶
func NewDefaultInterceptor() *defaultInterceptor
Types ¶
type Abort ¶
[ABORT, Details|dict, Reason|uri]
func (*Abort) MessageType ¶
func (msg *Abort) MessageType() MessageType
type AuthFunc ¶
type AuthFunc func(map[string]interface{}, map[string]interface{}) (string, map[string]interface{}, error)
AuthFunc takes the HELLO details and CHALLENGE details and returns the signature string and a details map
type Authenticate ¶
[AUTHENTICATE, Signature|string, Extra|dict]
func (*Authenticate) MessageType ¶
func (msg *Authenticate) MessageType() MessageType
type AuthenticationError ¶
type AuthenticationError string
func (AuthenticationError) Error ¶
func (e AuthenticationError) Error() string
type Authenticator ¶
type Authenticator interface { // Authenticate takes the HELLO details and returns a (WELCOME) details map if the // authentication is successful, otherwise it returns an error Authenticate(details map[string]interface{}) (map[string]interface{}, error) }
Authenticator describes a type that can handle authentication based solely on the HELLO message.
Use CRAuthenticator for more complex authentication schemes.
type Authorizer ¶
type BasicMethodHandler ¶
type BasicMethodHandler func(args []interface{}, kwargs map[string]interface{}) (result *CallResult)
BasicMethodHandler is an RPC endpoint that doesn't expect the `Details` map
type BinaryData ¶
type BinaryData []byte
Marshals and unmarshals byte arrays according to WAMP specifications: https://github.com/tavendo/WAMP/blob/master/spec/basic.md#binary-conversion-of-json-strings
This type *should* be used in types that will be marshalled as JSON.
func (BinaryData) MarshalJSON ¶
func (b BinaryData) MarshalJSON() ([]byte, error)
func (*BinaryData) UnmarshalJSON ¶
func (b *BinaryData) UnmarshalJSON(arr []byte) error
type Broker ¶
type Broker interface { // Publishes a message to all Subscribers. Publish(Sender, *Publish) // Subscribes to messages on a URI. Subscribe(Sender, *Subscribe) // Unsubscribes from messages on a URI. Unsubscribe(Sender, *Unsubscribe) }
A broker handles routing EVENTS from Publishers to Subscribers.
func NewDefaultBroker ¶
func NewDefaultBroker() Broker
NewDefaultBroker initializes and returns a simple broker that matches URIs to Subscribers.
type CRAuthenticator ¶
type CRAuthenticator interface { // accept HELLO details and returns a challenge map (which will be sent in a CHALLENGE message) Challenge(details map[string]interface{}) (map[string]interface{}, error) // accept a challenge map (same as was generated in Challenge) and a signature string, and // authenticates the signature string against the challenge. Returns a details map and error. Authenticate(challenge map[string]interface{}, signature string) (map[string]interface{}, error) }
CRAuthenticator describes a type that can handle challenge/response authentication.
func NewBasicTicketAuthenticator ¶
func NewBasicTicketAuthenticator(tickets ...string) CRAuthenticator
NewBasicTicketAuthenticator creates a basic ticket authenticator from a static set of valid tickets.
This method of ticket-based authentication is insecure, but useful for bootstrapping. Do not use this in production.
type Call ¶
type Call struct { Request ID Options map[string]interface{} Procedure URI Arguments []interface{} `wamp:"omitempty"` ArgumentsKw map[string]interface{} `wamp:"omitempty"` }
[CALL, Request|id, Options|dict, Procedure|uri] [CALL, Request|id, Options|dict, Procedure|uri, Arguments|list] [CALL, Request|id, Options|dict, Procedure|uri, Arguments|list, ArgumentsKw|dict]
func (*Call) MessageType ¶
func (msg *Call) MessageType() MessageType
type CallResult ¶
CallResult represents the result of a CALL.
type Cancel ¶
[CANCEL, CALL.Request|id, Options|dict]
func (*Cancel) MessageType ¶
func (msg *Cancel) MessageType() MessageType
type Challenge ¶
[CHALLENGE, AuthMethod|string, Extra|dict]
func (*Challenge) MessageType ¶
func (msg *Challenge) MessageType() MessageType
type Client ¶
type Client struct { Peer // ReceiveTimeout is the amount of time that the client will block waiting for a response from the router. ReceiveTimeout time.Duration // Auth is a map of WAMP authmethods to functions that will handle each auth type Auth map[string]AuthFunc // ReceiveDone is notified when the client's connection to the router is lost. ReceiveDone chan bool // contains filtered or unexported fields }
A Client routes messages to/from a WAMP router.
func NewWebsocketClient ¶
func NewWebsocketClient(serialization Serialization, url string) (*Client, error)
Creates a new websocket client.
func (*Client) BasicRegister ¶
func (c *Client) BasicRegister(procedure string, fn BasicMethodHandler) error
BasicRegister registers a BasicMethodHandler procedure with the router
func (*Client) Call ¶
func (c *Client) Call(procedure string, args []interface{}, kwargs map[string]interface{}) (*Result, error)
Call calls a procedure given a URI.
func (*Client) JoinRealm ¶
func (c *Client) JoinRealm(realm string, details map[string]interface{}) (map[string]interface{}, error)
JoinRealm joins a WAMP realm, but does not handle challenge/response authentication.
func (*Client) LeaveRealm ¶
LeaveRealm leaves the current realm without closing the connection to the server.
func (*Client) Receive ¶
func (c *Client) Receive()
Receive handles messages from the server until this client disconnects.
This function blocks and is most commonly run in a goroutine.
func (*Client) Register ¶
func (c *Client) Register(procedure string, fn MethodHandler, options map[string]interface{}) error
Register registers a MethodHandler procedure with the router.
func (*Client) Subscribe ¶
func (c *Client) Subscribe(topic string, fn EventHandler) error
Subscribe registers the EventHandler to be called for every message in the provided topic.
func (*Client) Unregister ¶
Unregister removes a procedure with the router
func (*Client) Unsubscribe ¶
Unsubscribe removes the registered EventHandler from the topic.
type Dealer ¶
type Dealer interface { // Register a procedure on an endpoint Register(Sender, *Register) // Unregister a procedure on an endpoint Unregister(Sender, *Unregister) // Call a procedure on an endpoint Call(Sender, *Call) // Return the result of a procedure call Yield(Sender, *Yield) // Handle an ERROR message from an invocation Error(Sender, *Error) }
A Dealer routes and manages RPC calls to callees.
func NewDefaultDealer ¶
func NewDefaultDealer() Dealer
type Error ¶
type Error struct { Type MessageType Request ID Details map[string]interface{} Error URI Arguments []interface{} `wamp:"omitempty"` ArgumentsKw map[string]interface{} `wamp:"omitempty"` }
[ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri] [ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri, Arguments|list] [ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri, Arguments|list, ArgumentsKw|dict]
func (*Error) MessageType ¶
func (msg *Error) MessageType() MessageType
type Event ¶
type Event struct { Subscription ID Publication ID Details map[string]interface{} Arguments []interface{} `wamp:"omitempty"` ArgumentsKw map[string]interface{} `wamp:"omitempty"` }
[EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict] [EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict, PUBLISH.Arguments|list] [EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict, PUBLISH.Arguments|list,
PUBLISH.ArgumentsKw|dict]
func (*Event) MessageType ¶
func (msg *Event) MessageType() MessageType
type EventHandler ¶
type EventHandler func(args []interface{}, kwargs map[string]interface{})
EventHandler handles a publish event.
type Goodbye ¶
[GOODBYE, Details|dict, Reason|uri]
func (*Goodbye) MessageType ¶
func (msg *Goodbye) MessageType() MessageType
type Heartbeat ¶
[HEARTBEAT, IncomingSeq|integer, OutgoingSeq|integer [HEARTBEAT, IncomingSeq|integer, OutgoingSeq|integer, Discard|string]
func (*Heartbeat) MessageType ¶
func (msg *Heartbeat) MessageType() MessageType
type Hello ¶
[HELLO, Realm|uri, Details|dict]
func (*Hello) MessageType ¶
func (msg *Hello) MessageType() MessageType
type ID ¶
type ID uint
An ID is a unique, non-negative number. Different uses may have additional restrictions.
type Interceptor ¶
type Interrupt ¶
[INTERRUPT, INVOCATION.Request|id, Options|dict]
func (*Interrupt) MessageType ¶
func (msg *Interrupt) MessageType() MessageType
type Invocation ¶
type Invocation struct { Request ID Registration ID Details map[string]interface{} Arguments []interface{} `wamp:"omitempty"` ArgumentsKw map[string]interface{} `wamp:"omitempty"` }
[INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict] [INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict, CALL.Arguments|list] [INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict, CALL.Arguments|list, CALL.ArgumentsKw|dict]
func (*Invocation) MessageType ¶
func (msg *Invocation) MessageType() MessageType
type JSONSerializer ¶
type JSONSerializer struct { }
JSONSerializer is an implementation of Serializer that handles serializing and deserializing JSON encoded payloads.
func (*JSONSerializer) Deserialize ¶
func (s *JSONSerializer) Deserialize(data []byte) (Message, error)
Deserialize unmarshals the payload into a message.
This method does not handle binary data according to WAMP specifications automatically, but instead uses the default implementation in encoding/json. Use the BinaryData type in your structures if using binary data.
func (*JSONSerializer) Serialize ¶
func (s *JSONSerializer) Serialize(msg Message) ([]byte, error)
Serialize marshals the payload into a message.
This method does not handle binary data according to WAMP specifications automatically, but instead uses the default implementation in encoding/json. Use the BinaryData type in your structures if using binary data.
type Logger ¶
type Logger interface { Println(v ...interface{}) Printf(format string, v ...interface{}) }
Logger is an interface compatible with log.Logger.
type Message ¶
type Message interface {
MessageType() MessageType
}
Message is a generic container for a WAMP message.
type MessagePackSerializer ¶
type MessagePackSerializer struct { }
MessagePack is an implementation of Serializer that handles serializing and deserializing msgpack encoded payloads.
func (*MessagePackSerializer) Deserialize ¶
func (s *MessagePackSerializer) Deserialize(data []byte) (Message, error)
Deserialize decodes a msgpack payload into a Message.
type MessageType ¶
type MessageType int
const ( HELLO MessageType = 1 WELCOME MessageType = 2 ABORT MessageType = 3 CHALLENGE MessageType = 4 AUTHENTICATE MessageType = 5 GOODBYE MessageType = 6 HEARTBEAT MessageType = 7 ERROR MessageType = 8 PUBLISH MessageType = 16 // Tx Rx PUBLISHED MessageType = 17 // Rx Tx SUBSCRIBE MessageType = 32 // Rx Tx SUBSCRIBED MessageType = 33 // Tx Rx UNSUBSCRIBE MessageType = 34 // Rx Tx UNSUBSCRIBED MessageType = 35 // Tx Rx EVENT MessageType = 36 // Tx Rx CALL MessageType = 48 // Tx Rx CANCEL MessageType = 49 // Tx Rx RESULT MessageType = 50 // Rx Tx REGISTER MessageType = 64 // Rx Tx REGISTERED MessageType = 65 // Tx Rx UNREGISTER MessageType = 66 // Rx Tx UNREGISTERED MessageType = 67 // Tx Rx INVOCATION MessageType = 68 // Tx Rx INTERRUPT MessageType = 69 // Tx Rx YIELD MessageType = 70 // Rx Tx )
func (MessageType) New ¶
func (mt MessageType) New() Message
func (MessageType) String ¶
func (mt MessageType) String() string
type MethodHandler ¶
type MethodHandler func( args []interface{}, kwargs map[string]interface{}, details map[string]interface{}, ) (result *CallResult)
MethodHandler is an RPC endpoint.
type NoSuchRealmError ¶
type NoSuchRealmError string
func (NoSuchRealmError) Error ¶
func (e NoSuchRealmError) Error() string
type Peer ¶
type Peer interface { Sender // Closes the peer connection and any channel returned from Receive(). // Multiple calls to Close() will have no effect. Close() error // Receive returns a channel of messages coming from the peer. Receive() <-chan Message }
Peer is the interface that must be implemented by all WAMP peers.
func NewWebsocketPeer ¶
func NewWebsocketPeer(serialization Serialization, url, origin string) (Peer, error)
NewWebsocketPeer connects to the websocket server at the specified url.
type Publish ¶
type Publish struct { Request ID Options map[string]interface{} Topic URI Arguments []interface{} `wamp:"omitempty"` ArgumentsKw map[string]interface{} `wamp:"omitempty"` }
[PUBLISH, Request|id, Options|dict, Topic|uri] [PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list] [PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list, ArgumentsKw|dict]
func (*Publish) MessageType ¶
func (msg *Publish) MessageType() MessageType
type Published ¶
[PUBLISHED, PUBLISH.Request|id, Publication|id]
func (*Published) MessageType ¶
func (msg *Published) MessageType() MessageType
type Realm ¶
type Realm struct { URI URI Broker Dealer Authorizer Interceptor CRAuthenticators map[string]CRAuthenticator Authenticators map[string]Authenticator // DefaultAuth func(details map[string]interface{}) (map[string]interface{}, error) AuthTimeout time.Duration // contains filtered or unexported fields }
A Realm is a WAMP routing and administrative domain.
Clients that have connected to a WAMP router are joined to a realm and all message delivery is handled by the realm.
type RealmExistsError ¶
type RealmExistsError string
func (RealmExistsError) Error ¶
func (e RealmExistsError) Error() string
type Register ¶
[REGISTER, Request|id, Options|dict, Procedure|uri]
func (*Register) MessageType ¶
func (msg *Register) MessageType() MessageType
type Registered ¶
[REGISTERED, REGISTER.Request|id, Registration|id]
func (*Registered) MessageType ¶
func (msg *Registered) MessageType() MessageType
type RemoteProcedure ¶
type Result ¶
type Result struct { Request ID Details map[string]interface{} Arguments []interface{} `wamp:"omitempty"` ArgumentsKw map[string]interface{} `wamp:"omitempty"` }
[RESULT, CALL.Request|id, Details|dict] [RESULT, CALL.Request|id, Details|dict, YIELD.Arguments|list] [RESULT, CALL.Request|id, Details|dict, YIELD.Arguments|list, YIELD.ArgumentsKw|dict]
func (*Result) MessageType ¶
func (msg *Result) MessageType() MessageType
type Router ¶
type Router interface { Accept(Peer) error Close() error RegisterRealm(URI, Realm) error GetLocalPeer(URI, map[string]interface{}) (Peer, error) AddSessionOpenCallback(func(uint, string)) AddSessionCloseCallback(func(uint, string)) }
A Router handles new Peers and routes requests to the requested Realm.
func NewDefaultRouter ¶
func NewDefaultRouter() Router
NewDefaultRouter creates a very basic WAMP router.
type Sender ¶
A Sender can send a message to its peer.
For clients, this sends a message to the router, and for routers, this sends a message to the client.
type Serialization ¶
type Serialization int
const ( // Use JSON-encoded strings as a payload. JSON Serialization = iota // Use msgpack-encoded strings as a payload. MSGPACK )
type Serializer ¶
type Serializer interface { Serialize(Message) ([]byte, error) Deserialize([]byte) (Message, error) }
Serialiazer is a generic WAMP message serializer used when sending data over a transport.
type Subscribe ¶
[SUBSCRIBE, Request|id, Options|dict, Topic|uri]
func (*Subscribe) MessageType ¶
func (msg *Subscribe) MessageType() MessageType
type Subscribed ¶
[SUBSCRIBED, SUBSCRIBE.Request|id, Subscription|id]
func (*Subscribed) MessageType ¶
func (msg *Subscribed) MessageType() MessageType
type URI ¶
type URI string
URIs are dot-separated identifiers, where each component *should* only contain letters, numbers or underscores.
See the documentation for specifics: https://github.com/tavendo/WAMP/blob/master/spec/basic.md#uris
type Unregister ¶
[UNREGISTER, Request|id, REGISTERED.Registration|id]
func (*Unregister) MessageType ¶
func (msg *Unregister) MessageType() MessageType
type Unregistered ¶
type Unregistered struct {
Request ID
}
[UNREGISTERED, UNREGISTER.Request|id]
func (*Unregistered) MessageType ¶
func (msg *Unregistered) MessageType() MessageType
type Unsubscribe ¶
[UNSUBSCRIBE, Request|id, SUBSCRIBED.Subscription|id]
func (*Unsubscribe) MessageType ¶
func (msg *Unsubscribe) MessageType() MessageType
type Unsubscribed ¶
type Unsubscribed struct {
Request ID
}
[UNSUBSCRIBED, UNSUBSCRIBE.Request|id]
func (*Unsubscribed) MessageType ¶
func (msg *Unsubscribed) MessageType() MessageType
type WebsocketServer ¶
type WebsocketServer struct { Router Upgrader *websocket.Upgrader // The serializer to use for text frames. Defaults to JSONSerializer. TextSerializer Serializer // The serializer to use for binary frames. Defaults to JSONSerializer. BinarySerializer Serializer // contains filtered or unexported fields }
WebsocketServer handles websocket connections.
func NewBasicWebsocketServer ¶
func NewBasicWebsocketServer(uri string) *WebsocketServer
Creates a new WebsocketServer with a single basic realm
func NewWebsocketServer ¶
func NewWebsocketServer(realms map[string]Realm) (*WebsocketServer, error)
Creates a new WebsocketServer from a map of realms
func (*WebsocketServer) GetLocalClient ¶
func (s *WebsocketServer) GetLocalClient(realm string, details map[string]interface{}) (*Client, error)
GetLocalClient returns a client connected to the specified realm
func (*WebsocketServer) RegisterProtocol ¶
func (s *WebsocketServer) RegisterProtocol(proto string, payloadType int, serializer Serializer) error
RegisterProtocol registers a serializer that should be used for a given protocol string and payload type.
func (*WebsocketServer) ServeHTTP ¶
func (s *WebsocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles a new HTTP connection.
type Welcome ¶
[WELCOME, Session|id, Details|dict]
func (*Welcome) MessageType ¶
func (msg *Welcome) MessageType() MessageType
type Yield ¶
type Yield struct { Request ID Options map[string]interface{} Arguments []interface{} `wamp:"omitempty"` ArgumentsKw map[string]interface{} `wamp:"omitempty"` }
[YIELD, INVOCATION.Request|id, Options|dict] [YIELD, INVOCATION.Request|id, Options|dict, Arguments|list] [YIELD, INVOCATION.Request|id, Options|dict, Arguments|list, ArgumentsKw|dict]
func (*Yield) MessageType ¶
func (msg *Yield) MessageType() MessageType