diff --git a/cluster.go b/cluster.go index d8bfd70..b9d79ee 100644 --- a/cluster.go +++ b/cluster.go @@ -15,7 +15,6 @@ import ( "github.com/mattn/go-isatty" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "go.uber.org/multierr" ) // ClusterState keeps track of information needed to rejoin the cluster @@ -120,9 +119,8 @@ func (c *cluster) update() { c.ml.UpdateNode(1 * time.Second) // we currently do not update after creation } -func (c *cluster) members() (<-chan []node, <-chan error) { +func (c *cluster) members() <-chan []node { changes := make(chan []node) - errc := make(chan error, 1) go func() { for { event := <-c.events @@ -140,31 +138,22 @@ func (c *cluster) members() (<-chan []node, <-chan error) { } nodes := make([]node, 0) - var errs error for _, n := range c.ml.Members() { if n.Name == c.localName { continue } - meta, err := decodeNodeMeta(n.Meta) - if err != nil { - errs = multierr.Append(errs, err) - continue - } nodes = append(nodes, node{ - Name: n.Name, - Addr: n.Addr, - nodeMeta: meta, + Name: n.Name, + Addr: n.Addr, + Meta: n.Meta, }) } c.state.Nodes = nodes changes <- nodes - if errs != nil { - errc <- errs - } c.saveState() } }() - return changes, errc + return changes } func computeClusterKey(state *ClusterState, clusterKey []byte) ([]byte, error) { diff --git a/go.mod b/go.mod index baf6b2b..5bc73e8 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,6 @@ require ( github.com/stevenroose/gonfig v0.1.5 github.com/stretchr/testify v1.4.0 // indirect github.com/vishvananda/netlink v1.1.0 - go.uber.org/multierr v1.5.0 golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200324154536-ceff61240acf ) diff --git a/main.go b/main.go index 53bc7aa..13c4565 100644 --- a/main.go +++ b/main.go @@ -49,7 +49,7 @@ func main() { wg.assignOverlayAddr((*net.IPNet)(config.OverlayNet), cluster.localName) cluster.update() - nodec, errc := cluster.members() // avoid deadlocks by starting before join + nodec := cluster.members() // avoid deadlocks by starting before join if err := backoff.RetryNotify( func() error { return cluster.join(config.Join) }, backoff.NewExponentialBackOff(), @@ -65,9 +65,17 @@ func main() { logrus.Debug("waiting for cluster events") for { select { - case nodes := <-nodec: + case rawNodes := <-nodec: logrus.Info("cluster members:\n") - for _, node := range nodes { + nodes := make([]node, 0) + for _, node := range rawNodes { + meta, err := decodeNodeMeta(node.Meta) + if err != nil { + logrus.Warnf("\t addr: %s, could not decode metadata", node.Addr) + continue + } + node.nodeMeta = meta + nodes = append(nodes, node) logrus.Infof("\taddr: %s, overlay: %s, pubkey: %s", node.Addr, node.OverlayAddr, node.PubKey) } if err := wg.setUpInterface(nodes); err != nil { @@ -79,8 +87,6 @@ func main() { logrus.WithError(err).Error("could not write hosts entries") } } - case errs := <-errc: - logrus.WithError(errs).Error("could not receive node info") case <-incomingSigs: logrus.Info("terminating...") cluster.leave() diff --git a/node.go b/node.go index 8fc75a7..49da3fc 100644 --- a/node.go +++ b/node.go @@ -19,6 +19,7 @@ type nodeMeta struct { type node struct { Name string Addr net.IP + Meta []byte nodeMeta }