fix: Fix 'q' key handling and connectivity status issues
- Fix 'q' key in detail/add/help screens to return to list instead of quitting - Only quit application with 'q' when on main list screen - Fix parseHandshake to accumulate all time units instead of returning early This resolves handshake timing discrepancy with wg show output - Increase connection status threshold from 3 to 5 minutes Allows ~12 missed keepalive intervals (25s each) Improves connectivity status accuracy for peers with marginal connections
This commit is contained in:
@@ -143,8 +143,9 @@ func finalizePeerStatus(peer *PeerStatus, handshake string, transfer string) Pee
|
||||
// Determine status based on handshake
|
||||
if handshake != "" {
|
||||
peer.LatestHandshake = parseHandshake(handshake)
|
||||
// Peer is considered connected if handshake is recent (within 3 minutes)
|
||||
if time.Since(peer.LatestHandshake) < 3*time.Minute {
|
||||
// Peer is considered connected if handshake is recent (within 5 minutes)
|
||||
// This allows for ~12 missed keepalive intervals (at 25 seconds each)
|
||||
if time.Since(peer.LatestHandshake) < 5*time.Minute {
|
||||
peer.Status = StatusConnected
|
||||
} else {
|
||||
peer.Status = StatusDisconnected
|
||||
@@ -159,27 +160,28 @@ func finalizePeerStatus(peer *PeerStatus, handshake string, transfer string) Pee
|
||||
// parseHandshake converts handshake string to time.Time
|
||||
func parseHandshake(handshake string) time.Time {
|
||||
now := time.Now()
|
||||
var totalDuration time.Duration
|
||||
parts := strings.Fields(handshake)
|
||||
|
||||
for i, part := range parts {
|
||||
if strings.HasSuffix(part, "second") || strings.HasSuffix(part, "seconds") {
|
||||
if val, err := strconv.Atoi(strings.TrimSuffix(part, "s")); err == nil {
|
||||
return now.Add(-time.Duration(val) * time.Second)
|
||||
totalDuration += time.Duration(val) * time.Second
|
||||
}
|
||||
}
|
||||
if strings.HasSuffix(part, "minute") || strings.HasSuffix(part, "minutes") {
|
||||
if val, err := strconv.Atoi(strings.TrimSuffix(part, "s")); err == nil {
|
||||
return now.Add(-time.Duration(val) * time.Minute)
|
||||
totalDuration += time.Duration(val) * time.Minute
|
||||
}
|
||||
}
|
||||
if strings.HasSuffix(part, "hour") || strings.HasSuffix(part, "hours") {
|
||||
if val, err := strconv.Atoi(strings.TrimSuffix(part, "s")); err == nil {
|
||||
return now.Add(-time.Duration(val) * time.Hour)
|
||||
totalDuration += time.Duration(val) * time.Hour
|
||||
}
|
||||
}
|
||||
if strings.HasSuffix(part, "day") || strings.HasSuffix(part, "days") {
|
||||
if val, err := strconv.Atoi(strings.TrimSuffix(part, "s")); err == nil {
|
||||
return now.Add(-time.Duration(val) * 24 * time.Hour)
|
||||
totalDuration += time.Duration(val) * 24 * time.Hour
|
||||
}
|
||||
}
|
||||
// Handle "ago" word
|
||||
@@ -188,7 +190,11 @@ func parseHandshake(handshake string) time.Time {
|
||||
}
|
||||
}
|
||||
|
||||
return now.Add(-time.Hour) // Default to 1 hour ago if parsing fails
|
||||
if totalDuration == 0 {
|
||||
return now.Add(-time.Hour) // Default to 1 hour ago if parsing fails
|
||||
}
|
||||
|
||||
return now.Add(-totalDuration)
|
||||
}
|
||||
|
||||
// CheckInterface verifies if the WireGuard interface exists and is accessible
|
||||
|
||||
Reference in New Issue
Block a user