Skip to content

Commit 155136a

Browse files
committed
all: status as atomic.Int32 instead of core.Volatile[int]
1 parent 2d67fde commit 155136a

38 files changed

Lines changed: 183 additions & 177 deletions

intra/backend/dnsx.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const ( // see dnsx/transport.go
6161

6262
const ( // from dnsx/queryerror.go
6363
// Start: Transaction started
64-
Start = iota
64+
Start int32 = iota
6565
// Complete : Transaction completed successfully
6666
Complete
6767
// SendFailed : Failed to send query
@@ -84,6 +84,8 @@ const ( // from dnsx/queryerror.go
8484
Unpaused
8585
// DEnd: Transport stopped
8686
DEnd
87+
// Unknown: Transport status is unknown
88+
Unknown int32 = 100
8789
)
8890

8991
const ( // from: dnsx/rethinkdns.go
@@ -105,7 +107,7 @@ type DNSTransport interface {
105107
// Returns nil if there isn't any.
106108
GetRelay() Proxy
107109
// State of the transport after previous query (see: queryerror.go)
108-
Status() int
110+
Status() int32
109111
}
110112

111113
type DNSTransportMult interface {

intra/backend/dnsx_listener.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type DNSSummary struct {
5050
// Relay server PID hops over, if any.
5151
RPID string
5252
// Transport status (Start, Complete, SendFailed, NoResponse, BadQuery, BadResponse, etc).
53-
Status int
53+
Status int32
5454
// CSV of Rethink DNS+ blocklists (local or remote) names (if used).
5555
Blocklists string
5656
// Actual target (domain name) that was blocked (could be a CNAME or HTTPS/SVCB alias) by Blocklists.

intra/backend/ipn_proxies.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ type Proxy interface {
231231
// DNS returns the ip:port or doh/dot url or dnscrypt stamp for this proxy.
232232
DNS() string
233233
// Status returns the status of this proxy.
234-
Status() int
234+
Status() int32
235235
// Ping pings this proxy.
236236
Ping() bool
237237
// Pause pauses this proxy.

intra/backend/rnet_services.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type Server interface {
4242
// Addr returns the address of the server.
4343
GetAddr() string
4444
// Status returns the status of the server.
45-
Status() int
45+
Status() int32
4646
// Stop stops the server.
4747
Stop() error
4848
// Refresh re-registers the server.

intra/bootstrap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func (b *bootstrap) IPPorts() []netip.AddrPort {
314314
return dnsx.NoIPPort
315315
}
316316

317-
func (b *bootstrap) Status() int {
317+
func (b *bootstrap) Status() int32 {
318318
if tr := b.tr; tr != nil {
319319
return tr.Status()
320320
}

intra/common.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"strconv"
1616
"strings"
1717
"sync"
18+
"sync/atomic"
1819
"time"
1920

2021
"slices"
@@ -97,7 +98,7 @@ type baseHandler struct {
9798

9899
// fields below are mutable
99100

100-
status *core.Volatile[int] // status of this handler
101+
status atomic.Int32 // status of this handler
101102
}
102103

103104
var _ netstack.GBaseConnHandler = (*baseHandler)(nil)
@@ -112,8 +113,8 @@ func newBaseHandler(pctx context.Context, proto string, r dnsx.Resolver, px ipn.
112113
listener: l,
113114
fwtracker: core.NewExpiringMap[string, string](pctx, proto+".fwtrack"),
114115
conntracker: core.NewConnMap(proto + ".conntrack"),
115-
status: core.NewVolatile(HDLOK),
116116
}
117+
h.status.Store(HDLOK)
117118
context.AfterFunc(pctx, h.End)
118119
return h
119120
}

intra/dns53/dot.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type dot struct {
5656
echlastattempt atomic.Int64 // last attempt fetching ech cfg; unix milli
5757

5858
est core.P2QuantileEstimator
59-
status *core.Volatile[int]
59+
status atomic.Int32
6060
}
6161

6262
var _ dnsx.Transport = (*dot)(nil)
@@ -109,7 +109,6 @@ func NewTLSTransport(ctx context.Context, id, rawurl string, addrs []string, px
109109
skipTLSVerify: skipTLSVerify,
110110
addrport: addrport, // may or may not be ipaddr
111111
port: port,
112-
status: core.NewVolatile(x.Start),
113112
proxies: px,
114113
relay: relay,
115114
relayref: relayref,
@@ -118,6 +117,7 @@ func NewTLSTransport(ctx context.Context, id, rawurl string, addrs []string, px
118117
est: core.NewP50Estimator(ctx),
119118
// echconfig/echlastattempt: zero values (nil) are fine
120119
}
120+
t.status.Store(dnsx.Start)
121121
echcfg := t.getOrCreateEchConfigIfNeeded()
122122
// local dialer: protect.MakeNsDialer(id, ctl)
123123
t.c = dnsclient(tlscfg)
@@ -407,7 +407,7 @@ func (t *dot) IPPorts() (ipps []netip.AddrPort) {
407407
return
408408
}
409409

410-
func (t *dot) Status() int {
410+
func (t *dot) Status() int32 {
411411
if px := t.GetRelay(); px != nil {
412412
if y, to := dnsx.OverrideStatusFrom(px); y {
413413
return to
@@ -417,7 +417,7 @@ func (t *dot) Status() int {
417417
if s == dnsx.Paused {
418418
// paused status is a pseudo state dependent on underlying relay
419419
// or requested pid, not a permanent state of this transport.
420-
t.status.Cas(s, dnsx.Unpaused)
420+
t.status.CompareAndSwap(s, dnsx.Unpaused)
421421
return dnsx.Unpaused
422422
}
423423
return s

intra/dns53/errorer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (t *errorer) IPPorts() []netip.AddrPort {
7777
return dnsx.NoIPPort
7878
}
7979

80-
func (*errorer) Status() int {
80+
func (*errorer) Status() int32 {
8181
return x.ClientError
8282
}
8383

intra/dns53/goos.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
"context"
1111
"net"
1212
"net/netip"
13+
"sync/atomic"
1314
"time"
1415

1516
x "github.com/celzero/firestack/intra/backend"
16-
"github.com/celzero/firestack/intra/core"
1717
"github.com/celzero/firestack/intra/dnsx"
1818
"github.com/celzero/firestack/intra/ipn"
1919
"github.com/celzero/firestack/intra/log"
@@ -31,7 +31,7 @@ type goosr struct {
3131
// dialer *protect.RDial
3232
exit ipn.Proxy // the only supported proxy is ipn.Exit
3333

34-
status *core.Volatile[int]
34+
status atomic.Int32
3535
}
3636

3737
var _ dnsx.Transport = (*goosr)(nil)
@@ -55,12 +55,12 @@ func NewGoosTransport(pctx context.Context, pxs ipn.ProxyProvider) (t *goosr, er
5555
}
5656
ctx, cancel := context.WithCancel(pctx)
5757
tx := &goosr{
58-
ctx: ctx,
59-
done: cancel,
60-
status: core.NewVolatile(x.Start),
58+
ctx: ctx,
59+
done: cancel,
6160
// dialer: d,
6261
exit: px,
6362
}
63+
tx.status.Store(dnsx.Start)
6464
tx.r = &net.Resolver{
6565
PreferGo: true,
6666
Dial: tx.pxdial, // dials in to ipn.Exit, always
@@ -208,7 +208,7 @@ func (t *goosr) IPPorts() []netip.AddrPort {
208208
return []netip.AddrPort{netip.AddrPortFrom(netip.IPv6Loopback(), uint16(53))}
209209
}
210210

211-
func (t *goosr) Status() int {
211+
func (t *goosr) Status() int32 {
212212
return t.status.Load()
213213
}
214214

intra/dns53/grounded.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
type grounded struct {
2222
id string
2323
ipport string
24-
status int
24+
status int32
2525
}
2626

2727
var _ dnsx.Transport = (*grounded)(nil)
@@ -86,7 +86,7 @@ func (t *grounded) IPPorts() []netip.AddrPort {
8686
return dnsx.NoIPPort
8787
}
8888

89-
func (t *grounded) Status() int {
89+
func (t *grounded) Status() int32 {
9090
return t.status
9191
}
9292

0 commit comments

Comments
 (0)