nonce 응답 추가
This commit is contained in:
@ -2,6 +2,8 @@ package wshandler
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
@ -44,7 +46,10 @@ func (ws *WebsocketPeerHandler) upgrade_core(conn *websocket.Conn, accid primiti
|
||||
ws.ClientConnected(peer, c)
|
||||
|
||||
var closeReason string
|
||||
|
||||
response := make([]byte, 255)
|
||||
for {
|
||||
response = response[:0]
|
||||
messageType, r, err := c.NextReader()
|
||||
if err != nil {
|
||||
if ce, ok := err.(*websocket.CloseError); ok {
|
||||
@ -61,11 +66,48 @@ func (ws *WebsocketPeerHandler) upgrade_core(conn *websocket.Conn, accid primiti
|
||||
}
|
||||
|
||||
if messageType == websocket.BinaryMessage {
|
||||
var size [1]byte
|
||||
r.Read(size[:])
|
||||
cmd := make([]byte, size[0])
|
||||
r.Read(cmd)
|
||||
ws.Call(peer, string(cmd), r)
|
||||
var flag [1]byte
|
||||
r.Read(flag[:])
|
||||
if flag[0] == 0xff {
|
||||
// nonce
|
||||
r.Read(response[1:5])
|
||||
|
||||
var size [1]byte
|
||||
cmd := make([]byte, size[0])
|
||||
r.Read(cmd)
|
||||
result, err := ws.Call(peer, string(cmd), r)
|
||||
|
||||
if err != nil {
|
||||
response[0] = 21 // 21 : Negative Ack
|
||||
response = append(response, []byte(err.Error())...)
|
||||
} else {
|
||||
response[0] = 6 // 6 : Acknowledgement
|
||||
|
||||
switch result := result.(type) {
|
||||
case string:
|
||||
response = append(response, []byte(result)...)
|
||||
|
||||
case int8, int16, int32, int64, uint8, uint16, uint32, uint64:
|
||||
response = append(response, []byte(fmt.Sprintf("%d", result))...)
|
||||
|
||||
case float32, float64:
|
||||
response = append(response, []byte(fmt.Sprintf("%f", result))...)
|
||||
|
||||
case []byte:
|
||||
response = append(response, result...)
|
||||
|
||||
default:
|
||||
j, _ := json.Marshal(result)
|
||||
response = append(response, j...)
|
||||
}
|
||||
}
|
||||
c.WriteMessage(websocket.BinaryMessage, response)
|
||||
} else {
|
||||
var size [1]byte
|
||||
cmd := make([]byte, size[0])
|
||||
r.Read(cmd)
|
||||
ws.Call(peer, string(cmd), r)
|
||||
}
|
||||
}
|
||||
}
|
||||
ws.ClientDisconnected(peer, closeReason)
|
||||
|
||||
Reference in New Issue
Block a user