From bfeed190ea335ec8d7158ebf8a53edfc8d918b5c Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Sat, 31 Aug 2013 21:53:08 -0700 Subject: [PATCH] feat(etcd): Default server listen and client listen to advertised IPs Map the advertised IP to the listening IP by default. This will make things nicer for the user. --- etcd.go | 4 ++-- util.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/etcd.go b/etcd.go index 0bc3ef4ed..46546e8cc 100644 --- a/etcd.go +++ b/etcd.go @@ -52,8 +52,8 @@ func init() { flag.StringVar(&argInfo.Name, "n", "default-name", "the node name (required)") flag.StringVar(&argInfo.EtcdURL, "c", "127.0.0.1:4001", "the advertised public hostname:port for etcd client communication") flag.StringVar(&argInfo.RaftURL, "s", "127.0.0.1:7001", "the advertised public hostname:port for raft server communication") - flag.StringVar(&argInfo.EtcdListenHost, "cl", "127.0.0.1", "the listening hostname for etcd client communication") - flag.StringVar(&argInfo.RaftListenHost, "sl", "127.0.0.1", "the listening hostname for raft server communication") + flag.StringVar(&argInfo.EtcdListenHost, "cl", "", "the listening hostname for etcd client communication (defaults to advertised ip)") + flag.StringVar(&argInfo.RaftListenHost, "sl", "", "the listening hostname for raft server communication (defaults to advertised ip)") flag.StringVar(&argInfo.WebURL, "w", "", "the hostname:port of web interface") flag.StringVar(&argInfo.RaftTLS.CAFile, "serverCAFile", "", "the path of the CAFile") diff --git a/util.go b/util.go index 8ddaa93cc..22cbed641 100644 --- a/util.go +++ b/util.go @@ -114,11 +114,16 @@ func sanitizeListenHost(listen string, advertised string) string { fatal(err) } - _, aport, err := net.SplitHostPort(aurl.Host) + ahost, aport, err := net.SplitHostPort(aurl.Host) if err != nil { fatal(err) } + // If the listen host isn't set use the advertised host + if listen == "" { + listen = ahost + } + return net.JoinHostPort(listen, aport) }