rpc: Several fixes for v5 endpoint compatibility.

It turns out that my previous change got a couple of things wrong.
With this change new binaries will be able to interact with services that use
v5 endpoints correctly.

Change-Id: I8052895dff3f0b6a4d6ab6ac7399d7881d85017c
diff --git a/profiles/internal/rpc/stream/message/control.go b/profiles/internal/rpc/stream/message/control.go
index 0e94e48..cb03ddc 100644
--- a/profiles/internal/rpc/stream/message/control.go
+++ b/profiles/internal/rpc/stream/message/control.go
@@ -208,10 +208,12 @@
 	if err = writeInt(w, m.VCI); err != nil {
 		return
 	}
-	if err = writeString(w, m.DstEndpoint.String()); err != nil {
+	// Note that when we send OpenVC we always use v4 endpoints because
+	// the server needs to get version information from them.
+	if err = writeString(w, m.DstEndpoint.VersionedString(4)); err != nil {
 		return
 	}
-	if err = writeString(w, m.SrcEndpoint.String()); err != nil {
+	if err = writeString(w, m.SrcEndpoint.VersionedString(4)); err != nil {
 		return
 	}
 	if err = writeCounters(w, m.Counters); err != nil {
diff --git a/profiles/internal/rpc/stream/message/message_test.go b/profiles/internal/rpc/stream/message/message_test.go
index 913d390..8bb99c7 100644
--- a/profiles/internal/rpc/stream/message/message_test.go
+++ b/profiles/internal/rpc/stream/message/message_test.go
@@ -11,9 +11,11 @@
 	"testing"
 
 	"v.io/v23/naming"
+	"v.io/v23/rpc/version"
 	"v.io/x/ref/profiles/internal/lib/iobuf"
+	inaming "v.io/x/ref/profiles/internal/naming"
 	"v.io/x/ref/profiles/internal/rpc/stream/crypto"
-	"v.io/x/ref/profiles/internal/rpc/version"
+	iversion "v.io/x/ref/profiles/internal/rpc/version"
 )
 
 // testControlCipher is a super-simple cipher that xor's each byte of the
@@ -69,13 +71,13 @@
 	counters.Add(12, 13, 10240)
 	tests := []Control{
 		&OpenVC{VCI: 2,
-			DstEndpoint: version.Endpoint("tcp", "batman.com:1990", naming.FixedRoutingID(0xba7)),
-			SrcEndpoint: version.Endpoint("tcp", "google.com:80", naming.FixedRoutingID(0xba6)),
+			DstEndpoint: iversion.Endpoint("tcp", "batman.com:1990", naming.FixedRoutingID(0xba7)),
+			SrcEndpoint: iversion.Endpoint("tcp", "google.com:80", naming.FixedRoutingID(0xba6)),
 		},
 		&OpenVC{
 			VCI:         4,
-			DstEndpoint: version.Endpoint("tcp", "batman.com:1990", naming.FixedRoutingID(0xba7)),
-			SrcEndpoint: version.Endpoint("tcp", "google.com:80", naming.FixedRoutingID(0xba6)),
+			DstEndpoint: iversion.Endpoint("tcp", "batman.com:1990", naming.FixedRoutingID(0xba7)),
+			SrcEndpoint: iversion.Endpoint("tcp", "google.com:80", naming.FixedRoutingID(0xba6)),
 			Counters:    counters,
 		},
 
@@ -83,12 +85,24 @@
 		&CloseVC{VCI: 2, Error: "some error"},
 
 		&SetupVC{
-			VCI:            1,
-			LocalEndpoint:  version.Endpoint("tcp", "batman.com:1990", naming.FixedRoutingID(0xba7)),
-			RemoteEndpoint: version.Endpoint("tcp", "bugsbunny.com:1940", naming.FixedRoutingID(0xbb)),
-			Counters:       counters,
+			VCI: 1,
+			LocalEndpoint: &inaming.Endpoint{
+				Protocol:      "tcp",
+				Address:       "batman.com:1990",
+				RID:           naming.FixedRoutingID(0xba7),
+				MinRPCVersion: version.DeprecatedRPCVersion,
+				MaxRPCVersion: version.DeprecatedRPCVersion,
+			},
+			RemoteEndpoint: &inaming.Endpoint{
+				Protocol:      "tcp",
+				Address:       "bugsbunny.com:1940",
+				RID:           naming.FixedRoutingID(0xbb),
+				MinRPCVersion: version.DeprecatedRPCVersion,
+				MaxRPCVersion: version.DeprecatedRPCVersion,
+			},
+			Counters: counters,
 			Setup: Setup{
-				Versions: version.Range{Min: 34, Max: 56},
+				Versions: iversion.Range{Min: 34, Max: 56},
 				Options: []SetupOption{
 					&NaclBox{PublicKey: crypto.BoxKey{'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd'}},
 					&NaclBox{PublicKey: crypto.BoxKey{7, 67, 31}},
@@ -100,7 +114,7 @@
 			VCI:      1,
 			Counters: counters,
 			Setup: Setup{
-				Versions: version.Range{Min: 34, Max: 56},
+				Versions: iversion.Range{Min: 34, Max: 56},
 				Options: []SetupOption{
 					&NaclBox{PublicKey: crypto.BoxKey{'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd'}},
 					&NaclBox{PublicKey: crypto.BoxKey{7, 67, 31}},
@@ -114,7 +128,7 @@
 		&OpenFlow{VCI: 1, Flow: 10, InitialCounters: 1 << 24},
 
 		&Setup{
-			Versions: version.Range{Min: 21, Max: 71},
+			Versions: iversion.Range{Min: 21, Max: 71},
 			Options: []SetupOption{
 				&NaclBox{PublicKey: crypto.BoxKey{'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd'}},
 				&NaclBox{PublicKey: crypto.BoxKey{7, 67, 31}},
diff --git a/profiles/internal/rpc/version/version.go b/profiles/internal/rpc/version/version.go
index f536b12..63be60b 100644
--- a/profiles/internal/rpc/version/version.go
+++ b/profiles/internal/rpc/version/version.go
@@ -193,6 +193,14 @@
 		return verror.New(errInternalTypeConversionError, nil, fmt.Sprintf("%T", remote))
 	}
 
+	if remoteEP.MinRPCVersion == version.DeprecatedRPCVersion &&
+		remoteEP.MaxRPCVersion == version.DeprecatedRPCVersion {
+		// If the remote endpoint no longer contains version information
+		// then compatibility wont be decided here.  We simply return
+		// true and allow the version negotiation to figure it out.
+		return nil
+	}
+
 	_, _, err := intersectRanges(r.Min, r.Max,
 		remoteEP.MinRPCVersion, remoteEP.MaxRPCVersion)