2015-12-04 06:42:56 -05:00
|
|
|
package outbound
|
|
|
|
|
2016-01-20 11:31:43 -05:00
|
|
|
import (
|
|
|
|
"github.com/v2ray/v2ray-core/common/log"
|
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
|
|
"github.com/v2ray/v2ray-core/proxy/vmess"
|
|
|
|
"github.com/v2ray/v2ray-core/proxy/vmess/command"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (this *VMessOutboundHandler) handleSwitchAccount(cmd *command.SwitchAccount) {
|
|
|
|
user := vmess.NewUser(vmess.NewID(cmd.ID), cmd.Level, cmd.AlterIds.Value())
|
|
|
|
dest := v2net.TCPDestination(cmd.Host, cmd.Port)
|
|
|
|
this.receiverManager.AddDetour(NewReceiver(dest, user), cmd.ValidMin)
|
|
|
|
}
|
|
|
|
|
2016-01-21 11:22:56 -05:00
|
|
|
func (this *VMessOutboundHandler) handleCommand(dest v2net.Destination, cmdId byte, data []byte) {
|
2016-01-20 11:31:43 -05:00
|
|
|
cmd, err := command.CreateResponseCommand(cmdId)
|
|
|
|
if err != nil {
|
|
|
|
log.Warning("VMessOut: Unknown response command (", cmdId, "): ", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := cmd.Unmarshal(data); err != nil {
|
|
|
|
log.Warning("VMessOut: Failed to parse response command: ", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
switch typedCommand := cmd.(type) {
|
|
|
|
case *command.SwitchAccount:
|
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
|
|
|
}
|