31 lines
774 B
Go
31 lines
774 B
Go
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()
|
|
if len(thisHost.Garage.Instances) > 0 {
|
|
return thisHost.GaragePeers()[0]
|
|
}
|
|
|
|
for _, peer := range b.GaragePeers() {
|
|
return peer
|
|
}
|
|
|
|
panic("no garage instances configured")
|
|
}
|