No more tcp/ws switching now that we allow endpoints without a protocol.

MultiPart: 3/3

Change-Id: I3ab21cd787bd623a61b3cee3cc53374e76175661
diff --git a/services/wsprd/browspr/browspr.go b/services/wsprd/browspr/browspr.go
index 0b8870c..c584e21 100644
--- a/services/wsprd/browspr/browspr.go
+++ b/services/wsprd/browspr/browspr.go
@@ -13,15 +13,9 @@
 	"v.io/core/veyron2/vlog"
 	"v.io/core/veyron2/vtrace"
 	"v.io/wspr/veyron/services/wsprd/account"
-	"v.io/wspr/veyron/services/wsprd/lib"
-	"v.io/wspr/veyron/services/wsprd/namespace"
 	"v.io/wspr/veyron/services/wsprd/principal"
 )
 
-func init() {
-	namespace.EpFormatter = lib.EndpointsToWs
-}
-
 // Browspr is an intermediary between our javascript code and the veyron
 // network that allows our javascript library to use veyron.
 type Browspr struct {
diff --git a/services/wsprd/browspr/browspr_test.go b/services/wsprd/browspr/browspr_test.go
index 68e1cf2..6ebeceb 100644
--- a/services/wsprd/browspr/browspr_test.go
+++ b/services/wsprd/browspr/browspr_test.go
@@ -14,7 +14,6 @@
 	"v.io/core/veyron2/ipc"
 	"v.io/core/veyron2/naming"
 	"v.io/core/veyron2/options"
-	"v.io/core/veyron2/vlog"
 	"v.io/wspr/veyron/services/wsprd/app"
 	"v.io/wspr/veyron/services/wsprd/lib"
 )
@@ -90,8 +89,8 @@
 		t.Fatalf("Failed to start mounttable server: %v", err)
 	}
 	defer mtServer.Stop()
-	tcpNamespaceRoot := "/" + mtEndpoint.String()
-	if err := veyron2.GetNamespace(ctx).SetRoots(tcpNamespaceRoot); err != nil {
+	root := mtEndpoint.Name()
+	if err := veyron2.GetNamespace(ctx).SetRoots(root); err != nil {
 		t.Fatalf("Failed to set namespace roots: %v", err)
 	}
 
@@ -106,7 +105,7 @@
 	if err != nil {
 		t.Fatalf("Error fetching published names: %v", err)
 	}
-	if len(names) != 1 || names[0] != tcpNamespaceRoot+"/"+mockServerName {
+	if len(names) != 1 || names[0] != naming.JoinAddressName(root, mockServerName) {
 		t.Fatalf("Incorrectly mounted server. Names: %v", names)
 	}
 	mountEntry, err := veyron2.GetNamespace(ctx).Resolve(ctx, mockServerName)
@@ -139,15 +138,11 @@
 		receivedResponse <- true
 	}
 
-	wsNamespaceRoots, err := lib.EndpointsToWs([]string{tcpNamespaceRoot})
-	if err != nil {
-		vlog.Fatal(err)
-	}
-	veyron2.GetNamespace(ctx).SetRoots(wsNamespaceRoots...)
-	browspr := NewBrowspr(ctx, postMessageHandler, &spec, "/mock:1234/identd", wsNamespaceRoots)
+	veyron2.GetNamespace(ctx).SetRoots(root)
+	browspr := NewBrowspr(ctx, postMessageHandler, &spec, "/mock:1234/identd", []string{root})
 
 	// browspr sets its namespace root to use the "ws" protocol, but we want to force "tcp" here.
-	browspr.namespaceRoots = []string{tcpNamespaceRoot}
+	browspr.namespaceRoots = []string{root}
 
 	browspr.accountManager.SetMockBlesser(newMockBlesserService(veyron2.GetPrincipal(ctx)))
 
diff --git a/services/wsprd/browspr/main/main_nacl.go b/services/wsprd/browspr/main/main_nacl.go
index f432fdf..b37d60d 100644
--- a/services/wsprd/browspr/main/main_nacl.go
+++ b/services/wsprd/browspr/main/main_nacl.go
@@ -18,7 +18,6 @@
 	"v.io/core/veyron2/vlog"
 	"v.io/wspr/veyron/services/wsprd/browspr"
 	"v.io/wspr/veyron/services/wsprd/channel/channel_nacl"
-	"v.io/wspr/veyron/services/wsprd/lib"
 )
 
 func main() {
@@ -225,18 +224,15 @@
 
 	// TODO(ataly, bprosnitz, caprita): The runtime MUST be cleaned up
 	// after use. Figure out the appropriate place to add the Cleanup call.
-	wsNamespaceRoots, err := lib.EndpointsToWs([]string{msg.NamespaceRoot})
-	if err != nil {
-		return nil, err
-	}
-	veyron2.GetNamespace(ctx).SetRoots(wsNamespaceRoots...)
+
+	veyron2.GetNamespace(ctx).SetRoots(msg.NamespaceRoot)
 
 	fmt.Printf("Starting browspr with config: proxy=%q mounttable=%q identityd=%q identitydBlessingRoot=%q ", msg.Proxy, msg.NamespaceRoot, msg.Identityd, msg.IdentitydBlessingRoot)
 	inst.browspr = browspr.NewBrowspr(ctx,
 		inst.BrowsprOutgoingPostMessage,
 		&listenSpec,
 		msg.Identityd,
-		wsNamespaceRoots)
+		[]string{msg.NamespaceRoot})
 
 	// Add the rpc handlers that depend on inst.browspr.
 	inst.channel.RegisterRequestHandler("auth:create-account", inst.browspr.HandleAuthCreateAccountRpc)
