1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-08-19 19:04:15 -04:00
v2fly/proxy/vmess/inbound/command.go

48 lines
1.3 KiB
Go
Raw Normal View History

2016-01-19 17:41:40 -05:00
package inbound
import (
"github.com/v2ray/v2ray-core/common/alloc"
2016-01-22 10:48:17 -05:00
"github.com/v2ray/v2ray-core/common/log"
2016-01-19 17:41:40 -05:00
"github.com/v2ray/v2ray-core/common/serial"
"github.com/v2ray/v2ray-core/proxy/vmess/command"
)
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 {
2016-01-21 11:22:56 -05:00
cmd = byte(1)
2016-01-19 17:41:40 -05:00
tag := this.features.Detour.ToTag
if this.space.HasInboundHandlerManager() {
handlerManager := this.space.InboundHandlerManager()
2016-01-21 11:29:18 -05:00
handler, availableMin := handlerManager.GetHandler(tag)
2016-01-22 10:48:17 -05:00
2016-01-19 17:41:40 -05:00
inboundHandler, ok := handler.(*VMessInboundHandler)
if ok {
if availableMin > 255 {
availableMin = 255
2016-01-19 17:41:40 -05:00
}
2016-01-22 10:48:17 -05:00
log.Info("VMessIn: Pick detour handler for port ", inboundHandler.Port(), " for ", availableMin, " minutes.")
user := inboundHandler.GetUser()
2016-01-19 17:41:40 -05:00
saCmd := &command.SwitchAccount{
Port: inboundHandler.Port(),
ID: user.ID.UUID(),
AlterIds: serial.Uint16Literal(len(user.AlterIDs)),
Level: user.Level,
ValidMin: byte(availableMin),
2016-01-19 17:41:40 -05:00
}
saCmd.Marshal(commandBytes)
}
}
}
if commandBytes.Len() > 256 {
buffer.AppendBytes(byte(0), byte(0))
} else {
buffer.AppendBytes(cmd, byte(commandBytes.Len()))
buffer.Append(commandBytes.Value)
}
}