Example #1
0
func (this *SwitchAccount) Unmarshal(data []byte) error {
	lenHost := int(data[0])
	if len(data) < lenHost+1 {
		return transport.CorruptedPacket
	}
	this.Host = v2net.ParseAddress(string(data[1 : 1+lenHost]))
	portStart := 1 + lenHost
	if len(data) < portStart+2 {
		return transport.CorruptedPacket
	}
	this.Port = v2net.PortFromBytes(data[portStart : portStart+2])
	idStart := portStart + 2
	if len(data) < idStart+16 {
		return transport.CorruptedPacket
	}
	this.ID, _ = uuid.ParseBytes(data[idStart : idStart+16])
	alterIdStart := idStart + 16
	if len(data) < alterIdStart+2 {
		return transport.CorruptedPacket
	}
	this.AlterIds = serial.ParseUint16(data[alterIdStart : alterIdStart+2])
	levelStart := alterIdStart + 2
	if len(data) < levelStart {
		return transport.CorruptedPacket
	}
	this.Level = vmess.UserLevel(data[levelStart])
	timeStart := levelStart + 1
	if len(data) < timeStart {
		return transport.CorruptedPacket
	}
	this.ValidMin = data[timeStart]
	return nil
}
Example #2
0
func TestReceiverUser(t *testing.T) {
	v2testing.Current(t)

	id := vmess.NewID(uuid.New())
	user := vmess.NewUser(id, vmess.UserLevel(0), 100)
	rec := NewReceiver(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80), user)
	assert.Bool(rec.HasUser(user)).IsTrue()
	assert.Int(len(rec.Accounts)).Equals(1)

	id2 := vmess.NewID(uuid.New())
	user2 := vmess.NewUser(id2, vmess.UserLevel(0), 100)
	assert.Bool(rec.HasUser(user2)).IsFalse()

	rec.AddUser(user2)
	assert.Bool(rec.HasUser(user2)).IsTrue()
	assert.Int(len(rec.Accounts)).Equals(2)
}
Example #3
0
func (u *ConfigUser) UnmarshalJSON(data []byte) error {
	type rawUser struct {
		IdString    string `json:"id"`
		EmailString string `json:"email"`
		LevelInt    int    `json:"level"`
	}
	var rawUserValue rawUser
	if err := json.Unmarshal(data, &rawUserValue); err != nil {
		return err
	}
	id, err := uuid.ParseString(rawUserValue.IdString)
	if err != nil {
		return err
	}
	u.Id = vmess.NewID(id)
	u.Email = rawUserValue.EmailString
	u.LevelValue = vmess.UserLevel(rawUserValue.LevelInt)
	return nil
}