alias대신 nonce를 받는 peer handler
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
package wshandler
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
@ -37,7 +38,7 @@ func (ws *WebsocketPeerHandler) RegisterHandlers(serveMux *http.ServeMux, prefix
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ws *WebsocketPeerHandler) upgrade_core(conn *websocket.Conn, accid primitive.ObjectID, alias string) {
|
||||
func (ws *WebsocketPeerHandler) upgrade_core(conn *websocket.Conn, accid primitive.ObjectID, nonce uint32) {
|
||||
go func(c *websocket.Conn, accid primitive.ObjectID) {
|
||||
peer := ws.CreatePeer(accid)
|
||||
ws.ClientConnected(peer, c)
|
||||
@ -109,15 +110,18 @@ func (ws *WebsocketPeerHandler) upgrade_nosession(w http.ResponseWriter, r *http
|
||||
return
|
||||
}
|
||||
|
||||
var alias string
|
||||
if v := r.Header.Get("AS-X-ALIAS"); len(v) > 0 {
|
||||
vt, _ := base64.StdEncoding.DecodeString(v)
|
||||
alias = string(vt)
|
||||
} else {
|
||||
alias = accid.Hex()
|
||||
}
|
||||
// var alias string
|
||||
// if v := r.Header.Get("AS-X-ALIAS"); len(v) > 0 {
|
||||
// vt, _ := base64.StdEncoding.DecodeString(v)
|
||||
// alias = string(vt)
|
||||
// } else {
|
||||
// alias = accid.Hex()
|
||||
// }
|
||||
|
||||
ws.upgrade_core(conn, accid, alias)
|
||||
nonce := rand.New(rand.NewSource(time.Now().UnixNano())).Uint32()
|
||||
ws.upgrade_core(conn, accid, nonce)
|
||||
|
||||
w.Write([]byte("asfadsf"))
|
||||
}
|
||||
|
||||
func (ws *WebsocketPeerHandler) upgrade(w http.ResponseWriter, r *http.Request) {
|
||||
@ -147,13 +151,15 @@ func (ws *WebsocketPeerHandler) upgrade(w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
var alias string
|
||||
if v := r.Header.Get("AS-X-ALIAS"); len(v) > 0 {
|
||||
vt, _ := base64.StdEncoding.DecodeString(v)
|
||||
alias = string(vt)
|
||||
} else {
|
||||
alias = authinfo.Account.Hex()
|
||||
}
|
||||
// var alias string
|
||||
// if v := r.Header.Get("AS-X-ALIAS"); len(v) > 0 {
|
||||
// vt, _ := base64.StdEncoding.DecodeString(v)
|
||||
// alias = string(vt)
|
||||
// } else {
|
||||
// alias = authinfo.Account.Hex()
|
||||
// }
|
||||
nonce := rand.New(rand.NewSource(time.Now().UnixNano())).Uint32()
|
||||
ws.upgrade_core(conn, authinfo.Account, nonce)
|
||||
|
||||
ws.upgrade_core(conn, authinfo.Account, alias)
|
||||
w.Write([]byte("asfadsf"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user