2020-03-10 12:20:34 -07:00
|
|
|
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
|
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
|
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/ava-labs/gecko/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Peerable can return a group of peers
|
2020-04-18 17:34:19 -07:00
|
|
|
type Peerable interface{ IPs() []utils.IPDesc }
|
2020-03-10 12:20:34 -07:00
|
|
|
|
|
|
|
// Networking provides helper methods for tracking the current network state
|
|
|
|
type Networking struct{ peers Peerable }
|
|
|
|
|
|
|
|
// Peers returns the current peers
|
|
|
|
func (n *Networking) Peers() ([]string, error) {
|
2020-04-18 17:34:19 -07:00
|
|
|
ipDescs := n.peers.IPs()
|
2020-03-10 12:20:34 -07:00
|
|
|
ips := make([]string, len(ipDescs))
|
|
|
|
for i, ipDesc := range ipDescs {
|
|
|
|
ips[i] = ipDesc.String()
|
|
|
|
}
|
|
|
|
sort.Strings(ips)
|
|
|
|
return ips, nil
|
|
|
|
}
|