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 ( import (
"github.com/esrrhs/go-engine/src/loggo" "github.com/esrrhs/go-engine/src/loggo"
"github.com/esrrhs/go-engine/src/pool"
"github.com/esrrhs/go-engine/src/rbuffergo" "github.com/esrrhs/go-engine/src/rbuffergo"
"golang.org/x/net/icmp" "golang.org/x/net/icmp"
"math" "math"
@ -33,21 +34,29 @@ func NewClient(addr string, server string, target string, timeout int, sproto in
return nil, err 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())) r := rand.New(rand.NewSource(time.Now().UnixNano()))
return &Client{ return &Client{
id: r.Intn(math.MaxInt16), id: r.Intn(math.MaxInt16),
ipaddr: ipaddr, ipaddr: ipaddr,
tcpaddr: tcpaddr, tcpaddr: tcpaddr,
addr: addr, addr: addr,
ipaddrServer: ipaddrServer, ipaddrServer: ipaddrServer,
addrServer: server, addrServer: server,
targetAddr: target, targetAddr: target,
timeout: timeout, timeout: timeout,
sproto: sproto, sproto: sproto,
rproto: rproto, rproto: rproto,
catch: catch, catch: catch,
key: key, key: key,
tcpmode: tcpmode, tcpmode: tcpmode,
sendFramePool: sendFramePool,
}, nil }, nil
} }
@ -62,6 +71,8 @@ type Client struct {
key int key int
tcpmode bool tcpmode bool
sendFramePool *pool.Pool
ipaddr *net.UDPAddr ipaddr *net.UDPAddr
tcpaddr *net.TCPAddr tcpaddr *net.TCPAddr
addr string addr string
@ -219,7 +230,7 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) error {
sendb := rbuffergo.New(1024*1024, false) sendb := rbuffergo.New(1024*1024, false)
recvb := rbuffergo.New(1024*1024, false) recvb := rbuffergo.New(1024*1024, false)
cutsize := 800 cutsize := FRAME_MAX_SIZE
sendwin := sendb.Capacity() / cutsize sendwin := sendb.Capacity() / cutsize
clientConn := &ClientConn{tcpaddr: tcpsrcaddr, id: uuid, activeTime: now, close: false, sendb: sendb, recvb: recvb} 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])) echoId := int(binary.BigEndian.Uint16(bytes[4:6]))
echoSeq := int(binary.BigEndian.Uint16(bytes[6:8])) echoSeq := int(binary.BigEndian.Uint16(bytes[6:8]))
my := &MyMsg{ my := &MyMsg{}
}
my.Unmarshal(bytes[8:n]) my.Unmarshal(bytes[8:n])
if (my.TYPE != (uint32)(DATA) && my.TYPE != (uint32)(PING) && my.TYPE != (uint32)(CATCH)) || if (my.TYPE != (uint32)(DATA) && my.TYPE != (uint32)(PING) && my.TYPE != (uint32)(CATCH)) ||
@ -262,3 +261,12 @@ type CatchMsg struct {
src *net.IPAddr src *net.IPAddr
data []byte data []byte
} }
const (
FRAME_MAX_SIZE int = 888
)
type Frame struct {
size int
data []byte
}