veyron2/ipc: force all protocols, including tcp, to be registered.

- this change implements and uses a consistent mechanism for
  registering the stream transport protocols to be used with RPC.
- it treats 'tcp' the same as any other 'user defined' protocol, such
  as websockets or unixfd
- protocols are generally registered by importing their package, whose
  init function performs the actual registration.
- the protocol packages should only be imported by profiles.
- in a future change, I propose to move lib/tcp, lib/websocket and lib/unixfd
  to profiles/internal.

Change-Id: I139757441b865c9b22778d1f2d9d1d2586357d35
diff --git a/profiles/chrome/chrome.go b/profiles/chrome/chrome.go
index cfead4e..9d16365 100644
--- a/profiles/chrome/chrome.go
+++ b/profiles/chrome/chrome.go
@@ -9,7 +9,8 @@
 	"veyron.io/veyron/veyron2/options"
 	"veyron.io/veyron/veyron2/rt"
 
-	"veyron.io/veyron/veyron/profiles"
+	_ "veyron.io/veyron/veyron/lib/websocket"
+	"veyron.io/veyron/veyron/profiles/internal/platform"
 )
 
 var ListenSpec = ipc.ListenSpec{}
@@ -35,7 +36,7 @@
 }
 
 func (*chrome) Platform() *veyron2.Platform {
-	p, _ := profiles.Platform()
+	p, _ := platform.Platform()
 	return p
 }
 
diff --git a/profiles/doc.go b/profiles/doc.go
index 635df9d..3c4ab07 100644
--- a/profiles/doc.go
+++ b/profiles/doc.go
@@ -10,11 +10,14 @@
 //
 // Profiles register themselves by calling veyron2/rt.RegisterProfile in their
 // init function and are hence are chosen by importing them into an
-// applications main package. More specific packages may use functionality
-// exposed by more general packages and rely on go's module dependency
-// algorithm to execute the init function from the more specific package
-// after the less specific one and hence override the earlier Profile
-// registration.
+// applications main package. It is possible, but discouraged, for more
+// specific packages may use functionality exposed by more general packages
+// and rely on go's module dependency algorithm to execute the init function
+// from the more specific package after the less specific one and hence
+// override the earlier Profile registration. This is discouraged because it
+// is harder for the reader to track the dependencies to see what is included
+// by each package. Commonly used functionality is placed in profiles/internal
+// for use by all profiles.
 //
 // This top level directory contains a 'generic' Profile and utility routines
 // used by other Profiles. It should be imported whenever possible and
diff --git a/profiles/gce/init.go b/profiles/gce/init.go
index b0143a7..d0f666c 100644
--- a/profiles/gce/init.go
+++ b/profiles/gce/init.go
@@ -17,8 +17,11 @@
 	"veyron.io/veyron/veyron/lib/appcycle"
 	"veyron.io/veyron/veyron/lib/flags"
 	"veyron.io/veyron/veyron/lib/netstate"
-	"veyron.io/veyron/veyron/profiles"
+	_ "veyron.io/veyron/veyron/lib/tcp"
+	_ "veyron.io/veyron/veyron/lib/websocket"
 	"veyron.io/veyron/veyron/profiles/internal/gce"
+	"veyron.io/veyron/veyron/profiles/internal/platform"
+	_ "veyron.io/veyron/veyron/runtimes/google/rt"
 )
 
 var (
@@ -49,8 +52,8 @@
 }
 
 func (p *profile) Platform() *veyron2.Platform {
-	platform, _ := profiles.Platform()
-	return platform
+	pstr, _ := platform.Platform()
+	return pstr
 }
 
 func (p *profile) String() string {
diff --git a/profiles/generic.go b/profiles/generic.go
index 96ddcb7..7442cda 100644
--- a/profiles/generic.go
+++ b/profiles/generic.go
@@ -7,7 +7,10 @@
 	"veyron.io/veyron/veyron2/rt"
 
 	"veyron.io/veyron/veyron/lib/appcycle"
+	_ "veyron.io/veyron/veyron/lib/tcp"
+	_ "veyron.io/veyron/veyron/lib/websocket"
 	"veyron.io/veyron/veyron/profiles/internal"
+	"veyron.io/veyron/veyron/profiles/internal/platform"
 	_ "veyron.io/veyron/veyron/runtimes/google/rt"
 )
 
