isle/go/bootstrap/garage.go

31 lines
774 B
Go
Raw Normal View History

package bootstrap
import (
"isle/garage"
)
// GaragePeers returns a Peer for each known garage instance in the network.
func (b Bootstrap) GaragePeers() []garage.RemotePeer {
var peers []garage.RemotePeer
for _, host := range b.Hosts {
peers = append(peers, host.GaragePeers()...)
}
return peers
}
// ChooseGaragePeer returns a Peer for a garage instance from the network. It
// will prefer a garage instance on this particular host, if there is one, but
// will otherwise return a random endpoint.
func (b Bootstrap) ChooseGaragePeer() garage.RemotePeer {
thisHost := b.ThisHost()
2022-11-05 15:55:17 +00:00
if len(thisHost.Garage.Instances) > 0 {
return thisHost.GaragePeers()[0]
}
for _, peer := range b.GaragePeers() {
return peer
}
panic("no garage instances configured")
}