@@ -142,19 +142,23 @@ type wgtun struct {
142142 refreshBa * core.Barrier [bool , string ] // 2mins refresh barrier
143143
144144 // TODO: move status to a state-machine for all proxies
145- status * core.Volatile [int ] // status of this interface
146- statusReason core.Volatile [string ] // last state transition reason
147- latestRefresh atomic.Int64 // last refresh time in unix millis
148- latestPing atomic.Int64 // last ping time in unix millis
149- latestErr core.Volatile [error ] // last open/dial err
150- latestRxErr core.Volatile [error ] // last rx error
151- latestTxErr core.Volatile [error ] // last tx error
152- latestGoodRx atomic.Int64 // last successful rx time in unix millis
153- latestGoodTx atomic.Int64 // last successful tx time in unix millis
154- latestRx atomic.Int64 // last (successful or not) rx time in unix millis
155- latestTx atomic.Int64 // last (successful or not) tx time in unix millis
156- errRx atomic.Int64 // rx error count
157- errTx atomic.Int64 // tx error count
145+ status * core.Volatile [int ] // status of this interface
146+ statusReason core.Volatile [string ] // last state transition reason
147+ latestRefresh atomic.Int64 // last refresh time in unix millis
148+ latestPing atomic.Int64 // last ping time in unix millis
149+ latestErr core.Volatile [error ] // last open/dial err
150+ latestRxErr core.Volatile [error ] // last rx error
151+ latestTxErr core.Volatile [error ] // last tx error
152+ latestRead atomic.Int64 // last read time in unix millis
153+ latestWrite atomic.Int64 // last write time in unix millis
154+ latestGoodRead atomic.Int64 // last successful read time in unix millis
155+ latestGoodWrite atomic.Int64 // last successful write time in unix millis
156+ latestGoodRx atomic.Int64 // last successful rx time in unix millis
157+ latestGoodTx atomic.Int64 // last successful tx time in unix millis
158+ latestRx atomic.Int64 // last (successful or not) rx time in unix millis
159+ latestTx atomic.Int64 // last (successful or not) tx time in unix millis
160+ errRx atomic.Int64 // rx error count
161+ errTx atomic.Int64 // tx error count
158162}
159163
160164type wgconn interface {
@@ -1619,6 +1623,8 @@ func (h *wgtun) listener(op wg.PktDir, err error) {
16191623 now := now ()
16201624 age := now - h .since
16211625 if err != nil { // failing
1626+ s = TKO
1627+ why = "TKO: " + err .Error ()
16221628 if op == wg .Opn { // could not open conn to wg endpoint
16231629 s = TNT
16241630 why = "TNT: could not open conn"
@@ -1632,9 +1638,6 @@ func (h *wgtun) listener(op wg.PktDir, err error) {
16321638 // recieve any incoming messages (nor outgoing as those use the same socket)
16331639 s = TNT
16341640 why = "TNT: closed " + string (op )
1635- } else {
1636- s = TKO
1637- why = "TKO: " + err .Error ()
16381641 }
16391642
16401643 if op == wg .Rcv && ! timedout (err ) { // read error
@@ -1644,6 +1647,12 @@ func (h *wgtun) listener(op wg.PktDir, err error) {
16441647 h .errTx .Add (1 )
16451648 h .latestTx .Store (now )
16461649 } // else: not a transport message
1650+
1651+ if op .Read () {
1652+ h .latestRead .Store (now )
1653+ } else if op .Write () {
1654+ h .latestWrite .Store (now )
1655+ }
16471656 } else { // ok
16481657 s = TOK
16491658 why = "TOK: ok"
@@ -1656,14 +1665,20 @@ func (h *wgtun) listener(op wg.PktDir, err error) {
16561665 h .latestTx .Store (now )
16571666 why = "TOK: write ok"
16581667 } // else: not a transport message
1668+
1669+ if op .Read () {
1670+ h .latestGoodRead .Store (now )
1671+ } else if op .Write () {
1672+ h .latestGoodWrite .Store (now )
1673+ }
16591674 }
16601675
16611676 softrefresh := false
16621677 const tenSecMillis = 10 * 1000
16631678 // s may also be TOK (for successful handshakes but not for transport data)
16641679 if age > tenSecMillis && (s == TOK || s == TKO ) {
1665- lastSuccessfulRead := h .latestGoodRx .Load ()
1666- lastSuccessfulWrite := h .latestGoodTx .Load ()
1680+ lastSuccessfulRead := h .latestGoodRead .Load ()
1681+ lastSuccessfulWrite := h .latestGoodWrite .Load ()
16671682 lastRead := h .latestRx .Load ()
16681683 lastWrite := h .latestTx .Load ()
16691684
@@ -1691,7 +1706,7 @@ func (h *wgtun) listener(op wg.PktDir, err error) {
16911706 } else if readThres || writeThres || readWriteDeviation {
16921707 why = fmt .Sprintf ("TZZ: r !ok? %t, w !ok? %t, rw apart? %t; overriding: %s" ,
16931708 readThres , writeThres , readWriteDeviation , why )
1694- s = TZZ
1709+ s = TNT
16951710 softrefresh = true
16961711 }
16971712 }
0 commit comments