2015-12-07 19:32:38 +00:00
|
|
|
package vmess
|
2015-09-05 17:48:38 +02:00
|
|
|
|
|
|
|
import (
|
2015-09-07 23:48:37 +02:00
|
|
|
"crypto/md5"
|
2015-10-13 18:27:29 +02:00
|
|
|
"errors"
|
2015-09-11 17:27:36 +02:00
|
|
|
|
2015-12-12 21:40:16 +01:00
|
|
|
"github.com/v2ray/v2ray-core/common/uuid"
|
2015-09-05 17:48:38 +02:00
|
|
|
)
|
|
|
|
|
2015-09-14 18:19:17 +02:00
|
|
|
const (
|
|
|
|
IDBytesLen = 16
|
|
|
|
)
|
|
|
|
|
2015-10-13 18:27:29 +02:00
|
|
|
var (
|
|
|
|
InvalidID = errors.New("Invalid ID.")
|
|
|
|
)
|
|
|
|
|
2015-09-07 12:00:46 +02:00
|
|
|
// The ID of en entity, in the form of an UUID.
|
2015-09-14 18:19:17 +02:00
|
|
|
type ID struct {
|
2015-12-12 21:40:16 +01:00
|
|
|
uuid *uuid.UUID
|
2015-09-26 22:32:45 +02:00
|
|
|
cmdKey [IDBytesLen]byte
|
2015-09-14 18:19:17 +02:00
|
|
|
}
|
|
|
|
|
2015-12-12 21:40:16 +01:00
|
|
|
func (this *ID) Bytes() []byte {
|
|
|
|
return this.uuid.Bytes()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *ID) String() string {
|
|
|
|
return this.uuid.String()
|
|
|
|
}
|
2015-09-16 00:06:22 +02:00
|
|
|
|
2015-12-12 21:40:16 +01:00
|
|
|
func NewID(uuid *uuid.UUID) *ID {
|
2015-09-16 00:06:22 +02:00
|
|
|
md5hash := md5.New()
|
2015-12-12 21:40:16 +01:00
|
|
|
md5hash.Write(uuid.Bytes())
|
2015-09-14 21:59:44 +02:00
|
|
|
md5hash.Write([]byte("c48619fe-8f02-49e0-b9e9-edf763e17e21"))
|
|
|
|
cmdKey := md5.Sum(nil)
|
|
|
|
|
2015-10-16 10:03:22 +00:00
|
|
|
return &ID{
|
2015-12-12 21:40:16 +01:00
|
|
|
uuid: uuid,
|
2015-09-23 22:17:25 +02:00
|
|
|
cmdKey: cmdKey,
|
2015-12-12 21:40:16 +01:00
|
|
|
}
|
2015-09-14 21:59:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v ID) CmdKey() []byte {
|
2015-09-23 22:17:25 +02:00
|
|
|
return v.cmdKey[:]
|
2015-09-07 23:48:19 +02:00
|
|
|
}
|