1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 23:47:07 -05:00

id cleanup

This commit is contained in:
Darien Raymond 2017-09-27 21:09:47 +02:00
parent 3a27ff8239
commit 59094b4959

View File

@ -5,6 +5,7 @@ import (
"crypto/md5" "crypto/md5"
"hash" "hash"
"v2ray.com/core/common"
"v2ray.com/core/common/uuid" "v2ray.com/core/common/uuid"
) )
@ -25,31 +26,32 @@ type ID struct {
} }
// Equals returns true if this ID equals to the other one. // Equals returns true if this ID equals to the other one.
func (v *ID) Equals(another *ID) bool { func (id *ID) Equals(another *ID) bool {
return v.uuid.Equals(another.uuid) return id.uuid.Equals(another.uuid)
} }
func (v *ID) Bytes() []byte { func (id *ID) Bytes() []byte {
return v.uuid.Bytes() return id.uuid.Bytes()
} }
func (v *ID) String() string { func (id *ID) String() string {
return v.uuid.String() return id.uuid.String()
} }
func (v *ID) UUID() *uuid.UUID { func (id *ID) UUID() *uuid.UUID {
return v.uuid return id.uuid
} }
func (v ID) CmdKey() []byte { func (id ID) CmdKey() []byte {
return v.cmdKey[:] return id.cmdKey[:]
} }
// NewID returns an ID with given UUID.
func NewID(uuid *uuid.UUID) *ID { func NewID(uuid *uuid.UUID) *ID {
id := &ID{uuid: uuid} id := &ID{uuid: uuid}
md5hash := md5.New() md5hash := md5.New()
md5hash.Write(uuid.Bytes()) common.Must2(md5hash.Write(uuid.Bytes()))
md5hash.Write([]byte("c48619fe-8f02-49e0-b9e9-edf763e17e21")) common.Must2(md5hash.Write([]byte("c48619fe-8f02-49e0-b9e9-edf763e17e21")))
md5hash.Sum(id.cmdKey[:0]) md5hash.Sum(id.cmdKey[:0])
return id return id
} }