Remove VOM from WSPR
Change-Id: Ibd9bcd9956183cb29aaf9eb2d8a4a9b3b6cb90b1
MultiPart: 2/2
diff --git a/services/wsprd/app/app.go b/services/wsprd/app/app.go
index 44c58ff..6c984ee 100644
--- a/services/wsprd/app/app.go
+++ b/services/wsprd/app/app.go
@@ -61,12 +61,12 @@
type serveRequest struct {
Name string
- ServerId uint64
+ ServerId uint32
}
type addRemoveNameRequest struct {
Name string
- ServerId uint64
+ ServerId uint32
}
type jsonCaveatValidator struct {
@@ -75,9 +75,9 @@
}
type blessingRequest struct {
- Handle int64
+ Handle int32
Caveats []jsonCaveatValidator
- DurationMs int64
+ DurationMs int32
Extension string
}
@@ -104,25 +104,25 @@
// Used to generate unique ids for requests initiated by the proxy.
// These ids will be even so they don't collide with the ids generated
// by the client.
- lastGeneratedId int64
+ lastGeneratedId int32
// Used to keep track of data (streams and cancellation functions) for
// outstanding requests.
- outstandingRequests map[int64]*outstandingRequest
+ outstandingRequests map[int32]*outstandingRequest
// Maps flowids to the server that owns them.
- flowMap map[int64]*server.Server
+ flowMap map[int32]*server.Server
// A manager that Handles fetching and caching signature of remote services
signatureManager lib.SignatureManager
// We maintain multiple Veyron server per pipe for serving JavaScript
// services.
- servers map[uint64]*server.Server
+ servers map[uint32]*server.Server
// Creates a client writer for a given flow. This is a member so that tests can override
// the default implementation.
- writerCreator func(id int64) lib.ClientWriter
+ writerCreator func(id int32) lib.ClientWriter
// There is only one client per Controller since there is a single principal per app.
client ipc.Client
@@ -136,7 +136,7 @@
// NewController creates a new Controller. writerCreator will be used to create a new flow for rpcs to
// javascript server. veyronProxyEP is an endpoint for the veyron proxy to serve through. It can't be empty.
// opts are any options that should be passed to the rt.New().
-func NewController(writerCreator func(id int64) lib.ClientWriter, profile veyron2.Profile, listenSpec *ipc.ListenSpec, namespaceRoots []string, opts ...veyron2.ROpt) (*Controller, error) {
+func NewController(writerCreator func(id int32) lib.ClientWriter, profile veyron2.Profile, listenSpec *ipc.ListenSpec, namespaceRoots []string, opts ...veyron2.ROpt) (*Controller, error) {
if profile != nil {
opts = append(opts, options.Profile{profile})
}
@@ -257,7 +257,7 @@
}
// CleanupFlow removes the bookkeping for a previously created flow.
-func (c *Controller) CleanupFlow(id int64) {
+func (c *Controller) CleanupFlow(id int32) {
c.Lock()
request := c.outstandingRequests[id]
delete(c.outstandingRequests, id)
@@ -283,7 +283,7 @@
// the handle to it. This function exists because JS only has
// a handle to the blessings to avoid shipping the certificate forest
// to JS and back.
-func (c *Controller) AddBlessings(blessings security.Blessings) int64 {
+func (c *Controller) AddBlessings(blessings security.Blessings) int32 {
return c.blessingsStore.Add(blessings)
}
@@ -311,14 +311,14 @@
func (c *Controller) setup() {
c.signatureManager = lib.NewSignatureManager()
- c.outstandingRequests = make(map[int64]*outstandingRequest)
- c.flowMap = make(map[int64]*server.Server)
- c.servers = make(map[uint64]*server.Server)
+ c.outstandingRequests = make(map[int32]*outstandingRequest)
+ c.flowMap = make(map[int32]*server.Server)
+ c.servers = make(map[uint32]*server.Server)
}
// SendOnStream writes data on id's stream. The actual network write will be
// done asynchronously. If there is an error, it will be sent to w.
-func (c *Controller) SendOnStream(id int64, data string, w lib.ClientWriter) {
+func (c *Controller) SendOnStream(id int32, data string, w lib.ClientWriter) {
c.Lock()
request := c.outstandingRequests[id]
if request == nil || request.stream == nil {
@@ -332,7 +332,7 @@
// SendVeyronRequest makes a veyron request for the given flowId. If signal is non-nil, it will receive
// the call object after it has been constructed.
-func (c *Controller) sendVeyronRequest(ctx context.T, id int64, msg *VeyronRPC, w lib.ClientWriter, stream *outstandingStream) {
+func (c *Controller) sendVeyronRequest(ctx context.T, id int32, msg *VeyronRPC, w lib.ClientWriter, stream *outstandingStream) {
sig, err := c.getSignature(ctx, msg.Name)
if err != nil {
w.Error(err)
@@ -373,7 +373,7 @@
}
// HandleVeyronRequest starts a veyron rpc and returns before the rpc has been completed.
-func (c *Controller) HandleVeyronRequest(ctx context.T, id int64, data string, w lib.ClientWriter) {
+func (c *Controller) HandleVeyronRequest(ctx context.T, id int32, data string, w lib.ClientWriter) {
msg, err := c.parseVeyronRequest(data)
if err != nil {
w.Error(verror2.Convert(verror2.Internal, ctx, err))
@@ -411,7 +411,7 @@
// HandleVeyronCancellation cancels the request corresponding to the
// given id if it is still outstanding.
-func (c *Controller) HandleVeyronCancellation(id int64) {
+func (c *Controller) HandleVeyronCancellation(id int32) {
c.Lock()
defer c.Unlock()
if request, ok := c.outstandingRequests[id]; ok && request.cancel != nil {
@@ -420,7 +420,7 @@
}
// CloseStream closes the stream for a given id.
-func (c *Controller) CloseStream(id int64) {
+func (c *Controller) CloseStream(id int32) {
c.Lock()
defer c.Unlock()
if request, ok := c.outstandingRequests[id]; ok && request.stream != nil {
@@ -430,7 +430,7 @@
c.logger.Errorf("close called on non-existent call: %v", id)
}
-func (c *Controller) maybeCreateServer(serverId uint64) (*server.Server, error) {
+func (c *Controller) maybeCreateServer(serverId uint32) (*server.Server, error) {
c.Lock()
defer c.Unlock()
if server, ok := c.servers[serverId]; ok {
@@ -444,7 +444,7 @@
return server, nil
}
-func (c *Controller) removeServer(serverId uint64) {
+func (c *Controller) removeServer(serverId uint32) {
c.Lock()
server := c.servers[serverId]
if server == nil {
@@ -491,7 +491,7 @@
// HandleLookupResponse handles the result of a Dispatcher.Lookup call that was
// run by the Javascript server.
-func (c *Controller) HandleLookupResponse(id int64, data string) {
+func (c *Controller) HandleLookupResponse(id int32, data string) {
c.Lock()
server := c.flowMap[id]
c.Unlock()
@@ -506,7 +506,7 @@
// HandleAuthResponse handles the result of a Authorizer.Authorize call that was
// run by the Javascript server.
-func (c *Controller) HandleAuthResponse(id int64, data string) {
+func (c *Controller) HandleAuthResponse(id int32, data string) {
c.Lock()
server := c.flowMap[id]
c.Unlock()
@@ -521,7 +521,7 @@
// HandleStopRequest takes a request to stop a server.
func (c *Controller) HandleStopRequest(data string, w lib.ClientWriter) {
- var serverId uint64
+ var serverId uint32
if err := json.Unmarshal([]byte(data), &serverId); err != nil {
w.Error(verror2.Convert(verror2.Internal, nil, err))
return
@@ -597,7 +597,7 @@
// HandleServerResponse handles the completion of outstanding calls to JavaScript services
// by filling the corresponding channel with the result from JavaScript.
-func (c *Controller) HandleServerResponse(id int64, data string) {
+func (c *Controller) HandleServerResponse(id int32, data string) {
c.Lock()
server := c.flowMap[id]
c.Unlock()
@@ -659,7 +659,7 @@
// HandleUnlinkJSBlessings removes the specified blessings from the JS blessings
// store. 'data' should be a JSON encoded number (representing the blessings handle).
func (c *Controller) HandleUnlinkJSBlessings(data string, w lib.ClientWriter) {
- var handle int64
+ var handle int32
if err := json.Unmarshal([]byte(data), &handle); err != nil {
w.Error(verror2.Convert(verror2.Internal, nil, err))
return
@@ -685,7 +685,7 @@
}
}
-func (c *Controller) getBlessingsHandle(handle int64) (*principal.BlessingsHandle, error) {
+func (c *Controller) getBlessingsHandle(handle int32) (*principal.BlessingsHandle, error) {
id := c.blessingsStore.Get(handle)
if id == nil {
return nil, verror2.Make(unknownBlessings, nil)
diff --git a/services/wsprd/app/app_test.go b/services/wsprd/app/app_test.go
index e36d846..7e5ba70 100644
--- a/services/wsprd/app/app_test.go
+++ b/services/wsprd/app/app_test.go
@@ -316,7 +316,7 @@
writer := testwriter.Writer{}
- writerCreator := func(int64) lib.ClientWriter {
+ writerCreator := func(int32) lib.ClientWriter {
return &writer
}
spec := profiles.LocalListenSpec
@@ -455,7 +455,7 @@
finalError: test.err,
}
// Let's replace the test writer with the mockJSServer
- rt.controller.writerCreator = func(int64) lib.ClientWriter {
+ rt.controller.writerCreator = func(int32) lib.ClientWriter {
return mock
}
diff --git a/services/wsprd/app/messaging.go b/services/wsprd/app/messaging.go
index d0cf3c4..cf2e23e 100644
--- a/services/wsprd/app/messaging.go
+++ b/services/wsprd/app/messaging.go
@@ -8,7 +8,7 @@
verror "veyron.io/veyron/veyron2/verror2"
"veyron.io/veyron/veyron2/vlog"
- "veyron.io/veyron/veyron2/vom"
+ "veyron.io/veyron/veyron2/vom2"
"veyron.io/wspr/veyron/services/wsprd/lib"
)
@@ -76,7 +76,10 @@
)
type Message struct {
- Id int64
+ // TODO(bprosnitz) Consider changing this ID to a larger value.
+ // TODO(bprosnitz) Consider making the ID have positive / negative value
+ // depending on whether from/to JS.
+ Id int32
// This contains the json encoded payload.
Data string
@@ -131,18 +134,26 @@
// ConstructOutgoingMessage constructs a message to send to javascript in a consistent format.
// TODO(bprosnitz) Don't double-encode
-func ConstructOutgoingMessage(messageId int64, messageType lib.ResponseType, data interface{}) (string, error) {
+func ConstructOutgoingMessage(messageId int32, messageType lib.ResponseType, data interface{}) (string, error) {
var buf bytes.Buffer
- if err := vom.ObjToJSON(&buf, vom.ValueOf(lib.Response{Type: messageType, Message: data})); err != nil {
+ enc, err := vom2.NewBinaryEncoder(&buf)
+ if err != nil {
+ return "", err
+ }
+ if err := enc.Encode(lib.Response{Type: messageType, Message: data}); err != nil {
return "", err
}
var buf2 bytes.Buffer
- if err := vom.ObjToJSON(&buf2, vom.ValueOf(Message{Id: messageId, Data: buf.String()})); err != nil {
+ enc2, err := vom2.NewBinaryEncoder(&buf2)
+ if err != nil {
+ return "", err
+ }
+ if err := enc2.Encode(Message{Id: messageId, Data: fmt.Sprintf("%x", buf.Bytes())}); err != nil {
return "", err
}
- return buf2.String(), nil
+ return fmt.Sprintf("%x", buf2.Bytes()), nil
}
// FormatAsVerror formats an error as a verror.
diff --git a/services/wsprd/app/mock_jsServer_test.go b/services/wsprd/app/mock_jsServer_test.go
index a9c127d..02c54f9 100644
--- a/services/wsprd/app/mock_jsServer_test.go
+++ b/services/wsprd/app/mock_jsServer_test.go
@@ -33,8 +33,8 @@
// can make sure that both sides are using the same flowId. This
// isn't a problem right now because the test doesn't do multiple flows
// at the same time.
- flowCount int64
- rpcFlow int64
+ flowCount int32
+ rpcFlow int32
}
func (m *mockJSServer) Send(responseType lib.ResponseType, msg interface{}) error {
@@ -218,7 +218,7 @@
}
- if field, got, want := "Handle", msg.Handle, int64(0); got != want {
+ if field, got, want := "Handle", msg.Handle, int32(0); got != want {
m.controller.HandleServerResponse(m.flowCount, internalErrJSON(fmt.Sprintf("unexpected value for %s: got %v, want %v", field, got, want)))
return nil
diff --git a/services/wsprd/browspr/browspr_test.go b/services/wsprd/browspr/browspr_test.go
index b834df6..f8a7cc0 100644
--- a/services/wsprd/browspr/browspr_test.go
+++ b/services/wsprd/browspr/browspr_test.go
@@ -206,18 +206,18 @@
}
var outMsg app.Message
- if err := json.Unmarshal([]byte(receivedMsg), &outMsg); err != nil {
+ if err := lib.VomDecode(receivedMsg, &outMsg); err != nil {
t.Fatalf("Failed to unmarshall outgoing message: %v", err)
}
- if outMsg.Id != int64(1) {
- t.Errorf("Id was %v, expected %v", outMsg.Id, int64(1))
+ if outMsg.Id != int32(1) {
+ t.Errorf("Id was %v, expected %v", outMsg.Id, int32(1))
}
if outMsg.Type != app.VeyronRequestMessage {
t.Errorf("Message type was %v, expected %v", outMsg.Type, app.MessageType(0))
}
var responseMsg lib.Response
- if err := json.Unmarshal([]byte(outMsg.Data), &responseMsg); err != nil {
+ if err := lib.VomDecode(outMsg.Data, &responseMsg); err != nil {
t.Fatalf("Failed to unmarshall outgoing response: %v", err)
}
if responseMsg.Type != lib.ResponseFinal {
diff --git a/services/wsprd/browspr/pipe.go b/services/wsprd/browspr/pipe.go
index b24bfac..f31e1fb 100644
--- a/services/wsprd/browspr/pipe.go
+++ b/services/wsprd/browspr/pipe.go
@@ -44,7 +44,7 @@
return pipe
}
-func (p *pipe) createWriter(messageId int64) lib.ClientWriter {
+func (p *pipe) createWriter(messageId int32) lib.ClientWriter {
return &postMessageWriter{
messageId: messageId,
p: p,
diff --git a/services/wsprd/browspr/writer.go b/services/wsprd/browspr/writer.go
index 2d1b9a4..6e464d2 100644
--- a/services/wsprd/browspr/writer.go
+++ b/services/wsprd/browspr/writer.go
@@ -7,7 +7,7 @@
// postMessageWriter is a lib.ClientWriter that handles sending messages over postMessage to the extension.
type postMessageWriter struct {
- messageId int64
+ messageId int32
p *pipe
}
diff --git a/services/wsprd/channel/channel.go b/services/wsprd/channel/channel.go
index 5ce860d..c2b7836 100644
--- a/services/wsprd/channel/channel.go
+++ b/services/wsprd/channel/channel.go
@@ -12,9 +12,9 @@
type Channel struct {
messageHandler MessageSender
- lastSeq uint64
+ lastSeq uint32
handlers map[string]RequestHandler
- pendingResponses map[uint64]chan Response
+ pendingResponses map[uint32]chan Response
lock sync.Mutex
}
@@ -22,7 +22,7 @@
return &Channel{
messageHandler: messageHandler,
handlers: map[string]RequestHandler{},
- pendingResponses: map[uint64]chan Response{},
+ pendingResponses: map[uint32]chan Response{},
}
}
diff --git a/services/wsprd/channel/channel.vdl b/services/wsprd/channel/channel.vdl
index 8f27c0a..e2856dd 100644
--- a/services/wsprd/channel/channel.vdl
+++ b/services/wsprd/channel/channel.vdl
@@ -2,12 +2,12 @@
type Request struct {
Type string
- Seq uint64
+ Seq uint32
Body any
}
type Response struct {
- ReqSeq uint64
+ ReqSeq uint32
Err string // TODO(bprosnitz) change this back to error when it is possible to do so. (issue 368)
Body any
}
diff --git a/services/wsprd/channel/channel.vdl.go b/services/wsprd/channel/channel.vdl.go
index ead937b..461c694 100644
--- a/services/wsprd/channel/channel.vdl.go
+++ b/services/wsprd/channel/channel.vdl.go
@@ -11,7 +11,7 @@
type Request struct {
Type string
- Seq uint64
+ Seq uint32
Body __vdlutil.Any
}
@@ -21,7 +21,7 @@
}
type Response struct {
- ReqSeq uint64
+ ReqSeq uint32
Err string // TODO(bprosnitz) change this back to error when it is possible to do so. (issue 368)
Body __vdlutil.Any
}
diff --git a/services/wsprd/ipc/server/dispatcher.go b/services/wsprd/ipc/server/dispatcher.go
index 851430d..2628338 100644
--- a/services/wsprd/ipc/server/dispatcher.go
+++ b/services/wsprd/ipc/server/dispatcher.go
@@ -16,58 +16,58 @@
type flowFactory interface {
createFlow() *Flow
- cleanupFlow(id int64)
+ cleanupFlow(id int32)
}
type invokerFactory interface {
- createInvoker(handle int64, signature []signature.Interface) (ipc.Invoker, error)
+ createInvoker(handle int32, signature []signature.Interface) (ipc.Invoker, error)
}
type authFactory interface {
- createAuthorizer(handle int64, hasAuthorizer bool) (security.Authorizer, error)
+ createAuthorizer(handle int32, hasAuthorizer bool) (security.Authorizer, error)
}
type lookupIntermediateReply struct {
- Handle int64
+ Handle int32
HasAuthorizer bool
Signature string
Err *verror2.Standard
}
type lookupReply struct {
- Handle int64
+ Handle int32
HasAuthorizer bool
Signature []signature.Interface
Err *verror2.Standard
}
type dispatcherRequest struct {
- ServerID uint64 `json:"serverId"`
+ ServerID uint32 `json:"serverId"`
Suffix string `json:"suffix"`
}
// dispatcher holds the invoker and the authorizer to be used for lookup.
type dispatcher struct {
mu sync.Mutex
- serverID uint64
+ serverID uint32
flowFactory flowFactory
invokerFactory invokerFactory
authFactory authFactory
logger vlog.Logger
- outstandingLookups map[int64]chan lookupReply
+ outstandingLookups map[int32]chan lookupReply
}
var _ ipc.Dispatcher = (*dispatcher)(nil)
// newDispatcher is a dispatcher factory.
-func newDispatcher(serverID uint64, flowFactory flowFactory, invokerFactory invokerFactory, authFactory authFactory, logger vlog.Logger) *dispatcher {
+func newDispatcher(serverID uint32, flowFactory flowFactory, invokerFactory invokerFactory, authFactory authFactory, logger vlog.Logger) *dispatcher {
return &dispatcher{
serverID: serverID,
flowFactory: flowFactory,
invokerFactory: invokerFactory,
authFactory: authFactory,
logger: logger,
- outstandingLookups: make(map[int64]chan lookupReply),
+ outstandingLookups: make(map[int32]chan lookupReply),
}
}
@@ -113,7 +113,7 @@
return invoker, auth, nil
}
-func (d *dispatcher) handleLookupResponse(id int64, data string) {
+func (d *dispatcher) handleLookupResponse(id int32, data string) {
d.mu.Lock()
ch := d.outstandingLookups[id]
d.mu.Unlock()
diff --git a/services/wsprd/ipc/server/dispatcher_test.go b/services/wsprd/ipc/server/dispatcher_test.go
index 62038a1..8b8e521 100644
--- a/services/wsprd/ipc/server/dispatcher_test.go
+++ b/services/wsprd/ipc/server/dispatcher_test.go
@@ -22,10 +22,10 @@
return &Flow{ID: 0, Writer: &m.writer}
}
-func (*mockFlowFactory) cleanupFlow(int64) {}
+func (*mockFlowFactory) cleanupFlow(int32) {}
type mockInvoker struct {
- handle int64
+ handle int32
sig []signature.Interface
}
@@ -55,12 +55,12 @@
type mockInvokerFactory struct{}
-func (mockInvokerFactory) createInvoker(handle int64, sig []signature.Interface) (ipc.Invoker, error) {
+func (mockInvokerFactory) createInvoker(handle int32, sig []signature.Interface) (ipc.Invoker, error) {
return &mockInvoker{handle: handle, sig: sig}, nil
}
type mockAuthorizer struct {
- handle int64
+ handle int32
hasAuthorizer bool
}
@@ -68,7 +68,7 @@
type mockAuthorizerFactory struct{}
-func (mockAuthorizerFactory) createAuthorizer(handle int64, hasAuthorizer bool) (security.Authorizer, error) {
+func (mockAuthorizerFactory) createAuthorizer(handle int32, hasAuthorizer bool) (security.Authorizer, error) {
return mockAuthorizer{handle: handle, hasAuthorizer: hasAuthorizer}, nil
}
diff --git a/services/wsprd/ipc/server/server.go b/services/wsprd/ipc/server/server.go
index 355749c..c8bf01c 100644
--- a/services/wsprd/ipc/server/server.go
+++ b/services/wsprd/ipc/server/server.go
@@ -19,14 +19,14 @@
)
type Flow struct {
- ID int64
+ ID int32
Writer lib.ClientWriter
}
// A request from the proxy to javascript to handle an RPC
type ServerRPCRequest struct {
- ServerId uint64
- Handle int64
+ ServerId uint32
+ Handle int32
Method string
Args []interface{}
Context ServerRPCRequestContext
@@ -46,12 +46,12 @@
type FlowHandler interface {
CreateNewFlow(server *Server, sender ipc.Stream) *Flow
- CleanupFlow(id int64)
+ CleanupFlow(id int32)
}
type HandleStore interface {
// Adds blessings to the store and returns handle to the blessings
- AddBlessings(blessings security.Blessings) int64
+ AddBlessings(blessings security.Blessings) int32
}
type ServerHelper interface {
@@ -85,8 +85,8 @@
// AuthRequest is a request for a javascript authorizer to run
// This is exported to make the app test easier.
type AuthRequest struct {
- ServerID uint64 `json:"serverID"`
- Handle int64 `json:"handle"`
+ ServerID uint32 `json:"serverID"`
+ Handle int32 `json:"handle"`
Context Context `json:"context"`
}
@@ -107,22 +107,22 @@
isListening bool
// The server id.
- id uint64
+ id uint32
helper ServerHelper
// The set of outstanding server requests.
- outstandingServerRequests map[int64]chan *lib.ServerRPCReply
+ outstandingServerRequests map[int32]chan *lib.ServerRPCReply
- outstandingAuthRequests map[int64]chan error
+ outstandingAuthRequests map[int32]chan error
}
-func NewServer(id uint64, listenSpec *ipc.ListenSpec, helper ServerHelper) (*Server, error) {
+func NewServer(id uint32, listenSpec *ipc.ListenSpec, helper ServerHelper) (*Server, error) {
server := &Server{
id: id,
helper: helper,
listenSpec: listenSpec,
- outstandingServerRequests: make(map[int64]chan *lib.ServerRPCReply),
- outstandingAuthRequests: make(map[int64]chan error),
+ outstandingServerRequests: make(map[int32]chan *lib.ServerRPCReply),
+ outstandingAuthRequests: make(map[int32]chan error),
}
var err error
if server.server, err = helper.RT().NewServer(); err != nil {
@@ -135,7 +135,7 @@
// communicate the result back via a channel to the caller
type remoteInvokeFunc func(methodName string, args []interface{}, call ipc.ServerCall) <-chan *lib.ServerRPCReply
-func (s *Server) createRemoteInvokerFunc(handle int64) remoteInvokeFunc {
+func (s *Server) createRemoteInvokerFunc(handle int32) remoteInvokeFunc {
return func(methodName string, args []interface{}, call ipc.ServerCall) <-chan *lib.ServerRPCReply {
flow := s.helper.CreateNewFlow(s, call)
replyChan := make(chan *lib.ServerRPCReply, 1)
@@ -232,7 +232,7 @@
type remoteAuthFunc func(security.Context) error
-func (s *Server) createRemoteAuthFunc(handle int64) remoteAuthFunc {
+func (s *Server) createRemoteAuthFunc(handle int32) remoteAuthFunc {
return func(ctx security.Context) error {
flow := s.helper.CreateNewFlow(s, nil)
replyChan := make(chan error, 1)
@@ -295,7 +295,7 @@
return nil
}
-func (s *Server) popServerRequest(id int64) chan *lib.ServerRPCReply {
+func (s *Server) popServerRequest(id int32) chan *lib.ServerRPCReply {
s.mu.Lock()
defer s.mu.Unlock()
ch := s.outstandingServerRequests[id]
@@ -304,7 +304,7 @@
return ch
}
-func (s *Server) HandleServerResponse(id int64, data string) {
+func (s *Server) HandleServerResponse(id int32, data string) {
ch := s.popServerRequest(id)
if ch == nil {
s.helper.GetLogger().Errorf("unexpected result from JavaScript. No channel "+
@@ -325,11 +325,11 @@
ch <- &reply
}
-func (s *Server) HandleLookupResponse(id int64, data string) {
+func (s *Server) HandleLookupResponse(id int32, data string) {
s.dispatcher.handleLookupResponse(id, data)
}
-func (s *Server) HandleAuthResponse(id int64, data string) {
+func (s *Server) HandleAuthResponse(id int32, data string) {
s.mu.Lock()
ch := s.outstandingAuthRequests[id]
s.mu.Unlock()
@@ -363,16 +363,16 @@
return s.helper.CreateNewFlow(s, nil)
}
-func (s *Server) cleanupFlow(id int64) {
+func (s *Server) cleanupFlow(id int32) {
s.helper.CleanupFlow(id)
}
-func (s *Server) createInvoker(handle int64, sig []signature.Interface) (ipc.Invoker, error) {
+func (s *Server) createInvoker(handle int32, sig []signature.Interface) (ipc.Invoker, error) {
remoteInvokeFunc := s.createRemoteInvokerFunc(handle)
return newInvoker(sig, remoteInvokeFunc), nil
}
-func (s *Server) createAuthorizer(handle int64, hasAuthorizer bool) (security.Authorizer, error) {
+func (s *Server) createAuthorizer(handle int32, hasAuthorizer bool) (security.Authorizer, error) {
if hasAuthorizer {
return &authorizer{authFunc: s.createRemoteAuthFunc(handle)}, nil
}
@@ -393,7 +393,7 @@
default:
}
}
- s.outstandingServerRequests = make(map[int64]chan *lib.ServerRPCReply)
+ s.outstandingServerRequests = make(map[int32]chan *lib.ServerRPCReply)
s.server.Stop()
}
diff --git a/services/wsprd/lib/writer.go b/services/wsprd/lib/writer.go
index bcf1f8d..d80ecb5 100644
--- a/services/wsprd/lib/writer.go
+++ b/services/wsprd/lib/writer.go
@@ -1,6 +1,6 @@
package lib
-type ResponseType int
+type ResponseType int32
const (
ResponseFinal ResponseType = 0
diff --git a/services/wsprd/principal/blessings.go b/services/wsprd/principal/blessings.go
index 444cf67..020ea57 100644
--- a/services/wsprd/principal/blessings.go
+++ b/services/wsprd/principal/blessings.go
@@ -6,11 +6,11 @@
)
type BlessingsHandle struct {
- Handle int64
+ Handle int32
PublicKey string
}
-func ConvertBlessingsToHandle(blessings security.Blessings, handle int64) *BlessingsHandle {
+func ConvertBlessingsToHandle(blessings security.Blessings, handle int32) *BlessingsHandle {
bytes, err := blessings.PublicKey().MarshalBinary()
if err != nil {
panic(err)
diff --git a/services/wsprd/principal/js_blessings_store.go b/services/wsprd/principal/js_blessings_store.go
index 785fec0..917432e 100644
--- a/services/wsprd/principal/js_blessings_store.go
+++ b/services/wsprd/principal/js_blessings_store.go
@@ -14,19 +14,19 @@
// all operations involving cryptographic operations call into go.
type JSBlessingsHandles struct {
mu sync.Mutex
- lastHandle int64
- store map[int64]security.Blessings
+ lastHandle int32
+ store map[int32]security.Blessings
}
// NewJSBlessingsHandles returns a newly initialized JSBlessingsHandles
func NewJSBlessingsHandles() *JSBlessingsHandles {
return &JSBlessingsHandles{
- store: map[int64]security.Blessings{},
+ store: map[int32]security.Blessings{},
}
}
// Add adds a Blessings to the store and returns the handle to it.
-func (s *JSBlessingsHandles) Add(blessings security.Blessings) int64 {
+func (s *JSBlessingsHandles) Add(blessings security.Blessings) int32 {
s.mu.Lock()
defer s.mu.Unlock()
s.lastHandle++
@@ -36,7 +36,7 @@
}
// Remove removes the Blessings associated with the handle.
-func (s *JSBlessingsHandles) Remove(handle int64) {
+func (s *JSBlessingsHandles) Remove(handle int32) {
s.mu.Lock()
defer s.mu.Unlock()
delete(s.store, handle)
@@ -44,7 +44,7 @@
// Get returns the Blessings represented by the handle. Returns nil
// if no Blessings exists for the handle.
-func (s *JSBlessingsHandles) Get(handle int64) security.Blessings {
+func (s *JSBlessingsHandles) Get(handle int32) security.Blessings {
s.mu.Lock()
defer s.mu.Unlock()
return s.store[handle]
diff --git a/services/wsprd/wspr/pipe.go b/services/wsprd/wspr/pipe.go
index d2b0922..faa8670 100644
--- a/services/wsprd/wspr/pipe.go
+++ b/services/wsprd/wspr/pipe.go
@@ -35,7 +35,7 @@
// Creates a client writer for a given flow. This is a member so that tests can override
// the default implementation.
- writerCreator func(id int64) lib.ClientWriter
+ writerCreator func(id int32) lib.ClientWriter
// There is a single write goroutine because ws.NewWriter() creates a new writer that
// writes to a shared buffer in the websocket, so it is not safe to have multiple go
@@ -46,11 +46,11 @@
req *http.Request
}
-func newPipe(w http.ResponseWriter, req *http.Request, wspr *WSPR, creator func(id int64) lib.ClientWriter) *pipe {
+func newPipe(w http.ResponseWriter, req *http.Request, wspr *WSPR, creator func(id int32) lib.ClientWriter) *pipe {
pipe := &pipe{logger: wspr.rt.Logger(), wspr: wspr, req: req}
if creator == nil {
- creator = func(id int64) lib.ClientWriter {
+ creator = func(id int32) lib.ClientWriter {
return &websocketWriter{p: pipe, id: id, logger: pipe.logger}
}
}
diff --git a/services/wsprd/wspr/writer.go b/services/wsprd/wspr/writer.go
index 01eed13..ebbc27b 100644
--- a/services/wsprd/wspr/writer.go
+++ b/services/wsprd/wspr/writer.go
@@ -1,7 +1,6 @@
package wspr
import (
- "bytes"
"fmt"
"path/filepath"
"runtime"
@@ -10,7 +9,6 @@
"veyron.io/veyron/veyron2/verror2"
"veyron.io/veyron/veyron2/vlog"
- "veyron.io/veyron/veyron2/vom"
"veyron.io/wspr/veyron/services/wsprd/app"
"github.com/gorilla/websocket"
@@ -26,24 +24,16 @@
type websocketWriter struct {
p *pipe
logger vlog.Logger
- id int64
+ id int32
}
func (w *websocketWriter) Send(messageType lib.ResponseType, data interface{}) error {
- var buf bytes.Buffer
- if err := vom.ObjToJSON(&buf, vom.ValueOf(response{Type: messageType, Message: data})); err != nil {
- w.logger.Error("Failed to marshal with", err)
+ msg, err := app.ConstructOutgoingMessage(w.id, messageType, data)
+ if err != nil {
return err
}
- var buf2 bytes.Buffer
-
- if err := vom.ObjToJSON(&buf2, vom.ValueOf(app.Message{Id: w.id, Data: buf.String()})); err != nil {
- w.logger.Error("Failed to write the message", err)
- return err
- }
-
- w.p.writeQueue <- wsMessage{messageType: websocket.TextMessage, buf: buf2.Bytes()}
+ w.p.writeQueue <- wsMessage{messageType: websocket.TextMessage, buf: []byte(msg)}
return nil
}