Skip to content

Commit 61f58d3

Browse files
committed
ipn/proxies,ipn/wg: enums for proxy status & wg gw op
1 parent 70b9d34 commit 61f58d3

3 files changed

Lines changed: 38 additions & 10 deletions

File tree

intra/ipn/proxies.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ const (
6868
AUTOMTU2 = "(auto)"
6969
)
7070

71+
type pxstatus int
72+
73+
func (s pxstatus) String() string {
74+
switch s {
75+
case TKO:
76+
return "notok"
77+
case TOK:
78+
return "ok"
79+
case TUP:
80+
return "up"
81+
case TZZ:
82+
return "idle"
83+
case TNT:
84+
return "unresponsive"
85+
case END:
86+
return "ended"
87+
default:
88+
return "unknown"
89+
}
90+
}
91+
7192
var (
7293
errProxyScheme = errors.New("proxy: unsupported scheme")
7394
errUnexpectedProxy = errors.New("proxy: unexpected type")

intra/ipn/wg/wgconn.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,16 @@ func (k floodkind) String() string {
9494
}
9595
}
9696

97-
type rwobserver func(op string, err error)
97+
type rwobserver func(op PktDir, err error)
9898
type connector func(network, to string) (net.PacketConn, error)
9999

100+
type PktDir string
101+
102+
const (
103+
Rcv PktDir = "recv"
104+
Snd PktDir = "send"
105+
)
106+
100107
type StdNetBind struct {
101108
id string
102109
connect connector
@@ -336,7 +343,7 @@ func (s *StdNetBind) makeReceiveFn(uc net.PacketConn) conn.ReceiveFunc {
336343
return func(bufs [][]byte, sizes []int, eps []conn.Endpoint) (n int, err error) {
337344
defer core.Recover(core.Exit11, "wgconn.recv."+s.id)
338345
defer func() {
339-
s.observer("r", err)
346+
s.observer(Rcv, err)
340347
}()
341348

342349
usingamz := s.amnezia.Load().Set()
@@ -379,7 +386,7 @@ func timedout(err error) bool {
379386
func (s *StdNetBind) Send(buf [][]byte, peer conn.Endpoint) (err error) {
380387
defer core.Recover(core.Exit11, "wgconn.send."+s.id)
381388
defer func() {
382-
s.observer("w", err)
389+
s.observer(Snd, err)
383390
}()
384391

385392
// the peer endpoint

intra/ipn/wgproxy.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ func (h *wgtun) serve(network, local string) (pc net.PacketConn, err error) {
13431343
return
13441344
}
13451345

1346-
func (h *wgtun) listener(op string, err error) {
1346+
func (h *wgtun) listener(op wg.PktDir, err error) {
13471347
if h.status.Load() == END {
13481348
return
13491349
}
@@ -1362,9 +1362,9 @@ func (h *wgtun) listener(op string, err error) {
13621362
}
13631363

13641364
if s == TOK {
1365-
if op == "r" {
1365+
if op == wg.Rcv { // read
13661366
h.latestRx.Store(now())
1367-
} else if op == "w" {
1367+
} else if op == wg.Snd { // write
13681368
h.latestTx.Store(now())
13691369
}
13701370
writeElapsedMs := h.latestTx.Load() - h.latestRx.Load() // may be negative
@@ -1373,17 +1373,17 @@ func (h *wgtun) listener(op string, err error) {
13731373
s = TNT
13741374
}
13751375
} else if s == TKO {
1376-
if op == "r" {
1376+
if op == wg.Rcv {
13771377
h.errRx.Add(1)
1378-
} else if op == "w" {
1378+
} else if op == wg.Snd {
13791379
h.errTx.Add(1)
13801380
}
13811381
}
13821382

13831383
if s != TOK && s != TUP {
13841384
if n := h.remote.Load().MaybeRefresh(); n > 0 {
1385-
log.I("wg: %s (%s) listener: %s; refreshed n domains: %d",
1386-
h.id, h.viaStatus(), op, n)
1385+
log.I("wg: %s (%s) listener: %s, state: %s; refreshed n domains: %d",
1386+
h.id, h.viaStatus(), op, pxstatus(s), n)
13871387
}
13881388
}
13891389

0 commit comments

Comments
 (0)