veyron: start the transition to using ListenX.

Change-Id: I2c7a9a7495367a89d25b0611357416309bfe9e17
diff --git a/runtimes/google/ipc/benchmarks/bmserver/main.go b/runtimes/google/ipc/benchmarks/bmserver/main.go
index 5d16296..f07afef 100644
--- a/runtimes/google/ipc/benchmarks/bmserver/main.go
+++ b/runtimes/google/ipc/benchmarks/bmserver/main.go
@@ -2,25 +2,17 @@
 package main
 
 import (
-	"flag"
-
-	"veyron.io/veyron/veyron/lib/signals"
-	"veyron.io/veyron/veyron/runtimes/google/ipc/benchmarks"
-
 	"veyron.io/veyron/veyron2/rt"
 	"veyron.io/veyron/veyron2/vlog"
-)
 
-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")
+	"veyron.io/veyron/veyron/lib/signals"
+	"veyron.io/veyron/veyron/profiles/roaming"
+	"veyron.io/veyron/veyron/runtimes/google/ipc/benchmarks"
 )
 
 func main() {
 	r := rt.Init()
-	addr, stop := benchmarks.StartServer(r, *protocol, *address)
+	addr, stop := benchmarks.StartServer(r, roaming.ListenSpec)
 	vlog.Infof("Listening on %s", addr)
 	defer stop()
 	<-signals.ShutdownOnSignals()
diff --git a/runtimes/google/ipc/benchmarks/ipc_test.go b/runtimes/google/ipc/benchmarks/ipc_test.go
index cfa7abb..9397219 100644
--- a/runtimes/google/ipc/benchmarks/ipc_test.go
+++ b/runtimes/google/ipc/benchmarks/ipc_test.go
@@ -3,15 +3,16 @@
 import (
 	"testing"
 
-	"veyron.io/veyron/veyron/runtimes/google/ipc/benchmarks"
-
 	"veyron.io/veyron/veyron2/rt"
+
+	"veyron.io/veyron/veyron/profiles"
+	"veyron.io/veyron/veyron/runtimes/google/ipc/benchmarks"
 )
 
 var runtime = rt.Init()
 
 func RunBenchmark(b *testing.B, payloadSize int) {
-	address, stop := benchmarks.StartServer(runtime, "tcp", "127.0.0.1:0")
+	address, stop := benchmarks.StartServer(runtime, profiles.LocalListenSpec)
 	ctx := runtime.NewContext()
 	defer stop()
 	benchmarks.CallEcho(ctx, address, 1, 1, nil) // Create VC
@@ -20,7 +21,7 @@
 }
 
 func RunStreamBenchmark(b *testing.B, rpcCount, messageCount, payloadSize int) {
-	address, stop := benchmarks.StartServer(runtime, "tcp", "127.0.0.1:0")
+	address, stop := benchmarks.StartServer(runtime, profiles.LocalListenSpec)
 	defer stop()
 	benchmarks.CallEchoStream(address, 1, 1, 1, nil) // Create VC
 	b.ResetTimer()
diff --git a/runtimes/google/ipc/benchmarks/server.go b/runtimes/google/ipc/benchmarks/server.go
index a4d7f41..86c28e9 100644
--- a/runtimes/google/ipc/benchmarks/server.go
+++ b/runtimes/google/ipc/benchmarks/server.go
@@ -32,12 +32,12 @@
 // StartServer starts a server that implements the Benchmark service. The
 // server listens to the given protocol and address, and returns the veyron
 // address of the server and a callback function to stop the server.
-func StartServer(runtime veyron2.Runtime, protocol, address string) (string, func()) {
+func StartServer(runtime veyron2.Runtime, listenSpec *ipc.ListenSpec) (string, func()) {
 	server, err := runtime.NewServer()
 	if err != nil {
 		vlog.Fatalf("NewServer failed: %v", err)
 	}
-	ep, err := server.Listen(protocol, address)
+	ep, err := server.ListenX(listenSpec)
 	if err != nil {
 		vlog.Fatalf("Listen failed: %v", err)
 	}
diff --git a/runtimes/google/ipc/debug_test.go b/runtimes/google/ipc/debug_test.go
index 872161d..6bcfc69 100644
--- a/runtimes/google/ipc/debug_test.go
+++ b/runtimes/google/ipc/debug_test.go
@@ -5,13 +5,14 @@
 	"sort"
 	"testing"
 
-	"veyron.io/veyron/veyron/lib/stats"
-	"veyron.io/veyron/veyron/runtimes/google/ipc/stream/manager"
-	tnaming "veyron.io/veyron/veyron/runtimes/google/testing/mocks/naming"
-
 	"veyron.io/veyron/veyron2/ipc"
 	"veyron.io/veyron/veyron2/naming"
 	"veyron.io/veyron/veyron2/services/mounttable/types"
+
+	"veyron.io/veyron/veyron/lib/stats"
+	"veyron.io/veyron/veyron/profiles"
+	"veyron.io/veyron/veyron/runtimes/google/ipc/stream/manager"
+	tnaming "veyron.io/veyron/veyron/runtimes/google/testing/mocks/naming"
 )
 
 func TestDebugServer(t *testing.T) {
@@ -24,7 +25,7 @@
 	}
 	defer server.Stop()
 	server.Serve("", ipc.LeafDispatcher(&testObject{}, nil))
-	ep, err := server.Listen("tcp4", "127.0.0.1:0")
+	ep, err := server.ListenX(profiles.LocalListenSpec)
 	if err != nil {
 		t.Fatalf("server.Listen failed: %v", err)
 	}
diff --git a/runtimes/google/ipc/full_test.go b/runtimes/google/ipc/full_test.go
index 979c98c..5d026f1 100644
--- a/runtimes/google/ipc/full_test.go
+++ b/runtimes/google/ipc/full_test.go
@@ -4,6 +4,7 @@
 	"errors"
 	"fmt"
 	"io"
+	"net"
 	"os"
 	"reflect"
 	"strings"
@@ -14,6 +15,7 @@
 	_ "veyron.io/veyron/veyron/lib/testutil"
 	"veyron.io/veyron/veyron/lib/testutil/blackbox"
 	tsecurity "veyron.io/veyron/veyron/lib/testutil/security"
+	"veyron.io/veyron/veyron/profiles"
 	imanager "veyron.io/veyron/veyron/runtimes/google/ipc/stream/manager"
 	"veyron.io/veyron/veyron/runtimes/google/ipc/stream/proxy"
 	"veyron.io/veyron/veyron/runtimes/google/ipc/stream/vc"
@@ -179,7 +181,7 @@
 		t.Errorf("InternalNewServer failed: %v", err)
 	}
 	vlog.VI(1).Info("server.Listen")
-	ep, err := server.Listen("tcp", "127.0.0.1:0")
+	ep, err := server.ListenX(profiles.LocalListenSpec)
 	if err != nil {
 		t.Errorf("server.Listen failed: %v", err)
 	}
@@ -317,7 +319,7 @@
 	if err != nil {
 		t.Errorf("InternalNewServer failed: %v", err)
 	}
-	_, err = server.Listen("tcp", "127.0.0.1:0")
+	_, err = server.ListenX(profiles.LocalListenSpec)
 	if err != nil {
 		t.Errorf("server.Listen failed: %v", err)
 	}
@@ -626,7 +628,7 @@
 		t.Fatal(err)
 	}
 	defer server.Stop()
-	if _, err := server.Listen("tcp", "127.0.0.1:0"); err != nil {
+	if _, err := server.ListenX(profiles.LocalListenSpec); err != nil {
 		t.Fatal(err)
 	}
 
@@ -1037,11 +1039,6 @@
 	}
 }
 
