Skip to content

Commit fc43536

Browse files
committed
settings: automode as go enum
1 parent b628036 commit fc43536

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

intra/settings/proxyopts.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,19 @@ func (p *ProxyOptions) Url() string {
114114
// backend.Auto uses remote proxies (ex: RPN).
115115
var AutoMode atomic.Int32
116116

117+
type AutoModeType int32
118+
117119
const (
118120
// local mode: backend.Auto uses local proxies (ex: ipn.Exit) only.
119-
AutoModeLocal = iota
121+
AutoModeLocal AutoModeType = iota
120122
// remote mode: backend.Auto uses remote proxies (ex: RPN) only.
121123
AutoModeRemote
122124
// hybrid mode: backend.Auto uses local and remote proxies.
123125
AutoModeHybrid
124126
)
125127

126-
// SetAutoMode sets the global AutoMode variable to y.
127-
// Indicates if backend.Auto proxy is in local, remote, or hybrid mode.
128-
func SetAutoMode(m int32) (ok bool) {
129-
s := max(m, AutoModeLocal)
130-
s = min(m, AutoModeHybrid)
131-
if m != s {
132-
return false
133-
}
134-
AutoMode.Store(m)
135-
return true
136-
}
137-
138-
func AutoModeStr() string {
139-
switch AutoMode.Load() {
128+
func (m AutoModeType) String() string {
129+
switch m {
140130
case AutoModeLocal:
141131
return "local"
142132
case AutoModeRemote:
@@ -148,14 +138,24 @@ func AutoModeStr() string {
148138
}
149139
}
150140

141+
// SetAutoMode sets the global AutoMode variable to y.
142+
// Indicates if backend.Auto proxy is in local, remote, or hybrid mode.
143+
func SetAutoMode(m AutoModeType) (prev int32) {
144+
return AutoMode.Swap(int32(m))
145+
}
146+
147+
func AutoModeStr() string {
148+
return AutoModeType(AutoMode.Load()).String()
149+
}
150+
151151
// backend.Auto must use remote proxies and never use local (ex: ipn.Exit) ones.
152152
func AutoAlwaysRemote() bool {
153-
return AutoMode.Load() == AutoModeRemote
153+
return AutoModeType(AutoMode.Load()) == AutoModeRemote
154154
}
155155

156156
// backend.Auto is effecively not active.
157157
func AutoActive() bool {
158-
return AutoMode.Load() != AutoModeLocal
158+
return AutoModeType(AutoMode.Load()) != AutoModeLocal
159159
}
160160

161161
// AutoDialsParallel is a global variable to instruct ipn.Auto proxy

0 commit comments

Comments
 (0)