add
This commit is contained in:
parent
65cd195ca8
commit
1402d824c6
13
client.go
13
client.go
@ -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,6 +34,13 @@ 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),
|
||||||
@ -48,6 +56,7 @@ func NewClient(addr string, server string, target string, timeout int, sproto in
|
|||||||
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}
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user