-/*
- * TODO(cnicolaou): temporarily remove these until we move ListenX over
- * to be Listen.
- */
-/*
 func TestPreferredAddress(t *testing.T) {
 	sm := imanager.InternalNew(naming.FixedRoutingID(0x555555555))
 	defer sm.Shutdown()
@@ -1051,12 +1048,15 @@
 		a.IP = net.ParseIP("1.1.1.1")
 		return a, nil
 	}
-	server, err := InternalNewServer(testContext(), sm, ns, vc.FixedLocalID(serverID), &veyron2.AddressChooserOpt{pa})
+	server, err := InternalNewServer(testContext(), sm, ns, vc.FixedLocalID(serverID))
 	if err != nil {
 		t.Errorf("InternalNewServer failed: %v", err)
 	}
 	defer server.Stop()
-	ep, err := server.Listen("tcp4", ":0")
+	spec := *profiles.LocalListenSpec
+	spec.Address = ":0"
+	spec.AddressChooser = pa
+	ep, err := server.ListenX(&spec)
 	iep := ep.(*inaming.Endpoint)
 	host, _, err := net.SplitHostPort(iep.Address)
 	if err != nil {
@@ -1066,7 +1066,7 @@
 		t.Errorf("got %q, want %q", got, want)
 	}
 	// Won't override the specified address.
-	ep, err = server.Listen("tcp4", "127.0.0.1:0")
+	ep, err = server.ListenX(profiles.LocalListenSpec)
 	iep = ep.(*inaming.Endpoint)
 	host, _, err = net.SplitHostPort(iep.Address)
 	if err != nil {
@@ -1081,25 +1081,31 @@
 	sm := imanager.InternalNew(naming.FixedRoutingID(0x555555555))
 	defer sm.Shutdown()
 	ns := tnaming.NewSimpleNamespace()
-	paerr := func(string, []net.Addr) (net.Addr, error) {
+	paerr := func(_ string, a []net.Addr) (net.Addr, error) {
 		return nil, fmt.Errorf("oops")
 	}
-	server, err := InternalNewServer(testContext(), sm, ns, vc.FixedLocalID(serverID), &veyron2.AddressChooserOpt{paerr})
+	server, err := InternalNewServer(testContext(), sm, ns, vc.FixedLocalID(serverID))
 	if err != nil {
 		t.Errorf("InternalNewServer failed: %v", err)
 	}
 	defer server.Stop()
-	ep, err := server.Listen("tcp4", ":0")
+	spec := *profiles.LocalListenSpec
+	spec.Address = ":0"
+	spec.AddressChooser = paerr
+	ep, err := server.ListenX(&spec)
 	iep := ep.(*inaming.Endpoint)
 	host, _, err := net.SplitHostPort(iep.Address)
 	if err != nil {
 		t.Errorf("unexpected error: %s", err)
 	}
-	if got, want := host, "0.0.0.0"; got != want {
-		t.Errorf("got %q, want %q", got, want)
+	ip := net.ParseIP(host)
+	if ip == nil {
+		t.Fatalf("failed to parse IP address: %q", host)
+	}
+	if !ip.IsUnspecified() {
+		t.Errorf("IP: %q is not unspecified", ip)
 	}
 }
-*/
 
 type proxyHandle struct {
 	ns      naming.Namespace
@@ -1163,7 +1169,9 @@
 		t.Fatal(err)
 	}
 	defer proxy.Stop()
