Browse Source

fix snifer

Darien Raymond 8 years ago
parent
commit
94405dd467
2 changed files with 13 additions and 1 deletions
  1. 1 1
      app/dispatcher/impl/default.go
  2. 12 0
      common/buf/multi_buffer.go

+ 1 - 1
app/dispatcher/impl/default.go

@@ -110,7 +110,7 @@ func snifer(ctx context.Context, sniferList []proxyman.KnownProtocols, outbound
 			if mb.IsEmpty() {
 				continue
 			}
-			nBytes, _ := mb.Read(payload)
+			nBytes := mb.Copy(payload)
 			for _, protocol := range sniferList {
 				var f func([]byte) (string, error)
 				switch protocol {

+ 12 - 0
common/buf/multi_buffer.go

@@ -31,6 +31,18 @@ func (mb *MultiBuffer) AppendMulti(buf MultiBuffer) {
 	*mb = append(*mb, buf...)
 }
 
+func (mb MultiBuffer) Copy(b []byte) int {
+	total := 0
+	for _, bb := range mb {
+		nBytes := copy(b[total:], bb.Bytes())
+		total += nBytes
+		if nBytes < bb.Len() {
+			break
+		}
+	}
+	return total
+}
+
 func (mb *MultiBuffer) Read(b []byte) (int, error) {
 	endIndex := len(*mb)
 	totalBytes := 0