You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/proxy/vmess/id.go

47 lines
687 B

package vmess
9 years ago
import (
9 years ago
"crypto/md5"
"errors"
"github.com/v2ray/v2ray-core/common/uuid"
9 years ago
)
const (
IDBytesLen = 16
)
var (
InvalidID = errors.New("Invalid ID.")
)
9 years ago
// The ID of en entity, in the form of an UUID.
type ID struct {
uuid *uuid.UUID
cmdKey [IDBytesLen]byte
}
func (this *ID) Bytes() []byte {
return this.uuid.Bytes()
}
func (this *ID) String() string {
return this.uuid.String()
}
9 years ago
func NewID(uuid *uuid.UUID) *ID {
9 years ago
md5hash := md5.New()
md5hash.Write(uuid.Bytes())
md5hash.Write([]byte("c48619fe-8f02-49e0-b9e9-edf763e17e21"))
cmdKey := md5.Sum(nil)
return &ID{
uuid: uuid,
cmdKey: cmdKey,
}
}
func (v ID) CmdKey() []byte {
return v.cmdKey[:]
9 years ago
}