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"
|
|
|
|
|
2016-01-20 11:31:43 -05:00
|
|
|
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-01-20 11:31:43 -05:00
|
|
|
)
|
|
|
|
|
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
|
2016-01-20 11:31:43 -05:00
|
|
|
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-01-20 11:31:43 -05:00
|
|
|
}
|
|
|
|
|
2016-02-27 10:41:21 -05:00
|
|
|
func (this *VMessOutboundHandler) handleCommand(dest v2net.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 {
|
|
|
|
typedCommand.Host = dest.Address()
|
|
|
|
}
|
2016-01-20 11:31:43 -05:00
|
|
|
this.handleSwitchAccount(typedCommand)
|
|
|
|
default:
|
|
|
|
}
|
2015-12-04 06:42:56 -05:00
|
|
|
}
|