wspr: Add VDL files for browspr and js communication
With guessType changing, we should rely more on VDL to ensure we send
the right information between the two.
valconv was removed, but since channel takes generic input from JS,
we still have to keep interface{} around and do some type casting.
Not included: Tests for the new error cases when type casting.
vom: https://vanadium-review.googlesource.com/#/c/2461/
veyron.js: https://vanadium-review.googlesource.com/#/c/2462/
viz: https://vanadium-review.googlesource.com/#/c/2511/
wsprd: https://vanadium-review.googlesource.com/2595
playground: https://vanadium-review.googlesource.com/#/c/2714/
MultiPart: 4/5
Change-Id: Ie0b4a8303a9ae0bc8943cb855c25fea4f6799daa
diff --git a/services/wsprd/account/account.go b/services/wsprd/account/account.go
index 8be6ea9..994bb4a 100644
--- a/services/wsprd/account/account.go
+++ b/services/wsprd/account/account.go
@@ -111,12 +111,6 @@
am.blesser = blesser
}
-// Caveat describes a restriction on the validity of a blessing/discharge.
-type Caveat struct {
- Type string `json:"type"`
- Args string `json:"args"`
-}
-
func constructCaveats(cavs []Caveat) ([]security.Caveat, []time.Time, error) {
var caveats []security.Caveat
var expirations []time.Time
diff --git a/services/wsprd/account/account.vdl b/services/wsprd/account/account.vdl
new file mode 100644
index 0000000..8863b83
--- /dev/null
+++ b/services/wsprd/account/account.vdl
@@ -0,0 +1,7 @@
+package account
+
+// Caveat describes a restriction on the validity of a blessing/discharge.
+type Caveat struct {
+ Type string
+ Args string
+}
\ No newline at end of file
diff --git a/services/wsprd/account/account.vdl.go b/services/wsprd/account/account.vdl.go
new file mode 100644
index 0000000..0f1db12
--- /dev/null
+++ b/services/wsprd/account/account.vdl.go
@@ -0,0 +1,24 @@
+// This file was auto-generated by the veyron vdl tool.
+// Source: account.vdl
+
+package account
+
+import (
+ // The non-user imports are prefixed with "__" to prevent collisions.
+ __vdl "v.io/core/veyron2/vdl"
+)
+
+// Caveat describes a restriction on the validity of a blessing/discharge.
+type Caveat struct {
+ Type string
+ Args string
+}
+
+func (Caveat) __VDLReflect(struct {
+ Name string "v.io/wspr/veyron/services/wsprd/account.Caveat"
+}) {
+}
+
+func init() {
+ __vdl.Register(Caveat{})
+}
diff --git a/services/wsprd/app/app.go b/services/wsprd/app/app.go
index c3d1a93..facfc68 100644
--- a/services/wsprd/app/app.go
+++ b/services/wsprd/app/app.go
@@ -50,15 +50,6 @@
retryTimeout = flag.Int("retry-timeout", 2, "Duration in seconds to retry starting an RPC call. 0 means never retry.")
}
-type VeyronRPC struct {
- Name string
- Method string
- InArgs []interface{}
- NumOutArgs int32
- IsStreaming bool
- Timeout int64
-}
-
type serveRequest struct {
Name string
ServerId uint32
@@ -69,13 +60,6 @@
ServerId uint32
}
-type blessingRequest struct {
- Handle int32
- Caveats []security.Caveat
- DurationMs int32
- Extension string
-}
-
type outstandingRequest struct {
stream *outstandingStream
cancel context.CancelFunc
@@ -215,7 +199,13 @@
func (c *Controller) startCall(ctx *context.T, w lib.ClientWriter, msg *VeyronRPC) (ipc.Call, error) {
methodName := lib.UppercaseFirstCharacter(msg.Method)
retryTimeoutOpt := options.RetryTimeout(time.Duration(*retryTimeout) * time.Second)
- clientCall, err := veyron2.GetClient(ctx).StartCall(ctx, msg.Name, methodName, msg.InArgs, retryTimeoutOpt)
+
+ // Convert inArgs from []vdl.AnyRep to []interface{}
+ inArgs := make([]interface{}, len(msg.InArgs))
+ for i, inArg := range msg.InArgs {
+ inArgs[i] = interface{}(inArg)
+ }
+ clientCall, err := veyron2.GetClient(ctx).StartCall(ctx, msg.Name, methodName, inArgs, retryTimeoutOpt)
if err != nil {
return nil, fmt.Errorf("error starting call (name: %v, method: %v, args: %v): %v", msg.Name, methodName, msg.InArgs, err)
}
@@ -653,7 +643,7 @@
return principal.ConvertBlessingsToHandle(id, handle), nil
}
-func (c *Controller) blessPublicKey(request blessingRequest) (*principal.BlessingsHandle, error) {
+func (c *Controller) blessPublicKey(request BlessingRequest) (*principal.BlessingsHandle, error) {
var blessee security.Blessings
if blessee = c.blessingsStore.Get(request.Handle); blessee == nil {
return nil, verror2.Make(invalidBlessingsHandle, nil)
@@ -680,7 +670,7 @@
// HandleBlessPublicKey handles a blessing request from JS.
func (c *Controller) HandleBlessPublicKey(data string, w lib.ClientWriter) {
- var request blessingRequest
+ var request BlessingRequest
if err := lib.VomDecode(data, &request); err != nil {
w.Error(verror2.Convert(verror2.Internal, nil, err))
return
diff --git a/services/wsprd/app/app.vdl b/services/wsprd/app/app.vdl
new file mode 100644
index 0000000..610933f
--- /dev/null
+++ b/services/wsprd/app/app.vdl
@@ -0,0 +1,23 @@
+// The app package contains the struct that keeps per javascript app state and handles translating
+// javascript requests to veyron requests and vice versa.
+package app
+
+import(
+ "v.io/core/veyron2/security"
+)
+
+type VeyronRPC struct {
+ Name string
+ Method string
+ InArgs []any
+ NumOutArgs int32
+ IsStreaming bool
+ Timeout int64
+}
+
+type BlessingRequest struct {
+ Handle int32
+ Caveats []security.Caveat
+ DurationMs int32
+ Extension string
+}
\ No newline at end of file
diff --git a/services/wsprd/app/app.vdl.go b/services/wsprd/app/app.vdl.go
new file mode 100644
index 0000000..bbce518
--- /dev/null
+++ b/services/wsprd/app/app.vdl.go
@@ -0,0 +1,44 @@
+// This file was auto-generated by the veyron vdl tool.
+// Source: app.vdl
+
+// The app package contains the struct that keeps per javascript app state and handles translating
+// javascript requests to veyron requests and vice versa.
+package app
+
+import (
+ "v.io/core/veyron2/security"
+
+ // The non-user imports are prefixed with "__" to prevent collisions.
+ __vdl "v.io/core/veyron2/vdl"
+)
+
+type VeyronRPC struct {
+ Name string
+ Method string
+ InArgs []__vdl.AnyRep
+ NumOutArgs int32
+ IsStreaming bool
+ Timeout int64
+}
+
+func (VeyronRPC) __VDLReflect(struct {
+ Name string "v.io/wspr/veyron/services/wsprd/app.VeyronRPC"
+}) {
+}
+
+type BlessingRequest struct {
+ Handle int32
+ Caveats []security.Caveat
+ DurationMs int32
+ Extension string
+}
+
+func (BlessingRequest) __VDLReflect(struct {
+ Name string "v.io/wspr/veyron/services/wsprd/app.BlessingRequest"
+}) {
+}
+
+func init() {
+ __vdl.Register(VeyronRPC{})
+ __vdl.Register(BlessingRequest{})
+}
diff --git a/services/wsprd/app/app_test.go b/services/wsprd/app/app_test.go
index 2aa6e54..987344a 100644
--- a/services/wsprd/app/app_test.go
+++ b/services/wsprd/app/app_test.go
@@ -183,7 +183,7 @@
type goServerTestCase struct {
method string
- inArgs []interface{}
+ inArgs []vdl.AnyRep
numOutArgs int32
streamingInputs []interface{}
expectedStream []lib.Response
@@ -243,7 +243,7 @@
func TestCallingGoServer(t *testing.T) {
runGoServerTestCase(t, goServerTestCase{
method: "Add",
- inArgs: []interface{}{2, 3},
+ inArgs: []vdl.AnyRep{2, 3},
numOutArgs: 1,
expectedStream: []lib.Response{
lib.Response{
@@ -257,7 +257,7 @@
func TestCallingGoServerWithError(t *testing.T) {
runGoServerTestCase(t, goServerTestCase{
method: "Divide",
- inArgs: []interface{}{1, 0},
+ inArgs: []vdl.AnyRep{1, 0},
numOutArgs: 1,
expectedError: verror2.Make(verror2.BadArg, nil, "div 0"),
})
diff --git a/services/wsprd/app/mock_jsServer_test.go b/services/wsprd/app/mock_jsServer_test.go
index 74dfcf6..21c230e 100644
--- a/services/wsprd/app/mock_jsServer_test.go
+++ b/services/wsprd/app/mock_jsServer_test.go
@@ -8,6 +8,7 @@
"sync"
"testing"
+ "v.io/core/veyron2/vdl"
"v.io/core/veyron2/vdl/vdlroot/src/signature"
"v.io/wspr/veyron/services/wsprd/ipc/server"
"v.io/wspr/veyron/services/wsprd/lib"
@@ -260,7 +261,7 @@
func (m *mockJSServer) handleStreamClose(msg interface{}) error {
m.sender.Wait()
reply := lib.ServerRPCReply{
- Results: []interface{}{m.finalResponse},
+ Results: []vdl.AnyRep{m.finalResponse},
Err: m.finalError,
}
vomReply, err := lib.VomEncode(reply)
diff --git a/services/wsprd/browspr/browspr.go b/services/wsprd/browspr/browspr.go
index 08dc3c1..9fbb1a7 100644
--- a/services/wsprd/browspr/browspr.go
+++ b/services/wsprd/browspr/browspr.go
@@ -8,8 +8,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
- "v.io/core/veyron2/vdl"
- "v.io/core/veyron2/vdl/valconv"
"v.io/core/veyron2/vlog"
"v.io/core/veyron2/vtrace"
"v.io/wspr/veyron/services/wsprd/account"
@@ -85,20 +83,12 @@
return instance.handleMessage(msg)
}
-// TODO(nlacasse): Define these message types in a real vdl file, and stop
-// using valconv to convert from *vdl.Value. This will make the function
-// signatures more clear.
-
-type cleanupMessage struct {
- InstanceId int32
-}
-
// HandleCleanupRpc cleans up the specified instance state. (For instance,
// when a browser tab is closed)
-func (b *Browspr) HandleCleanupRpc(val *vdl.Value) (interface{}, error) {
- var msg cleanupMessage
- if err := valconv.Convert(&msg, val); err != nil {
- return nil, err
+func (b *Browspr) HandleCleanupRpc(val interface{}) (interface{}, error) {
+ msg, found := val.(CleanupMessage)
+ if !found {
+ return nil, fmt.Errorf("HandleCleanupRpc did not receive CleanupMessage, received: %v", val)
}
b.mu.Lock()
@@ -115,19 +105,15 @@
return nil, nil
}
-type createAccountMessage struct {
- Token string
-}
-
// Handler for creating an account in the principal manager.
// A valid OAuth2 access token must be supplied in the request body,
// which is exchanged for blessings from the veyron blessing server.
// An account based on the blessings is then added to WSPR's principal
// manager, and the set of blessing strings are returned to the client.
-func (b *Browspr) HandleAuthCreateAccountRpc(val *vdl.Value) (interface{}, error) {
- var msg createAccountMessage
- if err := valconv.Convert(&msg, val); err != nil {
- return nil, err
+func (b *Browspr) HandleAuthCreateAccountRpc(val interface{}) (interface{}, error) {
+ msg, found := val.(CreateAccountMessage)
+ if !found {
+ return nil, fmt.Errorf("HandleAuthCreateAccountRpc did not receive CreateAccountMessage, received: %v", val)
}
ctx, _ := vtrace.SetNewTrace(b.ctx)
@@ -139,17 +125,11 @@
return account, nil
}
-type associateAccountMessage struct {
- Account string
- Origin string
- Caveats []account.Caveat
-}
-
// HandleAssociateAccountMessage associates an account with the specified origin.
-func (b *Browspr) HandleAuthAssociateAccountRpc(val *vdl.Value) (interface{}, error) {
- var msg associateAccountMessage
- if err := valconv.Convert(&msg, val); err != nil {
- return nil, err
+func (b *Browspr) HandleAuthAssociateAccountRpc(val interface{}) (interface{}, error) {
+ msg, found := val.(AssociateAccountMessage)
+ if !found {
+ return nil, fmt.Errorf("HandleAuthAssociateAccountRpc did not receive AssociateAccountMessage, received: %v", val)
}
if err := b.accountManager.AssociateAccount(msg.Origin, msg.Account, msg.Caveats); err != nil {
@@ -159,20 +139,17 @@
}
// HandleAuthGetAccountsRpc gets the root account name from the account manager.
-func (b *Browspr) HandleAuthGetAccountsRpc(*vdl.Value) (interface{}, error) {
+func (b *Browspr) HandleAuthGetAccountsRpc(interface{}) (interface{}, error) {
return b.accountManager.GetAccounts(), nil
}
-type originHasAccountMessage struct {
- Origin string
-}
-
// HandleAuthOriginHasAccountRpc returns true iff the origin has an associated
// principal.
-func (b *Browspr) HandleAuthOriginHasAccountRpc(val *vdl.Value) (interface{}, error) {
- var msg originHasAccountMessage
- if err := valconv.Convert(&msg, val); err != nil {
- return nil, err
+func (b *Browspr) HandleAuthOriginHasAccountRpc(val interface{}) (interface{}, error) {
+ msg, found := val.(OriginHasAccountMessage)
+ if !found {
+ return nil, fmt.Errorf("HandleAuthOriginHasAccountRpc did not receive OriginHasAccountMessage, received: %v", val)
}
+
return b.accountManager.OriginHasAccount(msg.Origin), nil
}
diff --git a/services/wsprd/browspr/browspr.vdl b/services/wsprd/browspr/browspr.vdl
new file mode 100644
index 0000000..1f38d99
--- /dev/null
+++ b/services/wsprd/browspr/browspr.vdl
@@ -0,0 +1,42 @@
+package browspr
+
+import(
+ "v.io/wspr/veyron/services/wsprd/account"
+)
+
+type StartMessage struct {
+ Identityd string
+ IdentitydBlessingRoot blessingRoot
+ Proxy string
+ NamespaceRoot string
+ LogLevel int32
+ LogModule string
+}
+
+// Copied from
+// v.io/core/veyron/services/identity/handlers/blessing_root.go, since
+// depcop prohibits importing that package.
+type blessingRoot struct {
+ Names []string
+ PublicKey string
+}
+
+type AssociateAccountMessage struct {
+ Account string
+ Origin string
+ Caveats []account.Caveat
+}
+
+type CreateAccountMessage struct {
+ Token string
+}
+
+type CleanupMessage struct {
+ InstanceId int32
+}
+
+type OriginHasAccountMessage struct {
+ Origin string
+}
+
+type GetAccountsMessage struct {}
\ No newline at end of file
diff --git a/services/wsprd/browspr/browspr.vdl.go b/services/wsprd/browspr/browspr.vdl.go
new file mode 100644
index 0000000..d7c3dd0
--- /dev/null
+++ b/services/wsprd/browspr/browspr.vdl.go
@@ -0,0 +1,94 @@
+// This file was auto-generated by the veyron vdl tool.
+// Source: browspr.vdl
+
+package browspr
+
+import (
+ "v.io/wspr/veyron/services/wsprd/account"
+
+ // The non-user imports are prefixed with "__" to prevent collisions.
+ __vdl "v.io/core/veyron2/vdl"
+)
+
+type StartMessage struct {
+ Identityd string
+ IdentitydBlessingRoot blessingRoot
+ Proxy string
+ NamespaceRoot string
+ LogLevel int32
+ LogModule string
+}
+
+func (StartMessage) __VDLReflect(struct {
+ Name string "v.io/wspr/veyron/services/wsprd/browspr.StartMessage"
+}) {
+}
+
+// Copied from
+// v.io/core/veyron/services/identity/handlers/blessing_root.go, since
+// depcop prohibits importing that package.
+type blessingRoot struct {
+ Names []string
+ PublicKey string
+}
+
+func (blessingRoot) __VDLReflect(struct {
+ Name string "v.io/wspr/veyron/services/wsprd/browspr.blessingRoot"
+}) {
+}
+
+type AssociateAccountMessage struct {
+ Account string
+ Origin string
+ Caveats []account.Caveat
+}
+
+func (AssociateAccountMessage) __VDLReflect(struct {
+ Name string "v.io/wspr/veyron/services/wsprd/browspr.AssociateAccountMessage"
+}) {
+}
+
+type CreateAccountMessage struct {
+ Token string
+}
+
+func (CreateAccountMessage) __VDLReflect(struct {
+ Name string "v.io/wspr/veyron/services/wsprd/browspr.CreateAccountMessage"
+}) {
+}
+
+type CleanupMessage struct {
+ InstanceId int32
+}
+
+func (CleanupMessage) __VDLReflect(struct {
+ Name string "v.io/wspr/veyron/services/wsprd/browspr.CleanupMessage"
+}) {
+}
+
+type OriginHasAccountMessage struct {
+ Origin string
+}
+
+func (OriginHasAccountMessage) __VDLReflect(struct {
+ Name string "v.io/wspr/veyron/services/wsprd/browspr.OriginHasAccountMessage"
+}) {
+}
+
+type GetAccountsMessage struct {
+}
+
+func (GetAccountsMessage) __VDLReflect(struct {
+ Name string "v.io/wspr/veyron/services/wsprd/browspr.GetAccountsMessage"
+}) {
+}
+
+func init() {
+ __vdl.Register(StartMessage{})
+ __vdl.Register(blessingRoot{})
+ __vdl.Register(AssociateAccountMessage{})
+ __vdl.Register(CreateAccountMessage{})
+ __vdl.Register(CleanupMessage{})
+ __vdl.Register(OriginHasAccountMessage{})
+ __vdl.Register(GetAccountsMessage{})
+}
diff --git a/services/wsprd/browspr/browspr_account_test.go b/services/wsprd/browspr/browspr_account_test.go
index c548133..90078c4 100644
--- a/services/wsprd/browspr/browspr_account_test.go
+++ b/services/wsprd/browspr/browspr_account_test.go
@@ -9,8 +9,6 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/security"
- "v.io/core/veyron2/vdl"
- "v.io/core/veyron2/vdl/valconv"
_ "v.io/core/veyron/profiles"
)
@@ -61,7 +59,7 @@
defer teardown()
// Verify that HandleAuthGetAccountsRpc returns empty.
- nilValue := valueOfOrPanic(nil)
+ nilValue := GetAccountsMessage{}
a, err := browspr.HandleAuthGetAccountsRpc(nilValue)
if err != nil {
t.Fatal("browspr.HandleAuthGetAccountsRpc(%v) failed: %v", nilValue, err)
@@ -71,9 +69,9 @@
}
// Add one account.
- message1 := valueOfOrPanic(createAccountMessage{
+ message1 := CreateAccountMessage{
Token: "mock-access-token-1",
- })
+ }
account1, err := browspr.HandleAuthCreateAccountRpc(message1)
if err != nil {
t.Fatalf("browspr.HandleAuthCreateAccountRpc(%v) failed: %v", message1, err)
@@ -94,9 +92,9 @@
}
// Add another account
- message2 := valueOfOrPanic(createAccountMessage{
+ message2 := CreateAccountMessage{
Token: "mock-access-token-2",
- })
+ }
account2, err := browspr.HandleAuthCreateAccountRpc(message2)
if err != nil {
t.Fatalf("browspr.HandleAuthCreateAccountsRpc(%v) failed: %v", message2, err)
@@ -138,9 +136,9 @@
origin := "https://my.webapp.com:443"
// Verify that HandleAuthOriginHasAccountRpc returns false
- hasAccountMessage := valueOfOrPanic(originHasAccountMessage{
+ hasAccountMessage := OriginHasAccountMessage{
Origin: origin,
- })
+ }
hasAccount, err := browspr.HandleAuthOriginHasAccountRpc(hasAccountMessage)
if err != nil {
t.Fatal(err)
@@ -149,10 +147,10 @@
t.Fatal("Expected browspr.HandleAuthOriginHasAccountRpc(%v) to be false but was true", hasAccountMessage)
}
- assocAccountMessage := valueOfOrPanic(associateAccountMessage{
+ assocAccountMessage := AssociateAccountMessage{
Account: account,
Origin: origin,
- })
+ }
if _, err := browspr.HandleAuthAssociateAccountRpc(assocAccountMessage); err != nil {
t.Fatalf("browspr.HandleAuthAssociateAccountRpc(%v) failed: %v", assocAccountMessage, err)
@@ -184,10 +182,10 @@
account := "mock-account"
origin := "https://my.webapp.com:443"
- message := valueOfOrPanic(associateAccountMessage{
+ message := AssociateAccountMessage{
Account: account,
Origin: origin,
- })
+ }
if _, err := browspr.HandleAuthAssociateAccountRpc(message); err == nil {
t.Fatalf("browspr.HandleAuthAssociateAccountRpc(%v) should have failed but did not.")
@@ -204,9 +202,9 @@
}
// Verify that HandleAuthOriginHasAccountRpc returns false
- hasAccountMessage := valueOfOrPanic(originHasAccountMessage{
+ hasAccountMessage := OriginHasAccountMessage{
Origin: origin,
- })
+ }
hasAccount, err := browspr.HandleAuthOriginHasAccountRpc(hasAccountMessage)
if err != nil {
t.Fatal(err)
@@ -215,20 +213,3 @@
t.Fatal("Expected browspr.HandleAuthOriginHasAccountRpc(%v) to be false but was true", hasAccountMessage)
}
}
-
-// Helper to create a *vdl.Value from interface.
-// TODO(nlacasse): Todd says there will eventually be a "ValueOf" somewhere
-// inside vom/vdl. Remove this once that is available.
-func valueOf(in interface{}) (*vdl.Value, error) {
- var out *vdl.Value
- err := valconv.Convert(&out, in)
- return out, err
-}
-
-func valueOfOrPanic(in interface{}) *vdl.Value {
- v, err := valueOf(in)
- if err != nil {
- panic(err)
- }
- return v
-}
diff --git a/services/wsprd/browspr/browspr_test.go b/services/wsprd/browspr/browspr_test.go
index 307192b..194368d 100644
--- a/services/wsprd/browspr/browspr_test.go
+++ b/services/wsprd/browspr/browspr_test.go
@@ -12,6 +12,7 @@
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/options"
+ "v.io/core/veyron2/vdl"
_ "v.io/core/veyron/profiles"
"v.io/core/veyron/runtimes/google/ipc/stream/proxy"
@@ -175,7 +176,7 @@
rpc := app.VeyronRPC{
Name: mockServerName,
Method: "BasicCall",
- InArgs: []interface{}{"InputValue"},
+ InArgs: []vdl.AnyRep{"InputValue"},
NumOutArgs: 1,
IsStreaming: false,
Timeout: (1 << 31) - 1,
diff --git a/services/wsprd/browspr/main/main_nacl.go b/services/wsprd/browspr/main/main_nacl.go
index 5901a94..b517611 100644
--- a/services/wsprd/browspr/main/main_nacl.go
+++ b/services/wsprd/browspr/main/main_nacl.go
@@ -12,8 +12,6 @@
vsecurity "v.io/core/veyron/security"
"v.io/core/veyron2"
"v.io/core/veyron2/security"
- "v.io/core/veyron2/vdl"
- "v.io/core/veyron2/vdl/valconv"
"v.io/core/veyron2/vlog"
"v.io/wspr/veyron/services/wsprd/browspr"
"v.io/wspr/veyron/services/wsprd/channel/channel_nacl"
@@ -131,23 +129,6 @@
return vsecurity.NewPrincipalFromSigner(security.NewInMemoryECDSASigner(ecdsaKey), state)
}
-type startMessage struct {
- Identityd string
- IdentitydBlessingRoot blessingRoot
- Proxy string
- NamespaceRoot string
- LogLevel int32
- LogModule string
-}
-
-// Copied from
-// v.io/core/veyron/services/identity/handlers/blessing_root.go, since
-// depcop prohibits importing that package.
-type blessingRoot struct {
- Names []string `json:"names"`
- PublicKey string `json:"publicKey"`
-}
-
// Base64-decode and unmarshal a public key.
func decodeAndUnmarshalPublicKey(k string) (security.PublicKey, error) {
decodedK, err := base64.URLEncoding.DecodeString(k)
@@ -157,12 +138,12 @@
return security.UnmarshalPublicKey(decodedK)
}
-func (inst *browsprInstance) HandleStartMessage(val *vdl.Value) (interface{}, error) {
+func (inst *browsprInstance) HandleStartMessage(val interface{}) (interface{}, error) {
fmt.Println("Starting Browspr")
- var msg startMessage
- if err := valconv.Convert(&msg, val); err != nil {
- return nil, err
+ msg, found := val.(browspr.StartMessage)
+ if !found {
+ return nil, fmt.Errorf("HandleStartMessage did not receive StartMessage, received: %v", val)
}
principal, err := inst.newPersistantPrincipal(msg.IdentitydBlessingRoot.Names)
diff --git a/services/wsprd/channel/channel_nacl/channel_nacl.go b/services/wsprd/channel/channel_nacl/channel_nacl.go
index d65d4bf..f77de0b 100644
--- a/services/wsprd/channel/channel_nacl/channel_nacl.go
+++ b/services/wsprd/channel/channel_nacl/channel_nacl.go
@@ -6,7 +6,6 @@
"runtime/ppapi"
"v.io/core/veyron2/vdl"
- "v.io/core/veyron2/vdl/valconv"
"v.io/core/veyron2/vom"
"v.io/wspr/veyron/services/wsprd/channel" // contains most of the logic, factored out for testing
)
@@ -16,8 +15,6 @@
ppapiInst ppapi.Instance
}
-type RequestHandler func(value *vdl.Value) (interface{}, error)
-
func sendMessageToBrowser(ppapiInst ppapi.Instance, m channel.Message) {
var outBuf bytes.Buffer
enc, err := vom.NewBinaryEncoder(&outBuf)
@@ -41,16 +38,10 @@
}
}
-func (c *Channel) RegisterRequestHandler(typ string, handler RequestHandler) {
- wrappedHandler := func(val interface{}) (interface{}, error) {
- var v *vdl.Value
- if err := valconv.Convert(&v, val); err != nil {
- return nil, err
- }
- return handler(v)
- }
- c.impl.RegisterRequestHandler(typ, wrappedHandler)
+func (c *Channel) RegisterRequestHandler(typ string, handler channel.RequestHandler) {
+ c.impl.RegisterRequestHandler(typ, handler)
}
+
func (c *Channel) PerformRpc(typ string, body interface{}) (*vdl.Value, error) {
iface, err := c.impl.PerformRpc(typ, body)
if err != nil {
diff --git a/services/wsprd/ipc/server/invoker.go b/services/wsprd/ipc/server/invoker.go
index dc0ab63..0f871b4 100644
--- a/services/wsprd/ipc/server/invoker.go
+++ b/services/wsprd/ipc/server/invoker.go
@@ -71,9 +71,15 @@
err = reply.Err
}
+ // Convert the reply.Results from []vdl.AnyRep to []interface{}
+ results := make([]interface{}, len(reply.Results)+1)
+ for i, r := range reply.Results {
+ results[i] = interface{}(r)
+ }
+
// Add error as last out arg.
// TODO(bprosnitz) Remove this when we stop sending error in out args in ipc.
- results := append(reply.Results, err)
+ results[len(reply.Results)] = err
return results, nil
}
diff --git a/services/wsprd/lib/writer.go b/services/wsprd/lib/writer.go
index d80ecb5..fb29903 100644
--- a/services/wsprd/lib/writer.go
+++ b/services/wsprd/lib/writer.go
@@ -25,9 +25,3 @@
Error(err error)
}
-
-// The response from the javascript server to the proxy.
-type ServerRPCReply struct {
- Results []interface{}
- Err error
-}
diff --git a/services/wsprd/lib/writer.vdl b/services/wsprd/lib/writer.vdl
new file mode 100644
index 0000000..a50c9af
--- /dev/null
+++ b/services/wsprd/lib/writer.vdl
@@ -0,0 +1,7 @@
+package lib
+
+// The response from the javascript server to the proxy.
+type ServerRPCReply struct {
+ Results []any
+ Err error
+}
diff --git a/services/wsprd/lib/writer.vdl.go b/services/wsprd/lib/writer.vdl.go
new file mode 100644
index 0000000..4fa6983
--- /dev/null
+++ b/services/wsprd/lib/writer.vdl.go
@@ -0,0 +1,24 @@
+// This file was auto-generated by the veyron vdl tool.
+// Source: writer.vdl
+
+package lib
+
+import (
+ // The non-user imports are prefixed with "__" to prevent collisions.
+ __vdl "v.io/core/veyron2/vdl"
+)
+
+// The response from the javascript server to the proxy.
+type ServerRPCReply struct {
+ Results []__vdl.AnyRep
+ Err error
+}
+
+func (ServerRPCReply) __VDLReflect(struct {
+ Name string "v.io/wspr/veyron/services/wsprd/lib.ServerRPCReply"
+}) {
+}
+
+func init() {
+ __vdl.Register(ServerRPCReply{})
+}