Esempio n. 1
0
/* wait for incoming messages from the UI */
func PyBridgeReceiver() {
	for {
		message := bridges.ReceiveFromPyBridge()
		switch message.Kind {
		case defs.MSG_MYNAME:
			localNameChannel <- message.Content
		case defs.MSG_GAME_TYPE:
			gameTypeChannel <- message.Content
		case defs.MSG_CON_REQ:
			valueType := strings.Split(message.Content, "|")[0]
			consensus.Propose(message.Content, valueType)
		case defs.MSG_CON_REPLY:
			valueType := strings.Split(message.Content, "|")[0]
			propCheckMutex.Lock()
			propCheck := propChecksMap[valueType]
			(*propCheck.Callback)(message.Content)
			delete(propChecksMap, valueType)
			propCheckMutex.Unlock()
		case defs.MSG_EXIT:
			// echo back to UI
			bridges.SendToPyBridge(message)
			// exit multegula
			exitChannel <- true
		default:
			go putMessageIntoSendChannel(message)
		}
	}
}
Esempio n. 2
0
func testConsensus(nodes messagePasser.Nodes) {
	localName := getLocalName()
	messagePasser.InitMessagePasser(nodes, localName)
	go outboundDispatcher()
	go inboundDispatcher()
	leader := nodes[0]
	consensus.InitConsensus(leader, nodes[1:], localName)
	go ConsensusReceiverRoutine()
	go ConsensusCheckReceiverRoutine()
	go ConsensusReachedRoutine()

	var proposalValue string
	for {
		if localName == leader.Name {
			fmt.Println("Hit enter to propose.")
			fmt.Scanf("%s", &proposalValue)
			consensus.Propose(proposalValue, "test")
		}
	}
}