-	if _, err := server.Listen(inaming.Network, "proxy"); err != nil {
+	spec := *profiles.LocalListenSpec
+	spec.Proxy = "proxy"
+	if _, err := server.ListenX(&spec); err != nil {
 		t.Fatal(err)
 	}
 	if err := server.Serve("mountpoint/server", testServerDisp{&testServer{}}); err != nil {
@@ -1230,7 +1238,9 @@
 	if err := server.Serve("server", disp); err != nil {
 		vlog.Fatalf("server.Register failed: %v", err)
 	}
-	ep, err := server.Listen("tcp", argv[0])
+	spec := *profiles.LocalListenSpec
+	spec.Address = argv[0]
+	ep, err := server.ListenX(&spec)
 	if err != nil {
 		vlog.Fatalf("server.Listen failed: %v", err)
 	}
diff --git a/runtimes/google/ipc/server.go b/runtimes/google/ipc/server.go
index 4167dd1..2de310a 100644
--- a/runtimes/google/ipc/server.go
+++ b/runtimes/google/ipc/server.go
@@ -300,11 +300,10 @@
 		if err != nil {
 			return nil, fmt.Errorf("failed to fork stream %q: %s", streamName, err)
 		}
-
 		_, port, _ := net.SplitHostPort(ep.Address)
 		dhcpl := &dhcpListener{ep: ep, port: port, ch: ch, name: streamName, publisher: publisher}
 
-		// We have a gorouting to listen for dhcp changes.
+		// We have a goroutine to listen for dhcp changes.
 		s.active.Add(1)
 		// goroutine to listen for address changes.
 		go func(dl *dhcpListener) {
@@ -332,16 +331,17 @@
 			vlog.Errorf("ipc: Listen on %v %v failed: %v", protocol, address, err)
 			return nil, err
 		}
-		// We have a goroutine for listen on proxy connections.
+		// We have a goroutine for listening on proxy connections.
 		s.active.Add(1)
 		go func(ln stream.Listener, ep naming.Endpoint, proxy string) {
 			s.proxyListenLoop(ln, ep, proxy)
 			s.active.Done()
 		}(pln, pep, listenSpec.Proxy)
+		s.publisher.AddServer(s.publishEP(pep))
+	} else {
+		s.publisher.AddServer(s.publishEP(ep))
 	}
-
 	s.Unlock()
-	s.publisher.AddServer(s.publishEP(ep))
 	return ep, nil
 }
 
