Ejemplo n.º 1
0
/*
 * Inits consensus when we receive a unicorn message
 */
func initConsensus(message messagePasser.Message) {
	nodeIndex, node, err := messagePasser.FindNodeByName(messagePasser.PeerNodes, message.Content)
	if err == nil {
		peers := append(messagePasser.PeerNodes[:nodeIndex])
		consensus.InitConsensus(node, peers, messagePasser.LocalNode.Name)

		go ConsensusReceiverRoutine()
		go ConsensusCheckReceiverRoutine()
		go ConsensusReachedRoutine()
	}
}
Ejemplo 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")
		}
	}
}