protocol fixups

This commit is contained in:
sawka 2024-10-21 16:38:54 -07:00
parent 337baaa4a1
commit e0ffa4fa86
2 changed files with 11 additions and 3 deletions

View File

@ -82,6 +82,7 @@ func handleNewListenerConn(conn net.Conn, router *wshutil.WshRouter) {
routeId, err := proxy.HandleClientProxyAuth(upstreamClient)
if err != nil {
log.Printf("error handling client proxy auth: %v\n", err)
conn.Close()
return
}
router.RegisterRoute(routeId, proxy, false)

View File

@ -137,15 +137,21 @@ func (p *WshRpcProxy) HandleClientProxyAuth(upstream *WshRpc) (string, error) {
}
resp, err := upstream.SendRpcRequest(msg.Command, msg.Data, nil)
if err != nil {
return "", fmt.Errorf("error authenticating: %w", err)
respErr := fmt.Errorf("error authenticating: %w", err)
p.sendResponseError(msg, respErr)
return "", respErr
}
var respData wshrpc.CommandAuthenticateRtnData
err = utilfn.ReUnmarshal(&respData, resp)
if err != nil {
return "", fmt.Errorf("error unmarshalling authenticate response: %w", err)
respErr := fmt.Errorf("error unmarshalling authenticate response: %w", err)
p.sendResponseError(msg, respErr)
return "", respErr
}
if respData.AuthToken == "" {
return "", fmt.Errorf("no auth token in authenticate response")
respErr := fmt.Errorf("no auth token in authenticate response")
p.sendResponseError(msg, respErr)
return "", respErr
}
p.SetAuthToken(respData.AuthToken)
announceMsg := RpcMessage{
@ -155,6 +161,7 @@ func (p *WshRpcProxy) HandleClientProxyAuth(upstream *WshRpc) (string, error) {
}
announceBytes, _ := json.Marshal(announceMsg)
upstream.SendRpcMessage(announceBytes)
p.sendAuthenticateResponse(msg, respData.RouteId)
return respData.RouteId, nil
}
}