lncfg: update verifyPort to map a plain port to localhost:port
This commit is contained in:
parent
5d66635aee
commit
f5f68858de
@ -1,11 +1,14 @@
|
|||||||
package lncfg
|
package lncfg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
"net"
|
|
||||||
"fmt"
|
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/tor"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -159,26 +162,38 @@ func ParseAddressString(strAddress string, defaultPort string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// verifyPort makes sure that an address string has both a host and a port.
|
// verifyPort makes sure that an address string has both a host and a port. If
|
||||||
// If there is no port found, the default port is appended.
|
// there is no port found, the default port is appended. If the address is just
|
||||||
func verifyPort(strAddress string, defaultPort string) string {
|
// a port, then we'll assume that the user is using the short cut to specify a
|
||||||
host, port, err := net.SplitHostPort(strAddress)
|
// localhost:port address.
|
||||||
|
func verifyPort(address string, defaultPort string) string {
|
||||||
|
host, port, err := net.SplitHostPort(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If we already have an IPv6 address with brackets, don't use
|
// If the address itself is just an integer, then we'll assume
|
||||||
// the JoinHostPort function, since it will always add a pair
|
// that we're mapping this directly to a localhost:port pair.
|
||||||
// of brackets too.
|
// This ensures we maintain the legacy behavior.
|
||||||
if strings.HasPrefix(strAddress, "[") {
|
if _, err := strconv.Atoi(address); err == nil {
|
||||||
strAddress = strAddress + ":" + defaultPort
|
return net.JoinHostPort("localhost", address)
|
||||||
} else {
|
|
||||||
strAddress = net.JoinHostPort(strAddress, defaultPort)
|
|
||||||
}
|
|
||||||
} else if host == "" && port == "" {
|
|
||||||
// The string ':' is parsed as valid empty host and empty port.
|
|
||||||
// But in that case, we want the default port to be applied too.
|
|
||||||
strAddress = ":" + defaultPort
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return strAddress
|
// Otherwise, we'll assume that the address just failed to
|
||||||
|
// attach its own port, so we'll use the default port. In the
|
||||||
|
// case of IPv6 addresses, if the host is already surrounded by
|
||||||
|
// brackets, then we'll avoid using the JoinHostPort function,
|
||||||
|
// since it will always add a pair of brackets.
|
||||||
|
if strings.HasPrefix(address, "[") {
|
||||||
|
return address + ":" + defaultPort
|
||||||
|
}
|
||||||
|
return net.JoinHostPort(address, defaultPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
// In the case that both the host and port are empty, we'll use the
|
||||||
|
// default port.
|
||||||
|
if host == "" && port == "" {
|
||||||
|
return ":" + defaultPort
|
||||||
|
}
|
||||||
|
|
||||||
|
return address
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientAddressDialer creates a gRPC dialer that can also dial unix socket
|
// ClientAddressDialer creates a gRPC dialer that can also dial unix socket
|
||||||
|
Loading…
Reference in New Issue
Block a user