veyron/go/src/...: replace "127.0.0.1:0" and "localhost:0" with ":0" in address flag default for binaries, and make sure to override --address to "127.0.0.1:0" in tests (since GCE requires ipv4).

Change-Id: Id12564f3e49fe57807fcf4c224cec8fb5e66c900
diff --git a/runtimes/google/ipc/benchmarks/bmserver/main.go b/runtimes/google/ipc/benchmarks/bmserver/main.go
index 017ad69..d0e5d25 100644
--- a/runtimes/google/ipc/benchmarks/bmserver/main.go
+++ b/runtimes/google/ipc/benchmarks/bmserver/main.go
@@ -12,8 +12,10 @@
 )
 
 var (
-	address  = flag.String("address", ":0", "address to listen on")
+	// TODO(rthellend): Remove the protocol and address flags when the config
+	// manager is working.
 	protocol = flag.String("protocol", "tcp", "protocol to listen on")
+	address  = flag.String("address", ":0", "address to listen on")
 )
 
 func main() {
diff --git a/runtimes/google/ipc/full_test.go b/runtimes/google/ipc/full_test.go
index 0020de0..5b87cbb 100644
--- a/runtimes/google/ipc/full_test.go
+++ b/runtimes/google/ipc/full_test.go
@@ -265,7 +265,7 @@
 		t.Errorf("InternalNewServer failed: %v", err)
 	}
 	vlog.VI(1).Info("server.Listen")
-	ep, err := server.Listen("tcp", "localhost:0")
+	ep, err := server.Listen("tcp", "127.0.0.1:0")
 	if err != nil {
 		t.Errorf("server.Listen failed: %v", err)
 	}
@@ -403,7 +403,7 @@
 	if err != nil {
 		t.Errorf("InternalNewServer failed: %v", err)
 	}
-	_, err = server.Listen("tcp", "localhost:0")
+	_, err = server.Listen("tcp", "127.0.0.1:0")
 	if err != nil {
 		t.Errorf("server.Listen failed: %v", err)
 	}
@@ -979,12 +979,12 @@
 			t.Errorf("InternalNewServer failed: %v", err)
 			continue
 		}
