TBR Add bulk caveat validation callback support to ForContext

If a callback function is added to the context with key
"customChainValidator", it will be called when it is necessary to
validate caveats.

This is intended to be used to allow javascript to receive caveats in
bulk for validation.

In addition, this:
- Adds VanadiumContext() to security context
- Fixes naming in javascript gen.go

MultiPart: 1/2

Change-Id: I8d0dd4dda572a7d78b8226cf3030f5fcbcaa64b0
diff --git a/runtimes/google/ipc/default_authorizer_test.go b/runtimes/google/ipc/default_authorizer_test.go
index ff992b7..45af448 100644
--- a/runtimes/google/ipc/default_authorizer_test.go
+++ b/runtimes/google/ipc/default_authorizer_test.go
@@ -4,6 +4,8 @@
 	"testing"
 
 	vsecurity "v.io/core/veyron/security"
+	"v.io/core/veyron2"
+	"v.io/core/veyron2/context"
 	"v.io/core/veyron2/security"
 )
 
@@ -73,11 +75,14 @@
 			U(bob, B(che, "family")),
 			true}, // {ali, bob/friend, che/friend} talking to {bob, che/family}
 	}
+	ctx, shutdown := veyron2.Init()
+	defer shutdown()
 	for _, test := range tests {
 		err := authorizer.Authorize(&mockSecurityContext{
 			p: pali,
 			l: test.local,
 			r: test.remote,
+			c: ctx,
 		})
 		if (err == nil) != test.authorized {
 			t.Errorf("Local:%v Remote:%v. Got %v", test.local, test.remote, err)
@@ -89,8 +94,10 @@
 	security.Context
 	p    security.Principal
 	l, r security.Blessings
+	c    *context.T
 }
 
 func (c *mockSecurityContext) LocalPrincipal() security.Principal  { return c.p }
 func (c *mockSecurityContext) LocalBlessings() security.Blessings  { return c.l }
 func (c *mockSecurityContext) RemoteBlessings() security.Blessings { return c.r }
+func (c *mockSecurityContext) VanadiumContext() *context.T         { return c.c }
diff --git a/runtimes/google/ipc/reserved.go b/runtimes/google/ipc/reserved.go
index d202b30..3ea6276 100644
--- a/runtimes/google/ipc/reserved.go
+++ b/runtimes/google/ipc/reserved.go
@@ -358,3 +358,4 @@
 func (c *mutableContext) RemoteDischarges() map[string]security.Discharge { return c.M.RemoteDischarges }
 func (c *mutableContext) Blessings() security.Blessings                   { return c.M.Blessings }
 func (c *mutableContext) Server() ipc.Server                              { return c.M.Server }
+func (c *mutableContext) VanadiumContext() *context.T                     { return c.T }
diff --git a/runtimes/google/ipc/server.go b/runtimes/google/ipc/server.go
index 84fad16..5b8a8bb 100644
--- a/runtimes/google/ipc/server.go
+++ b/runtimes/google/ipc/server.go
@@ -207,6 +207,7 @@
 	}
 	dc := InternalNewDischargeClient(ctx, client)
 	s.listenerOpts = append(s.listenerOpts, dc)
+	s.listenerOpts = append(s.listenerOpts, vc.DialContext{ctx})
 	blessingsStatsName := naming.Join(statsPrefix, "security", "blessings")
 	if blessings != nil {
 		// TODO(caprita): revist printing the blessings with %s, and
@@ -1268,6 +1269,10 @@
 	return fs.T
 }
 