diff --git a/runtimes/google/ipc/stream/proxy/proxy.go b/runtimes/google/ipc/stream/proxy/proxy.go
index b0d2147..f4b6b7a 100644
--- a/runtimes/google/ipc/stream/proxy/proxy.go
+++ b/runtimes/google/ipc/stream/proxy/proxy.go
@@ -5,6 +5,7 @@
 	"fmt"
 	"net"
 	"sync"
+
 	"veyron.io/veyron/veyron/runtimes/google/ipc/stream/id"
 	"veyron.io/veyron/veyron/runtimes/google/ipc/stream/message"
 	"veyron.io/veyron/veyron/runtimes/google/ipc/stream/vc"
@@ -13,6 +14,7 @@
 	"veyron.io/veyron/veyron/runtimes/google/lib/bqueue/drrqueue"
 	"veyron.io/veyron/veyron/runtimes/google/lib/iobuf"
 	"veyron.io/veyron/veyron/runtimes/google/lib/upcqueue"
+
 	"veyron.io/veyron/veyron2/naming"
 	"veyron.io/veyron/veyron2/security"
 	"veyron.io/veyron/veyron2/verror"
diff --git a/runtimes/google/ipc/stream/proxy/proxy_test.go b/runtimes/google/ipc/stream/proxy/proxy_test.go
index ff9eb2b..8803604 100644
--- a/runtimes/google/ipc/stream/proxy/proxy_test.go
+++ b/runtimes/google/ipc/stream/proxy/proxy_test.go
@@ -8,15 +8,15 @@
 	"strings"
 	"testing"
 
+	"veyron.io/veyron/veyron2/ipc/stream"
+	"veyron.io/veyron/veyron2/naming"
+	"veyron.io/veyron/veyron2/security"
+
 	_ "veyron.io/veyron/veyron/lib/testutil"
 	"veyron.io/veyron/veyron/runtimes/google/ipc/stream/manager"
 	"veyron.io/veyron/veyron/runtimes/google/ipc/stream/proxy"
 	"veyron.io/veyron/veyron/runtimes/google/ipc/stream/vc"
 	isecurity "veyron.io/veyron/veyron/runtimes/google/security"
