isle/go/garage/peer.go

49 lines
1.1 KiB
Go
Raw Normal View History

package garage
import (
"fmt"
"net"
"strconv"
)
2025-01-07 14:40:50 +00:00
// Node describes the common fields of both a [RemoteNode] and [LocalNode]
type Node struct {
IP string
RPCPort int
S3APIPort int
}
2025-01-07 14:40:50 +00:00
// RPCAddr returns the address of the node's RPC port.
func (p Node) RPCAddr() string {
return net.JoinHostPort(p.IP, strconv.Itoa(p.RPCPort))
}
2025-01-07 14:40:50 +00:00
// S3APIAddr returns the address of the node's S3 API port.
func (p Node) S3APIAddr() string {
return net.JoinHostPort(p.IP, strconv.Itoa(p.S3APIPort))
}
2025-01-07 14:40:50 +00:00
// RemoteNode describes all information necessary to connect to a given garage
// node.
type RemoteNode struct {
Node
ID string
}
// RPCNodeAddr returns the full node address (e.g. "id@ip:port") of the garage
// node for use in communicating over RPC.
func (p RemoteNode) RPCNodeAddr() string {
return fmt.Sprintf("%s@%s", p.ID, p.RPCAddr())
}
2025-01-07 14:40:50 +00:00
// LocalNode describes the configuration of a local garage instance.
type LocalNode struct {
Node
AdminPort int
}
// AdminAddr returns the address of the node's S3 API port.
func (p LocalNode) AdminAddr() string {
return net.JoinHostPort(p.IP, strconv.Itoa(p.AdminPort))
}