Add text selection and copy capability to terminal UI
This commit is contained in:
@@ -15,6 +15,15 @@ const (
|
||||
StatusConnected = "Connected"
|
||||
// StatusDisconnected indicates a peer is not connected
|
||||
StatusDisconnected = "Disconnected"
|
||||
|
||||
// QualityExcellent indicates handshake was very recent (< 30s)
|
||||
QualityExcellent = "Excellent"
|
||||
// QualityGood indicates handshake was recent (< 2m)
|
||||
QualityGood = "Good"
|
||||
// QualityFair indicates handshake was acceptable (< 5m)
|
||||
QualityFair = "Fair"
|
||||
// QualityPoor indicates handshake was old (> 5m)
|
||||
QualityPoor = "Poor"
|
||||
)
|
||||
|
||||
// PeerStatus represents the status of a WireGuard peer
|
||||
@@ -25,7 +34,8 @@ type PeerStatus struct {
|
||||
LatestHandshake time.Time `json:"latest_handshake"`
|
||||
TransferRx string `json:"transfer_rx"`
|
||||
TransferTx string `json:"transfer_tx"`
|
||||
Status string `json:"status"` // "Connected" or "Disconnected"
|
||||
Status string `json:"status"` // "Connected" or "Disconnected"
|
||||
Quality string `json:"quality,omitempty"` // "Excellent", "Good", "Fair", "Poor" (if connected)
|
||||
}
|
||||
|
||||
// GetClientStatus checks if a specific client is connected
|
||||
@@ -119,6 +129,20 @@ func parsePeersOutput(output string) []PeerStatus {
|
||||
return peers
|
||||
}
|
||||
|
||||
// CalculateQuality returns the connection quality based on handshake time
|
||||
func CalculateQuality(timeSinceHandshake time.Duration) string {
|
||||
if timeSinceHandshake < 30*time.Second {
|
||||
return QualityExcellent
|
||||
}
|
||||
if timeSinceHandshake < 2*time.Minute {
|
||||
return QualityGood
|
||||
}
|
||||
if timeSinceHandshake < 5*time.Minute {
|
||||
return QualityFair
|
||||
}
|
||||
return QualityPoor
|
||||
}
|
||||
|
||||
// finalizePeerStatus determines the peer's status based on handshake time
|
||||
func finalizePeerStatus(peer *PeerStatus, handshake string, transfer string) PeerStatus {
|
||||
peer.TransferRx = ""
|
||||
@@ -140,13 +164,16 @@ func finalizePeerStatus(peer *PeerStatus, handshake string, transfer string) Pee
|
||||
}
|
||||
}
|
||||
|
||||
// Determine status based on handshake
|
||||
// Determine status and quality based on handshake
|
||||
if handshake != "" {
|
||||
peer.LatestHandshake = parseHandshake(handshake)
|
||||
timeSinceHandshake := time.Since(peer.LatestHandshake)
|
||||
|
||||
// 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 {
|
||||
if timeSinceHandshake < 5*time.Minute {
|
||||
peer.Status = StatusConnected
|
||||
peer.Quality = calculateQuality(timeSinceHandshake)
|
||||
} else {
|
||||
peer.Status = StatusDisconnected
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user