From 50fb2fdb4eb10fcf99ea90d117cbe5227f0204db Mon Sep 17 00:00:00 2001 From: esrrhs Date: Wed, 19 Dec 2018 15:05:22 +0800 Subject: [PATCH] add --- client.go | 11 ++++++++++- server.go | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index e338626..28f0413 100644 --- a/client.go +++ b/client.go @@ -156,6 +156,15 @@ func (p *Client) Accept() error { func (p *Client) processPacket(packet *Packet) { + if packet.msgType == PING { + t := time.Time{} + t.UnmarshalBinary(packet.data) + d := time.Now().Sub(t) + fmt.Printf("pong from %s %s %d\n", packet.src.String(), d.String(), packet.rproto) + sendICMP(*p.conn, packet.src, "", "", (uint32)(DATA), packet.data, packet.rproto, 0) + return + } + fmt.Printf("processPacket %s %s %d\n", packet.id, packet.src.String(), len(packet.data)) clientConn := p.localIdToConnMap[packet.id] @@ -205,5 +214,5 @@ func (p *Client) ping() { now := time.Now() b, _ := now.MarshalBinary() sendICMP(*p.conn, p.ipaddrServer, p.targetAddr, "", (uint32)(PING), b, p.sproto, p.rproto) - fmt.Printf("ping %s %s\n", p.addrServer, now.String()) + fmt.Printf("ping %s %s %d %d\n", p.addrServer, now.String(), p.sproto, p.rproto) } diff --git a/server.go b/server.go index a7c84ef..e8a4fde 100644 --- a/server.go +++ b/server.go @@ -62,7 +62,7 @@ func (p *Server) processPacket(packet *Packet) { if packet.msgType == PING { t := time.Time{} t.UnmarshalBinary(packet.data) - fmt.Printf("pong from %s %s\n", packet.src.String(), t.String()) + fmt.Printf("ping from %s %s %d\n", packet.src.String(), t.String(), packet.rproto) sendICMP(*p.conn, packet.src, "", "", (uint32)(DATA), packet.data, packet.rproto, 0) return }