2015-12-04 06:42:56 -05:00
|
|
|
package outbound
|
|
|
|
|
2016-01-20 11:31:43 -05:00
|
|
|
import (
|
2016-07-25 10:48:09 -04:00
|
|
|
"time"
|
|
|
|
|
2017-01-13 17:42:39 -05:00
|
|
|
"v2ray.com/core/common/net"
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/common/protocol"
|
2016-12-15 05:51:09 -05:00
|
|
|
"v2ray.com/core/common/serial"
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/proxy/vmess"
|
2016-01-20 11:31:43 -05:00
|
|
|
)
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
|
2016-10-12 12:43:55 -04:00
|
|
|
account := &vmess.Account{
|
2016-09-17 18:41:21 -04:00
|
|
|
Id: cmd.ID.String(),
|
|
|
|
AlterId: uint32(cmd.AlterIds),
|
|
|
|
}
|
2016-10-16 08:22:21 -04:00
|
|
|
|
2016-09-17 18:41:21 -04:00
|
|
|
user := &protocol.User{
|
|
|
|
Email: "",
|
|
|
|
Level: cmd.Level,
|
2016-12-15 05:51:09 -05:00
|
|
|
Account: serial.ToTypedMessage(account),
|
2016-05-28 07:44:11 -04:00
|
|
|
}
|
2017-01-13 17:42:39 -05:00
|
|
|
dest := net.TCPDestination(cmd.Host, cmd.Port)
|
2016-07-25 10:48:09 -04:00
|
|
|
until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
|
2016-11-27 15:39:09 -05:00
|
|
|
v.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user))
|
2016-01-20 11:31:43 -05:00
|
|
|
}
|
|
|
|
|
2017-01-13 17:42:39 -05:00
|
|
|
func (v *VMessOutboundHandler) handleCommand(dest net.Destination, cmd protocol.ResponseCommand) {
|
2016-01-20 11:31:43 -05:00
|
|
|
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 {
|
2016-09-20 05:53:05 -04:00
|
|
|
typedCommand.Host = dest.Address
|
2016-01-21 11:22:56 -05:00
|
|
|
}
|
2016-11-27 15:39:09 -05:00
|
|
|
v.handleSwitchAccount(typedCommand)
|
2016-01-20 11:31:43 -05:00
|
|
|
default:
|
|
|
|
}
|
2015-12-04 06:42:56 -05:00
|
|
|
}
|