Fix: connectivity of ssr auth_chain_(ab) protocol (#1180)

This commit is contained in:
goomadao 2021-01-13 23:35:41 +08:00 committed by GitHub
parent e4cdea2111
commit ff430df845
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -230,7 +230,7 @@ func (a *authChain) initUserKeyAndID() {
if len(params) >= 2 { if len(params) >= 2 {
if userID, err := strconv.ParseUint(params[0], 10, 32); err == nil { if userID, err := strconv.ParseUint(params[0], 10, 32); err == nil {
binary.LittleEndian.PutUint32(a.uid[:], uint32(userID)) binary.LittleEndian.PutUint32(a.uid[:], uint32(userID))
a.userKey = []byte(params[1])[:len(a.userKey)] a.userKey = []byte(params[1])
} }
} }
@ -292,6 +292,10 @@ func (a *authChain) packAuthData(data []byte) (outData []byte) {
defer a.mutex.Unlock() defer a.mutex.Unlock()
a.connectionID++ a.connectionID++
if a.connectionID > 0xFF000000 { if a.connectionID > 0xFF000000 {
a.clientID = nil
}
if len(a.clientID) == 0 {
a.clientID = make([]byte, 4)
rand.Read(a.clientID) rand.Read(a.clientID)
b := make([]byte, 4) b := make([]byte, 4)
rand.Read(b) rand.Read(b)
@ -351,7 +355,7 @@ func (a *authChain) packAuthData(data []byte) (outData []byte) {
// data // data
chunkLength, randLength := a.packedDataLen(data) chunkLength, randLength := a.packedDataLen(data)
if chunkLength <= 1500 { if chunkLength+authHeadLength <= cap(outData) {
outData = outData[:authHeadLength+chunkLength] outData = outData[:authHeadLength+chunkLength]
} else { } else {
newOutData := make([]byte, authHeadLength+chunkLength) newOutData := make([]byte, authHeadLength+chunkLength)