mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-17 06:46:33 -05:00
move uuid.Next to protocol
This commit is contained in:
parent
413a3a4eb6
commit
67c7d6da4a
@ -56,11 +56,25 @@ func NewID(uuid uuid.UUID) *ID {
|
||||
return id
|
||||
}
|
||||
|
||||
func nextId(u *uuid.UUID) uuid.UUID {
|
||||
md5hash := md5.New()
|
||||
common.Must2(md5hash.Write(u.Bytes()))
|
||||
common.Must2(md5hash.Write([]byte("16167dc8-16b6-4e6d-b8bb-65dd68113a81")))
|
||||
var newid uuid.UUID
|
||||
for {
|
||||
md5hash.Sum(newid[:0])
|
||||
if !newid.Equals(u) {
|
||||
return newid
|
||||
}
|
||||
common.Must2(md5hash.Write([]byte("533eff8a-4113-4b10-b5ce-0f5d76b98cd2")))
|
||||
}
|
||||
}
|
||||
|
||||
func NewAlterIDs(primary *ID, alterIDCount uint16) []*ID {
|
||||
alterIDs := make([]*ID, alterIDCount)
|
||||
prevID := primary.UUID()
|
||||
for idx := range alterIDs {
|
||||
newid := prevID.Next()
|
||||
newid := nextId(&prevID)
|
||||
// TODO: check duplicates
|
||||
alterIDs[idx] = NewID(newid)
|
||||
prevID = newid
|
||||
|
@ -2,7 +2,6 @@ package uuid // import "v2ray.com/core/common/uuid"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
|
||||
@ -46,21 +45,6 @@ func (u *UUID) Equals(another *UUID) bool {
|
||||
return bytes.Equal(u.Bytes(), another.Bytes())
|
||||
}
|
||||
|
||||
// Next generates a deterministic random UUID based on this UUID.
|
||||
func (u *UUID) Next() UUID {
|
||||
md5hash := md5.New()
|
||||
common.Must2(md5hash.Write(u.Bytes()))
|
||||
common.Must2(md5hash.Write([]byte("16167dc8-16b6-4e6d-b8bb-65dd68113a81")))
|
||||
var newid UUID
|
||||
for {
|
||||
md5hash.Sum(newid[:0])
|
||||
if !newid.Equals(u) {
|
||||
return newid
|
||||
}
|
||||
common.Must2(md5hash.Write([]byte("533eff8a-4113-4b10-b5ce-0f5d76b98cd2")))
|
||||
}
|
||||
}
|
||||
|
||||
// New creates a UUID with random value.
|
||||
func New() UUID {
|
||||
var uuid UUID
|
||||
|
Loading…
Reference in New Issue
Block a user