1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00
v2fly/proxy/vmess/outbound/command.go

35 lines
1017 B
Go
Raw Normal View History

package outbound
import (
2016-07-25 10:48:09 -04:00
"time"
v2net "github.com/v2ray/v2ray-core/common/net"
2016-02-27 10:41:21 -05:00
"github.com/v2ray/v2ray-core/common/protocol"
2016-07-25 11:36:24 -04:00
"github.com/v2ray/v2ray-core/proxy/vmess"
)
2016-02-27 10:41:21 -05:00
func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
2016-05-07 15:07:46 -04:00
primary := protocol.NewID(cmd.ID)
2016-05-24 15:55:46 -04:00
alters := protocol.NewAlterIDs(primary, cmd.AlterIds)
2016-07-25 11:36:24 -04:00
account := &vmess.Account{
2016-05-28 07:44:11 -04:00
ID: primary,
AlterIDs: alters,
}
2016-07-25 11:36:24 -04:00
user := protocol.NewUser(cmd.Level, "")
user.Account = account
dest := v2net.TCPDestination(cmd.Host, cmd.Port)
2016-07-25 10:48:09 -04:00
until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
this.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user))
}
2016-02-27 10:41:21 -05:00
func (this *VMessOutboundHandler) handleCommand(dest v2net.Destination, cmd protocol.ResponseCommand) {
switch typedCommand := cmd.(type) {
2016-02-27 10:41:21 -05:00
case *protocol.CommandSwitchAccount:
2016-01-21 11:22:56 -05:00
if typedCommand.Host == nil {
typedCommand.Host = dest.Address()
}
this.handleSwitchAccount(typedCommand)
default:
}
}