gecko/api/admin/networking.go

28 lines
632 B
Go

// (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
type Peerable interface{ Peers() []utils.IPDesc }
// 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) {
ipDescs := n.peers.Peers()
ips := make([]string, len(ipDescs))
for i, ipDesc := range ipDescs {
ips[i] = ipDesc.String()
}
sort.Strings(ips)
return ips, nil
}