2018-06-04 16:40:04 +00:00
|
|
|
package element
|
|
|
|
|
2018-09-19 01:59:54 +00:00
|
|
|
import "github.com/gogo/protobuf/proto"
|
2018-06-04 16:40:04 +00:00
|
|
|
|
|
|
|
// Peers returns all known peers in the cluster
|
2018-09-19 01:59:54 +00:00
|
|
|
func (a *Agent) Peers() ([]*Peer, error) {
|
2018-06-04 16:40:04 +00:00
|
|
|
self := a.members.LocalNode()
|
2018-09-19 01:59:54 +00:00
|
|
|
var state State
|
|
|
|
if err := proto.Unmarshal(self.Meta, &state); err != nil {
|
2018-06-04 16:40:04 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2018-09-19 01:59:54 +00:00
|
|
|
var peers []*Peer
|
|
|
|
for _, p := range state.Peers {
|
2018-06-04 16:40:04 +00:00
|
|
|
peers = append(peers, p)
|
|
|
|
}
|
|
|
|
return peers, nil
|
|
|
|
}
|
|
|
|
|
2018-09-19 01:59:54 +00:00
|
|
|
// Self returns the local peer information
|
|
|
|
func (a *Agent) Self() *Peer {
|
|
|
|
return a.state.Self
|
2018-06-04 16:40:04 +00:00
|
|
|
}
|