veyron/runtimes/google/ipc: Add deadline and cancellation propagation to the context.

I have revised the CL and it's worth a good look now.  I have moved the derivation
functions to the interface instead of being at the top level as in go.nets Context.
This allows us to control construction, but makes it more difficult for users to
define new context types (though it's not clear if this would be a common concern).

I have also made a separate construction method for having a default deadline
NewDefaultContext().  However it's worth keeping in mind that creating deadlines
leaks resources for the duration of the deadline unless the corresponding context
is canceled.

Change-Id: I2fa4c1d64ff6207286ffff828ed1a7aa1588afc3
diff --git a/tools/namespace/impl/impl.go b/tools/namespace/impl/impl.go
index ad3cc43..7fe764b 100644
--- a/tools/namespace/impl/impl.go
+++ b/tools/namespace/impl/impl.go
@@ -28,7 +28,9 @@
 	}
 	pattern := args[0]
 	ns := rt.R().Namespace()
-	c, err := ns.Glob(rt.R().NewContext(), pattern)
+	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	defer cancel()
+	c, err := ns.Glob(ctx, pattern)
 	if err != nil {
 		vlog.Infof("ns.Glob(%q) failed: %v", pattern, err)
 		return err
@@ -70,7 +72,9 @@
 		return fmt.Errorf("TTL parse error: %v", err)
 	}
 	ns := rt.R().Namespace()
-	if err = ns.Mount(rt.R().NewContext(), name, server, ttl); err != nil {
+	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	defer cancel()
+	if err = ns.Mount(ctx, name, server, ttl); err != nil {
 		vlog.Infof("ns.Mount(%q, %q, %s) failed: %v", name, server, ttl, err)
 		return err
 	}
@@ -97,7 +101,9 @@
 	name := args[0]
 	server := args[1]
 	ns := rt.R().Namespace()
-	if err := ns.Unmount(rt.R().NewContext(), name, server); err != nil {
+	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	defer cancel()
+	if err := ns.Unmount(ctx, name, server); err != nil {
 		vlog.Infof("ns.Unmount(%q, %q) failed: %v", name, server, err)
 		return err
 	}
@@ -120,7 +126,9 @@
 	}
 	name := args[0]
 	ns := rt.R().Namespace()
-	servers, err := ns.Resolve(rt.R().NewContext(), name)
+	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	defer cancel()
+	servers, err := ns.Resolve(ctx, name)
 	if err != nil {
 		vlog.Infof("ns.Resolve(%q) failed: %v", name, err)
 		return err
@@ -146,7 +154,9 @@
 	}
 	name := args[0]
 	ns := rt.R().Namespace()
-	servers, err := ns.ResolveToMountTable(rt.R().NewContext(), name)
+	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	defer cancel()
+	servers, err := ns.ResolveToMountTable(ctx, name)
 	if err != nil {
 		vlog.Infof("ns.ResolveToMountTable(%q) failed: %v", name, err)
 		return err
@@ -172,7 +182,9 @@
 	}
 	name := args[0]
 	ns := rt.R().Namespace()
-	servers, err := ns.Unresolve(rt.R().NewContext(), name)
+	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	defer cancel()
+	servers, err := ns.Unresolve(ctx, name)
 	if err != nil {
 		vlog.Infof("ns.Unresolve(%q) failed: %v", name, err)
 		return err