-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'SagerNet:dev' into dev
- Loading branch information
Showing
42 changed files
with
1,173 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Foundation | ||
|
||
public struct Connection: Codable { | ||
public let id: String | ||
public let inbound: String | ||
public let inboundType: String | ||
public let ipVersion: Int32 | ||
public let network: String | ||
public let source: String | ||
public let destination: String | ||
public let domain: String | ||
public let displayDestination: String | ||
public let protocolName: String | ||
public let user: String | ||
public let fromOutbound: String | ||
public let createdAt: Date | ||
public let closedAt: Date? | ||
public var upload: Int64 | ||
public var download: Int64 | ||
public var uploadTotal: Int64 | ||
public var downloadTotal: Int64 | ||
public let rule: String | ||
public let outbound: String | ||
public let outboundType: String | ||
public let chain: [String] | ||
|
||
var hashValue: Int { | ||
var value = id.hashValue | ||
(value, _) = value.addingReportingOverflow(upload.hashValue) | ||
(value, _) = value.addingReportingOverflow(download.hashValue) | ||
(value, _) = value.addingReportingOverflow(uploadTotal.hashValue) | ||
(value, _) = value.addingReportingOverflow(downloadTotal.hashValue) | ||
return value | ||
} | ||
|
||
func performSearch(_ content: String) -> Bool { | ||
for item in content.components(separatedBy: " ") { | ||
let itemSep = item.components(separatedBy: ":") | ||
if itemSep.count == 2 { | ||
if !performSearchType(type: itemSep[0], value: itemSep[1]) { | ||
return false | ||
} | ||
continue | ||
} | ||
if !performSearchPlain(item) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
private func performSearchPlain(_ content: String) -> Bool { | ||
destination.contains(content) || | ||
domain.contains(content) | ||
} | ||
|
||
private func performSearchType(type: String, value: String) -> Bool { | ||
switch type { | ||
// TODO: impl more | ||
case "network": | ||
return network == value | ||
case "inbound": | ||
return inbound.contains(value) | ||
case "inbound.type": | ||
return inboundType == value | ||
case "source": | ||
return source.contains(value) | ||
case "destination": | ||
return destination.contains(value) | ||
default: | ||
return false | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
ApplicationLibrary/Views/Connections/ConnectionDetailsView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Foundation | ||
import Libbox | ||
import SwiftUI | ||
|
||
public struct ConnectionDetailsView: View { | ||
private let connection: Connection | ||
public init(_ connection: Connection) { | ||
self.connection = connection | ||
} | ||
|
||
public var body: some View { | ||
FormView { | ||
if connection.closedAt != nil { | ||
FormTextItem("State", "Closed") | ||
FormTextItem("Created At", connection.createdAt.myFormat) | ||
} else { | ||
FormTextItem("State", "Active") | ||
FormTextItem("Created At", connection.createdAt.myFormat) | ||
} | ||
if let closedAt = connection.closedAt { | ||
FormTextItem("Closed At", closedAt.myFormat) | ||
} | ||
FormTextItem("Upload", LibboxFormatBytes(connection.uploadTotal)) | ||
FormTextItem("Download", LibboxFormatBytes(connection.downloadTotal)) | ||
Section("Metadata") { | ||
FormTextItem("Inbound", connection.inbound) | ||
FormTextItem("Inbound Type", connection.inboundType) | ||
FormTextItem("IP Version", "\(connection.ipVersion)") | ||
FormTextItem("Network", connection.network.uppercased()) | ||
FormTextItem("Source", connection.source) | ||
FormTextItem("Destination", connection.destination) | ||
if !connection.domain.isEmpty { | ||
FormTextItem("Domain", connection.domain) | ||
} | ||
if !connection.protocolName.isEmpty { | ||
FormTextItem("Protocol", connection.protocolName) | ||
} | ||
if !connection.user.isEmpty { | ||
FormTextItem("User", connection.user) | ||
} | ||
if !connection.fromOutbound.isEmpty { | ||
FormTextItem("From Outbound", connection.fromOutbound) | ||
} | ||
if !connection.rule.isEmpty { | ||
FormTextItem("Match Rule", connection.rule) | ||
} | ||
FormTextItem("Outbound", connection.outbound) | ||
FormTextItem("Outbound Type", connection.outboundType) | ||
if connection.chain.count > 1 { | ||
FormTextItem("Chain", connection.chain.reversed().joined(separator: "/")) | ||
} | ||
} | ||
} | ||
.navigationTitle("Connection") | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
ApplicationLibrary/Views/Connections/ConnectionListPage.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Foundation | ||
import SwiftUI | ||
|
||
public enum ConnectionListPage: Int, CaseIterable, Identifiable { | ||
public var id: Self { | ||
self | ||
} | ||
|
||
case active | ||
case closed | ||
} | ||
|
||
public extension ConnectionListPage { | ||
var title: String { | ||
switch self { | ||
case .active: | ||
return NSLocalizedString("Active", comment: "") | ||
case .closed: | ||
return NSLocalizedString("Closed", comment: "") | ||
} | ||
} | ||
|
||
var label: some View { | ||
switch self { | ||
case .active: | ||
return Label(title, systemImage: "play.fill") | ||
case .closed: | ||
return Label(title, systemImage: "stop.fill") | ||
} | ||
} | ||
} |
Oops, something went wrong.