alias대신 nonce를 받는 peer handler
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -105,3 +106,13 @@ func TestPeerApiBroker(t *testing.T) {
|
|||||||
func1args, _ = json.Marshal([]any{float64(111.1), []int{99, 98}})
|
func1args, _ = json.Marshal([]any{float64(111.1), []int{99, 98}})
|
||||||
ws.Call(peer, "test.ApiFunc3", bytes.NewBuffer(func1args))
|
ws.Call(peer, "test.ApiFunc3", bytes.NewBuffer(func1args))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOverflow(t *testing.T) {
|
||||||
|
var x uint32
|
||||||
|
x = math.MaxUint32
|
||||||
|
|
||||||
|
var y uint32
|
||||||
|
y = x + 1
|
||||||
|
|
||||||
|
fmt.Printf("%x, %x", x, y)
|
||||||
|
}
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
package wshandler
|
package wshandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"io"
|
"io"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"repositories.action2quare.com/ayo/gocommon"
|
"repositories.action2quare.com/ayo/gocommon"
|
||||||
@ -37,7 +38,7 @@ func (ws *WebsocketPeerHandler) RegisterHandlers(serveMux *http.ServeMux, prefix
|
|||||||
return nil
|
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) {
|
go func(c *websocket.Conn, accid primitive.ObjectID) {
|
||||||
peer := ws.CreatePeer(accid)
|
peer := ws.CreatePeer(accid)
|
||||||
ws.ClientConnected(peer, c)
|
ws.ClientConnected(peer, c)
|
||||||
@ -109,15 +110,18 @@ func (ws *WebsocketPeerHandler) upgrade_nosession(w http.ResponseWriter, r *http
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var alias string
|
// var alias string
|
||||||
if v := r.Header.Get("AS-X-ALIAS"); len(v) > 0 {
|
// if v := r.Header.Get("AS-X-ALIAS"); len(v) > 0 {
|
||||||
vt, _ := base64.StdEncoding.DecodeString(v)
|
// vt, _ := base64.StdEncoding.DecodeString(v)
|
||||||
alias = string(vt)
|
// alias = string(vt)
|
||||||
} else {
|
// } else {
|
||||||
alias = accid.Hex()
|
// 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) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var alias string
|
// var alias string
|
||||||
if v := r.Header.Get("AS-X-ALIAS"); len(v) > 0 {
|
// if v := r.Header.Get("AS-X-ALIAS"); len(v) > 0 {
|
||||||
vt, _ := base64.StdEncoding.DecodeString(v)
|
// vt, _ := base64.StdEncoding.DecodeString(v)
|
||||||
alias = string(vt)
|
// alias = string(vt)
|
||||||
} else {
|
// } else {
|
||||||
alias = authinfo.Account.Hex()
|
// 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