forked from LyleMi/ja3proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.go
64 lines (52 loc) · 1.08 KB
/
debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"encoding/hex"
"io"
"log"
"net"
"unicode"
)
type DebugWriter struct {
Name string
Conn net.Conn
}
func (writer DebugWriter) Write(data []byte) (n int, err error) {
if unicode.IsPrint(rune(data[0])) {
log.Printf("%s send %d bytes: \n%s", writer.Name, len(data), string(data))
} else {
log.Printf("%s send %d bytes: \n%s", writer.Name, len(data), hex.Dump(data))
}
return writer.Conn.Write(data)
}
func debugJunction(destConn net.Conn, clientConn net.Conn) {
chDone := make(chan bool)
go func() {
defer func() {
destConn.Close()
chDone <- true
}()
writer := &DebugWriter{
Name: clientConn.RemoteAddr().String(),
Conn: destConn,
}
_, err := io.Copy(writer, clientConn)
if err != nil {
log.Println("copy dest to client error:", err)
}
}()
go func() {
defer func() {
clientConn.Close()
chDone <- true
}()
writer := &DebugWriter{
Name: destConn.RemoteAddr().String(),
Conn: clientConn,
}
_, err := io.Copy(writer, destConn)
if err != nil {
log.Println("copy client to dest error:", err)
}
}()
<-chDone
}