From 22625e8cc4792a71174af5fc69f0f63ba4b808d8 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 24 Jan 2019 00:00:46 +0100 Subject: Tunnel: support getting runtime configuration Signed-off-by: Jason A. Donenfeld --- WireGuard/WireGuard/UI/TunnelViewModel.swift | 18 ++++++++++++++++++ .../UI/macOS/ParseError+WireGuardAppError.swift | 4 ++++ 2 files changed, 22 insertions(+) (limited to 'WireGuard/WireGuard/UI') diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift index 07d1bac..9124a00 100644 --- a/WireGuard/WireGuard/UI/TunnelViewModel.swift +++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift @@ -40,6 +40,9 @@ class TunnelViewModel { case endpoint case persistentKeepAlive case allowedIPs + case rxBytes + case txBytes + case lastHandshakeTime case excludePrivateIPs case deletePeer @@ -50,6 +53,9 @@ class TunnelViewModel { case .endpoint: return tr("tunnelPeerEndpoint") case .persistentKeepAlive: return tr("tunnelPeerPersistentKeepalive") case .allowedIPs: return tr("tunnelPeerAllowedIPs") + case .rxBytes: return tr("tunnelPeerRxBytes") + case .txBytes: return tr("tunnelPeerTxBytes") + case .lastHandshakeTime: return tr("tunnelPeerLastHandshakeTime") case .excludePrivateIPs: return tr("tunnelPeerExcludePrivateIPs") case .deletePeer: return tr("deletePeerButtonTitle") } @@ -248,6 +254,18 @@ class TunnelViewModel { if let persistentKeepAlive = config.persistentKeepAlive { scratchpad[.persistentKeepAlive] = String(persistentKeepAlive) } + // TODO(roopc): These next 3 fields should be prettier + // - bytes() in https://git.zx2c4.com/WireGuard/tree/src/tools/show.c#n185 + // - ago() in https://git.zx2c4.com/WireGuard/tree/src/tools/show.c#n158 + if let rxBytes = config.rxBytes { + scratchpad[.rxBytes] = String(rxBytes) + } + if let txBytes = config.txBytes { + scratchpad[.txBytes] = String(txBytes) + } + if let lastHandshakeTime = config.lastHandshakeTime { + scratchpad[.lastHandshakeTime] = lastHandshakeTime.description + } updateExcludePrivateIPsFieldState() } diff --git a/WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift b/WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift index 9f2c009..6afbadb 100644 --- a/WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift +++ b/WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift @@ -43,6 +43,10 @@ extension TunnelConfiguration.ParseError: WireGuardAppError { return (tr(format: "macAlertPersistentKeepliveInvalid (%@)", value), tr("alertInvalidPeerMessagePersistentKeepaliveInvalid")) case .peerHasUnrecognizedKey(let value): return (tr(format: "macAlertUnrecognizedPeerKey (%@)", value), tr("macAlertInfoUnrecognizedPeerKey")) + case .peerHasInvalidTransferBytes(let line): + return (tr(format: "macAlertInvalidLine (%@)", String(line)), "") + case .peerHasInvalidLastHandshakeTime(let line): + return (tr(format: "macAlertInvalidLine (%@)", String(line)), "") case .multiplePeersWithSamePublicKey: return (tr("alertInvalidPeerMessagePublicKeyDuplicated"), "") case .multipleEntriesForKey(let value): -- cgit v1.2.3-59-g8ed1b