@@ -150,6 +150,7 @@ type wgtun struct {
150150 // TODO: move status to a state-machine for all proxies
151151 status * core.Volatile [int ] // status of this interface
152152 statusReason core.Volatile [string ] // last state transition reason
153+ latestOpen atomic.Int64 // last open time in unix millis
153154 latestRefresh atomic.Int64 // last refresh time in unix millis
154155 latestPing atomic.Int64 // last ping time in unix millis
155156 latestErr core.Volatile [error ] // last open/dial err
@@ -1265,6 +1266,7 @@ func (w *wgproxy) Stat() (out *x.RouterStats) {
12651266 out .LastGoodRx = w .latestGoodRx .Load ()
12661267 out .LastGoodTx = w .latestGoodTx .Load ()
12671268 out .LastRefresh = w .latestRefresh .Load ()
1269+ out .LastOpen = w .latestOpen .Load ()
12681270 out .Since = w .since
12691271 out .Status = pxstatus (w .status .Load ()).String ()
12701272 out .StatusReason = w .statusReason .Load ()
@@ -1720,10 +1722,12 @@ func (h *wgtun) listener(op wg.PktDir, err error) (ended bool) {
17201722 why = "TNT: closed; prev: " + pxstatus (s ).String ()
17211723 s = TNT
17221724 return
1725+ } else if op == wg .Opn {
1726+ h .latestOpen .Store (now ())
17231727 }
17241728
17251729 now := now ()
1726- age := now - h .since
1730+ age := now - h .latestOpen . Load ()
17271731 if err != nil { // failing
17281732 s = TKO
17291733 why = "TKO: " + err .Error ()
@@ -1738,6 +1742,8 @@ func (h *wgtun) listener(op wg.PktDir, err error) (ended bool) {
17381742 // on net.ErrClosed, wg stops recieving routine for all peers; this among
17391743 // other things mean that the wg.Device is effectively down and would not
17401744 // recieve any incoming messages (nor outgoing as those use the same socket)
1745+ // Note that, there could be multiple receive functions (not just one) and
1746+ // the other ones (one each per ip family) may be running just fine.
17411747 s = TNT
17421748 why = "TNT: closed " + string (op )
17431749 }
@@ -1791,7 +1797,7 @@ func (h *wgtun) listener(op wg.PktDir, err error) (ended bool) {
17911797 hasNewReads := lastRead > age
17921798
17931799 // too much time since last good write and good reads
1794- readWriteDeviation := (hasNewReads || hasNewWrites ) && deviationMs > markTNTAfterMillis
1800+ readWriteDeviation := (hasNewReads || hasNewWrites ) && deviationMs > 2 * markTNTAfterMillis
17951801 // too much time since last attempted read was good
17961802 readThres := hasNewReads && readElapsedMs > markTNTAfterMillis
17971803 // too much time since last attempted write was good
0 commit comments