@@ 94,36 94,30 @@ func bootstrap() {
ch := make(chan int, 1)
closeElection = ch
+ go findPeers(ch)
- go func() {
- fmt.Println("press ENTER to solidify group of voters and start voting")
- stdReader := bufio.NewReader(os.Stdin)
- _, err := stdReader.ReadString('\n')
+ fmt.Println("press ENTER to solidify group of voters and start voting")
+ stdReader := bufio.NewReader(os.Stdin)
+ _, err := stdReader.ReadString('\n')
+ if err != nil {
+ panic(err)
+ }
+
+ logger.Info("ENTER has been pressed; closing election")
+ n := len(me.otherVoters)
+ closeElection <- n
+ close(closeElection)
+ for _, voter := range me.otherVoters {
+ stream, err := me.h.NewStream(me.ctx, voter.ID, protocolID)
if err != nil {
panic(err)
}
-
- logger.Info("ENTER has been pressed; closing election")
- n := len(me.otherVoters)
- closeElection <- n
- close(closeElection)
- for _, voter := range me.otherVoters {
- stream, err := me.h.NewStream(me.ctx, voter.ID, protocolID)
- if err != nil {
- panic(err)
- }
- writer := bufio.NewWriter(stream)
- writer.WriteString(fmt.Sprintf("close\n%d", n))
- writer.Flush()
- stream.Close()
- }
- }()
-
- findPeers(ch)
-
- select {} // temporary
+ writer := bufio.NewWriter(stream)
+ writer.WriteString(fmt.Sprintf("close\n%d", n))
+ writer.Flush()
+ stream.Close()
+ }
} else { // we are a slave
-
logger.Info("attempting to open stream with master peer...")
stream, err := me.h.NewStream(me.ctx, masterID, protocolID)
rw := bufio.NewReadWriter(bufio.NewReader(stream), bufio.NewWriter(stream))