func (f *FailureNotifier) NextConnected(id int) int {
	f.mutex.RLock()
	id++
	if id == f.n {
		id = 0
	}
	for !f.up[id] {
		id++
		if id == f.n {
			id = 0
		}
	}
	f.mutex.RUnlock()
	return id
}
Return the ID of the next connected node
package msgs
import (
	"fmt"
	"github.com/golang/glog"
	"sync"
)
type FailureNotifier struct {
	up         []bool
	mutex      sync.RWMutex
	subscribed [](chan bool)
	n          int
}
func NewFailureNotifier(n int) *FailureNotifier {
	return &FailureNotifier{
		make([]bool, n),
		sync.RWMutex{},
		make([](chan bool), n),
		n}
}
func (f *FailureNotifier) NotifyOnFailure(id int) chan bool {
	note := make(chan bool, 1)
	f.subscribed[id] = note
	return note
}
func (f *FailureNotifier) IsConnected(id int) bool {
	f.mutex.RLock()
	up := f.up[id]
	f.mutex.RUnlock()
	return up
}