v2ray-core/proxy/vmess/outbound/command.go

41 lines
1.0 KiB
Go
Raw Normal View History

package outbound
import (
2016-07-25 14:48:09 +00:00
"time"
2017-01-13 22:42:39 +00:00
"v2ray.com/core/common/net"
2016-08-20 18:55:45 +00:00
"v2ray.com/core/common/protocol"
2016-12-15 10:51:09 +00:00
"v2ray.com/core/common/serial"
2016-08-20 18:55:45 +00:00
"v2ray.com/core/proxy/vmess"
)
2017-02-13 12:16:37 +00:00
func (v *Handler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
2016-10-12 16:43:55 +00:00
account := &vmess.Account{
2016-09-17 22:41:21 +00:00
Id: cmd.ID.String(),
AlterId: uint32(cmd.AlterIds),
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_LEGACY,
},
2016-09-17 22:41:21 +00:00
}
2016-10-16 12:22:21 +00:00
2016-09-17 22:41:21 +00:00
user := &protocol.User{
Email: "",
Level: cmd.Level,
2016-12-15 10:51:09 +00:00
Account: serial.ToTypedMessage(account),
2016-05-28 11:44:11 +00:00
}
2017-01-13 22:42:39 +00:00
dest := net.TCPDestination(cmd.Host, cmd.Port)
2016-07-25 14:48:09 +00:00
until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
2016-11-27 20:39:09 +00:00
v.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user))
}
2017-02-13 12:16:37 +00:00
func (v *Handler) handleCommand(dest net.Destination, cmd protocol.ResponseCommand) {
switch typedCommand := cmd.(type) {
2016-02-27 15:41:21 +00:00
case *protocol.CommandSwitchAccount:
2016-01-21 16:22:56 +00:00
if typedCommand.Host == nil {
2016-09-20 09:53:05 +00:00
typedCommand.Host = dest.Address
2016-01-21 16:22:56 +00:00
}
2016-11-27 20:39:09 +00:00
v.handleSwitchAccount(typedCommand)
default:
}
}