1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-28 14:56:33 -04:00

move uuid.Next to protocol

This commit is contained in:
Darien Raymond 2018-04-14 21:14:35 +02:00
parent 413a3a4eb6
commit 67c7d6da4a
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 15 additions and 17 deletions

View File

@ -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

View File

@ -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