mirror of
https://github.com/daeuniverse/dae.git
synced 2025-07-30 22:59:00 +07:00
optimize: remove rush-answer detector because it does always work in all districts
This commit is contained in:
@ -7,9 +7,9 @@ package dialer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/daeuniverse/dae/common/consts"
|
||||
"github.com/mzz2017/softwind/pkg/fastrand"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/daeuniverse/dae/common/consts"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@ -138,10 +138,8 @@ func (a *AliveDialerSet) NotifyLatencyChange(dialer *Dialer, alive bool) {
|
||||
// Dialer: not alive -> alive.
|
||||
if index == -NotAlive {
|
||||
a.log.WithFields(logrus.Fields{
|
||||
"dialer": dialer.property.Name,
|
||||
"group": a.dialerGroupName,
|
||||
"network": a.CheckTyp.StringWithoutDns(),
|
||||
}).Infoln("NOT ALIVE -> ALIVE:")
|
||||
"group": a.dialerGroupName,
|
||||
}).Infof("[NOT ALIVE --%v-> ALIVE] %v", a.CheckTyp.String(), dialer.property.Name)
|
||||
}
|
||||
a.dialerToIndex[dialer] = len(a.inorderedAliveDialerSet)
|
||||
a.inorderedAliveDialerSet = append(a.inorderedAliveDialerSet, dialer)
|
||||
@ -151,10 +149,8 @@ func (a *AliveDialerSet) NotifyLatencyChange(dialer *Dialer, alive bool) {
|
||||
if index >= 0 {
|
||||
// Dialer: alive -> not alive.
|
||||
a.log.WithFields(logrus.Fields{
|
||||
"dialer": dialer.property.Name,
|
||||
"group": a.dialerGroupName,
|
||||
"network": a.CheckTyp.StringWithoutDns(),
|
||||
}).Infoln("ALIVE -> NOT ALIVE:")
|
||||
"group": a.dialerGroupName,
|
||||
}).Infof("[ALIVE --%v-> NOT ALIVE] %v", a.CheckTyp.String(), dialer.property.Name)
|
||||
// Remove the dialer from inorderedAliveDialerSet.
|
||||
if index >= len(a.inorderedAliveDialerSet) {
|
||||
a.log.Panicf("index:%v >= len(a.inorderedAliveDialerSet):%v", index, len(a.inorderedAliveDialerSet))
|
||||
|
@ -167,6 +167,7 @@ func ParseCheckDnsOption(ctx context.Context, dnsHostPort string) (opt *CheckDns
|
||||
type TcpCheckOptionRaw struct {
|
||||
opt *TcpCheckOption
|
||||
mu sync.Mutex
|
||||
Log *logrus.Logger
|
||||
Raw string
|
||||
}
|
||||
|
||||
@ -176,6 +177,7 @@ func (c *TcpCheckOptionRaw) Option() (opt *TcpCheckOption, err error) {
|
||||
if c.opt == nil {
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
|
||||
defer cancel()
|
||||
ctx = context.WithValue(ctx, "logger", c.Log)
|
||||
tcpCheckOption, err := ParseTcpCheckOption(ctx, c.Raw)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse tcp_check_url: %w", err)
|
||||
@ -238,6 +240,7 @@ func (d *Dialer) aliveBackground() {
|
||||
if !opt.Ip4.IsValid() {
|
||||
d.Log.WithFields(logrus.Fields{
|
||||
"link": d.TcpCheckOptionRaw.Raw,
|
||||
"dialer": d.property.Name,
|
||||
"network": typ.String(),
|
||||
}).Debugln("Skip check due to no DNS record.")
|
||||
return false, nil
|
||||
@ -259,6 +262,7 @@ func (d *Dialer) aliveBackground() {
|
||||
if !opt.Ip6.IsValid() {
|
||||
d.Log.WithFields(logrus.Fields{
|
||||
"link": d.TcpCheckOptionRaw.Raw,
|
||||
"dialer": d.property.Name,
|
||||
"network": typ.String(),
|
||||
}).Debugln("Skip check due to no DNS record.")
|
||||
return false, nil
|
||||
@ -280,6 +284,7 @@ func (d *Dialer) aliveBackground() {
|
||||
if !opt.Ip4.IsValid() {
|
||||
d.Log.WithFields(logrus.Fields{
|
||||
"link": d.CheckDnsOptionRaw.Raw,
|
||||
"dialer": d.property.Name,
|
||||
"network": typ.String(),
|
||||
}).Debugln("Skip check due to no DNS record.")
|
||||
return false, nil
|
||||
@ -301,6 +306,7 @@ func (d *Dialer) aliveBackground() {
|
||||
if !opt.Ip6.IsValid() {
|
||||
d.Log.WithFields(logrus.Fields{
|
||||
"link": d.CheckDnsOptionRaw.Raw,
|
||||
"dialer": d.property.Name,
|
||||
"network": typ.String(),
|
||||
}).Debugln("Skip check due to no DNS record.")
|
||||
return false, nil
|
||||
@ -523,9 +529,16 @@ func (d *Dialer) HttpCheck(ctx context.Context, u *netutils.URL, ip netip.Addr)
|
||||
defer resp.Body.Close()
|
||||
// Judge the status code.
|
||||
if page := path.Base(req.URL.Path); strings.HasPrefix(page, "generate_") {
|
||||
return strconv.Itoa(resp.StatusCode) == strings.TrimPrefix(page, "generate_"), nil
|
||||
if strconv.Itoa(resp.StatusCode) != strings.TrimPrefix(page, "generate_") {
|
||||
return false, fmt.Errorf("unexpected status code: %v", resp.StatusCode)
|
||||
}
|
||||
return true, nil
|
||||
} else {
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 500 {
|
||||
return false, fmt.Errorf("bad status code: %v", resp.StatusCode)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
return resp.StatusCode >= 200 && resp.StatusCode < 500, nil
|
||||
}
|
||||
|
||||
func (d *Dialer) DnsCheck(ctx context.Context, dns netip.AddrPort, tcp bool) (ok bool, err error) {
|
||||
|
@ -6,10 +6,10 @@
|
||||
package outbound
|
||||
|
||||
import (
|
||||
"github.com/mzz2017/softwind/pkg/fastrand"
|
||||
"github.com/daeuniverse/dae/common/consts"
|
||||
"github.com/daeuniverse/dae/component/outbound/dialer"
|
||||
"github.com/daeuniverse/dae/pkg/logger"
|
||||
"github.com/mzz2017/softwind/pkg/fastrand"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@ -43,7 +43,7 @@ func TestDialerGroup_Select_Fixed(t *testing.T) {
|
||||
g := NewDialerGroup(option, "test-group", dialers, DialerSelectionPolicy{
|
||||
Policy: consts.DialerSelectionPolicy_Fixed,
|
||||
FixedIndex: fixedIndex,
|
||||
}, func(alive bool, networkType *dialer.NetworkType) {})
|
||||
}, func(alive bool, networkType *dialer.NetworkType, isInit bool) {})
|
||||
for i := 0; i < 10; i++ {
|
||||
d, _, err := g.Select(TestNetworkType)
|
||||
if err != nil {
|
||||
@ -90,7 +90,7 @@ func TestDialerGroup_Select_MinLastLatency(t *testing.T) {
|
||||
}
|
||||
g := NewDialerGroup(option, "test-group", dialers, DialerSelectionPolicy{
|
||||
Policy: consts.DialerSelectionPolicy_MinLastLatency,
|
||||
}, func(alive bool, networkType *dialer.NetworkType) {})
|
||||
}, func(alive bool, networkType *dialer.NetworkType, isInit bool) {})
|
||||
|
||||
// Test 1000 times.
|
||||
for i := 0; i < 1000; i++ {
|
||||
@ -155,7 +155,7 @@ func TestDialerGroup_Select_Random(t *testing.T) {
|
||||
}
|
||||
g := NewDialerGroup(option, "test-group", dialers, DialerSelectionPolicy{
|
||||
Policy: consts.DialerSelectionPolicy_Random,
|
||||
}, func(alive bool, networkType *dialer.NetworkType) {})
|
||||
}, func(alive bool, networkType *dialer.NetworkType, isInit bool) {})
|
||||
count := make([]int, len(dialers))
|
||||
for i := 0; i < 100; i++ {
|
||||
d, _, err := g.Select(TestNetworkType)
|
||||
@ -195,7 +195,7 @@ func TestDialerGroup_SetAlive(t *testing.T) {
|
||||
}
|
||||
g := NewDialerGroup(option, "test-group", dialers, DialerSelectionPolicy{
|
||||
Policy: consts.DialerSelectionPolicy_Random,
|
||||
}, func(alive bool, networkType *dialer.NetworkType) {})
|
||||
}, func(alive bool, networkType *dialer.NetworkType, isInit bool) {})
|
||||
zeroTarget := 3
|
||||
g.MustGetAliveDialerSet(TestNetworkType).NotifyLatencyChange(dialers[zeroTarget], false)
|
||||
count := make([]int, len(dialers))
|
||||
|
Reference in New Issue
Block a user