Exemple #1
0
// Processes a response from the downstream service.
func (h *hub) processResponse(res baps3.Message) {
	log.Println("New response:", res.String())
	switch res.Word() {
	case baps3.RsEnd: // Handle, broadcast and update state
		h.handleRsEnd(res)
		fallthrough
	case baps3.RsTime, baps3.RsState: // Broadcast _AND_ update state
		h.broadcast(res)
		fallthrough
	case baps3.RsOhai, baps3.RsFeatures: // Just update state
		if err := h.downstreamState.Update(res); err != nil {
			log.Fatal("Error updating state: " + err.Error())
		}
	default:
		h.broadcast(res)
	}
}
Exemple #2
0
// Handles a request from a client.
// Falls through to the connector cReqCh if command is "not understood".
func (h *hub) processRequest(c *Client, req baps3.Message) {
	log.Println("New request:", req.String())
	if reqFunc, ok := REQ_FUNC_MAP[req.Word()]; ok {
		responses := reqFunc(h, req)
		for _, resp := range responses {
			// TODO: Add a "is fail word" func to baps3-go?
			if resp.Word() == baps3.RsFail || resp.Word() == baps3.RsWhat {
				// failures only go to sender
				sendInvalidCmd(c, *resp, req)
			} else {
				h.broadcast(*resp)
			}
		}
	} else {
		h.cReqCh <- req
	}
}