This commit is contained in:
esrrhs 2018-12-19 15:50:21 +08:00
parent d9579c3c48
commit 5ed93bee2b
2 changed files with 40 additions and 0 deletions

View File

@ -49,6 +49,11 @@ type Client struct {
localAddrToConnMap map[string]*ClientConn
localIdToConnMap map[string]*ClientConn
sendPacket uint64
recvPacket uint64
sendPacketSize uint64
recvPacketSize uint64
}
type ClientConn struct {
@ -112,6 +117,7 @@ func (p *Client) Run() {
case <-interval.C:
p.checkTimeoutConn()
p.ping()
p.showNet()
case r := <-recv:
p.processPacket(r)
}
@ -151,6 +157,9 @@ func (p *Client) Accept() error {
clientConn.activeTime = now
sendICMP(*p.conn, p.ipaddrServer, p.targetAddr, clientConn.id, (uint32)(DATA), bytes[:n], p.sproto, p.rproto)
p.sendPacket++
p.sendPacketSize += (uint64)(n)
}
}
@ -184,6 +193,9 @@ func (p *Client) processPacket(packet *Packet) {
clientConn.close = true
return
}
p.recvPacket++
p.recvPacketSize += (uint64)(len(packet.data))
}
func (p *Client) Close(clientConn *ClientConn) {
@ -216,3 +228,11 @@ func (p *Client) ping() {
sendICMP(*p.conn, p.ipaddrServer, p.targetAddr, "", (uint32)(PING), b, p.sproto, p.rproto)
fmt.Printf("ping %s %s %d %d\n", p.addrServer, now.String(), p.sproto, p.rproto)
}
func (p *Client) showNet() {
fmt.Printf("send %d/s %dKB/s recv %d/s %dKB/s\n", p.sendPacket, p.sendPacket/1024, p.recvPacket, p.recvPacket/1024)
p.sendPacket = 0
p.recvPacket = 0
p.sendPacketSize = 0
p.recvPacketSize = 0
}

View File

@ -19,6 +19,11 @@ type Server struct {
conn *icmp.PacketConn
localConnMap map[string]*ServerConn
sendPacket uint64
recvPacket uint64
sendPacketSize uint64
recvPacketSize uint64
}
type ServerConn struct {
@ -51,6 +56,7 @@ func (p *Server) Run() {
select {
case <-interval.C:
p.checkTimeoutConn()
p.showNet()
case r := <-recv:
p.processPacket(r)
}
@ -100,6 +106,9 @@ func (p *Server) processPacket(packet *Packet) {
udpConn.close = true
return
}
p.recvPacket++
p.recvPacketSize += (uint64)(len(packet.data))
}
func (p *Server) Recv(conn *ServerConn, id string, src *net.IPAddr) {
@ -128,6 +137,9 @@ func (p *Server) Recv(conn *ServerConn, id string, src *net.IPAddr) {
conn.activeTime = now
sendICMP(*p.conn, src, "", id, (uint32)(DATA), bytes[:n], conn.rproto, 0)
p.sendPacket++
p.sendPacketSize += (uint64)(n)
}
}
@ -155,3 +167,11 @@ func (p *Server) checkTimeoutConn() {
}
}
}
func (p *Server) showNet() {
fmt.Printf("send %d/s %dKB/s recv %d/s %dKB/s\n", p.sendPacket, p.sendPacket/1024, p.recvPacket, p.recvPacket/1024)
p.sendPacket = 0
p.recvPacket = 0
p.sendPacketSize = 0
p.recvPacketSize = 0
}