无多路复用版本
This commit is contained in:
parent
1c49851d13
commit
c4c6f1c4ff
1
go.mod
1
go.mod
@ -4,7 +4,6 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/spf13/cobra v1.5.0
|
||||
github.com/xtaci/smux v1.5.16
|
||||
)
|
||||
|
||||
require (
|
||||
|
@ -59,6 +59,40 @@ func handlerClient(conn net.Conn, serverAddress string, fakeAddressSNI string) {
|
||||
dial.NetConn().SetDeadline(time.Now())
|
||||
dial.NetConn().SetDeadline(time.Time{})
|
||||
|
||||
go io.Copy(conn, dial.NetConn())
|
||||
go io.Copy(dial.NetConn(), conn)
|
||||
p := &PackAppData{Conn: dial.NetConn()}
|
||||
|
||||
go io.Copy(conn, p)
|
||||
go io.Copy(p, conn)
|
||||
}
|
||||
|
||||
func MyCopy(src io.ReadWriteCloser, dst io.ReadWriteCloser) {
|
||||
buf := make([]byte, 32*1024)
|
||||
for {
|
||||
nr, er := src.Read(buf)
|
||||
if nr > 0 {
|
||||
nw, ew := dst.Write(buf[0:nr])
|
||||
if nw < 0 || nr < nw {
|
||||
nw = 0
|
||||
if ew == nil {
|
||||
fmt.Printf("err1:\n")
|
||||
}
|
||||
}
|
||||
if ew != nil {
|
||||
fmt.Printf("err2:%v\n", ew)
|
||||
break
|
||||
}
|
||||
if nr != nw {
|
||||
fmt.Printf("nr != nw \n")
|
||||
break
|
||||
}
|
||||
}
|
||||
if er != nil {
|
||||
if er != io.EOF {
|
||||
fmt.Printf("err3:%v\n", er)
|
||||
} else {
|
||||
fmt.Println("EOF")
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,15 +23,6 @@ func TestName(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestName2(t *testing.T) {
|
||||
dial, err := tls.DialWithDialer(&net.Dialer{
|
||||
Timeout: time.Second * 5,
|
||||
}, "tcp", "evan.run:443", &tls.Config{
|
||||
ServerName: "evan.run",
|
||||
})
|
||||
|
||||
err = dial.Handshake()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
time.Sleep(time.Minute)
|
||||
v := "12345678"
|
||||
fmt.Println(v[2:2])
|
||||
}
|
||||
|
44
shadow/packer.go
Normal file
44
shadow/packer.go
Normal file
@ -0,0 +1,44 @@
|
||||
package shadow
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
var (
|
||||
AppDataHeader = []byte{0x17, 0x3, 0x3}
|
||||
)
|
||||
|
||||
type PackAppData struct {
|
||||
Conn net.Conn
|
||||
}
|
||||
|
||||
func (m PackAppData) Read(p []byte) (n int, err error) {
|
||||
buf := make([]byte, 32*1024)
|
||||
read, err := m.Conn.Read(buf[0:5])
|
||||
if bytes.Equal(buf[0:3], AppDataHeader) {
|
||||
u := int(binary.BigEndian.Uint16(buf[3:5]))
|
||||
r, err := m.Conn.Read(buf[5 : u+5])
|
||||
copy(p, buf[5:r+5])
|
||||
return r, err
|
||||
} else {
|
||||
fmt.Println("Header is not present")
|
||||
return read, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m PackAppData) Write(p []byte) (n int, err error) {
|
||||
t := make([]byte, len(p)+5)
|
||||
copy(t[0:], AppDataHeader)
|
||||
binary.BigEndian.PutUint16(t[3:], uint16(len(p)))
|
||||
copy(t[5:], p)
|
||||
write, err := m.Conn.Write(t)
|
||||
write = write - 5
|
||||
return write, err
|
||||
}
|
||||
|
||||
func (m PackAppData) Close() error {
|
||||
return m.Conn.Close()
|
||||
}
|
@ -68,8 +68,10 @@ func handler(conn net.Conn, targetAddress string, fakeAddress string) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
go io.Copy(realConnection, conn)
|
||||
go io.Copy(conn, realConnection)
|
||||
|
||||
p := &PackAppData{Conn: conn}
|
||||
go io.Copy(realConnection, p)
|
||||
go io.Copy(p, realConnection)
|
||||
}
|
||||
|
||||
func processHandshake(src net.Conn, dst net.Conn, waitCh chan int) {
|
||||
|
Loading…
Reference in New Issue
Block a user