Example #1
0
func (this *VMessInboundHandler) generateCommand(request *protocol.RequestHeader) protocol.ResponseCommand {
	if this.features != nil && this.features.Detour != nil {

		tag := this.features.Detour.ToTag
		if this.inboundHandlerManager != nil {
			handler, availableMin := this.inboundHandlerManager.GetHandler(tag)
			inboundHandler, ok := handler.(*VMessInboundHandler)
			if ok {
				if availableMin > 255 {
					availableMin = 255
				}

				log.Info("VMessIn: Pick detour handler for port ", inboundHandler.Port(), " for ", availableMin, " minutes.")
				user := inboundHandler.GetUser(request.User.Email)
				return &protocol.CommandSwitchAccount{
					Port:     inboundHandler.Port(),
					ID:       user.ID.UUID(),
					AlterIds: serial.Uint16Literal(len(user.AlterIDs)),
					Level:    user.Level,
					ValidMin: byte(availableMin),
				}
			}
		}
	}

	return nil
}
Example #2
0
func Authenticate(buffer *alloc.Buffer) {
	fnvHash := fnv.New32a()
	fnvHash.Write(buffer.Value)

	buffer.SliceBack(4)
	fnvHash.Sum(buffer.Value[:0])

	buffer.Prepend(serial.Uint16Literal(uint16(buffer.Len())).Bytes())
}
Example #3
0
func (this *VMessInboundHandler) generateCommand(buffer *alloc.Buffer) {
	cmd := byte(0)
	commandBytes := alloc.NewSmallBuffer().Clear()
	defer commandBytes.Release()

	if this.features != nil && this.features.Detour != nil {

		tag := this.features.Detour.ToTag
		if this.space.HasInboundHandlerManager() {
			handlerManager := this.space.InboundHandlerManager()
			handler, availableMin := handlerManager.GetHandler(tag)
			inboundHandler, ok := handler.(*VMessInboundHandler)
			if ok {
				if availableMin > 255 {
					availableMin = 255
				}
				cmd = byte(1)
				log.Info("VMessIn: Pick detour handler for port ", inboundHandler.Port(), " for ", availableMin, " minutes.")
				user := inboundHandler.GetUser()
				saCmd := &command.SwitchAccount{
					Port:     inboundHandler.Port(),
					ID:       user.ID.UUID(),
					AlterIds: serial.Uint16Literal(len(user.AlterIDs)),
					Level:    user.Level,
					ValidMin: byte(availableMin),
				}
				saCmd.Marshal(commandBytes)
			}
		}
	}

	if cmd == 0 || commandBytes.Len()+4 > 256 {
		buffer.AppendBytes(byte(0), byte(0))
	} else {
		buffer.AppendBytes(cmd, byte(commandBytes.Len()+4))
		fnv1hash := fnv.New32a()
		fnv1hash.Write(commandBytes.Value)
		hashValue := fnv1hash.Sum32()
		buffer.AppendBytes(byte(hashValue>>24), byte(hashValue>>16), byte(hashValue>>8), byte(hashValue))
		buffer.Append(commandBytes.Value)
	}
}
Example #4
0
func (this *VMessInboundHandler) generateCommand(buffer *alloc.Buffer) {
	cmd := byte(0)
	commandBytes := alloc.NewSmallBuffer().Clear()
	defer commandBytes.Release()

	if this.features != nil && this.features.Detour != nil {
		tag := this.features.Detour.ToTag
		if this.space.HasInboundHandlerManager() {
			handlerManager := this.space.InboundHandlerManager()
			handler, availableSec := handlerManager.GetHandler(tag)
			inboundHandler, ok := handler.(*VMessInboundHandler)
			if ok {
				user := inboundHandler.GetUser()
				availableMin := availableSec / 60
				if availableMin > 255 {
					availableMin = 255
				}

				saCmd := &command.SwitchAccount{
					Port:     inboundHandler.Port(),
					ID:       user.ID.UUID(),
					AlterIds: serial.Uint16Literal(len(user.AlterIDs)),
					Level:    user.Level,
					ValidMin: byte(availableMin),
				}
				saCmd.Marshal(commandBytes)
			}
		}
	}

	if commandBytes.Len() > 256 {
		buffer.AppendBytes(byte(0), byte(0))
	} else {
		buffer.AppendBytes(cmd, byte(commandBytes.Len()))
		buffer.Append(commandBytes.Value)
	}
}
Example #5
0
func (this Port) String() string {
	return serial.Uint16Literal(this).String()
}
Example #6
0
// Bytes returns the correspoding bytes of this Port, in big endian order.
func (this Port) Bytes() []byte {
	return serial.Uint16Literal(this).Bytes()
}
Example #7
0
func Uint16(value uint16) *Uint16Subject {
	return &Uint16Subject{value: serial.Uint16Literal(value)}
}
Example #8
0
func (subject *Uint16Subject) LessThan(expectation uint16) {
	if subject.value.Value() >= expectation {
		subject.Fail(subject.DisplayString(), "is less than", serial.Uint16Literal(expectation))
	}
}
Example #9
0
func (subject *Uint16Subject) GreaterThan(expectation uint16) {
	if subject.value.Value() <= expectation {
		subject.Fail(subject.DisplayString(), "is greater than", serial.Uint16Literal(expectation))
	}
}
Example #10
0
func (subject *Uint16Subject) Equals(expectation uint16) {
	if subject.value.Value() != expectation {
		subject.Fail(subject.DisplayString(), "is equal to", serial.Uint16Literal(expectation))
	}
}