1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-05-07 04:59:07 -04:00

move fundamental interfaces from vmess to common

This commit is contained in:
v2ray
2016-02-03 11:58:42 +01:00
parent e8b0505c01
commit 2147ba5ab3
19 changed files with 67 additions and 63 deletions

51
common/protocol/id.go Normal file
View File

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