+func (fs *flowServer) VanadiumContext() *context.T {
+	return fs.T
+}
+
 // TODO(cnicolaou): remove Name from ipc.ServerContext and all of
 // its implementations
 func (fs *flowServer) Name() string {
diff --git a/runtimes/google/ipc/stream/manager/listener.go b/runtimes/google/ipc/stream/manager/listener.go
index 9dbb227..be0a658 100644
--- a/runtimes/google/ipc/stream/manager/listener.go
+++ b/runtimes/google/ipc/stream/manager/listener.go
@@ -6,7 +6,6 @@
 	"net"
 	"strings"
 	"sync"
-	"time"
 
 	"v.io/core/veyron/runtimes/google/ipc/stream/proxy"
 	"v.io/core/veyron/runtimes/google/ipc/stream/vif"
@@ -155,16 +154,6 @@
 
 func (ln *proxyListener) connect() (*vif.VIF, naming.Endpoint, error) {
 	vlog.VI(1).Infof("Connecting to proxy at %v", ln.proxyEP)
-	// TODO(cnicolaou, ashankar): probably want to set a timeout here.
-	var timeout time.Duration
-	vf, err := ln.manager.FindOrDialVIF(ln.proxyEP, &DialTimeout{Duration: timeout})
-	if err != nil {
-		return nil, nil, err
-	}
-	if err := vf.StartAccepting(ln.opts...); err != nil {
-		return nil, nil, fmt.Errorf("already connected to proxy and accepting connections? VIF: %v, StartAccepting error: %v", vf, err)
-	}
-	// Proxy protocol: See veyron/runtimes/google/ipc/stream/proxy/protocol.vdl
 	// Requires dialing a VC to the proxy, need to extract options (like the identity)
 	// from ln.opts to do so.
 	var dialOpts []stream.VCOpt
@@ -173,6 +162,15 @@
 			dialOpts = append(dialOpts, dopt)
 		}
 	}
+	// TODO(cnicolaou, ashankar): probably want to set a timeout here. (is this covered by opts?)
+	vf, err := ln.manager.FindOrDialVIF(ln.proxyEP, dialOpts...)
+	if err != nil {
+		return nil, nil, err
+	}
+	if err := vf.StartAccepting(ln.opts...); err != nil {
+		return nil, nil, fmt.Errorf("already connected to proxy and accepting connections? VIF: %v, StartAccepting error: %v", vf, err)
+	}
+	// Proxy protocol: See veyron/runtimes/google/ipc/stream/proxy/protocol.vdl
 	vc, err := vf.Dial(ln.proxyEP, dialOpts...)
 	if err != nil {
 		vf.StopAccepting()
diff --git a/runtimes/google/ipc/stream/vc/auth.go b/runtimes/google/ipc/stream/vc/auth.go
index 864f272..a176017 100644
--- a/runtimes/google/ipc/stream/vc/auth.go
+++ b/runtimes/google/ipc/stream/vc/auth.go
@@ -73,6 +73,7 @@
 		// How do we get that working?
 		// One option is to have a UnionOfBlessings of all blessings of the client in the BlessingStore
 		// made available to serverAuthContext.LocalBlessings for this call.
+		VanadiumContext: ctx,
 	}))
 	client = principal.BlessingStore().ForPeer(serverB...)
 	if client == nil {
diff --git a/runtimes/google/ipc/stream/vc/vc.go b/runtimes/google/ipc/stream/vc/vc.go
index a3d5bee..074bc72 100644
--- a/runtimes/google/ipc/stream/vc/vc.go
+++ b/runtimes/google/ipc/stream/vc/vc.go
@@ -132,7 +132,8 @@
 // DialContext establishes the context under which a VC Dial was initiated.
 type DialContext struct{ *context.T }
 
-func (DialContext) IPCStreamVCOpt() {}
+func (DialContext) IPCStreamVCOpt()       {}
+func (DialContext) IPCStreamListenerOpt() {}
 
 // InternalNew creates a new VC, which implements the stream.VC interface.
 //
diff --git a/runtimes/google/vtrace/vtrace.go b/runtimes/google/vtrace/vtrace.go
index 1f2572b..17db581 100644
--- a/runtimes/google/vtrace/vtrace.go
+++ b/runtimes/google/vtrace/vtrace.go
@@ -173,10 +173,3 @@
 	}
 	return context.WithValue(nctx, storeKey, store), nil
 }
-
-// TODO(mattr): Remove this function once the old Runtime type is deprecated.
-func DeprecatedInit(ctx *context.T, store *Store) *context.T {
-	ctx = vtrace.WithManager(ctx, manager{})
-	ctx = context.WithValue(ctx, storeKey, store)
-	return ctx
-}