protocol: Don't call it legacy
This commit is contained in:
parent
044a4a11e1
commit
b2231f6307
2 changed files with 24 additions and 24 deletions
|
|
@ -21,7 +21,7 @@ func (am ActionMap) Handle(auth *auth.Auth, conn *websocket.Connection) (name st
|
||||||
// select based on the negotiated subprotocol
|
// select based on the negotiated subprotocol
|
||||||
switch conn.Subprotocol() {
|
switch conn.Subprotocol() {
|
||||||
case "":
|
case "":
|
||||||
return am.handleLegacyProtocol(auth, conn)
|
return am.handleV1Protocol(auth, conn)
|
||||||
default:
|
default:
|
||||||
<-conn.WritePrepared(msgUnknownSubprotocol)
|
<-conn.WritePrepared(msgUnknownSubprotocol)
|
||||||
return "", errUnknownSubprotocol
|
return "", errUnknownSubprotocol
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errLegacyReadParamsTimeout = errors.New("timeout reading the first message")
|
errReadParamsTimeout = errors.New("timeout reading the first message")
|
||||||
errLegacyUnknownAction = errors.New("unknown action call")
|
errUnknownAction = errors.New("unknown action call")
|
||||||
errLegacyIncorrectParams = errors.New("invalid number of parameters")
|
errIncorrectParams = errors.New("invalid number of parameters")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Handle handles the legacy protocol version.
|
// Handle handles the v1 protocol version.
|
||||||
// This is mostly used for legacy clients.
|
// It is frozen and should not be changed.
|
||||||
//
|
//
|
||||||
// There are two kinds of messages:
|
// There are two kinds of messages:
|
||||||
//
|
//
|
||||||
|
|
@ -33,7 +33,7 @@ var (
|
||||||
// Finally it will send a ResultMessage once handling is complete.
|
// Finally it will send a ResultMessage once handling is complete.
|
||||||
//
|
//
|
||||||
// A corresponding client implementation of this can be found in ..../remote/proto.ts
|
// A corresponding client implementation of this can be found in ..../remote/proto.ts
|
||||||
func (am ActionMap) handleLegacyProtocol(auth *auth.Auth, conn *websocket.Connection) (name string, err error) {
|
func (am ActionMap) handleV1Protocol(auth *auth.Auth, conn *websocket.Connection) (name string, err error) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
// once we have finished executing send a binary message (indicating success) to the client.
|
// once we have finished executing send a binary message (indicating success) to the client.
|
||||||
|
|
@ -48,7 +48,7 @@ func (am ActionMap) handleLegacyProtocol(auth *auth.Auth, conn *websocket.Connec
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate a result message
|
// generate a result message
|
||||||
var result LegacyResultMessage
|
var result ResultMessage
|
||||||
if err == nil {
|
if err == nil {
|
||||||
result.Success = true
|
result.Success = true
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -103,25 +103,25 @@ func (am ActionMap) handleLegacyProtocol(auth *auth.Auth, conn *websocket.Connec
|
||||||
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var call LegacyCallMessage
|
var call CallMessage
|
||||||
select {
|
select {
|
||||||
case buffer := <-binaryMessages:
|
case buffer := <-binaryMessages:
|
||||||
if err := json.Unmarshal(buffer, &call); err != nil {
|
if err := json.Unmarshal(buffer, &call); err != nil {
|
||||||
return "", errLegacyUnknownAction
|
return "", errUnknownAction
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-time.After(1 * time.Second):
|
case <-time.After(1 * time.Second):
|
||||||
return "", errLegacyReadParamsTimeout
|
return "", errReadParamsTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that the given action exists!
|
// check that the given action exists!
|
||||||
// and has the right number of parameters!
|
// and has the right number of parameters!
|
||||||
action, ok := am[call.Call]
|
action, ok := am[call.Call]
|
||||||
if !ok || action.Handle == nil {
|
if !ok || action.Handle == nil {
|
||||||
return call.Call, errLegacyUnknownAction
|
return call.Call, errUnknownAction
|
||||||
}
|
}
|
||||||
if action.NumParams != len(call.Params) {
|
if action.NumParams != len(call.Params) {
|
||||||
return call.Call, errLegacyIncorrectParams
|
return call.Call, errIncorrectParams
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that we have the given permission
|
// check that we have the given permission
|
||||||
|
|
@ -137,7 +137,7 @@ func (am ActionMap) handleLegacyProtocol(auth *auth.Auth, conn *websocket.Connec
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
var signal LegacySignalMessage
|
var signal SignalMessage
|
||||||
|
|
||||||
for binary := range binaryMessages {
|
for binary := range binaryMessages {
|
||||||
signal.Signal = ""
|
signal.Signal = ""
|
||||||
|
|
@ -148,7 +148,7 @@ func (am ActionMap) handleLegacyProtocol(auth *auth.Auth, conn *websocket.Connec
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we got a cancel message, do the cancellation!
|
// if we got a cancel message, do the cancellation!
|
||||||
if signal.Signal == LegacySignalCancel {
|
if signal.Signal == SignalCancel {
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -179,25 +179,25 @@ func (am ActionMap) handleLegacyProtocol(auth *auth.Auth, conn *websocket.Connec
|
||||||
return call.Call, action.Handle(ctx, inputR, output, call.Params...)
|
return call.Call, action.Handle(ctx, inputR, output, call.Params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LegacyCallMessage is sent by the client to the server to invoke a remote procedure
|
// CallMessage is sent by the client to the server to invoke a remote procedure
|
||||||
type LegacyCallMessage struct {
|
type CallMessage struct {
|
||||||
Call string `json:"call"`
|
Call string `json:"call"`
|
||||||
Params []string `json:"params,omitempty"`
|
Params []string `json:"params,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LegacySignalMessage is sent from the client to the server to stop the current procedure
|
// SignalMessage is sent from the client to the server to stop the current procedure
|
||||||
type LegacySignalMessage struct {
|
type SignalMessage struct {
|
||||||
Signal LegacySignal `json:"signal"`
|
Signal Signal `json:"signal"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LegacySignal string
|
type Signal string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LegacySignalCancel LegacySignal = "cancel"
|
SignalCancel Signal = "cancel"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LegacyResultMessage is sent by the server to the client to report the success of a remote procedure
|
// ResultMessage is sent by the server to the client to report the success of a remote procedure
|
||||||
type LegacyResultMessage struct {
|
type ResultMessage struct {
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue