2022-10-15 14:28:03 +00:00
|
|
|
package bootstrap
|
|
|
|
|
|
|
|
import (
|
2023-08-05 21:53:17 +00:00
|
|
|
"isle/garage"
|
2022-10-15 14:28:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GaragePeers returns a Peer for each known garage instance in the network.
|
2022-10-28 22:09:18 +00:00
|
|
|
func (b Bootstrap) GaragePeers() []garage.RemotePeer {
|
|
|
|
var peers []garage.RemotePeer
|
2022-10-15 14:28:03 +00:00
|
|
|
for _, host := range b.Hosts {
|
2024-11-05 20:25:04 +00:00
|
|
|
peers = append(peers, host.GaragePeers()...)
|
2022-10-15 14:28:03 +00:00
|
|
|
}
|
|
|
|
return peers
|
|
|
|
}
|
|
|
|
|
2022-10-16 13:38:15 +00:00
|
|
|
// 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.
|
2022-10-28 22:09:18 +00:00
|
|
|
func (b Bootstrap) ChooseGaragePeer() garage.RemotePeer {
|
2022-10-16 13:38:15 +00:00
|
|
|
thisHost := b.ThisHost()
|
2022-11-05 15:55:17 +00:00
|
|
|
if len(thisHost.Garage.Instances) > 0 {
|
2024-11-05 20:25:04 +00:00
|
|
|
return thisHost.GaragePeers()[0]
|
2022-10-16 13:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, peer := range b.GaragePeers() {
|
|
|
|
return peer
|
|
|
|
}
|
|
|
|
|
|
|
|
panic("no garage instances configured")
|
|
|
|
}
|