add
This commit is contained in:
1 parent
e1cdec8c00
commit
8efea89357
2 files changed
+10
-18
No files matched your search
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewClient(addr string, server string, target string, timeout int, sproto int, rproto int, pingSeq int) (*Client, error) {
|
||||
func NewClient(addr string, server string, target string, timeout int, sproto int, rproto int) (*Client, error) {
|
||||
|
||||
ipaddr, err := net.ResolveUDPAddr("udp", addr)
|
||||
if err != nil {
|
||||
@@ -32,7 +32,6 @@ func NewClient(addr string, server string, target string, timeout int, sproto in
|
||||
timeout: timeout,
|
||||
sproto: sproto,
|
||||
rproto: rproto,
|
||||
pingSeq: pingSeq,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -43,7 +42,6 @@ type Client struct {
|
||||
timeout int
|
||||
sproto int
|
||||
rproto int
|
||||
pingSeq int
|
||||
|
||||
ipaddr *net.UDPAddr
|
||||
addr string
|
||||
@@ -121,16 +119,12 @@ func (p *Client) Run() {
|
||||
interval := time.NewTicker(time.Second)
|
||||
defer interval.Stop()
|
||||
|
||||
intervalPing := time.NewTicker(time.Millisecond * (time.Duration)(p.pingSeq))
|
||||
defer intervalPing.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-interval.C:
|
||||
p.checkTimeoutConn()
|
||||
p.showNet()
|
||||
case <-intervalPing.C:
|
||||
p.ping()
|
||||
p.showNet()
|
||||
case r := <-recv:
|
||||
p.processPacket(r)
|
||||
}
|
||||
@@ -241,11 +235,13 @@ func (p *Client) checkTimeoutConn() {
|
||||
}
|
||||
|
||||
func (p *Client) ping() {
|
||||
now := time.Now()
|
||||
b, _ := now.MarshalBinary()
|
||||
sendICMP(p.id, p.sequence, *p.conn, p.ipaddrServer, p.targetAddr, "", (uint32)(PING), b, p.sproto, p.rproto)
|
||||
fmt.Printf("ping %s %s %d %d %d %d\n", p.addrServer, now.String(), p.sproto, p.rproto, p.id, p.sequence)
|
||||
p.sequence++
|
||||
if p.sendPacket == 0 {
|
||||
now := time.Now()
|
||||
b, _ := now.MarshalBinary()
|
||||
sendICMP(p.id, p.sequence, *p.conn, p.ipaddrServer, p.targetAddr, "", (uint32)(PING), b, p.sproto, p.rproto)
|
||||
fmt.Printf("ping %s %s %d %d %d %d\n", p.addrServer, now.String(), p.sproto, p.rproto, p.id, p.sequence)
|
||||
p.sequence++
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Client) showNet() {
|
||||
|
||||
Reference in new issue
Block a user