mirror of
https://github.com/gluster/glusterd2.git
synced 2026-02-06 15:46:00 +01:00
The name of the configurable options should represent the services provided or consumer of the port and not the protocol used. * Renamed 'rpcaddress' to 'peeraddress': Denotes the address used for peer to peer communication. * Renamed 'restaddress' to 'clientaddress': Denotes the address used by clients to communicate with glusterd2. Coincidentally, these are analogous to those provided by etcd. Signed-off-by: Prashanth Pai <ppai@redhat.com>
41 lines
986 B
Go
41 lines
986 B
Go
package utils
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
"strings"
|
|
|
|
config "github.com/spf13/viper"
|
|
)
|
|
|
|
// FormRemotePeerAddress will check and validate peeraddress provided. It will
|
|
// return an address of the form <ip:port>
|
|
func FormRemotePeerAddress(peeraddress string) (string, error) {
|
|
|
|
host, port, err := net.SplitHostPort(peeraddress)
|
|
if err != nil {
|
|
// net.SplitHostPort() returns an error if port is missing.
|
|
if strings.HasPrefix(err.Error(), "missing port in address") {
|
|
host = peeraddress
|
|
port = config.GetString("defaultpeerport")
|
|
} else {
|
|
return "", err
|
|
}
|
|
}
|
|
|
|
if host == "" {
|
|
return "", errors.New("Invalid peer address")
|
|
}
|
|
|
|
remotePeerAddress := host + ":" + port
|
|
return remotePeerAddress, nil
|
|
}
|
|
|
|
// IsPeerAddressSame checks if two peer addresses are same by normalizing
|
|
// each address to <ip>:<port> form.
|
|
func IsPeerAddressSame(addr1 string, addr2 string) bool {
|
|
r1, _ := FormRemotePeerAddress(addr1)
|
|
r2, _ := FormRemotePeerAddress(addr2)
|
|
return r1 == r2
|
|
}
|