@@ -41,8 +44,8 @@
 }
 
 func (*generic) Platform() *veyron2.Platform {
-	p, _ := Platform()
-	return p
+	pstr, _ := platform.Platform()
+	return pstr
 }
 
 func (g *generic) Init(rt veyron2.Runtime, _ *config.Publisher) (veyron2.AppCycle, error) {
diff --git a/profiles/platform_darwin.go b/profiles/internal/platform/platform_darwin.go
similarity index 97%
rename from profiles/platform_darwin.go
rename to profiles/internal/platform/platform_darwin.go
index c4a36fa..22d788c 100644
--- a/profiles/platform_darwin.go
+++ b/profiles/internal/platform/platform_darwin.go
@@ -1,4 +1,4 @@
-package profiles
+package platform
 
 // #include <sys/utsname.h>
 // #include <errno.h>
diff --git a/profiles/platform_linux.go b/profiles/internal/platform/platform_linux.go
similarity index 97%
rename from profiles/platform_linux.go
rename to profiles/internal/platform/platform_linux.go
index f0d969f..5a34b14 100644
--- a/profiles/platform_linux.go
+++ b/profiles/internal/platform/platform_linux.go
@@ -1,4 +1,4 @@
-package profiles
+package platform
 
 import (
 	"syscall"
diff --git a/profiles/platform_nacl.go b/profiles/internal/platform/platform_nacl.go
similarity index 96%
rename from profiles/platform_nacl.go
rename to profiles/internal/platform/platform_nacl.go
index 0b73e9c..5ae8c67 100644
--- a/profiles/platform_nacl.go
+++ b/profiles/internal/platform/platform_nacl.go
@@ -1,6 +1,6 @@
 // +build nacl
 
-package profiles
+package platform
 
 import (
 	"veyron.io/veyron/veyron2"
diff --git a/profiles/uts_str_linux_arm.go b/profiles/internal/platform/uts_str_linux_arm.go
similarity index 94%
rename from profiles/uts_str_linux_arm.go
rename to profiles/internal/platform/uts_str_linux_arm.go
index f2326ab..c519595 100644
--- a/profiles/uts_str_linux_arm.go
+++ b/profiles/internal/platform/uts_str_linux_arm.go
@@ -1,6 +1,6 @@
 // +build linux,arm
 
-package profiles
+package platform
 
 // str converts the input byte slice to a string, ignoring everything following
 // a null character (including the null character).
diff --git a/profiles/uts_str_linux_nonarm.go b/profiles/internal/platform/uts_str_linux_nonarm.go
similarity index 94%
rename from profiles/uts_str_linux_nonarm.go
rename to profiles/internal/platform/uts_str_linux_nonarm.go
index 4a97742..84256e5 100644
--- a/profiles/uts_str_linux_nonarm.go
+++ b/profiles/internal/platform/uts_str_linux_nonarm.go
@@ -1,6 +1,6 @@
 // +build linux,!arm
 
-package profiles
+package platform
 
 // str converts the input byte slice to a string, ignoring everything following
 // a null character (including the null character).
diff --git a/profiles/roaming/roaming.go b/profiles/roaming/roaming.go
index 837a5b8..4bf8b26 100644
--- a/profiles/roaming/roaming.go
+++ b/profiles/roaming/roaming.go
@@ -22,9 +22,13 @@
 	"veyron.io/veyron/veyron/lib/flags"
 	"veyron.io/veyron/veyron/lib/netconfig"
 	"veyron.io/veyron/veyron/lib/netstate"
-	"veyron.io/veyron/veyron/profiles"
+	_ "veyron.io/veyron/veyron/lib/tcp"
+	_ "veyron.io/veyron/veyron/lib/websocket"
 	"veyron.io/veyron/veyron/profiles/internal"
+	"veyron.io/veyron/veyron/profiles/internal/platform"
+	_ "veyron.io/veyron/veyron/runtimes/google/rt"
 	"veyron.io/veyron/veyron/services/mgmt/debug"
+
 	// TODO(cnicolaou,ashankar): move this into flags.
 	sflag "veyron.io/veyron/veyron/security/flag"
 )
@@ -56,8 +60,8 @@
 }
 
 func (p *profile) Platform() *veyron2.Platform {
-	platform, _ := profiles.Platform()
-	return platform
+	pstr, _ := platform.Platform()
+	return pstr
 }
 
 func (p *profile) Name() string {
diff --git a/profiles/static/static.go b/profiles/static/static.go
index 2720f1d..86cda56 100644
--- a/profiles/static/static.go
+++ b/profiles/static/static.go
@@ -14,8 +14,11 @@
 	"veyron.io/veyron/veyron/lib/appcycle"
 	"veyron.io/veyron/veyron/lib/flags"
 	"veyron.io/veyron/veyron/lib/netstate"
-	"veyron.io/veyron/veyron/profiles"
+	_ "veyron.io/veyron/veyron/lib/tcp"
+	_ "veyron.io/veyron/veyron/lib/websocket"
 	"veyron.io/veyron/veyron/profiles/internal"
+	"veyron.io/veyron/veyron/profiles/internal/platform"
+	_ "veyron.io/veyron/veyron/runtimes/google/rt"
 	"veyron.io/veyron/veyron/services/mgmt/debug"
 	// TODO(cnicolaou,ashankar): move this into flags.
 	sflag "veyron.io/veyron/veyron/security/flag"
@@ -53,8 +56,8 @@
 }
 
 func (*static) Platform() *veyron2.Platform {
-	p, _ := profiles.Platform()
-	return p
+	pstr, _ := platform.Platform()
+	return pstr
 }
 
 func (p *static) Init(rt veyron2.Runtime, _ *config.Publisher) (veyron2.AppCycle, error) {