Documentation ¶
Index ¶
- Constants
- func Upgrade(rw http.ResponseWriter, r *http.Request) (*websocket.Conn, error)
- type AgentClient
- type AgentMessage
- type AgentStatusRequest
- type AgentStatusResponse
- type DashboardClient
- type DashboardMessage
- type Notification
- type Pool
- func (pool *Pool) AgentMessageReceived(message AgentMessage)
- func (pool *Pool) AgentRegistered(c *AgentClient)
- func (pool *Pool) AgentUnregistered(c *AgentClient)
- func (pool *Pool) DashboardClientRegistered(c *DashboardClient)
- func (pool *Pool) DashboardClientUnregistered(c *DashboardClient)
- func (pool *Pool) DashboardMessageReceived(message DashboardMessage)
- func (pool *Pool) HandleAgentStatusRequest(msg WebSocketMessage) (AgentStatusResponse, error)
- func (pool *Pool) HandleNotification(msg WebSocketMessage) error
- func (pool *Pool) HandleRuleDetectionAlert(msg WebSocketMessage) error
- func (pool *Pool) Start()
- type RuleDetectionAlert
- type WebSocketMessage
Constants ¶
const ( WsError int64 = -1 WsNotification int64 = 1 WsAgentStatusRequest int64 = 2 WsAgentStatusResponse int64 = 3 WsAgentDisconnectedNotification int64 = 4 WsAgentConnectedNotification int64 = 5 WsRuleDetectionAlert int64 = 6 )
Message Types
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AgentClient ¶
func (*AgentClient) Read ¶
func (c *AgentClient) Read()
* This function will wait for a message to be sent by the client and based on the message type different functions from the pool will be called
type AgentMessage ¶
type AgentMessage struct { C *AgentClient Type int `json:"type"` Body string `json:"body"` }
type AgentStatusRequest ¶
type AgentStatusRequest struct {
AgentId string `json:"agentId"`
}
type AgentStatusResponse ¶
type DashboardClient ¶
* This structure will define a client that connected to the chat service. * Each client will have a unique id, a websocket connection that will be used to send and receive messages * The client structure will also have a pointer to the pool structure which will be used for conccurency
func (*DashboardClient) Read ¶
func (c *DashboardClient) Read()
* This function will wait for a message to be sent by the client and based on the message type different functions from the pool will be called
type DashboardMessage ¶
type DashboardMessage struct { C *DashboardClient Type int `json:"type"` Body string `json:"body"` }
* This structure will define a message that can be sent/received on the websocket * The type variable will be used to determine if the websocket message is text or binary as it will have different values based on that * The body will be the payload that the other users it is delivered to should receive
type Notification ¶
Notification Websocket message
type Pool ¶
type Pool struct { RegisterDashboard chan *DashboardClient //Channel which will handle new dashboard client connections UnregisterDashboard chan *DashboardClient //Channel which will handle a dashboard client disconnecting DashboardClients map[*DashboardClient]bool //A map of dashboard client connections and associated state of the connection (true for online) DashboardBroadcast chan DashboardMessage //Channel which will be used to handle a message from the dashboard client RegisterAgent chan *AgentClient //Channel which will handle new agent connections UnregisterAgent chan *AgentClient //Channgel which will handle agent client disconnecting AgentClients map[*AgentClient]bool //A map of dashboard client connections and associated state of the connection (true for online) AgentBroadcast chan AgentMessage //Channel which will be used to handle a message from the agent // contains filtered or unexported fields }
* This structure will handle concurrent connections using channels * Each channel will have a particular functionality
func NewPool ¶
func NewPool(l logging.ILogger, dbConn database.IConnection, conf config.Configuration) *Pool
* This function will create a new pool that can then be used when starting the chat service
func (*Pool) AgentMessageReceived ¶
func (pool *Pool) AgentMessageReceived(message AgentMessage)
* This function will handle when a message is recevied from a client * There should be more types of messages that can be received from the client
func (*Pool) AgentRegistered ¶
func (pool *Pool) AgentRegistered(c *AgentClient)
func (*Pool) AgentUnregistered ¶
func (pool *Pool) AgentUnregistered(c *AgentClient)
func (*Pool) DashboardClientRegistered ¶
func (pool *Pool) DashboardClientRegistered(c *DashboardClient)
* This function will handle the register of a client (the client connected to the websocket) * It should be registered in the pool
func (*Pool) DashboardClientUnregistered ¶
func (pool *Pool) DashboardClientUnregistered(c *DashboardClient)
func (*Pool) DashboardMessageReceived ¶
func (pool *Pool) DashboardMessageReceived(message DashboardMessage)
* This function will handle when a message is recevied from a client * There should be more types of messages that can be received from the client
func (*Pool) HandleAgentStatusRequest ¶
func (pool *Pool) HandleAgentStatusRequest(msg WebSocketMessage) (AgentStatusResponse, error)
func (*Pool) HandleNotification ¶
func (pool *Pool) HandleNotification(msg WebSocketMessage) error
func (*Pool) HandleRuleDetectionAlert ¶
func (pool *Pool) HandleRuleDetectionAlert(msg WebSocketMessage) error
type RuleDetectionAlert ¶
type WebSocketMessage ¶
type WebSocketMessage struct { Type int64 `json:"type"` //The type of the message Data interface{} `json:"data"` //The data of the message as interface (can be any struct) }
WebSocket message format