Skip to content

Commit

Permalink
chore: refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
mzz2017 committed Jan 8, 2024
1 parent 03458bf commit c2fc9d6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions component/outbound/dialer/connectivity_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ type CheckOption struct {
func (d *Dialer) ActivateCheck() {
d.tickerMu.Lock()
defer d.tickerMu.Unlock()
if d.InstanceOption.CheckEnabled {
if d.InstanceOption.DisableCheck || d.checkActivated {
return
}
d.InstanceOption.CheckEnabled = true
d.checkActivated = true
go d.aliveBackground()
}

Expand Down
7 changes: 3 additions & 4 deletions component/outbound/dialer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type Dialer struct {
checkCh chan time.Time
ctx context.Context
cancel context.CancelFunc

checkActivated bool
}

type GlobalOption struct {
Expand All @@ -48,7 +50,7 @@ type GlobalOption struct {
}

type InstanceOption struct {
CheckEnabled bool
DisableCheck bool
}

type Property struct {
Expand Down Expand Up @@ -78,9 +80,6 @@ func NewDialer(dialer netproxy.Dialer, option *GlobalOption, iOption InstanceOpt
ctx: ctx,
cancel: cancel,
}
if iOption.CheckEnabled {
go d.aliveBackground()
}
return d
}

Expand Down
2 changes: 1 addition & 1 deletion component/outbound/dialer_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var log = logger.NewLogger("trace", false, nil)

func newDirectDialer(option *dialer.GlobalOption, fullcone bool) *dialer.Dialer {
_d, p := dialer.NewDirectDialer(option, true)
d := dialer.NewDialer(_d, option, dialer.InstanceOption{CheckEnabled: false}, p)
d := dialer.NewDialer(_d, option, dialer.InstanceOption{DisableCheck: false}, p)
return d
}

Expand Down
2 changes: 1 addition & 1 deletion component/outbound/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewDialerSetFromLinks(option *dialer.GlobalOption, tagToNodeList map[string
}
for subscriptionTag, nodes := range tagToNodeList {
for _, node := range nodes {
d, err := dialer.NewFromLink(option, dialer.InstanceOption{CheckEnabled: false}, node, subscriptionTag)
d, err := dialer.NewFromLink(option, dialer.InstanceOption{DisableCheck: false}, node, subscriptionTag)
if err != nil {
option.Log.Infof("failed to parse node: %v", err)
continue
Expand Down
4 changes: 2 additions & 2 deletions control/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ func NewControlPlane(
}
disableKernelAliveCallback := dialMode != consts.DialMode_Ip
_direct, directProperty := dialer.NewDirectDialer(option, true)
direct := dialer.NewDialer(_direct, option, dialer.InstanceOption{CheckEnabled: false}, directProperty)
direct := dialer.NewDialer(_direct, option, dialer.InstanceOption{DisableCheck: true}, directProperty)
_block, blockProperty := dialer.NewBlockDialer(option, func() { /*Dialer Outbound*/ })
block := dialer.NewDialer(_block, option, dialer.InstanceOption{CheckEnabled: false}, blockProperty)
block := dialer.NewDialer(_block, option, dialer.InstanceOption{DisableCheck: true}, blockProperty)
outbounds := []*outbound.DialerGroup{
outbound.NewDialerGroup(option, consts.OutboundDirect.String(),
[]*dialer.Dialer{direct}, []*dialer.Annotation{{}},
Expand Down

0 comments on commit c2fc9d6

Please sign in to comment.