Skip to content

Commit

Permalink
Tweaks the advertise address signature.
Browse files Browse the repository at this point in the history
  • Loading branch information
slackpad committed Feb 23, 2017
1 parent 52cde68 commit 78dd4e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions net_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,38 +123,37 @@ func (t *NetTransport) GetAutoBindPort() int {
}

// See Transport.
func (t *NetTransport) FinalAdvertiseAddr(addr string, port int) (net.IP, int, error) {
func (t *NetTransport) FinalAdvertiseAddr(ip string, port int) (net.IP, int, error) {
var advertiseAddr net.IP
var advertisePort int
if addr != "" {
if ip != "" {
// If they've supplied an address, use that.
ip := net.ParseIP(addr)
if ip == nil {
return nil, 0, fmt.Errorf("Failed to parse advertise address %q", addr)
advertiseAddr = net.ParseIP(ip)
if advertiseAddr == nil {
return nil, 0, fmt.Errorf("Failed to parse advertise address %q", ip)
}

// Ensure IPv4 conversion if necessary.
if ip4 := ip.To4(); ip4 != nil {
ip = ip4
if ip4 := advertiseAddr.To4(); ip4 != nil {
advertiseAddr = ip4
}
advertiseAddr = ip
advertisePort = port
} else {
if t.config.BindAddrs[0] == "0.0.0.0" {
// Otherwise, if we're not bound to a specific IP, let's
// use a suitable private IP address.
var err error
addr, err = sockaddr.GetPrivateIP()
ip, err = sockaddr.GetPrivateIP()
if err != nil {
return nil, 0, fmt.Errorf("Failed to get interface addresses: %v", err)
}
if addr == "" {
if ip == "" {
return nil, 0, fmt.Errorf("No private IP address found, and explicit IP not provided")
}

advertiseAddr = net.ParseIP(addr)
advertiseAddr = net.ParseIP(ip)
if advertiseAddr == nil {
return nil, 0, fmt.Errorf("Failed to parse advertise address: %q", addr)
return nil, 0, fmt.Errorf("Failed to parse advertise address: %q", ip)
}
} else {
// Use the IP that we're bound to, based on the first
Expand Down
2 changes: 1 addition & 1 deletion transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Transport interface {
// FinalAdvertiseAddr is given the user's configured values (which
// might be empty) and returns the desired IP and port to advertise to
// the rest of the cluster.
FinalAdvertiseAddr(addr string, port int) (net.IP, int, error)
FinalAdvertiseAddr(ip string, port int) (net.IP, int, error)

// WriteTo is a packet-oriented interface that fires off the given
// payload to the given address in a connectionless fashion. This should
Expand Down

0 comments on commit 78dd4e7

Please sign in to comment.