1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 18:06:15 -05:00
v2fly/proxy/vmess/id.go

52 lines
816 B
Go
Raw Normal View History

2015-12-07 14:32:38 -05:00
package vmess
2015-09-05 11:48:38 -04:00
import (
2015-09-07 17:48:37 -04:00
"crypto/md5"
"errors"
2015-12-12 15:40:16 -05:00
"github.com/v2ray/v2ray-core/common/uuid"
2015-09-05 11:48:38 -04:00
)
2015-09-14 12:19:17 -04:00
const (
IDBytesLen = 16
)
var (
InvalidID = errors.New("Invalid ID.")
)
2015-09-07 06:00:46 -04:00
// The ID of en entity, in the form of an UUID.
2015-09-14 12:19:17 -04:00
type ID struct {
2015-12-12 15:40:16 -05:00
uuid *uuid.UUID
2015-09-26 16:32:45 -04:00
cmdKey [IDBytesLen]byte
2015-09-14 12:19:17 -04:00
}
func (this *ID) Equals(another *ID) bool {
return this.uuid.Equals(another.uuid)
}
2015-12-12 15:40:16 -05:00
func (this *ID) Bytes() []byte {
return this.uuid.Bytes()
}
func (this *ID) String() string {
return this.uuid.String()
}
2015-09-15 18:06:22 -04:00
2016-01-08 18:10:57 -05:00
func (this *ID) UUID() *uuid.UUID {
return this.uuid
}
func (v ID) CmdKey() []byte {
return v.cmdKey[:]
}
2015-12-12 15:40:16 -05:00
func NewID(uuid *uuid.UUID) *ID {
id := &ID{uuid: uuid}
2015-09-15 18:06:22 -04:00
md5hash := md5.New()
2015-12-12 15:40:16 -05:00
md5hash.Write(uuid.Bytes())
2015-09-14 15:59:44 -04:00
md5hash.Write([]byte("c48619fe-8f02-49e0-b9e9-edf763e17e21"))
2016-01-20 11:45:50 -05:00
md5hash.Sum(id.cmdKey[:0])
return id
2015-09-07 17:48:19 -04:00
}