mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
vmess: support alterID
This commit is contained in:
1 parent
14cded4665
commit
f6fae13d88
3 files changed
+95
-51
No files matched your search
+32
-7
@@ -1,12 +1,15 @@
|
||||
package vmess
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/nadoo/glider/common/log"
|
||||
)
|
||||
|
||||
// User of vmess client
|
||||
@@ -16,16 +19,38 @@ type User struct {
|
||||
}
|
||||
|
||||
// NewUser .
|
||||
func NewUser(uuidStr string) (*User, error) {
|
||||
uuid, err := StrToUUID(uuidStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func NewUser(uuid [16]byte) *User {
|
||||
u := &User{UUID: uuid}
|
||||
copy(u.CmdKey[:], GetKey(uuid))
|
||||
return u
|
||||
}
|
||||
|
||||
return u, nil
|
||||
func nextID(oldID [16]byte) (newID [16]byte) {
|
||||
md5hash := md5.New()
|
||||
md5hash.Write(oldID[:])
|
||||
md5hash.Write([]byte("16167dc8-16b6-4e6d-b8bb-65dd68113a81"))
|
||||
for {
|
||||
md5hash.Sum(newID[:0])
|
||||
if !bytes.Equal(oldID[:], newID[:]) {
|
||||
log.F("oldID: %x, newID: %x", oldID, newID)
|
||||
return
|
||||
}
|
||||
md5hash.Write([]byte("533eff8a-4113-4b10-b5ce-0f5d76b98cd2"))
|
||||
}
|
||||
}
|
||||
|
||||
// GenAlterIDUsers generates users according to primary user's id and alterID
|
||||
func (u *User) GenAlterIDUsers(alterID int) []*User {
|
||||
users := make([]*User, alterID)
|
||||
preID := u.UUID
|
||||
for i := 0; i < alterID; i++ {
|
||||
newID := nextID(preID)
|
||||
// NOTE: alterID user is a user which have a different uuid but a same cmdkey with the primary user.
|
||||
users[i] = &User{UUID: newID, CmdKey: u.CmdKey}
|
||||
preID = newID
|
||||
}
|
||||
|
||||
return users
|
||||
}
|
||||
|
||||
// StrToUUID converts string to uuid.
|
||||
|
||||
Reference in new issue
Block a user