diff --git a/common/protocol/id.go b/common/protocol/id.go index 6deb0cce..f5827a97 100755 --- a/common/protocol/id.go +++ b/common/protocol/id.go @@ -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 diff --git a/common/uuid/uuid.go b/common/uuid/uuid.go index 788b7346..9679942a 100755 --- a/common/uuid/uuid.go +++ b/common/uuid/uuid.go @@ -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