Example #1
0
func receiveRoutine() {
	for {
		messagePasser.Push(&receiveQueue, messagePasser.Receive())
	}
}
Example #2
0
/* receive message from messagePasser and route to correct location */
func inboundDispatcher() {
	for {
		// get message from MessagePasser
		message := messagePasser.Receive()

		// Based on the type of message, determine where it needs routed
		switch message.Kind {

		// UI Messages
		case defs.MSG_BALL_DEFLECTED:
			fallthrough
		case defs.MSG_BALL_MISSED:
			fallthrough
		case defs.MSG_BLOCK_BROKEN:
			fallthrough
		case defs.MSG_CON_CHECK:
			fallthrough
		case defs.MSG_CON_COMMIT:
			fallthrough
		case defs.MSG_DEAD_NODE:
			fallthrough
		case defs.MSG_DEAD_UNICORN:
			fallthrough
		case defs.MSG_FORCE_COMMIT:
			fallthrough
		case defs.MSG_KILL_NODE:
			fallthrough
		case defs.MSG_PADDLE_DIR:
			fallthrough
		case defs.MSG_PAUSE_UPDATE:
			fallthrough
		case defs.MSG_REJOIN_ACK:
			fallthrough
		case defs.MSG_REJOIN_REQ:
			fallthrough
		case defs.MSG_START_PLAY:
			fallthrough
		case defs.MSG_SYNC_ERROR:
			bridges.SendToPyBridge(message)
		case defs.MSG_UNICORN:
			initConsensus(message)
			bridges.SendToPyBridge(message)

		// election messages
		case defs.MSG_BULLY_ELECTION:
			fallthrough
		case defs.MSG_BULLY_ANSWER:
			fallthrough
		case defs.MSG_BULLY_ARE_YOU_ALIVE:
			fallthrough
		case defs.MSG_BULLY_IAM_ALIVE:
			bullySelection.PutMessageToReceiveChannel(message)
		case defs.MSG_BULLY_UNICORN:
			initConsensus(message)
			bullySelection.PutMessageToReceiveChannel(message)

		// consensus messages
		case defs.CONSENSUS_ACCEPT_KIND:
			fallthrough
		case defs.CONSENSUS_REJECT_KIND:
			fallthrough
		case defs.CONSENSUS_PROPOSE_KIND:
			fallthrough
		case defs.CONSENSUS_COMMIT_KIND:
			consensus.ReceiveMessage(message)
		default:
			fmt.Printf("inboundDispatcher couldn't recognize message: %+v\n", message)
		}
	}
}