diff --git a/services/wsprd/lib/ws_endpoint.go b/services/wsprd/lib/ws_endpoint.go
deleted file mode 100644
index 9479c7b..0000000
--- a/services/wsprd/lib/ws_endpoint.go
+++ /dev/null
@@ -1,35 +0,0 @@
-package lib
-
-import (
-	"fmt"
-	"regexp"
-
-	"v.io/core/veyron2"
-	"v.io/core/veyron2/naming"
-)
-
-// Turns a list of names into a list of names that use the "ws" protocol.
-func EndpointsToWs(names []string) ([]string, error) {
-	outNames := []string{}
-	tcpRegexp := regexp.MustCompile(`@tcp\d*@`)
-	for _, name := range names {
-		addr, suff := naming.SplitAddressName(name)
-		ep, err := veyron2.NewEndpoint(addr)
-		if err != nil {
-			return nil, fmt.Errorf("rt.NewEndpoint(%v) failed: %v", addr, err)
-		}
-		// Replace only the first match.
-		first := true
-		wsEp := tcpRegexp.ReplaceAllFunc([]byte(ep.String()), func(s []byte) []byte {
-			if first {
-				first = false
-				return []byte("@ws@")
-			}
-			return s
-		})
-		wsName := naming.JoinAddressName(string(wsEp), suff)
-
-		outNames = append(outNames, wsName)
-	}
-	return outNames, nil
-}
diff --git a/services/wsprd/lib/ws_endpoint_test.go b/services/wsprd/lib/ws_endpoint_test.go
deleted file mode 100644
index 260fa9d..0000000
--- a/services/wsprd/lib/ws_endpoint_test.go
+++ /dev/null
@@ -1,29 +0,0 @@
-package lib
-
-import (
-	"testing"
-)
-
-func TestWsNames(t *testing.T) {
-	testdata := map[string]string{
-		"/@3@tcp@127.0.0.1:46504@d7b41510a6e78033ed86e38efb61ef52@4@6@m@@":                     "/@3@ws@127.0.0.1:46504@d7b41510a6e78033ed86e38efb61ef52@4@6@m@@",
-		"/@3@tcp4@example.com:46504@d7b41510a6e78033ed86e38efb61ef52@4@6@m@@/more/stuff":       "/@3@ws@example.com:46504@d7b41510a6e78033ed86e38efb61ef52@4@6@m@@/more/stuff",
-		"/@3@ws@example.com:46504@d7b41510a6e78033ed86e38efb61ef52@4@6@m@@/more/stuff":         "/@3@ws@example.com:46504@d7b41510a6e78033ed86e38efb61ef52@4@6@m@@/more/stuff",
-		"/@3@tcp@[::]:60624@21ba0c2508adfe8507eb953e526bd5a2@4@6@m@@":                          "/@3@ws@[::]:60624@21ba0c2508adfe8507eb953e526bd5a2@4@6@m@@",
-		"/@3@tcp4@tcpexampletcp.com:46504@d7b41510a6e78033ed86e38efb61ef52@4@6@m@@/more/stuff": "/@3@ws@tcpexampletcp.com:46504@d7b41510a6e78033ed86e38efb61ef52@4@6@m@@/more/stuff",
-		"/example.com:12345":                          "/@3@ws@example.com:12345@00000000000000000000000000000000@@@m@@",
-		"/example.com:12345/more/stuff/in/suffix/tcp": "/@3@ws@example.com:12345@00000000000000000000000000000000@@@m@@/more/stuff/in/suffix/tcp",
-	}
-
-	for name, expectedWsName := range testdata {
-		inputNames := []string{name}
-		actualWsNames, err := EndpointsToWs(inputNames)
-		if err != nil {
-			t.Fatal(err)
-		}
-		expectedWsNames := []string{expectedWsName}
-		if len(actualWsNames) != 1 || actualWsNames[0] != expectedWsNames[0] {
-			t.Errorf("expected wsNames(%v) to be %v but got %v", inputNames, expectedWsNames, actualWsNames)
-		}
-	}
-}