Documentation
¶
Index ¶
- func CleanNowPure() error
- func Initialize() error
- func LogDebug(c *Client, args ...interface{})
- func LogDebugf(c *Client, fmt string, args ...interface{})
- func LogErr(c *Client, msg string, err error)
- func LogError(c *Client, fmt string, args ...interface{})
- func LogErrorf(c *Client, fmt string, args ...interface{})
- func LogInfo(c *Client, args ...interface{})
- func LogInfof(c *Client, fmt string, args ...interface{})
- func LogWarn(c *Client, fmt string, args ...interface{})
- func LogWarnf(c *Client, fmt string, args ...interface{})
- func Shutdown(ctx context.Context) error
- func Start()
- type Application
- func (a Application) AddMailbox(id string, forNameplate bool, side string) error
- func (a Application) AllocateNameplate(side string) (string, error)
- func (a Application) ClaimNameplate(name, side string) (string, error)
- func (a *Application) Cleanup(since int64) error
- func (a Application) FindNameplate() (string, error)
- func (a *Application) Free()
- func (a Application) FreeMailbox(id string)
- func (a Application) GetNameplateIDs() ([]string, error)
- func (a Application) OpenMailbox(id, side string) (*Mailbox, error)
- func (a Application) ReleaseNameplate(name, side string) error
- func (a Application) StillInUse() bool
- type Client
- func (c *Client) Close()
- func (c *Client) HandleAdd(m msg.Add) error
- func (c *Client) HandleAllocate(m msg.Allocate) error
- func (c *Client) HandleBind(m msg.Bind) error
- func (c *Client) HandleClaim(m msg.Claim) error
- func (c *Client) HandleClose(m msg.Close) error
- func (c *Client) HandleList(m msg.List) error
- func (c *Client) HandleOpen(m msg.Open) error
- func (c *Client) HandlePing(m msg.Ping)
- func (c *Client) HandleRelease(m msg.Release) error
- func (c Client) IsBound() bool
- func (c *Client) OnConnect()
- func (c *Client) OnMessage(src []byte)
- type Mailbox
- func (m *Mailbox) AddListener(listener MailboxListener, stopCallback MailboxListenerStop) int
- func (m *Mailbox) AddMessage(msg MailboxMessage) error
- func (m *Mailbox) Close(side string, mood string) error
- func (m *Mailbox) Delete() error
- func (m *Mailbox) GetMessages() ([]MailboxMessage, error)
- func (m *Mailbox) HasListeners() bool
- func (m *Mailbox) Open(side string) error
- func (m *Mailbox) RemoveAllListeners()
- func (m *Mailbox) RemoveListener(handle int)
- func (m *Mailbox) Touch() error
- type MailboxListener
- type MailboxListenerStop
- type MailboxMessage
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanNowPure ¶
func CleanNowPure() error
CleanNowPure runs the cleaning operation without actually spinning up the service resources
func LogDebug ¶
func LogDebug(c *Client, args ...interface{})
LogDebug is a convenience wrapper for logging usage statistics given the relay server settings
func LogDebugf ¶
LogDebugf is a convenience wrapper for logging usage statistics given the relay server settings
func LogInfo ¶
func LogInfo(c *Client, args ...interface{})
LogInfo is a convenience wrapper for logging usage statistics given the relay server settings
func LogInfof ¶
LogInfof is a convenience wrapper for logging usage statistics given the relay server settings
Types ¶
type Application ¶
Application holds the data for interacting with an individual applications usage with the relay server. All mailboxes are broken down into their parent apps so that a wider variety of client apps can exist on one server without conflicting with each others protocols
func NewApplication ¶
func NewApplication(id string) (Application, error)
NewApplication creates a new application container and returns it as a pointer, or error if something failed.
func (Application) AddMailbox ¶
func (a Application) AddMailbox(id string, forNameplate bool, side string) error
AddMailbox creates a new mailbox in the application
func (Application) AllocateNameplate ¶
func (a Application) AllocateNameplate(side string) (string, error)
AllocateNameplate generates a new nameplate ID and associates with a mailbox. The returned value is the nameplate ID
func (Application) ClaimNameplate ¶
func (a Application) ClaimNameplate(name, side string) (string, error)
ClaimNameplate claims a nameplate and it's respective mailbox. Returns the mailbox ID, or an error if one occured
func (*Application) Cleanup ¶
func (a *Application) Cleanup(since int64) error
Cleanup updates and removes mailboxes and nameplates as needed via timeouts.
func (Application) FindNameplate ¶
func (a Application) FindNameplate() (string, error)
FindNameplate attempts to find an available nameplate to return back for clients to use
func (*Application) Free ¶
func (a *Application) Free()
Free is called when the service is closing and the final death-throws should be performed
func (Application) FreeMailbox ¶
func (a Application) FreeMailbox(id string)
FreeMailbox removes a mailbox listing from the application memory. Does not remove it from the database
func (Application) GetNameplateIDs ¶
func (a Application) GetNameplateIDs() ([]string, error)
GetNameplateIDs returns all the nameplate IDs used by the current application. This should only be allowed if the config option AllowList is true.
func (Application) OpenMailbox ¶
func (a Application) OpenMailbox(id, side string) (*Mailbox, error)
OpenMailbox marks the mailbox as opened
func (Application) ReleaseNameplate ¶
func (a Application) ReleaseNameplate(name, side string) error
ReleaseNameplate removes the claim on a nameplates side. If no other claims are on the nameplate, then the whole thing is cleared out
func (Application) StillInUse ¶
func (a Application) StillInUse() bool
StillInUse returns true if the application (by ID) is still being used, or registered, in the database. If it is not, then it's safe to delete it during cleaning
type Client ¶
type Client struct { App *Application Side string Nameplate string Mailbox *Mailbox Allocated bool Claimed bool Released bool Listening bool Closed bool // contains filtered or unexported fields }
Client wraps up the websocket connection with a sending buffer and functions for transfering messages
func (*Client) Close ¶
func (c *Client) Close()
Close terminates the client connection and cleans up resources it had bound.
func (*Client) HandleAdd ¶
HandleAdd command from the client to add a message to the opened mailbox of this client. Adding messages will also trigger broadcasts for any listners currently on the service for the specified mailbox. Which of course means, it echos back immediately
func (*Client) HandleAllocate ¶
HandleAllocate command is received from client when they want to allocate, or reserve, a nameplate slot for message transfer. Clients can only allocate 1 during a connection. Allocate generates a new nameplate and returns it
func (*Client) HandleBind ¶
HandleBind handles bind messages.
func (*Client) HandleClaim ¶
HandleClaim command from client when they want to claim a specific nameplate instead of auto-generating one for them. Clients can only allocate 1 during a connection.
func (*Client) HandleClose ¶
HandleClose command from the client to close it's connection to an opened mailbox. The "mailbox" field is optional, but if supplied must match the currently open one.
func (*Client) HandleList ¶
HandleList handles list commands from the client who would like to know the available nameplates. This is optional for whether the server will allow it via the AllowList relay server configuration option. If this option is not available, an empty list is returned back to the client
func (*Client) HandleOpen ¶
HandleOpen command from the client to open the specified mailbox (by ID) for reading. Will also bind the listeners for event callbacks.
func (*Client) HandlePing ¶
HandlePing handles ping messages and responds back with the matching Pong message
func (*Client) HandleRelease ¶
HandleRelease command from client when they want to release their hold, or side, of a nameplate. They can provide the nameplate as a means of double checking but the current client one is inferred. If they do supply it, it must match. This command must come after claim.
func (*Client) OnConnect ¶
func (c *Client) OnConnect()
OnConnect is called when the client has successfully been registered to the server
func (*Client) OnMessage ¶
OnMessage called when a message from the client is received and it needs to be handled/processed. From this point we have a message as only the bytes and need to handle it appropriately. We need to do all steps and validation here as necessary. So this will be broken down into the message types.
type Mailbox ¶
Mailbox holds an association with an application as well as its on ID. Here the client messages are stored for retrieval later and transmitting between users
func NewMailbox ¶
NewMailbox returns a new mailbox address with the provided information
func (*Mailbox) AddListener ¶
func (m *Mailbox) AddListener(listener MailboxListener, stopCallback MailboxListenerStop) int
AddListener registers a callback for mailbox messages and returns an integer handle for de-registration
func (*Mailbox) AddMessage ¶
func (m *Mailbox) AddMessage(msg MailboxMessage) error
AddMessage inserts a new message into the mailbox
func (*Mailbox) GetMessages ¶
func (m *Mailbox) GetMessages() ([]MailboxMessage, error)
GetMessages returns the messages currently present in this mailbox
func (*Mailbox) HasListeners ¶
HasListeners returns true if there are any listeners registered
func (*Mailbox) RemoveAllListeners ¶
func (m *Mailbox) RemoveAllListeners()
RemoveAllListeners calls the stop callback on each listener, and then clears all the listners
func (*Mailbox) RemoveListener ¶
RemoveListener removes a previously registered listener by it's given handle
type MailboxListener ¶
type MailboxListener func(MailboxMessage)
MailboxListener is a callback function that receives new mailbox messages when they are added to the one the listener has subscribed too.
type MailboxListenerStop ¶
type MailboxListenerStop func()
MailboxListenerStop is another callback function like MailboxListener, which is used in conjunction. When the service needs to remove a mailbox with an attached listener, this callback is called to alert the listener that they are going to loose their hook.
type MailboxMessage ¶
type MailboxMessage struct { ID string AppID string MailboxID string Side string Phase string Body string ServerRX int64 }
MailboxMessage is an individual entry within a parent Mailbox
type Service ¶
type Service struct { Welcome msg.WelcomeInfo Apps map[string]Application }
Service encompases the actual relay service for use by clients. Essentially most of this package handles the actual network connections and message handling. This object is the actual implementation (or at least the start of it)
func NewService ¶
NewService initializes the relay service object and returns it as a pointer, if we can not start one then nil, error is returned instead
func (*Service) CleanApps ¶
CleanApps iterates the apps registered to the service and runs the cleaining process on each one
func (Service) GetAllApps ¶
GetAllApps returns all the application IDs in memory, and in the database. I will admit, this function was A LOT shorter in the Python version.
func (*Service) GetApp ¶
func (s *Service) GetApp(id string) *Application
GetApp finds an application registered with the relay service. If not found, it will create and initialize the object for it