-		if _, err := server.Listen("tcp", "localhost:0"); err != nil {
+		if _, err := server.Listen("tcp", "127.0.0.1:0"); err != nil {
 			t.Errorf("server.Listen failed: %v", err)
 			server.Stop()
 			continue
 		}
-		if _, err := server.Listen("tcp", "localhost:0"); err != nil {
+		if _, err := server.Listen("tcp", "127.0.0.1:0"); err != nil {
 			t.Errorf("server.Listen failed: %v", err)
 			server.Stop()
 			continue
@@ -1216,7 +1216,7 @@
 	if err != nil {
 		vlog.Fatal(err)
 	}
-	proxy, err := proxy.New(rid, nil, "tcp4", "127.0.0.1:0", "")
+	proxy, err := proxy.New(rid, nil, "tcp", "127.0.0.1:0", "")
 	if err != nil {
 		vlog.Fatal(err)
 	}
diff --git a/runtimes/google/ipc/stream/benchmark/throughput_flow.go b/runtimes/google/ipc/stream/benchmark/throughput_flow.go
index 7c1ea25..8f2392c 100644
--- a/runtimes/google/ipc/stream/benchmark/throughput_flow.go
+++ b/runtimes/google/ipc/stream/benchmark/throughput_flow.go
@@ -27,7 +27,7 @@
 func createListeners(mode veyron2.VCSecurityLevel, m stream.Manager, N int) (servers []listener, err error) {
 	for i := 0; i < N; i++ {
 		var l listener
-		if l.ln, l.ep, err = m.Listen("tcp", "localhost:0", mode); err != nil {
+		if l.ln, l.ep, err = m.Listen("tcp", "127.0.0.1:0", mode); err != nil {
 			return
 		}
 		servers = append(servers, l)
diff --git a/runtimes/google/ipc/stream/manager/manager_test.go b/runtimes/google/ipc/stream/manager/manager_test.go
index 84a78ee..6c78e89 100644
--- a/runtimes/google/ipc/stream/manager/manager_test.go
+++ b/runtimes/google/ipc/stream/manager/manager_test.go
@@ -45,7 +45,7 @@
 	server := InternalNew(naming.FixedRoutingID(0x55555555))
 	client := InternalNew(naming.FixedRoutingID(0xcccccccc))
 
-	ln, ep, err := server.Listen("tcp", "localhost:0")
+	ln, ep, err := server.Listen("tcp", "127.0.0.1:0")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -133,7 +133,7 @@
 	serverID := newID("server")
 	// VCSecurityLevel is intentionally not provided to Listen - to test
 	// default behavior.
-	ln, ep, err := server.Listen("tcp", "localhost:0", vc.FixedLocalID(serverID))
+	ln, ep, err := server.Listen("tcp", "127.0.0.1:0", vc.FixedLocalID(serverID))
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -191,11 +191,10 @@
 
 func TestListenEndpoints(t *testing.T) {
 	server := InternalNew(naming.FixedRoutingID(0xcafe))
-	ln1, ep1, err1 := server.Listen("tcp", "localhost:0")
-	ln2, ep2, err2 := server.Listen("tcp", "localhost:0")
-	// Since "localhost:0" was used as the network address, a random port
-	// will be assigned in each case. The endpoint should include that
-	// random port.
+	ln1, ep1, err1 := server.Listen("tcp", "127.0.0.1:0")
+	ln2, ep2, err2 := server.Listen("tcp", "127.0.0.1:0")
+	// Since "127.0.0.1:0" was used as the network address, a random port will be
+	// assigned in each case. The endpoint should include that random port.
 	if err1 != nil {
 		t.Error(err1)
 	}
@@ -231,7 +230,7 @@
 func TestCloseListener(t *testing.T) {
 	server := InternalNew(naming.FixedRoutingID(0x5e97e9))
 
-	ln, ep, err := server.Listen("tcp", "localhost:0")
+	ln, ep, err := server.Listen("tcp", "127.0.0.1:0")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -250,7 +249,7 @@
 
 func TestShutdown(t *testing.T) {
 	server := InternalNew(naming.FixedRoutingID(0x5e97e9))
-	ln, _, err := server.Listen("tcp", "localhost:0")
+	ln, _, err := server.Listen("tcp", "127.0.0.1:0")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -260,7 +259,7 @@
 		t.Errorf("expecting %d listeners, got %d for %s", n, expect, debugString(server))
 	}
 	server.Shutdown()
-	if _, _, err := server.Listen("tcp", "localhost:0"); err == nil {
+	if _, _, err := server.Listen("tcp", "127.0.0.1:0"); err == nil {
 		t.Error("server should have shut down")
 	}
 	if n, expect := numListeners(server), 0; n != expect {
@@ -272,7 +271,7 @@
 	server := InternalNew(naming.FixedRoutingID(0x55555555))
 	client := InternalNew(naming.FixedRoutingID(0xcccccccc))
 
-	ln, ep, err := server.Listen("tcp", "localhost:0")
+	ln, ep, err := server.Listen("tcp", "127.0.0.1:0")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -295,7 +294,7 @@
 
 func TestSessionTicketCache(t *testing.T) {
 	server := InternalNew(naming.FixedRoutingID(0x55555555))
-	_, ep, err := server.Listen("tcp", "localhost:0", vc.FixedLocalID(newID("server")))
+	_, ep, err := server.Listen("tcp", "127.0.0.1:0", vc.FixedLocalID(newID("server")))
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -319,7 +318,7 @@
 
 	// Have the server read from each flow and write to rchan.
 	rchan := make(chan string)
-	ln, ep, err := server.Listen("tcp", "localhost:0", vc.FixedLocalID(newID("server")))
+	ln, ep, err := server.Listen("tcp", "127.0.0.1:0", vc.FixedLocalID(newID("server")))
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -393,9 +392,9 @@
 	server := InternalNew(naming.FixedRoutingID(0x55555555))
 	client := InternalNew(naming.FixedRoutingID(0xcccccccc))
 
-	// Using "tcp4" instead of "tcp" because the latter can end up with
-	// IPv6 addresses and our Google Compute Engine integration test
-	// machines cannot resolve IPv6 addresses.
+	// Using "tcp4" instead of "tcp" because the latter can end up with IPv6
+	// addresses and our Google Compute Engine integration test machines cannot
+	// resolve IPv6 addresses.
 	// As of April 2014, https://developers.google.com/compute/docs/networking
 	// said that IPv6 is not yet supported.
 	ln, ep, err := server.Listen("tcp4", "127.0.0.1:0")
@@ -404,14 +403,13 @@
 	}
 	go acceptLoop(ln)
 
-	// We'd like an endpoint that contains an address that's different
-	// to the one used for the connection. In practice this is awkward
-	// to achieve since we don't want to listen on ":0" since that will
-	// annoy firewalls. Instead we listen on 127.0.0.1 and we fabricate an
-	// endpoint that doesn't contain 127.0.0.1 by using ":0" to create it.
-	// This leads to an endpoint such that the address
-	// encoded in the endpoint (e.g. "0.0.0.0:55324") is different from
-	// address of the connection (e.g. "127.0.0.1:55324").
+	// We'd like an endpoint that contains an address that's different than the
+	// one used for the connection. In practice this is awkward to achieve since
+	// we don't want to listen on ":0" since that will annoy firewalls. Instead we
+	// listen on 127.0.0.1 and we fabricate an endpoint that doesn't contain
+	// 127.0.0.1 by using ":0" to create it. This leads to an endpoint such that
+	// the address encoded in the endpoint (e.g. "0.0.0.0:55324") is different
+	// from the address of the connection (e.g. "127.0.0.1:55324").
 	_, port, _ := net.SplitHostPort(ep.Addr().String())
 	nep := version.Endpoint(ep.Addr().Network(), net.JoinHostPort("", port), ep.RoutingID())
 
diff --git a/runtimes/google/ipc/stream/proxy/proxy_test.go b/runtimes/google/ipc/stream/proxy/proxy_test.go
index c5ccf58..cd1d7b4 100644
--- a/runtimes/google/ipc/stream/proxy/proxy_test.go
+++ b/runtimes/google/ipc/stream/proxy/proxy_test.go
@@ -28,12 +28,7 @@
 }
 
 func TestProxy(t *testing.T) {
-	// Using "tcp4" instead of "tcp" because the latter can end up with
-	// IPv6 addresses and our Google Compute Engine integration test
-	// machines cannot resolve IPv6 addresses.
-	// As of April 2014, https://developers.google.com/compute/docs/networking
-	// said that IPv6 is not yet supported.
-	proxy, err := proxy.New(naming.FixedRoutingID(0xbbbbbbbbbbbbbbbb), nil, "tcp4", "127.0.0.1:0", "")
+	proxy, err := proxy.New(naming.FixedRoutingID(0xbbbbbbbbbbbbbbbb), nil, "tcp", "127.0.0.1:0", "")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -93,7 +88,7 @@
 }
 
 func TestDuplicateRoutingID(t *testing.T) {
-	proxy, err := proxy.New(naming.FixedRoutingID(0xbbbbbbbbbbbbbbbb), nil, "tcp4", "127.0.0.1:0", "")
+	proxy, err := proxy.New(naming.FixedRoutingID(0xbbbbbbbbbbbbbbbb), nil, "tcp", "127.0.0.1:0", "")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -121,7 +116,7 @@
 
 func TestProxyIdentity(t *testing.T) {
 	proxyID := newID("proxy")
-	proxy, err := proxy.New(naming.FixedRoutingID(0xbbbbbbbbbbbbbbbb), proxyID, "tcp4", "127.0.0.1:0", "")
+	proxy, err := proxy.New(naming.FixedRoutingID(0xbbbbbbbbbbbbbbbb), proxyID, "tcp", "127.0.0.1:0", "")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -145,7 +140,7 @@
 }
 
 func TestServerIdentity(t *testing.T) {
-	proxy, err := proxy.New(naming.FixedRoutingID(0xbbbbbbbbbbbbbbbb), nil, "tcp4", "127.0.0.1:0", "")
+	proxy, err := proxy.New(naming.FixedRoutingID(0xbbbbbbbbbbbbbbbb), nil, "tcp", "127.0.0.1:0", "")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -185,7 +180,7 @@
 }
 
 func TestHostPort(t *testing.T) {
-	proxy, err := proxy.New(naming.FixedRoutingID(0xbbbbbbbbbbbbbbbb), nil, "tcp4", "127.0.0.1:0", "")
+	proxy, err := proxy.New(naming.FixedRoutingID(0xbbbbbbbbbbbbbbbb), nil, "tcp", "127.0.0.1:0", "")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -202,7 +197,7 @@
 }
 
 func TestClientBecomesServer(t *testing.T) {
-	proxy, err := proxy.New(naming.FixedRoutingID(0xbbbbbbbbbbbbbbbb), nil, "tcp4", "127.0.0.1:0", "")
+	proxy, err := proxy.New(naming.FixedRoutingID(0xbbbbbbbbbbbbbbbb), nil, "tcp", "127.0.0.1:0", "")
 	if err != nil {
 		t.Fatal(err)
 	}
diff --git a/runtimes/google/rt/http.go b/runtimes/google/rt/http.go
index c05e8cd..a890dac 100644
--- a/runtimes/google/rt/http.go
+++ b/runtimes/google/rt/http.go
@@ -26,12 +26,12 @@
 }
 
 func (rt *vrt) initHTTPDebugServer() {
-	// TODO(ashankar,cnicolaou): Change the default debug address to
-	// the empty string.
-	// In March 2014 this was temporarily set to "127.0.0.1:0" so that the debugging
-	// HTTP server always runs, which was useful during initial veyron
-	// development. We restrict it to localhost to avoid annoying firewall
-	// warnings and to provide a modicum of security.
+	// TODO(ashankar,cnicolaou): Change the default debug address to the empty
+	// string.
+	// In March 2014 this was temporarily set to "127.0.0.1:0" so that the
+	// debugging HTTP server always runs, which was useful during initial veyron
+	// development. We restrict it in this way to avoid annoying firewall warnings
+	// and to provide a modicum of security.
 	rt.debug.addr = "127.0.0.1:0"
 	rt.debug.mux = http.NewServeMux()
 }
diff --git a/runtimes/google/vsync/vsyncd/main.go b/runtimes/google/vsync/vsyncd/main.go
index 66c8633..a915550 100644
--- a/runtimes/google/vsync/vsyncd/main.go
+++ b/runtimes/google/vsync/vsyncd/main.go
@@ -12,18 +12,23 @@
 	"veyron2/vlog"
 )
 
-func main() {
-	peerEndpoints := flag.String("peers", "",
-		"comma separated list of endpoints of the vsync peer")
-	peerDeviceIDs := flag.String("peerids", "",
-		"comma separated list of deviceids of the vsync peer")
-	devid := flag.String("devid", "", "Device ID")
-	storePath := flag.String("store", os.TempDir(), "path to store files")
-	vstoreEndpoint := flag.String("vstore", "", "endpoint of the local Veyron store")
-	// TODO(rthellend): Remove the address flag when the config manager is working.
-	address := flag.String("address", ":0", "address to listen on")
-	syncTick := flag.Duration("synctick", 0, "clock tick duration for sync with a peer (e.g. 10s)")
+var (
+	// TODO(rthellend): Remove the protocol and address flags when the config
+	// manager is working.
+	protocol = flag.String("protocol", "tcp", "protocol to listen on")
+	address  = flag.String("address", ":0", "address to listen on")
 
+	peerEndpoints = flag.String("peers", "",
+		"comma separated list of endpoints of the vsync peer")
+	peerDeviceIDs = flag.String("peerids", "",
+		"comma separated list of deviceids of the vsync peer")
+	devid          = flag.String("devid", "", "Device ID")
+	storePath      = flag.String("store", os.TempDir(), "path to store files")
+	vstoreEndpoint = flag.String("vstore", "", "endpoint of the local Veyron store")
+	syncTick       = flag.Duration("synctick", 0, "clock tick duration for sync with a peer (e.g. 10s)")
+)
+
+func main() {
 	flag.Parse()
 	if *devid == "" {
 		vlog.Fatalf("syncd:: --devid needs to be specified")
@@ -50,7 +55,7 @@
 	syncDisp := vsync.NewSyncDispatcher(syncService, auth)
 
 	// Create an endpoint and begin listening.
-	if endpoint, err := s.Listen("tcp", *address); err == nil {
+	if endpoint, err := s.Listen(*protocol, *address); err == nil {
 		vlog.VI(0).Infof("syncd:: Listening now at %v", endpoint)
 	} else {
 		vlog.Fatalf("syncd:: error listening to service: err %v", err)