From 013c6124d901dc09e3b80988e7512401a12d5136 Mon Sep 17 00:00:00 2001 From: esrrhs Date: Sun, 27 Oct 2019 19:06:55 +0800 Subject: [PATCH] add --- client.go | 16 +++++---- cmd/main.go | 10 ++++-- framemgr.go | 64 +++++++++++++++++++++++++++++++++--- msg.pb.go | 90 ++++++++++++++++++++++++++++++--------------------- msg.proto | 12 ++++--- pingtunnel.go | 3 +- server.go | 12 +++---- 7 files changed, 144 insertions(+), 63 deletions(-) diff --git a/client.go b/client.go index d3f2d27..6e33b3b 100644 --- a/client.go +++ b/client.go @@ -17,7 +17,7 @@ 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) (*Client, error) { + tcpmode int, tcpmode_buffersize int, tcpmode_maxwin int, tcpmode_resend_timems int, tcpmode_compress int) (*Client, error) { var ipaddr *net.UDPAddr var tcpaddr *net.TCPAddr @@ -55,6 +55,7 @@ func NewClient(addr string, server string, target string, timeout int, key int, tcpmode_buffersize: tcpmode_buffersize, tcpmode_maxwin: tcpmode_maxwin, tcpmode_resend_timems: tcpmode_resend_timems, + tcpmode_compress: tcpmode_compress, }, nil } @@ -70,6 +71,7 @@ type Client struct { tcpmode_buffersize int tcpmode_maxwin int tcpmode_resend_timems int + tcpmode_compress int ipaddr *net.UDPAddr tcpaddr *net.TCPAddr @@ -207,7 +209,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) + fm := NewFrameMgr(p.tcpmode_buffersize, p.tcpmode_maxwin, p.tcpmode_resend_timems, p.tcpmode_compress) now := time.Now() clientConn := &ClientConn{tcpaddr: tcpsrcaddr, id: uuid, activeRecvTime: now, activeSendTime: now, close: false, @@ -231,7 +233,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, p.tcpmode_buffersize, p.tcpmode_maxwin, p.tcpmode_resend_timems, p.tcpmode_compress, p.timeout) p.sendPacket++ p.sendPacketSize += (uint64)(len(mb)) @@ -291,7 +293,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, + p.tcpmode, 0, 0, 0, 0, 0) p.sendPacket++ p.sendPacketSize += (uint64)(len(mb)) @@ -352,7 +354,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, + p.tcpmode, 0, 0, 0, 0, 0) p.sendPacket++ p.sendPacketSize += (uint64)(len(mb)) @@ -424,7 +426,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, + p.tcpmode, 0, 0, 0, 0, p.timeout) p.sequence++ @@ -527,7 +529,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) loggo.Info("ping %s %s %d %d %d %d", p.addrServer, now.String(), p.sproto, p.rproto, p.id, p.sequence) p.sequence++ diff --git a/cmd/main.go b/cmd/main.go index 07a5f96..4275d6e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -36,8 +36,8 @@ Usage: -key 设置的密码,默认0 Set password, default 0 - -tcp 设置是否转发tcp,默认false - Set the switch to forward tcp, the default is false + -tcp 设置是否转发tcp,默认0 + Set the switch to forward tcp, the default is 0 -tcp_bs tcp的发送接收缓冲区大小,默认10MB Tcp send and receive buffer size, default 10MB @@ -47,6 +47,9 @@ Usage: -tcp_rst tcp的超时发送时间,默认400ms Tcp timeout resend time, default 400ms + + -tcp_gz tcp数据开启压缩,默认0 + Whether the tcp data is compressed or not, the default is 0. ` func main() { @@ -61,6 +64,7 @@ func main() { tcpmode_buffersize := flag.Int("tcp_bs", 10*1024*1024, "tcp mode buffer size") tcpmode_maxwin := flag.Int("tcp_mw", 10000, "tcp mode max win") tcpmode_resend_timems := flag.Int("tcp_rst", 400, "tcp mode resend time ms") + tcpmode_compress := flag.Int("tcp_gz", 0, "tcp data compress") flag.Usage = func() { fmt.Printf(usage) } @@ -103,7 +107,7 @@ func main() { } c, err := pingtunnel.NewClient(*listen, *server, *target, *timeout, *key, - *tcpmode, *tcpmode_buffersize, *tcpmode_maxwin, *tcpmode_resend_timems) + *tcpmode, *tcpmode_buffersize, *tcpmode_maxwin, *tcpmode_resend_timems, *tcpmode_compress) if err != nil { loggo.Error("ERROR: %s", err.Error()) return diff --git a/framemgr.go b/framemgr.go index d58eb6a..dfc9651 100644 --- a/framemgr.go +++ b/framemgr.go @@ -1,10 +1,13 @@ package pingtunnel import ( + "bytes" + "compress/zlib" "container/list" "github.com/esrrhs/go-engine/src/common" "github.com/esrrhs/go-engine/src/loggo" "github.com/esrrhs/go-engine/src/rbuffergo" + "io" "sync" "time" ) @@ -16,6 +19,7 @@ type FrameMgr struct { recvlock sync.Locker windowsize int resend_timems int + compress int sendwin *list.List sendlist *list.List @@ -38,14 +42,14 @@ type FrameMgr struct { connected bool } -func NewFrameMgr(buffersize int, windowsize int, resend_timems int) *FrameMgr { +func NewFrameMgr(buffersize int, windowsize int, resend_timems int, compress int) *FrameMgr { sendb := rbuffergo.New(buffersize, false) recvb := rbuffergo.New(buffersize, false) fm := &FrameMgr{sendb: sendb, recvb: recvb, recvlock: &sync.Mutex{}, - windowsize: windowsize, resend_timems: resend_timems, + windowsize: windowsize, resend_timems: resend_timems, compress: compress, sendwin: list.New(), sendlist: list.New(), sendid: 0, recvwin: list.New(), recvlist: list.New(), recvid: 0, close: false, remoteclosed: false, closesend: false, @@ -94,6 +98,14 @@ func (fm *FrameMgr) cutSendBufferToWindow() { Data: make([]byte, FRAME_MAX_SIZE)} fm.sendb.Read(fd.Data) + if fm.compress > 0 { + newb := fm.compressData(fd.Data) + if len(newb) < len(fd.Data) { + fd.Data = newb + fd.Compress = true + } + } + f := &Frame{Type: (int32)(Frame_DATA), Id: (int32)(fm.sendid), Data: fd} @@ -112,6 +124,14 @@ func (fm *FrameMgr) cutSendBufferToWindow() { Data: make([]byte, fm.sendb.Size())} fm.sendb.Read(fd.Data) + if fm.compress > 0 { + newb := fm.compressData(fd.Data) + if len(newb) < len(fd.Data) { + fd.Data = newb + fd.Compress = true + } + } + f := &Frame{Type: (int32)(Frame_DATA), Id: (int32)(fm.sendid), Data: fd} @@ -287,11 +307,27 @@ func (fm *FrameMgr) processRecvFrame(f *Frame) bool { if f.Data.Type == (int32)(FrameData_USER_DATA) { left := fm.recvb.Capacity() - fm.recvb.Size() if left >= len(f.Data.Data) { - fm.recvb.Write(f.Data.Data) + src := f.Data.Data + if f.Data.Compress { + err, old := fm.deCompressData(src) + if err != nil { + loggo.Error("recv frame deCompressData error %d", f.Id) + return false + } + if left < len(old) { + return false + } + loggo.Debug("deCompressData recv frame %d %d %d", + f.Id, len(src), len(old)) + src = old + } + + fm.recvb.Write(src) loggo.Debug("combined recv frame to recv buffer %d %d", - f.Id, len(f.Data.Data)) + f.Id, len(src)) return true } + return false } else if f.Data.Type == (int32)(FrameData_CLOSE) { fm.remoteclosed = true loggo.Debug("recv remote close frame %d", f.Id) @@ -309,7 +345,6 @@ func (fm *FrameMgr) processRecvFrame(f *Frame) bool { loggo.Error("recv frame type error %d", f.Data.Type) return false } - return false } func (fm *FrameMgr) combineWindowToRecvBuffer() { @@ -512,3 +547,22 @@ func (fm *FrameMgr) sendConnectRsp() { fm.sendwin.PushBack(f) loggo.Debug("send connect rsp") } + +func (fm *FrameMgr) compressData(src []byte) []byte { + var b bytes.Buffer + w := zlib.NewWriter(&b) + w.Write(src) + return b.Bytes() +} + +func (fm *FrameMgr) deCompressData(src []byte) (error, []byte) { + b := bytes.NewReader(src) + r, err := zlib.NewReader(b) + if err != nil { + return err, nil + } + var out bytes.Buffer + io.Copy(&out, r) + r.Close() + return nil, out.Bytes() +} diff --git a/msg.pb.go b/msg.pb.go index 67c7d32..e9c5a20 100644 --- a/msg.pb.go +++ b/msg.pb.go @@ -121,11 +121,12 @@ type MyMsg struct { Rproto int32 `protobuf:"zigzag32,5,opt,name=rproto,proto3" json:"rproto,omitempty"` Magic int32 `protobuf:"zigzag32,6,opt,name=magic,proto3" json:"magic,omitempty"` Key int32 `protobuf:"zigzag32,7,opt,name=key,proto3" json:"key,omitempty"` - Tcpmode int32 `protobuf:"varint,8,opt,name=tcpmode,proto3" json:"tcpmode,omitempty"` - TcpmodeBuffersize int32 `protobuf:"varint,9,opt,name=tcpmode_buffersize,json=tcpmodeBuffersize,proto3" json:"tcpmode_buffersize,omitempty"` - TcpmodeMaxwin int32 `protobuf:"varint,10,opt,name=tcpmode_maxwin,json=tcpmodeMaxwin,proto3" json:"tcpmode_maxwin,omitempty"` - TcpmodeResendTimems int32 `protobuf:"varint,11,opt,name=tcpmode_resend_timems,json=tcpmodeResendTimems,proto3" json:"tcpmode_resend_timems,omitempty"` - Timeout int32 `protobuf:"varint,12,opt,name=timeout,proto3" json:"timeout,omitempty"` + Timeout int32 `protobuf:"varint,8,opt,name=timeout,proto3" json:"timeout,omitempty"` + Tcpmode int32 `protobuf:"varint,9,opt,name=tcpmode,proto3" json:"tcpmode,omitempty"` + TcpmodeBuffersize int32 `protobuf:"varint,10,opt,name=tcpmode_buffersize,json=tcpmodeBuffersize,proto3" json:"tcpmode_buffersize,omitempty"` + 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"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -205,6 +206,13 @@ func (m *MyMsg) GetKey() int32 { return 0 } +func (m *MyMsg) GetTimeout() int32 { + if m != nil { + return m.Timeout + } + return 0 +} + func (m *MyMsg) GetTcpmode() int32 { if m != nil { return m.Tcpmode @@ -233,9 +241,9 @@ func (m *MyMsg) GetTcpmodeResendTimems() int32 { return 0 } -func (m *MyMsg) GetTimeout() int32 { +func (m *MyMsg) GetTcpmodeCompress() int32 { if m != nil { - return m.Timeout + return m.TcpmodeCompress } return 0 } @@ -243,6 +251,7 @@ func (m *MyMsg) GetTimeout() int32 { 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"` + Compress bool `protobuf:"varint,3,opt,name=compress,proto3" json:"compress,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -287,6 +296,13 @@ func (m *FrameData) GetData() []byte { return nil } +func (m *FrameData) GetCompress() bool { + if m != nil { + return m.Compress + } + return false +} + type Frame struct { Type int32 `protobuf:"varint,1,opt,name=type,proto3" json:"type,omitempty"` Resend bool `protobuf:"varint,2,opt,name=resend,proto3" json:"resend,omitempty"` @@ -378,33 +394,35 @@ func init() { func init() { proto.RegisterFile("msg.proto", fileDescriptor_c06e4cca6c2cc899) } var fileDescriptor_c06e4cca6c2cc899 = []byte{ - // 448 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x52, 0xcb, 0x8e, 0xd3, 0x30, - 0x14, 0xc5, 0x79, 0xb4, 0xcd, 0x6d, 0x67, 0xe4, 0x31, 0x0f, 0x59, 0x2c, 0x50, 0x14, 0x09, 0x91, - 0x0d, 0xb3, 0x18, 0x24, 0x58, 0x77, 0x3a, 0xa5, 0x1a, 0x41, 0x1f, 0xb8, 0x65, 0x01, 0x9b, 0x2a, - 0x33, 0xf1, 0x44, 0x16, 0xe3, 0xb4, 0x4a, 0x5c, 0x41, 0xf9, 0x27, 0x3e, 0x81, 0x6f, 0xe0, 0x8f, - 0x10, 0xf2, 0xad, 0x93, 0x22, 0xc1, 0xca, 0xe7, 0xdc, 0x7b, 0xe4, 0x73, 0x7d, 0x7c, 0x21, 0xd2, - 0x75, 0x71, 0xbe, 0xad, 0x36, 0x66, 0x93, 0xfc, 0xf6, 0x20, 0x9c, 0xee, 0xa7, 0x75, 0xc1, 0x4e, - 0xc1, 0x53, 0x39, 0x27, 0x31, 0x49, 0x23, 0xe1, 0xa9, 0x9c, 0x31, 0x08, 0xcc, 0x7e, 0x2b, 0xb9, - 0x17, 0x93, 0x34, 0x14, 0x88, 0xd9, 0x13, 0xe8, 0x98, 0xac, 0x2a, 0xa4, 0xe1, 0x3e, 0xea, 0x1c, - 0xb3, 0xda, 0x3c, 0x33, 0x19, 0x0f, 0x62, 0x92, 0x0e, 0x04, 0x62, 0xab, 0xad, 0xd0, 0x83, 0x87, - 0x31, 0x49, 0xcf, 0x84, 0x63, 0xec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0x20, 0x1c, 0xbd, 0x9f, 0x2f, - 0xc7, 0xd4, 0x4f, 0x7e, 0x11, 0x08, 0xd1, 0xee, 0xbf, 0x56, 0xf6, 0xcb, 0xf0, 0x79, 0x68, 0xd6, - 0x13, 0x8e, 0xb1, 0xa7, 0xd0, 0xb3, 0xa7, 0x7d, 0x1b, 0x7e, 0xbc, 0x2f, 0x5a, 0xee, 0xd6, 0x26, - 0xc0, 0x5b, 0xec, 0xda, 0x3c, 0x73, 0xe3, 0xda, 0x4f, 0xef, 0x5f, 0xc0, 0x79, 0xfb, 0xb8, 0xe3, - 0x5a, 0xd8, 0x53, 0xe5, 0xbc, 0x13, 0xfb, 0x69, 0x28, 0x1c, 0x4b, 0x5e, 0xff, 0x13, 0x58, 0x17, - 0x7c, 0x31, 0xfe, 0x40, 0x89, 0x05, 0xc3, 0xd1, 0x3b, 0xea, 0xb5, 0x11, 0xfa, 0x88, 0xe6, 0xb3, - 0x09, 0x0d, 0x2e, 0x07, 0x9f, 0x61, 0xab, 0xca, 0xc2, 0xec, 0xca, 0x52, 0xde, 0xdf, 0x74, 0x70, - 0xc7, 0x5e, 0xfd, 0x09, 0x00, 0x00, 0xff, 0xff, 0xbe, 0x98, 0x97, 0x18, 0xe2, 0x02, 0x00, 0x00, + // 478 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, 0x4f, 0x2d, 0x0b, 0xfc, 0x90, 0xed, 0x08, 0xc2, 0x17, 0xf0, 0x2b, 0x2c, 0xf8, 0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7f, 0xfd, 0xdf, 0x34, 0xfb, 0x40, 0xe5, 0xf4, + 0x03, 0x23, 0x1a, 0x4c, 0xc2, 0x77, 0xcc, 0xea, 0xe6, 0x4b, 0x11, 0x2d, 0x17, 0x33, 0x66, 0x9f, + 0x8d, 0x3e, 0x43, 0x99, 0xe6, 0x49, 0xb3, 0xcf, 0x73, 0xf5, 0xf5, 0xb2, 0x87, 0xb7, 0xfa, 0xea, + 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x25, 0xde, 0x04, 0xfd, 0x2a, 0x03, 0x00, 0x00, } diff --git a/msg.proto b/msg.proto index 8b3765c..c52c3db 100644 --- a/msg.proto +++ b/msg.proto @@ -15,11 +15,12 @@ message MyMsg { sint32 rproto = 5; sint32 magic = 6; sint32 key = 7; - int32 tcpmode = 8; - int32 tcpmode_buffersize = 9; - int32 tcpmode_maxwin = 10; - int32 tcpmode_resend_timems = 11; - int32 timeout = 12; + int32 timeout = 8; + int32 tcpmode = 9; + int32 tcpmode_buffersize = 10; + int32 tcpmode_maxwin = 11; + int32 tcpmode_resend_timems = 12; + int32 tcpmode_compress = 13; } message FrameData { @@ -31,6 +32,7 @@ message FrameData { } int32 type = 1; bytes data = 2; + bool compress = 3; } message Frame { diff --git a/pingtunnel.go b/pingtunnel.go index 6929f73..cbef0b4 100644 --- a/pingtunnel.go +++ b/pingtunnel.go @@ -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 int, tcpmode_buffer_size int, tcpmode_maxwin int, tcpmode_resend_time int, tcpmode_compress int, timeout int) { m := &MyMsg{ @@ -32,6 +32,7 @@ func sendICMP(id int, sequence int, conn icmp.PacketConn, server *net.IPAddr, ta TcpmodeBuffersize: (int32)(tcpmode_buffer_size), TcpmodeMaxwin: (int32)(tcpmode_maxwin), TcpmodeResendTimems: (int32)(tcpmode_resend_time), + TcpmodeCompress: (int32)(tcpmode_compress), Timeout: (int32)(timeout), Magic: (int32)(MyMsg_MAGIC), } diff --git a/server.go b/server.go index d6b88b6..b905217 100644 --- a/server.go +++ b/server.go @@ -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) return } @@ -117,7 +117,7 @@ func (p *Server) processPacket(packet *Packet) { return } - fm := NewFrameMgr((int)(packet.my.TcpmodeBuffersize), (int)(packet.my.TcpmodeMaxwin), (int)(packet.my.TcpmodeResendTimems)) + fm := NewFrameMgr((int)(packet.my.TcpmodeBuffersize), (int)(packet.my.TcpmodeMaxwin), (int)(packet.my.TcpmodeResendTimems), (int)(packet.my.TcpmodeCompress)) 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 +195,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) p.sendPacket++ p.sendPacketSize += (uint64)(len(mb)) @@ -255,7 +255,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) p.sendPacket++ p.sendPacketSize += (uint64)(len(mb)) @@ -315,7 +315,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) p.sendPacket++ p.sendPacketSize += (uint64)(len(mb)) @@ -378,7 +378,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) p.sendPacket++