2022-10-15 14:28:03 +00:00
|
|
|
package garage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2024-11-08 16:46:44 +00:00
|
|
|
// RemoteNode describes all information necessary to connect to a given garage
|
2022-10-28 22:09:18 +00:00
|
|
|
// node.
|
2024-11-08 16:46:44 +00:00
|
|
|
type RemoteNode struct {
|
2022-10-28 22:09:18 +00:00
|
|
|
ID string
|
2022-10-15 14:28:03 +00:00
|
|
|
IP string
|
|
|
|
RPCPort int
|
|
|
|
S3APIPort int
|
|
|
|
}
|
|
|
|
|
2024-11-08 16:46:44 +00:00
|
|
|
// LocalNode describes the configuration of a local garage instance.
|
|
|
|
type LocalNode struct {
|
|
|
|
RemoteNode
|
2022-10-15 14:28:03 +00:00
|
|
|
|
2022-10-28 22:09:18 +00:00
|
|
|
AdminPort int
|
|
|
|
}
|
2022-10-15 14:28:03 +00:00
|
|
|
|
2024-11-08 16:46:44 +00:00
|
|
|
// RPCAddr returns the address of the node's RPC port.
|
|
|
|
func (p RemoteNode) RPCAddr() string {
|
2022-10-15 14:28:03 +00:00
|
|
|
return net.JoinHostPort(p.IP, strconv.Itoa(p.RPCPort))
|
|
|
|
}
|
|
|
|
|
2024-11-08 16:46:44 +00:00
|
|
|
// RPCNodeAddr returns the full node address (e.g. "id@ip:port") of the garage
|
2022-10-15 14:28:03 +00:00
|
|
|
// node for use in communicating over RPC.
|
2024-11-08 16:46:44 +00:00
|
|
|
func (p RemoteNode) RPCNodeAddr() string {
|
2022-10-28 22:09:18 +00:00
|
|
|
return fmt.Sprintf("%s@%s", p.ID, p.RPCAddr())
|
2022-10-15 14:28:03 +00:00
|
|
|
}
|
|
|
|
|
2024-11-08 16:46:44 +00:00
|
|
|
// S3APIAddr returns the address of the node's S3 API port.
|
|
|
|
func (p RemoteNode) S3APIAddr() string {
|
2022-10-15 14:28:03 +00:00
|
|
|
return net.JoinHostPort(p.IP, strconv.Itoa(p.S3APIPort))
|
|
|
|
}
|
2022-10-28 22:09:18 +00:00
|
|
|
|
2024-11-08 16:46:44 +00:00
|
|
|
// AdminAddr returns the address of the node's S3 API port.
|
|
|
|
func (p LocalNode) AdminAddr() string {
|
2022-10-28 22:09:18 +00:00
|
|
|
return net.JoinHostPort(p.IP, strconv.Itoa(p.AdminPort))
|
|
|
|
}
|