v2fly/proxy/vmess/outbound/command.go

35 lines
978 B
Go
Raw Normal View History

package outbound
import (
2016-07-25 14:48:09 +00:00
"time"
2016-08-20 18:55:45 +00:00
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/proxy/vmess"
)
2016-02-27 15:41:21 +00:00
func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
2016-05-07 19:07:46 +00:00
primary := protocol.NewID(cmd.ID)
2016-05-24 19:55:46 +00:00
alters := protocol.NewAlterIDs(primary, cmd.AlterIds)
2016-07-25 15:36:24 +00:00
account := &vmess.Account{
2016-05-28 11:44:11 +00:00
ID: primary,
AlterIDs: alters,
}
2016-07-25 15:36:24 +00:00
user := protocol.NewUser(cmd.Level, "")
user.Account = account
dest := v2net.TCPDestination(cmd.Host, cmd.Port)
2016-07-25 14:48:09 +00:00
until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
this.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user))
}
2016-02-27 15:41:21 +00:00
func (this *VMessOutboundHandler) handleCommand(dest v2net.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 {
typedCommand.Host = dest.Address()
}
this.handleSwitchAccount(typedCommand)
default:
}
}