This commit is contained in:
esrrhs 2019-10-28 11:58:01 +08:00
parent 1f8263a322
commit 2b6ecc47ae
8 changed files with 198 additions and 51 deletions

View File

@ -17,7 +17,8 @@ const (
)
func NewClient(addr string, server string, target string, timeout int, key int,
tcpmode int, tcpmode_buffersize int, tcpmode_maxwin int, tcpmode_resend_timems int, tcpmode_compress int) (*Client, error) {
tcpmode int, tcpmode_buffersize int, tcpmode_maxwin int, tcpmode_resend_timems int, tcpmode_compress int,
tcpmode_stat int) (*Client, error) {
var ipaddr *net.UDPAddr
var tcpaddr *net.TCPAddr
@ -56,6 +57,7 @@ func NewClient(addr string, server string, target string, timeout int, key int,
tcpmode_maxwin: tcpmode_maxwin,
tcpmode_resend_timems: tcpmode_resend_timems,
tcpmode_compress: tcpmode_compress,
tcpmode_stat: tcpmode_stat,
}, nil
}
@ -72,6 +74,7 @@ type Client struct {
tcpmode_maxwin int
tcpmode_resend_timems int
tcpmode_compress int
tcpmode_stat int
ipaddr *net.UDPAddr
tcpaddr *net.TCPAddr
@ -209,7 +212,7 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) {
uuid := UniqueId()
tcpsrcaddr := conn.RemoteAddr().(*net.TCPAddr)
fm := NewFrameMgr(p.tcpmode_buffersize, p.tcpmode_maxwin, p.tcpmode_resend_timems, p.tcpmode_compress)
fm := NewFrameMgr(p.tcpmode_buffersize, p.tcpmode_maxwin, p.tcpmode_resend_timems, p.tcpmode_compress, p.tcpmode_stat)
now := time.Now()
clientConn := &ClientConn{tcpaddr: tcpsrcaddr, id: uuid, activeRecvTime: now, activeSendTime: now, close: false,
@ -233,7 +236,7 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) {
p.sequence++
sendICMP(p.id, p.sequence, *p.conn, p.ipaddrServer, p.targetAddr, clientConn.id, (uint32)(MyMsg_DATA), mb,
SEND_PROTO, RECV_PROTO, p.key,
p.tcpmode, p.tcpmode_buffersize, p.tcpmode_maxwin, p.tcpmode_resend_timems, p.tcpmode_compress,
p.tcpmode, p.tcpmode_buffersize, p.tcpmode_maxwin, p.tcpmode_resend_timems, p.tcpmode_compress, p.tcpmode_stat,
p.timeout)
p.sendPacket++
p.sendPacketSize += (uint64)(len(mb))
@ -293,7 +296,7 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) {
p.sequence++
sendICMP(p.id, p.sequence, *p.conn, p.ipaddrServer, p.targetAddr, clientConn.id, (uint32)(MyMsg_DATA), mb,
SEND_PROTO, RECV_PROTO, p.key,
p.tcpmode, 0, 0, 0, 0,
p.tcpmode, 0, 0, 0, 0, 0,
0)
p.sendPacket++
p.sendPacketSize += (uint64)(len(mb))
@ -354,7 +357,7 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) {
p.sequence++
sendICMP(p.id, p.sequence, *p.conn, p.ipaddrServer, p.targetAddr, clientConn.id, (uint32)(MyMsg_DATA), mb,
SEND_PROTO, RECV_PROTO, p.key,
p.tcpmode, 0, 0, 0, 0,
p.tcpmode, 0, 0, 0, 0, 0,
0)
p.sendPacket++
p.sendPacketSize += (uint64)(len(mb))
@ -426,7 +429,7 @@ func (p *Client) Accept() error {
clientConn.activeSendTime = now
sendICMP(p.id, p.sequence, *p.conn, p.ipaddrServer, p.targetAddr, clientConn.id, (uint32)(MyMsg_DATA), bytes[:n],
SEND_PROTO, RECV_PROTO, p.key,
p.tcpmode, 0, 0, 0, 0,
p.tcpmode, 0, 0, 0, 0, 0,
p.timeout)
p.sequence++
@ -529,7 +532,7 @@ func (p *Client) ping() {
b, _ := now.MarshalBinary()
sendICMP(p.id, p.sequence, *p.conn, p.ipaddrServer, p.targetAddr, "", (uint32)(MyMsg_PING), b,
SEND_PROTO, RECV_PROTO, p.key,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0)
loggo.Info("ping %s %s %d %d %d %d", p.addrServer, now.String(), p.sproto, p.rproto, p.id, p.sequence)
p.sequence++

View File

@ -51,6 +51,9 @@ Usage:
-tcp_gz 当数据包超过这个大小tcp将压缩数据0表示不压缩默认0
Tcp will compress data when the packet exceeds this size, 0 means no compression, default 0
-tcp_stat 打印tcp的监控默认0
Print tcp connection statistic, default 0 is off
-nolog 不写日志文件只打印标准输出默认0
Do not write log files, only print standard output, default 0 is off
@ -70,6 +73,7 @@ func main() {
tcpmode_resend_timems := flag.Int("tcp_rst", 400, "tcp mode resend time ms")
tcpmode_compress := flag.Int("tcp_gz", 0, "tcp data compress")
nolog := flag.Int("nolog", 0, "write log file")
tcpmode_stat := flag.Int("tcp_stat", 0, "print tcp stat")
flag.Usage = func() {
fmt.Printf(usage)
}
@ -117,7 +121,8 @@ func main() {
}
c, err := pingtunnel.NewClient(*listen, *server, *target, *timeout, *key,
*tcpmode, *tcpmode_buffersize, *tcpmode_maxwin, *tcpmode_resend_timems, *tcpmode_compress)
*tcpmode, *tcpmode_buffersize, *tcpmode_maxwin, *tcpmode_resend_timems, *tcpmode_compress,
*tcpmode_stat)
if err != nil {
loggo.Error("ERROR: %s", err.Error())
return

View File

@ -8,10 +8,30 @@ import (
"github.com/esrrhs/go-engine/src/loggo"
"github.com/esrrhs/go-engine/src/rbuffergo"
"io"
"strconv"
"sync"
"time"
)
type FrameStat struct {
sendDataNum int
recvDataNum int
sendReqNum int
recvReqNum int
sendAckNum int
recvAckNum int
sendDataNumsMap map[int32]int
recvDataNumsMap map[int32]int
sendReqNumsMap map[int32]int
recvReqNumsMap map[int32]int
sendAckNumsMap map[int32]int
recvAckNumsMap map[int32]int
sendping int
sendpong int
recvping int
recvpong int
}
type FrameMgr struct {
sendb *rbuffergo.RBuffergo
recvb *rbuffergo.RBuffergo
@ -40,9 +60,13 @@ type FrameMgr struct {
sendmap map[int32]int64
connected bool
fs *FrameStat
openstat int
lastPrintStat int64
}
func NewFrameMgr(buffersize int, windowsize int, resend_timems int, compress int) *FrameMgr {
func NewFrameMgr(buffersize int, windowsize int, resend_timems int, compress int, openstat int) *FrameMgr {
sendb := rbuffergo.New(buffersize, false)
recvb := rbuffergo.New(buffersize, false)
@ -55,8 +79,10 @@ func NewFrameMgr(buffersize int, windowsize int, resend_timems int, compress int
close: false, remoteclosed: false, closesend: false,
lastPingTime: time.Now().UnixNano(), rttns: (int64)(resend_timems * 1000),
reqmap: make(map[int32]int64), sendmap: make(map[int32]int64),
connected: false}
connected: false, openstat: openstat, lastPrintStat: time.Now().UnixNano()}
if openstat > 0 {
fm.resetStat()
}
return fm
}
@ -83,6 +109,8 @@ func (fm *FrameMgr) Update() {
fm.calSendList()
fm.ping()
fm.printStat()
}
func (fm *FrameMgr) cutSendBufferToWindow() {
@ -175,6 +203,10 @@ func (fm *FrameMgr) calSendList() {
fm.sendlist.PushBack(f)
f.Resend = false
fm.sendmap[f.Id] = cur
if fm.openstat > 0 {
fm.fs.sendDataNum++
fm.fs.sendDataNumsMap[f.Id]++
}
loggo.Debug("push frame to sendlist %d %d", f.Id, len(f.Data.Data))
}
}
@ -212,6 +244,10 @@ func (fm *FrameMgr) preProcessRecvList() (map[int32]int, map[int32]int, map[int3
}
} else if f.Type == (int32)(Frame_DATA) {
tmpackto[f.Id] = f
if fm.openstat > 0 {
fm.fs.recvDataNum++
fm.fs.recvDataNumsMap[f.Id]++
}
loggo.Debug("recv data %d %d", f.Id, len(f.Data.Data))
} else if f.Type == (int32)(Frame_PING) {
fm.processPing(f)
@ -227,7 +263,7 @@ func (fm *FrameMgr) preProcessRecvList() (map[int32]int, map[int32]int, map[int3
func (fm *FrameMgr) processRecvList(tmpreq map[int32]int, tmpack map[int32]int, tmpackto map[int32]*Frame) {
for id, _ := range tmpreq {
for id, num := range tmpreq {
for e := fm.sendwin.Front(); e != nil; e = e.Next() {
f := e.Value.(*Frame)
if f.Id == id {
@ -236,9 +272,13 @@ func (fm *FrameMgr) processRecvList(tmpreq map[int32]int, tmpack map[int32]int,
break
}
}
if fm.openstat > 0 {
fm.fs.recvReqNum += num
fm.fs.recvReqNumsMap[id] += num
}
}
for id, _ := range tmpack {
for id, num := range tmpack {
for e := fm.sendwin.Front(); e != nil; e = e.Next() {
f := e.Value.(*Frame)
if f.Id == id {
@ -248,6 +288,10 @@ func (fm *FrameMgr) processRecvList(tmpreq map[int32]int, tmpack map[int32]int,
break
}
}
if fm.openstat > 0 {
fm.fs.recvAckNum += num
fm.fs.recvAckNumsMap[id] += num
}
}
if len(tmpackto) > 0 {
@ -257,6 +301,10 @@ func (fm *FrameMgr) processRecvList(tmpreq map[int32]int, tmpack map[int32]int,
if fm.addToRecvWin(rf) {
tmp[index] = id
index++
if fm.openstat > 0 {
fm.fs.sendAckNum++
fm.fs.sendAckNumsMap[id]++
}
loggo.Debug("add data to win %d %d", rf.Id, len(rf.Data.Data))
}
}
@ -407,6 +455,10 @@ func (fm *FrameMgr) combineWindowToRecvBuffer() {
for id, _ := range reqtmp {
f.Dataid[index] = (int32)(id)
index++
if fm.openstat > 0 {
fm.fs.sendReqNum++
fm.fs.sendReqNumsMap[(int32)(id)]++
}
}
fm.sendlist.PushBack(f)
loggo.Debug("send req %d %s", f.Id, common.Int32ArrayToString(f.Dataid, ","))
@ -442,11 +494,14 @@ func (fm *FrameMgr) IsRemoteClosed() bool {
func (fm *FrameMgr) ping() {
cur := time.Now().UnixNano()
if cur-fm.lastPingTime > (int64)(time.Second) {
fm.lastPingTime = cur
f := &Frame{Type: (int32)(Frame_PING), Resend: false, Sendtime: cur,
Id: 0}
fm.sendlist.PushBack(f)
loggo.Debug("send ping %d", cur)
fm.lastPingTime = cur
if fm.openstat > 0 {
fm.fs.sendping++
}
}
}
@ -454,6 +509,10 @@ func (fm *FrameMgr) processPing(f *Frame) {
rf := &Frame{Type: (int32)(Frame_PONG), Resend: false, Sendtime: f.Sendtime,
Id: 0}
fm.sendlist.PushBack(rf)
if fm.openstat > 0 {
fm.fs.recvping++
fm.fs.sendpong++
}
loggo.Debug("recv ping %d", f.Sendtime)
}
@ -462,6 +521,9 @@ func (fm *FrameMgr) processPong(f *Frame) {
if cur > f.Sendtime {
rtt := cur - f.Sendtime
fm.rttns = (fm.rttns + rtt) / 2
if fm.openstat > 0 {
fm.fs.recvpong++
}
loggo.Debug("recv pong %d %dms", rtt, fm.rttns/1000/1000)
}
}
@ -567,3 +629,56 @@ func (fm *FrameMgr) deCompressData(src []byte) (error, []byte) {
r.Close()
return nil, out.Bytes()
}
func (fm *FrameMgr) resetStat() {
fm.fs = &FrameStat{}
fm.fs.sendDataNumsMap = make(map[int32]int)
fm.fs.recvDataNumsMap = make(map[int32]int)
fm.fs.sendReqNumsMap = make(map[int32]int)
fm.fs.recvReqNumsMap = make(map[int32]int)
fm.fs.sendAckNumsMap = make(map[int32]int)
fm.fs.recvAckNumsMap = make(map[int32]int)
}
func (fm *FrameMgr) printStat() {
if fm.openstat > 0 {
cur := time.Now().UnixNano()
if cur-fm.lastPrintStat > (int64)(time.Second) {
fm.lastPrintStat = cur
fs := fm.fs
loggo.Info("\nsendDataNum %d\nrecvDataNum %d\nsendReqNum %d\nrecvReqNum %d\nsendAckNum %d\nrecvAckNum %d\n"+
"sendDataNumsMap %s\nrecvDataNumsMap %s\nsendReqNumsMap %s\nrecvReqNumsMap %s\nsendAckNumsMap %s\nrecvAckNumsMap %s\n"+
"sendping %d\nrecvping %d\nsendpong %d\nrecvpong %d\n",
fs.sendDataNum, fs.recvDataNum,
fs.sendReqNum, fs.recvReqNum,
fs.sendAckNum, fs.recvAckNum,
fm.printStatMap(&fs.sendDataNumsMap), fm.printStatMap(&fs.recvDataNumsMap),
fm.printStatMap(&fs.sendReqNumsMap), fm.printStatMap(&fs.recvReqNumsMap),
fm.printStatMap(&fs.sendAckNumsMap), fm.printStatMap(&fs.recvAckNumsMap),
fs.sendping, fs.recvping,
fs.sendpong, fs.recvpong)
fm.resetStat()
}
}
}
func (fm *FrameMgr) printStatMap(m *map[int32]int) string {
tmp := make(map[int]int)
for _, v := range *m {
tmp[v]++
}
max := 0
for k, _ := range tmp {
if k > max {
max = k
}
}
var ret string
for i := 1; i <= max; i++ {
ret += strconv.Itoa(i) + "->" + strconv.Itoa(tmp[i]) + ","
}
if len(ret) <= 0 {
ret = "none"
}
return ret
}

View File

@ -127,6 +127,7 @@ type MyMsg struct {
TcpmodeMaxwin int32 `protobuf:"varint,11,opt,name=tcpmode_maxwin,json=tcpmodeMaxwin,proto3" json:"tcpmode_maxwin,omitempty"`
TcpmodeResendTimems int32 `protobuf:"varint,12,opt,name=tcpmode_resend_timems,json=tcpmodeResendTimems,proto3" json:"tcpmode_resend_timems,omitempty"`
TcpmodeCompress int32 `protobuf:"varint,13,opt,name=tcpmode_compress,json=tcpmodeCompress,proto3" json:"tcpmode_compress,omitempty"`
TcpmodeStat int32 `protobuf:"varint,14,opt,name=tcpmode_stat,json=tcpmodeStat,proto3" json:"tcpmode_stat,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -248,6 +249,13 @@ func (m *MyMsg) GetTcpmodeCompress() int32 {
return 0
}
func (m *MyMsg) GetTcpmodeStat() int32 {
if m != nil {
return m.TcpmodeStat
}
return 0
}
type FrameData struct {
Type int32 `protobuf:"varint,1,opt,name=type,proto3" json:"type,omitempty"`
Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
@ -394,35 +402,36 @@ func init() {
func init() { proto.RegisterFile("msg.proto", fileDescriptor_c06e4cca6c2cc899) }
var fileDescriptor_c06e4cca6c2cc899 = []byte{
// 478 bytes of a gzipped FileDescriptorProto
// 493 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x52, 0xcb, 0x6e, 0xd3, 0x40,
0x14, 0x65, 0x3c, 0x76, 0x12, 0xdf, 0x24, 0x65, 0x3a, 0x3c, 0x34, 0x62, 0x81, 0x2c, 0x4b, 0x08,
0xb3, 0xa0, 0x8b, 0x22, 0xc1, 0x3a, 0x75, 0x43, 0x54, 0x41, 0x1e, 0x4c, 0xc2, 0x02, 0x36, 0x91,
0x1b, 0x4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0x04, 0xbc, 0x37, 0x75, 0x9c, 0xcb, 0x73, 0xbd, 0x82, 0x76, 0x85, 0xe4, 0xd6,
0x0a, 0xdb, 0x55, 0x59, 0xb7, 0x56, 0xf5, 0x08, 0x06, 0x5d, 0x48, 0xbd, 0xd8, 0x81, 0xe8, 0x78,
0xf0, 0xda, 0xb4, 0x3e, 0x02, 0xef, 0xc3, 0x7a, 0x2a, 0xb6, 0x37, 0xfd, 0xa3, 0xe5, 0x62, 0x81,
0xfd, 0xfb, 0x1a, 0x89, 0xf5, 0x8a, 0x5a, 0xcc, 0x03, 0x37, 0x7a, 0xb7, 0x5c, 0x4f, 0xa9, 0x1d,
0xfc, 0x21, 0xe0, 0x62, 0x94, 0xff, 0xc6, 0xd0, 0xd7, 0x81, 0xf3, 0xc2, 0x20, 0x03, 0x61, 0x98,
0x8e, 0xa2, 0xbf, 0x7a, 0xc0, 0x18, 0xc5, 0x16, 0x1d, 0x37, 0x17, 0xea, 0xe0, 0xbf, 0xe8, 0x0b,
0x7d, 0x6c, 0x9e, 0xa2, 0xef, 0x6b, 0x78, 0x0a, 0x27, 0xdd, 0xc3, 0x6f, 0x2e, 0x50, 0x7f, 0xb3,
0x84, 0xf7, 0x7c, 0x3b, 0x74, 0x85, 0x61, 0xc1, 0xab, 0x7f, 0xa6, 0xd9, 0x07, 0x5b, 0x4c, 0xdf,
0x53, 0xa2, 0xc1, 0x24, 0x7a, 0x4b, 0xad, 0x6e, 0xbe, 0x36, 0xa2, 0xe5, 0x62, 0x46, 0x9d, 0xb3,
0xd1, 0x27, 0xa8, 0xb2, 0x22, 0x55, 0xfb, 0xa2, 0x90, 0x5f, 0x2e, 0x7b, 0x78, 0xce, 0x2f, 0xff,
0x06, 0x00, 0x00, 0xff, 0xff, 0x5b, 0xf2, 0xbf, 0x87, 0x4d, 0x03, 0x00, 0x00,
}

View File

@ -21,6 +21,7 @@ message MyMsg {
int32 tcpmode_maxwin = 11;
int32 tcpmode_resend_timems = 12;
int32 tcpmode_compress = 13;
int32 tcpmode_stat = 14;
}
message FrameData {

View File

@ -18,7 +18,7 @@ import (
func sendICMP(id int, sequence int, conn icmp.PacketConn, server *net.IPAddr, target string,
connId string, msgType uint32, data []byte, sproto int, rproto int, key int,
tcpmode int, tcpmode_buffer_size int, tcpmode_maxwin int, tcpmode_resend_time int, tcpmode_compress int,
tcpmode int, tcpmode_buffer_size int, tcpmode_maxwin int, tcpmode_resend_time int, tcpmode_compress int, tcpmode_stat int,
timeout int) {
m := &MyMsg{
@ -33,6 +33,7 @@ func sendICMP(id int, sequence int, conn icmp.PacketConn, server *net.IPAddr, ta
TcpmodeMaxwin: (int32)(tcpmode_maxwin),
TcpmodeResendTimems: (int32)(tcpmode_resend_time),
TcpmodeCompress: (int32)(tcpmode_compress),
TcpmodeStat: (int32)(tcpmode_stat),
Timeout: (int32)(timeout),
Magic: (int32)(MyMsg_MAGIC),
}

View File

@ -101,4 +101,16 @@ func Test0001(t *testing.T) {
_, ddd := fm.deCompressData(dd)
fmt.Println("fm.deCompressData = ", (string)(ddd))
mm := make(map[int32]int)
mm[1] = 1
mm[2] = 1
mm[3] = 1
mm[4] = 2
mm[6] = 7
mms := fm.printStatMap(&mm)
fmt.Println("fm.printStatMap = ", mms)
fm.openstat = 1
fm.resetStat()
fm.printStat()
}

View File

@ -89,7 +89,7 @@ func (p *Server) processPacket(packet *Packet) {
loggo.Info("ping from %s %s %d %d %d", packet.src.String(), t.String(), packet.my.Rproto, packet.echoId, packet.echoSeq)
sendICMP(packet.echoId, packet.echoSeq, *p.conn, packet.src, "", "", (uint32)(MyMsg_PING), packet.my.Data,
(int)(packet.my.Rproto), -1, p.key,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0)
return
}
@ -117,7 +117,8 @@ func (p *Server) processPacket(packet *Packet) {
return
}
fm := NewFrameMgr((int)(packet.my.TcpmodeBuffersize), (int)(packet.my.TcpmodeMaxwin), (int)(packet.my.TcpmodeResendTimems), (int)(packet.my.TcpmodeCompress))
fm := NewFrameMgr((int)(packet.my.TcpmodeBuffersize), (int)(packet.my.TcpmodeMaxwin), (int)(packet.my.TcpmodeResendTimems), (int)(packet.my.TcpmodeCompress),
(int)(packet.my.TcpmodeStat))
localConn = &ServerConn{timeout: (int)(packet.my.Timeout), tcpconn: targetConn, tcpaddrTarget: ipaddrTarget, id: id, activeRecvTime: now, activeSendTime: now, close: false,
rproto: (int)(packet.my.Rproto), fm: fm, tcpmode: (int)(packet.my.Tcpmode)}
@ -195,7 +196,7 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) {
mb, _ := proto.Marshal(f)
sendICMP(p.echoId, p.echoSeq, *p.conn, src, "", id, (uint32)(MyMsg_DATA), mb,
conn.rproto, -1, p.key,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0)
p.sendPacket++
p.sendPacketSize += (uint64)(len(mb))
@ -255,7 +256,7 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) {
}
sendICMP(p.echoId, p.echoSeq, *p.conn, src, "", id, (uint32)(MyMsg_DATA), mb,
conn.rproto, -1, p.key,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0)
p.sendPacket++
p.sendPacketSize += (uint64)(len(mb))
@ -315,7 +316,7 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) {
mb, _ := proto.Marshal(f)
sendICMP(p.echoId, p.echoSeq, *p.conn, src, "", id, (uint32)(MyMsg_DATA), mb,
conn.rproto, -1, p.key,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0)
p.sendPacket++
p.sendPacketSize += (uint64)(len(mb))
@ -378,7 +379,7 @@ func (p *Server) Recv(conn *ServerConn, id string, src *net.IPAddr) {
sendICMP(p.echoId, p.echoSeq, *p.conn, src, "", id, (uint32)(MyMsg_DATA), bytes[:n],
conn.rproto, -1, p.key,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0)
p.sendPacket++