veyron2/vdl: Signature cleanups.
MultiPart: 1/3
A collection of Signature-related cleanups:
o Rename standard vdl package to stdvdl, since it clashes with
veyron2/vdl.
o Move signature types (InterfaceSig, MethodSig, etc) into
stdvdl, so that javascript codegen can depend on it.
o Replace in/out stream hacks with optional type.
o Ensure Signature and MethodSignature really work with vom2.
There are upcoming CLs that fix wspr and veyron.js.
Change-Id: Ib2dfc84215c91b9cb7583ce318786eb06a47b3f8
diff --git a/runtimes/google/ipc/glob.go b/runtimes/google/ipc/glob.go
index c320a82..2e5dddd 100644
--- a/runtimes/google/ipc/glob.go
+++ b/runtimes/google/ipc/glob.go
@@ -9,6 +9,7 @@
"veyron.io/veyron/veyron2/naming"
"veyron.io/veyron/veyron2/security"
"veyron.io/veyron/veyron2/services/security/access"
+ "veyron.io/veyron/veyron2/vdl/vdlroot/src/signature"
"veyron.io/veyron/veyron2/verror"
"veyron.io/veyron/veyron2/vlog"
@@ -72,7 +73,7 @@
}}
}
-func (r *reservedMethods) Signature(ctxOrig ipc.ServerContext) ([]ipc.InterfaceSig, error) {
+func (r *reservedMethods) Signature(ctxOrig ipc.ServerContext) ([]signature.Interface, error) {
// Copy the original context to shield ourselves from changes the flowServer makes.
ctx := copyMutableContext(ctxOrig)
ctx.M.Method = "__Signature"
@@ -102,7 +103,7 @@
return sig, nil
}
-func (r *reservedMethods) MethodSignature(ctxOrig ipc.ServerContext, method string) (ipc.MethodSig, error) {
+func (r *reservedMethods) MethodSignature(ctxOrig ipc.ServerContext, method string) (signature.Method, error) {
// Copy the original context to shield ourselves from changes the flowServer makes.
ctx := copyMutableContext(ctxOrig)
ctx.M.Method = method
@@ -116,17 +117,17 @@
disp = r.dispReserved
}
if disp == nil {
- return ipc.MethodSig{}, verror.NoExistf("ipc: no such method %q", ctx.Method())
+ return signature.Method{}, verror.NoExistf("ipc: no such method %q", ctx.Method())
}
obj, auth, err := disp.Lookup(ctx.Suffix())
switch {
case err != nil:
- return ipc.MethodSig{}, err
+ return signature.Method{}, err
case obj == nil:
- return ipc.MethodSig{}, verror.NoExistf("ipc: no such method %q", ctx.Method())
+ return signature.Method{}, verror.NoExistf("ipc: no such method %q", ctx.Method())
}
if verr := authorize(ctx, auth); verr != nil {
- return ipc.MethodSig{}, verr
+ return signature.Method{}, verr
}
return objectToInvoker(obj).MethodSignature(ctx, ctx.Method())
}
diff --git a/runtimes/google/ipc/signature_test.go b/runtimes/google/ipc/signature_test.go
index 4ffcb7e..83d9c78 100644
--- a/runtimes/google/ipc/signature_test.go
+++ b/runtimes/google/ipc/signature_test.go
@@ -10,6 +10,8 @@
"veyron.io/veyron/veyron2/ipc/reserved"
"veyron.io/veyron/veyron2/naming"
"veyron.io/veyron/veyron2/rt"
+ "veyron.io/veyron/veyron2/vdl"
+ "veyron.io/veyron/veyron2/vdl/vdlroot/src/signature"
"veyron.io/veyron/veyron/lib/testutil"
"veyron.io/veyron/veyron/profiles"
@@ -34,12 +36,30 @@
type sigImpl struct{}
-func (sigImpl) NonStreaming0(ipc.ServerContext) {}
+func (sigImpl) NonStreaming0(ipc.ServerContext) { panic("X") }
+func (sigImpl) NonStreaming1(_ ipc.ServerContext, _ string) error { panic("X") }
+func (sigImpl) Streaming0(_ *streamStringBool) { panic("X") }
+func (sigImpl) Streaming1(_ *streamStringBool, _ int64) (float64, error) { panic("X") }
-// TODO(toddw): This test doesn't work yet, because we try to send *vdl.Type
-// back over the wire for the new Signature format, but that depends on vom2
-// support for typeobject and encoding *vdl.Type. Re-enable this test when we
-// have vom2 optionally enabled in our stack.
+type streamStringBool struct{ ipc.ServerCall }
+
+func (*streamStringBool) Init(ipc.ServerCall) { panic("X") }
+func (*streamStringBool) RecvStream() interface {
+ Advance() bool
+ Value() string
+ Err() error
+} {
+ panic("X")
+}
+func (*streamStringBool) SendStream() interface {
+ Send(_ bool) error
+} {
+ panic("X")
+}
+
+// TODO(toddw): This test only works with vom2, since we need to send *vdl.Type
+// over the wire for the new Signature format. Re-enable this test when the
+// vom2 transition is done.
func disabledTestMethodSignature(t *testing.T) {
runtime, err := rt.New()
if err != nil {
@@ -52,17 +72,34 @@
t.Fatalf("startSigServer: %v", err)
}
defer stop()
+ name := naming.JoinAddressName(ep, "")
tests := []struct {
Method string
- Want ipc.MethodSig
+ Want signature.Method
}{
- {"NonStreaming0", ipc.MethodSig{
+ {"NonStreaming0", signature.Method{
Name: "NonStreaming0",
}},
+ {"NonStreaming1", signature.Method{
+ Name: "NonStreaming1",
+ InArgs: []signature.Arg{{Type: vdl.StringType}},
+ OutArgs: []signature.Arg{{Type: vdl.ErrorType}},
+ }},
+ {"Streaming0", signature.Method{
+ Name: "Streaming0",
+ InStream: &signature.Arg{Type: vdl.StringType},
+ OutStream: &signature.Arg{Type: vdl.BoolType},
+ }},
+ {"Streaming1", signature.Method{
+ Name: "Streaming1",
+ InArgs: []signature.Arg{{Type: vdl.Int64Type}},
+ OutArgs: []signature.Arg{{Type: vdl.Float64Type}, {Type: vdl.ErrorType}},
+ InStream: &signature.Arg{Type: vdl.StringType},
+ OutStream: &signature.Arg{Type: vdl.BoolType},
+ }},
}
for _, test := range tests {
- name := naming.JoinAddressName(ep, "")
sig, err := reserved.MethodSignature(runtime.NewContext(), name, test.Method)
if err != nil {
t.Errorf("call failed: %v", err)
@@ -72,3 +109,57 @@
}
}
}
+
+// TODO(toddw): This test only works with vom2, since we need to send *vdl.Type
+// over the wire for the new Signature format. Re-enable this test when the
+// vom2 transition is done.
+func disabledTestSignature(t *testing.T) {
+ runtime, err := rt.New()
+ if err != nil {
+ t.Fatalf("Couldn't initialize runtime: %s", err)
+ }
+ defer runtime.Cleanup()
+
+ ep, stop, err := startSigServer(runtime, sigImpl{})
+ if err != nil {
+ t.Fatalf("startSigServer: %v", err)
+ }
+ defer stop()
+ name := naming.JoinAddressName(ep, "")
+
+ want := []signature.Interface{
+ signature.Interface{
+ Doc: "The empty interface contains methods not attached to any interface.",
+ Methods: []signature.Method{
+ {
+ Name: "NonStreaming0",
+ },
+ {
+ Name: "NonStreaming1",
+ InArgs: []signature.Arg{{Type: vdl.StringType}},
+ OutArgs: []signature.Arg{{Type: vdl.ErrorType}},
+ },
+ {
+ Name: "Streaming0",
+ InStream: &signature.Arg{Type: vdl.StringType},
+ OutStream: &signature.Arg{Type: vdl.BoolType},
+ },
+ {
+ Name: "Streaming1",
+ InArgs: []signature.Arg{{Type: vdl.Int64Type}},
+ OutArgs: []signature.Arg{{Type: vdl.Float64Type}, {Type: vdl.ErrorType}},
+ InStream: &signature.Arg{Type: vdl.StringType},
+ OutStream: &signature.Arg{Type: vdl.BoolType},
+ },
+ },
+ },
+ }
+
+ sig, err := reserved.Signature(runtime.NewContext(), name)
+ if err != nil {
+ t.Errorf("call failed: %v", err)
+ }
+ if got, want := sig, want; !reflect.DeepEqual(got, want) {
+ t.Errorf("got %#v, want %#v", got, want)
+ }
+}
diff --git a/services/mgmt/node/impl/proxy_invoker.go b/services/mgmt/node/impl/proxy_invoker.go
index a7ab7c4..0f87e7e 100644
--- a/services/mgmt/node/impl/proxy_invoker.go
+++ b/services/mgmt/node/impl/proxy_invoker.go
@@ -8,6 +8,7 @@
"veyron.io/veyron/veyron2/naming"
"veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/services/security/access"
+ "veyron.io/veyron/veyron2/vdl/vdlroot/src/signature"
)
// proxyInvoker is an ipc.Invoker implementation that proxies all requests
@@ -126,7 +127,7 @@
// TODO(toddw): Expose a helper function that performs all error checking based
// on reflection, to simplify the repeated logic processing results.
-func (p *proxyInvoker) Signature(ctx ipc.ServerContext) ([]ipc.InterfaceSig, error) {
+func (p *proxyInvoker) Signature(ctx ipc.ServerContext) ([]signature.Interface, error) {
call, ok := ctx.(ipc.ServerCall)
if !ok {
return nil, fmt.Errorf("couldn't upgrade ipc.ServerContext to ipc.ServerCall")
@@ -145,18 +146,18 @@
}
return nil, err
}
- var res []ipc.InterfaceSig
+ var res []signature.Interface
if results[0] != nil {
- sig, ok := results[0].([]ipc.InterfaceSig)
+ sig, ok := results[0].([]signature.Interface)
if !ok {
- return nil, fmt.Errorf("unexpected result value type. Got %T, want []ipc.InterfaceSig.", sig)
+ return nil, fmt.Errorf("unexpected result value type. Got %T, want []signature.Interface.", sig)
}
}
return res, nil
}
-func (p *proxyInvoker) MethodSignature(ctx ipc.ServerContext, method string) (ipc.MethodSig, error) {
- empty := ipc.MethodSig{}
+func (p *proxyInvoker) MethodSignature(ctx ipc.ServerContext, method string) (signature.Method, error) {
+ empty := signature.Method{}
call, ok := ctx.(ipc.ServerCall)
if !ok {
return empty, fmt.Errorf("couldn't upgrade ipc.ServerContext to ipc.ServerCall")
@@ -175,11 +176,11 @@
}
return empty, err
}
- var res ipc.MethodSig
+ var res signature.Method
if results[0] != nil {
- sig, ok := results[0].(ipc.MethodSig)
+ sig, ok := results[0].(signature.Method)
if !ok {
- return empty, fmt.Errorf("unexpected result value type. Got %T, want ipc.MethodSig.", sig)
+ return empty, fmt.Errorf("unexpected result value type. Got %T, want signature.Method.", sig)
}
}
return res, nil