add
This commit is contained in:
parent
f46cac4904
commit
0481f15f07
10
client.go
10
client.go
@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewClient(addr string, server string, target string, timeout int, sproto int, rproto int) (*Client, error) {
|
||||
func NewClient(addr string, server string, target string, timeout int, sproto int, rproto int, pingSeq int) (*Client, error) {
|
||||
|
||||
ipaddr, err := net.ResolveUDPAddr("udp", addr)
|
||||
if err != nil {
|
||||
@ -32,6 +32,7 @@ func NewClient(addr string, server string, target string, timeout int, sproto in
|
||||
timeout: timeout,
|
||||
sproto: sproto,
|
||||
rproto: rproto,
|
||||
pingSeq: pingSeq,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -42,6 +43,7 @@ type Client struct {
|
||||
timeout int
|
||||
sproto int
|
||||
rproto int
|
||||
pingSeq int
|
||||
|
||||
ipaddr *net.UDPAddr
|
||||
addr string
|
||||
@ -119,12 +121,16 @@ 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.ping()
|
||||
p.showNet()
|
||||
case <-intervalPing.C:
|
||||
p.ping()
|
||||
case r := <-recv:
|
||||
p.processPacket(r)
|
||||
}
|
||||
|
@ -36,6 +36,9 @@ Usage:
|
||||
|
||||
-rproto 客户端接收ping协议的协议,默认是0
|
||||
The protocol that the client receives the ping. The default is 0.
|
||||
|
||||
-ping 客户端发送ping协议的间隔
|
||||
The protocol that the client receives the ping. The default is 0.
|
||||
`
|
||||
|
||||
func main() {
|
||||
@ -47,6 +50,7 @@ func main() {
|
||||
timeout := flag.Int("timeout", 60, "conn timeout")
|
||||
sproto := flag.Int("sproto", 8, "send ping proto")
|
||||
rproto := flag.Int("rproto", 0, "recv ping proto")
|
||||
ping := flag.Int("ping", 1000, "recv ping proto")
|
||||
flag.Usage = func() {
|
||||
fmt.Printf(usage)
|
||||
}
|
||||
@ -76,7 +80,7 @@ func main() {
|
||||
fmt.Printf("server %s\n", *server)
|
||||
fmt.Printf("target %s\n", *target)
|
||||
|
||||
c, err := pingtunnel.NewClient(*listen, *server, *target, *timeout, *sproto, *rproto)
|
||||
c, err := pingtunnel.NewClient(*listen, *server, *target, *timeout, *sproto, *rproto, *ping)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err.Error())
|
||||
return
|
||||
|
@ -35,7 +35,6 @@ type ServerConn struct {
|
||||
rproto int
|
||||
echoId int
|
||||
echoSeq int
|
||||
sendEchoId int
|
||||
}
|
||||
|
||||
func (p *Server) Run() {
|
||||
@ -143,11 +142,6 @@ func (p *Server) Recv(conn *ServerConn, id string, src *net.IPAddr) {
|
||||
|
||||
sendICMP(conn.echoId, conn.echoSeq, *p.conn, src, "", id, (uint32)(DATA), bytes[:n], conn.rproto, -1)
|
||||
|
||||
if conn.sendEchoId == conn.echoId {
|
||||
conn.echoSeq++
|
||||
}
|
||||
conn.sendEchoId = conn.echoId
|
||||
|
||||
p.sendPacket++
|
||||
p.sendPacketSize += (uint64)(n)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user