command.go 973 B

12345678910111213141516171819202122232425262728293031
  1. package outbound
  2. import (
  3. "github.com/v2ray/v2ray-core/common/log"
  4. v2net "github.com/v2ray/v2ray-core/common/net"
  5. "github.com/v2ray/v2ray-core/proxy/vmess"
  6. "github.com/v2ray/v2ray-core/proxy/vmess/command"
  7. )
  8. func (this *VMessOutboundHandler) handleSwitchAccount(cmd *command.SwitchAccount) {
  9. user := vmess.NewUser(vmess.NewID(cmd.ID), cmd.Level, cmd.AlterIds.Value())
  10. dest := v2net.TCPDestination(cmd.Host, cmd.Port)
  11. this.receiverManager.AddDetour(NewReceiver(dest, user), cmd.ValidMin)
  12. }
  13. func (this *VMessOutboundHandler) handleCommand(cmdId byte, data []byte) {
  14. cmd, err := command.CreateResponseCommand(cmdId)
  15. if err != nil {
  16. log.Warning("VMessOut: Unknown response command (", cmdId, "): ", err)
  17. return
  18. }
  19. if err := cmd.Unmarshal(data); err != nil {
  20. log.Warning("VMessOut: Failed to parse response command: ", err)
  21. return
  22. }
  23. switch typedCommand := cmd.(type) {
  24. case *command.SwitchAccount:
  25. this.handleSwitchAccount(typedCommand)
  26. default:
  27. }
  28. }