Fix: pinger should return max_int as rtt when its

status is dead
This commit is contained in:
Cong Zuo 2024-01-10 09:53:22 +08:00
parent ec7709b424
commit b349b464ac
2 changed files with 9 additions and 2 deletions

View file

@ -70,6 +70,12 @@ tc qdisc add dev $interface parent 1:1 handle 2: netem delay $delay
# remove tc rules
tc qdisc del dev $interface root
# drop output packets to ip
iptables -I OUTPUT -d $ip -j DROP
# remove iptables rule
iptables -D OUTPUT 1
```
### cherrypick from old `http2ping` branch after 2023 Clash holocaust:

View file

@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"fmt"
"math"
"sync/atomic"
"time"
@ -67,7 +68,7 @@ func NewHTTP2Pinger(config *Config, proxy constant.Proxy) *http2Pinger {
}
func (p *http2Pinger) doPing(tlsConn *tls.Conn, http2Conn *http2.ClientConn) (uint32, error) {
tlsConn.SetDeadline(time.Now().Add(p.config.Interval * 5))
tlsConn.SetDeadline(time.Now().Add(p.config.Interval))
defer tlsConn.SetDeadline(time.Time{})
start := time.Now()
@ -158,7 +159,7 @@ func (p *http2Pinger) pingLoop() {
func (p *http2Pinger) GetSmoothRtt() uint32 {
switch p.statusCode.Load() {
case PINGER_STATUS_DEAD:
return 0
return math.MaxUint32
case PINGER_STATUS_PINGING:
fallthrough
case PINGER_STATUS_IDLE: