]> Cypherpunks.ru repositories - nncp.git/commitdiff
Debug friendly if conditions
authorSergey Matveev <stargrave@stargrave.org>
Sun, 30 May 2021 16:01:05 +0000 (19:01 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 30 May 2021 16:18:47 +0000 (19:18 +0300)
src/sp.go

index d7e4882b4a757f8863e08928912e950a4d87162d..2dde928eaeecff5a84841cb0d8889a1a8306793c 100644 (file)
--- a/src/sp.go
+++ b/src/sp.go
@@ -795,13 +795,20 @@ func (state *SPState) StartWorkers(
                                pingTicker.Stop()
                                return
                        case now := <-deadlineTicker.C:
-                               if (now.Sub(state.RxLastNonPing) >= state.onlineDeadline &&
-                                       now.Sub(state.TxLastNonPing) >= state.onlineDeadline) ||
-                                       (state.maxOnlineTime > 0 && state.mustFinishAt.Before(now)) ||
-                                       (now.Sub(state.RxLastSeen) >= 2*PingTimeout) {
-                                       state.SetDead()
-                                       conn.Close() // #nosec G104
+                               if now.Sub(state.RxLastNonPing) >= state.onlineDeadline &&
+                                       now.Sub(state.TxLastNonPing) >= state.onlineDeadline {
+                                       goto Deadlined
                                }
+                               if state.maxOnlineTime > 0 && state.mustFinishAt.Before(now) {
+                                       goto Deadlined
+                               }
+                               if now.Sub(state.RxLastSeen) >= 2*PingTimeout {
+                                       goto Deadlined
+                               }
+                               break
+                       Deadlined:
+                               state.SetDead()
+                               conn.Close() // #nosec G104
                        case now := <-pingTicker.C:
                                if now.After(state.TxLastSeen.Add(PingTimeout)) {
                                        state.wg.Add(1)