func testBootstrap(nodes messagePasser.Nodes) { localName := getLocalName() _, localNode, _ := messagePasser.FindNodeByName(nodes, localName) fmt.Println("Contacting the bootstrap server...") peers, err := bootstrapClient.GetNodes(localNode) if err != nil { fmt.Println("Got error:", err) } else { fmt.Printf("Got peers: %+v\n", peers) } }
/* * 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() } }
/* * get destination name * @param nodes * the available nodes to contact * * @return destination name string **/ func getDest(nodes []messagePasser.Node) string { fmt.Println("To: (ex. lunwen OR 1)") var destName string fmt.Scanf("%v", &destName) // Check if input is an ID id, err := strconv.Atoi(destName) if err == nil && id >= 0 && id < len(nodes) { return nodes[id].Name } // else input must be a name var destNode messagePasser.Node for len(destName) > 0 { _, destNode, err = messagePasser.FindNodeByName(nodes, destName) if err == nil { break } fmt.Printf("Couldn't find '%v', please try again:\n", destName) fmt.Scanf("%v", &destName) } return destNode.Name }