-
-	"veyron.io/veyron/veyron2/ipc/stream"
-	"veyron.io/veyron/veyron2/naming"
-	"veyron.io/veyron/veyron2/security"
 )
 
 func newID(name string) security.PrivateID {
diff --git a/runtimes/google/rt/ipc_test.go b/runtimes/google/rt/ipc_test.go
index 16da093..3f97b45 100644
--- a/runtimes/google/rt/ipc_test.go
+++ b/runtimes/google/rt/ipc_test.go
@@ -7,15 +7,16 @@
 	"testing"
 	"time"
 
-	_ "veyron.io/veyron/veyron/lib/testutil"
-	isecurity "veyron.io/veyron/veyron/runtimes/google/security"
-	vsecurity "veyron.io/veyron/veyron/security"
-
 	"veyron.io/veyron/veyron2"
 	"veyron.io/veyron/veyron2/ipc"
 	"veyron.io/veyron/veyron2/naming"
 	"veyron.io/veyron/veyron2/rt"
 	"veyron.io/veyron/veyron2/security"
+
+	_ "veyron.io/veyron/veyron/lib/testutil"
+	"veyron.io/veyron/veyron/profiles"
+	isecurity "veyron.io/veyron/veyron/runtimes/google/security"
+	vsecurity "veyron.io/veyron/veyron/security"
 )
 
 type testService struct{}
@@ -155,7 +156,7 @@
 			t.Errorf("serverR.NewServer(...) failed: %s", err)
 			continue
 		}
-		endpoint, err := server.Listen("tcp", "127.0.0.1:0")
+		endpoint, err := server.ListenX(profiles.LocalListenSpec)
 		if err != nil {
 			t.Errorf("error listening to service: ", err)
 			continue
diff --git a/runtimes/google/rt/mgmt.go b/runtimes/google/rt/mgmt.go
index 95b11d3..86e4802 100644
--- a/runtimes/google/rt/mgmt.go
+++ b/runtimes/google/rt/mgmt.go
@@ -6,13 +6,14 @@
 	"sync"
 	"time"
 
-	"veyron.io/veyron/veyron/runtimes/google/appcycle"
-	"veyron.io/veyron/veyron/services/mgmt/lib/exec"
-
 	"veyron.io/veyron/veyron2"
 	"veyron.io/veyron/veyron2/ipc"
 	"veyron.io/veyron/veyron2/mgmt"
 	"veyron.io/veyron/veyron2/naming"
+
+	"veyron.io/veyron/veyron/profiles"
+	"veyron.io/veyron/veyron/runtimes/google/appcycle"
+	"veyron.io/veyron/veyron/services/mgmt/lib/exec"
 )
 
 type mgmtImpl struct {
@@ -53,7 +54,7 @@
 	}
 	// TODO(caprita): We should pick the address to listen on from config.
 	var ep naming.Endpoint
-	if ep, err = m.server.Listen("tcp", "127.0.0.1:0"); err != nil {
+	if ep, err = m.server.ListenX(profiles.LocalListenSpec); err != nil {
 		return err
 	}
 	if err := m.server.Serve("", ipc.LeafDispatcher(appcycle.NewServerAppCycle(m), nil)); err != nil {
diff --git a/runtimes/google/rt/mgmt_test.go b/runtimes/google/rt/mgmt_test.go
index d11e082..df084f2 100644
--- a/runtimes/google/rt/mgmt_test.go
+++ b/runtimes/google/rt/mgmt_test.go
@@ -16,6 +16,7 @@
 	_ "veyron.io/veyron/veyron/lib/testutil"
 	"veyron.io/veyron/veyron/lib/testutil/blackbox"
 	"veyron.io/veyron/veyron/lib/testutil/security"
+	"veyron.io/veyron/veyron/profiles"
 	"veyron.io/veyron/veyron/runtimes/google/rt"
 	vflag "veyron.io/veyron/veyron/security/flag"
 	"veyron.io/veyron/veyron/services/mgmt/node"
@@ -247,7 +248,7 @@
 	ch := make(chan string)
 
 	var ep naming.Endpoint
-	if ep, err = server.Listen("tcp", "127.0.0.1:0"); err != nil {
+	if ep, err = server.ListenX(profiles.LocalListenSpec); err != nil {
 		t.Fatalf("Got error: %v", err)
 	}
 	if err := server.Serve("", ipc.LeafDispatcher(node.NewServerConfig(&configServer{ch}), vflag.NewAuthorizerOrDie())); err != nil {