无多路复用版本
This commit is contained in:
@ -2,7 +2,6 @@ package shadow
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/xtaci/smux"
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
@ -61,21 +60,16 @@ func handler(conn net.Conn, targetAddress string, fakeAddress string) {
|
||||
conn.SetDeadline(time.Now())
|
||||
conn.SetDeadline(time.Time{})
|
||||
|
||||
//Process real tcp connection
|
||||
session, err := smux.Server(conn, nil)
|
||||
realConnection, err := net.Dial("tcp", targetAddress)
|
||||
if err != nil {
|
||||
fmt.Printf("[Server] smux error: %v\n", err)
|
||||
fmt.Printf("[Server] Dial target error : %v\n", err)
|
||||
return
|
||||
}
|
||||
for {
|
||||
stream, err := session.AcceptStream()
|
||||
if err != nil {
|
||||
fmt.Printf("[Server] AcceptStream error: %v\n", err)
|
||||
break
|
||||
}
|
||||
go handlerMux(stream, targetAddress)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
go io.Copy(realConnection, conn)
|
||||
go io.Copy(conn, realConnection)
|
||||
}
|
||||
|
||||
func processHandshake(src net.Conn, dst net.Conn, waitCh chan int) {
|
||||
@ -123,17 +117,3 @@ func processHandshake(src net.Conn, dst net.Conn, waitCh chan int) {
|
||||
}
|
||||
waitCh <- 1
|
||||
}
|
||||
|
||||
func handlerMux(conn *smux.Stream, targetAddress string) {
|
||||
|
||||
realConnection, err := net.Dial("tcp", targetAddress)
|
||||
if err != nil {
|
||||
fmt.Printf("[Server] Dial target error : %v\n", err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
go io.Copy(realConnection, conn)
|
||||
go io.Copy(conn, realConnection)
|
||||
}
|
||||
|
Reference in New Issue
Block a user