Skip to content

Commit

Permalink
Use version to match rtty client
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
Jianhui Zhao committed Oct 2, 2018
1 parent 00dc15c commit cce118d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
)

const (
/* Match the version with the device */
RTTY_PROTO_VERSION = 1
/* Minimal version required of the device: 6.2.0 */
RTTY_REQUIRED_VERSION = (6 << 16) | (2 << 8) | 0

/* Max lose ping times */
RTTY_MAX_LOSE_PING = 3
Expand Down Expand Up @@ -188,7 +188,7 @@ func (c *Client) keepAlive(keepalive int64) {
/* serveWs handles websocket requests from the peer. */
func serveWs(br *Broker, w http.ResponseWriter, r *http.Request) {
keepalive, _ := strconv.ParseInt(r.URL.Query().Get("keepalive"), 10, 64)
proto, _ := strconv.Atoi(r.URL.Query().Get("proto"))
ver, _ := strconv.Atoi(r.URL.Query().Get("ver"))
isDev := r.URL.Query().Get("device") != ""
devid := r.URL.Query().Get("devid")

Expand All @@ -202,16 +202,20 @@ func serveWs(br *Broker, w http.ResponseWriter, r *http.Request) {
msg := fmt.Sprintf(`{"type":"register","err":1,"msg":"devid required"}`)
conn.WriteMessage(websocket.TextMessage, []byte(msg))
rlog.Println("devid required")
conn.Close()
time.AfterFunc(100*time.Millisecond, func() {
conn.Close()
})
return
}

if isDev {
if proto != RTTY_PROTO_VERSION {
msg := fmt.Sprintf(`{"type":"register","err":1,"msg":"proto number is not matched"}`)
if ver < RTTY_REQUIRED_VERSION {
msg := fmt.Sprintf(`{"type":"register","err":1,"msg":"version is not matched"}`)
conn.WriteMessage(websocket.TextMessage, []byte(msg))
rlog.Printf("proto number is not matched for device '%s', you need to update your server(rttys) or client(rtty) or both them", devid)
conn.Close()
rlog.Printf("version is not matched for device '%s', you need to update your server(rttys) or client(rtty) or both them", devid)
time.AfterFunc(100*time.Millisecond, func() {
conn.Close()
})
return
}
}
Expand Down

0 comments on commit cce118d

Please sign in to comment.