浏览代码

handle response command in vmess outbound.

Darien Raymond 10 年之前
父节点
当前提交
6bb53251e9
共有 3 个文件被更改,包括 21 次插入2 次删除
  1. 1 1
      proxy/vmess/inbound/inbound.go
  2. 5 0
      proxy/vmess/outbound/command.go
  3. 15 1
      proxy/vmess/outbound/outbound.go

+ 1 - 1
proxy/vmess/inbound/inbound.go

@@ -1,4 +1,4 @@
-package vmess
+package inbound
 
 import (
 	"crypto/md5"

+ 5 - 0
proxy/vmess/outbound/command.go

@@ -0,0 +1,5 @@
+package outbound
+
+func handleCommand(command byte, data []byte) error {
+	return nil
+}

+ 15 - 1
proxy/vmess/outbound/outbound.go

@@ -178,7 +178,21 @@ func handleResponse(conn net.Conn, request *protocol.VMessRequest, output chan<-
 	}
 	log.Info("VMessOut received %d bytes from %s", buffer.Len()-4, conn.RemoteAddr().String())
 
-	buffer.SliceFrom(4)
+	responseBegin := 4
+	if buffer.Value[2] != 0 {
+		dataLen := int(buffer.Value[3])
+		if buffer.Len() < dataLen+4 { // Rare case
+			diffBuffer := make([]byte, dataLen+4-buffer.Len())
+			v2net.ReadAllBytes(decryptResponseReader, diffBuffer)
+			buffer.Append(diffBuffer)
+		}
+		command := buffer.Value[2]
+		data := buffer.Value[4 : 4+dataLen]
+		go handleCommand(command, data)
+		responseBegin = 4 + dataLen
+	}
+
+	buffer.SliceFrom(responseBegin)
 	output <- buffer
 
 	if !isUDP {