Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidLogin error = fmt.Errorf("invalid LOGIN") )
Functions ¶
Types ¶
type Authenticator ¶
type Authenticator interface { // Auth determines whether cred is a valid credential for user in the given // authentication scheme. // The underlying network connection is provided to allow TLS state to be // extracted or challenge/response approaches. Auth(c net.Conn, user []byte, scheme []byte, cred []byte) bool // supported authentication schemes Unauthorized() []byte }
The Authenticator interface is used to accpet or reject LOGIN attempts.
type AuthenticatorFunc ¶
func SecretAuth ¶
func SecretAuth(sharedSecret []byte) AuthenticatorFunc
type Connection ¶
type Connection struct { User string // contains filtered or unexported fields }
Connection represents an open client connection to an SSMP server after a successful LOGIN.
func NewConnection ¶
func NewConnection(c net.Conn, a Authenticator, d *Dispatcher) (*Connection, error)
NewConnection creates a SSMP connection out of a streaming netwrok connection.
This method blocks until either a first message is received or a 10s timeout elapses.
Each accepted connection spawns a goroutine continuously reading from the underlying network connection and triggering the Dispatcher. The caller must keep track of the returned Connection and call the Close method to stop the read goroutine and close the udnerlying netwrok connection.
errInvalidLogin is returned if the first message is not a well-formed LOGIN request. errUnauthorized is returned if the authenticator doesn't accept the provided credentials.
func (*Connection) Broadcast ¶
func (c *Connection) Broadcast(payload []byte)
Broadcast sends an identical payload to all users sharing at least one topic. This method is not safe to call from multiple goroutines simultaneously. It should only be called from the connection's read goroutine.
func (*Connection) Cleanup ¶
func (c *Connection) Cleanup()
Cleanup logic, called from the read goroutine to avoid races
func (*Connection) Close ¶
func (c *Connection) Close()
Close unsubscribes from all topics and closes the underlying network connection. This method us safe to call from multiple goroutines simultaneously.
func (*Connection) Subscribe ¶
func (c *Connection) Subscribe(t *Topic)
Subscribe adds a Topic to the list of subscriptions for the connection. This method is not safe to call from multiple goroutines simultaneously. It should only be called from the connection's read goroutine.
func (*Connection) Unsubscribe ¶
func (c *Connection) Unsubscribe(n []byte)
Unsubscribe removes a topic from the list of subscriptions for the connection. This method is not safe to call from multiple goroutines simultaneously. It should only be called from the connection's read goroutine.
func (*Connection) Write ¶
func (c *Connection) Write(payload []byte) error
Write writes an arbitrary payload to the underlying network connection. The payload MUST be a valid encoding of a SSMP response or event. This method us safe to call from multiple goroutines simultaneously.
type ConnectionManager ¶
type ConnectionManager struct {
// contains filtered or unexported fields
}
A ConnectionManager manages a set of Connection. All methods are safe to call from multiple goroutines simultaneously.
func (*ConnectionManager) GetConnection ¶
func (s *ConnectionManager) GetConnection(user []byte) *Connection
func (*ConnectionManager) RemoveConnection ¶
func (s *ConnectionManager) RemoveConnection(c *Connection)
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
A Dispatcher parses incoming requests and reacts to them appropriately. All methods are safe to call from multiple goroutines simultaneously.
func NewDispatcher ¶
func NewDispatcher(topics *TopicManager, connections *ConnectionManager) *Dispatcher
NewDispatcher creates a SSMP dispatcher using the given TopicManager and ConnectionManager.
func (*Dispatcher) Dispatch ¶
func (d *Dispatcher) Dispatch(c *Connection, verb []byte) bool
Dispatch parses req, reacts appropriately and sends a response to c.
func (*Dispatcher) GetConnection ¶
func (d *Dispatcher) GetConnection(user []byte) *Connection
func (*Dispatcher) RemoveConnection ¶
func (d *Dispatcher) RemoveConnection(c *Connection)
type MultiSchemeAuthenticator ¶
type MultiSchemeAuthenticator struct { Schemes map[string]AuthenticatorFunc // contains filtered or unexported fields }
MultiSchemeAuthenticator maps authentication schems to corresponding AuthenticatorFunc
func (*MultiSchemeAuthenticator) Auth ¶
func (a *MultiSchemeAuthenticator) Auth(c net.Conn, user, scheme, cred []byte) bool
func (*MultiSchemeAuthenticator) Unauthorized ¶
func (a *MultiSchemeAuthenticator) Unauthorized() []byte
type Server ¶
type Server struct { ConnectionManager TopicManager // contains filtered or unexported fields }
server implements Server, ConnectionManager and TopicManager
func NewServer ¶
NewServer creates a new SSMP server from a TCP Listener, an Authenticator and a TLS configuration.
func (*Server) ListeningPort ¶
ListeningPort returns the TCP port to which the underlying Listener is bound.
func (*Server) Serve ¶
Serve accept connections in the calling goroutine and only returns in case of error.
type Topic ¶
type Topic struct { Name string // contains filtered or unexported fields }
Topic represents a SSMP multicast topic.
All methods can be safely called from multiple goroutines simultaneously.
func NewTopic ¶
func NewTopic(name string, tm *TopicManager) *Topic
NewTopic creates a new Topic with a given name. The topic keeps track of the TopicManager to self-harvest when the last subscriber set becomes empty.
func (*Topic) ForAll ¶
func (t *Topic) ForAll(v TopicVisitor)
ForAll executes v once for every subscribers.
func (*Topic) Subscribe ¶
func (t *Topic) Subscribe(c *Connection, presence bool) bool
Subscribe adds a connection to the set of subscribers. The presence flag indicates whether the connection is interested in receiving presence events about other subscribers. It returns true if a new subscription was made, or false if the connection was already subscribed to the topic.
func (*Topic) Unsubscribe ¶
func (t *Topic) Unsubscribe(c *Connection) bool
Unsubscribe removes a connection from the set of subscribers. It returns true if the connection was unsubscribed, or false it it wasn't subscribed to the topic.
type TopicManager ¶
type TopicManager struct {
// contains filtered or unexported fields
}
A TopicManager manages a set of Topic. All methods are safe to call from multiple goroutines simultaneously.
func (*TopicManager) GetOrCreateTopic ¶
func (s *TopicManager) GetOrCreateTopic(name []byte) *Topic
func (*TopicManager) GetTopic ¶
func (s *TopicManager) GetTopic(name []byte) *Topic
func (*TopicManager) RemoveTopic ¶
func (s *TopicManager) RemoveTopic(name string)
type TopicVisitor ¶
type TopicVisitor func(c *Connection, wantsPresence bool)