This commit is contained in:
esrrhs 2019-10-18 21:30:54 +08:00
parent 65cd195ca8
commit 1402d824c6
2 changed files with 35 additions and 16 deletions

View File

@ -2,6 +2,7 @@ package pingtunnel
import (
"github.com/esrrhs/go-engine/src/loggo"
"github.com/esrrhs/go-engine/src/pool"
"github.com/esrrhs/go-engine/src/rbuffergo"
"golang.org/x/net/icmp"
"math"
@ -33,21 +34,29 @@ func NewClient(addr string, server string, target string, timeout int, sproto in
return nil, err
}
var sendFramePool *pool.Pool
if tcpmode {
sendFramePool = pool.New(func() interface{} {
return Frame{size: 0, data: make([]byte, FRAME_MAX_SIZE)}
})
}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
return &Client{
id: r.Intn(math.MaxInt16),
ipaddr: ipaddr,
tcpaddr: tcpaddr,
addr: addr,
ipaddrServer: ipaddrServer,
addrServer: server,
targetAddr: target,
timeout: timeout,
sproto: sproto,
rproto: rproto,
catch: catch,
key: key,
tcpmode: tcpmode,
id: r.Intn(math.MaxInt16),
ipaddr: ipaddr,
tcpaddr: tcpaddr,
addr: addr,
ipaddrServer: ipaddrServer,
addrServer: server,
targetAddr: target,
timeout: timeout,
sproto: sproto,
rproto: rproto,
catch: catch,
key: key,
tcpmode: tcpmode,
sendFramePool: sendFramePool,
}, nil
}
@ -62,6 +71,8 @@ type Client struct {
key int
tcpmode bool
sendFramePool *pool.Pool
ipaddr *net.UDPAddr
tcpaddr *net.TCPAddr
addr string
@ -219,7 +230,7 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) error {
sendb := rbuffergo.New(1024*1024, false)
recvb := rbuffergo.New(1024*1024, false)
cutsize := 800
cutsize := FRAME_MAX_SIZE
sendwin := sendb.Capacity() / cutsize
clientConn := &ClientConn{tcpaddr: tcpsrcaddr, id: uuid, activeTime: now, close: false, sendb: sendb, recvb: recvb}

View File

@ -206,8 +206,7 @@ func recvICMP(conn icmp.PacketConn, recv chan<- *Packet) {
echoId := int(binary.BigEndian.Uint16(bytes[4:6]))
echoSeq := int(binary.BigEndian.Uint16(bytes[6:8]))
my := &MyMsg{
}
my := &MyMsg{}
my.Unmarshal(bytes[8:n])
if (my.TYPE != (uint32)(DATA) && my.TYPE != (uint32)(PING) && my.TYPE != (uint32)(CATCH)) ||
@ -262,3 +261,12 @@ type CatchMsg struct {
src *net.IPAddr
data []byte
}
const (
FRAME_MAX_SIZE int = 888
)
type Frame struct {
size int
data []byte
}