Skip to content

Commit

Permalink
完善 Routing
Browse files Browse the repository at this point in the history
  • Loading branch information
yanue committed Jul 21, 2024
1 parent 25a4f51 commit a7202a4
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 48 deletions.
76 changes: 38 additions & 38 deletions V2rayU/Base.lproj/PreferenceRouting.xib
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,50 @@
</button>
</subviews>
</view>
<segmentedControl verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="yay-tY-9RI">
<rect key="frame" x="25" y="55" width="220" height="23"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="smallSquare" trackingMode="selectOne" id="GHx-a5-Me0">
<font key="font" metaFont="system"/>
<segments>
<segment image="NSAddTemplate" imageScaling="none" width="62"/>
<segment image="NSMenuMixedStateTemplate" imageScaling="none" width="61" tag="1"/>
<segment width="89" enabled="NO"/>
</segments>
<connections>
<action selector="addRemoveServer:" target="-2" id="icc-rY-Qe0"/>
</connections>
</segmentedCell>
</segmentedControl>
<button verticalHuggingPriority="750" id="RRU-nZ-itS">
<rect key="frame" x="75" y="11" width="120" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="save" bezelStyle="rounded" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="8g2-Nj-m07">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="saveRouting:" target="-2" id="q5Z-CO-QXQ"/>
</connections>
</button>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ntV-Ym-8MI">
<rect key="frame" x="27" y="315" width="83" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Rouing Rules" id="E4W-rN-0eq">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<scrollView focusRingType="none" fixedFrame="YES" borderType="line" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="in5-Uo-f8c">
<rect key="frame" x="25" y="66" width="220" height="241"/>
<rect key="frame" x="25" y="56" width="220" height="251"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<clipView key="contentView" copiesOnScroll="NO" id="vCh-HN-u7f">
<rect key="frame" x="1" y="1" width="218" height="239"/>
<rect key="frame" x="1" y="1" width="218" height="249"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnResizing="NO" multipleSelection="NO" emptySelection="NO" autosaveColumns="NO" typeSelect="NO" id="L49-ez-XJl">
<rect key="frame" x="0.0" y="0.0" width="218" height="239"/>
<rect key="frame" x="0.0" y="0.0" width="218" height="249"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -339,41 +374,6 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
<segmentedControl verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="yay-tY-9RI">
<rect key="frame" x="25" y="55" width="220" height="23"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="smallSquare" trackingMode="selectOne" id="GHx-a5-Me0">
<font key="font" metaFont="system"/>
<segments>
<segment image="NSAddTemplate" imageScaling="none" width="62"/>
<segment image="NSMenuMixedStateTemplate" imageScaling="none" width="61" tag="1"/>
<segment width="89" enabled="NO"/>
</segments>
<connections>
<action selector="addRemoveServer:" target="-2" id="icc-rY-Qe0"/>
</connections>
</segmentedCell>
</segmentedControl>
<button verticalHuggingPriority="750" id="RRU-nZ-itS">
<rect key="frame" x="75" y="11" width="120" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="save" bezelStyle="rounded" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="8g2-Nj-m07">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="saveRouting:" target="-2" id="q5Z-CO-QXQ"/>
</connections>
</button>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ntV-Ym-8MI">
<rect key="frame" x="27" y="315" width="83" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Rouing Rules" id="E4W-rN-0eq">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<point key="canvasLocation" x="-130" y="-187"/>
</view>
Expand Down
2 changes: 1 addition & 1 deletion V2rayU/Ping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class PingServer: NSObject, URLSessionDataDelegate {
vCfg.httpHost = "127.0.0.1"
vCfg.socksHost = "127.0.0.1"
vCfg.httpPort = String(bindPort)
vCfg.socksPort = String(bindPort + 1)
vCfg.socksPort = String(bindPort - 1)
jsonText = vCfg.combineManual()

do {
Expand Down
4 changes: 2 additions & 2 deletions V2rayU/Preference/PreferenceRouting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ final class PreferenceRoutingViewController: NSViewController, PreferencePane, N


@IBAction func goHelp(_ sender: Any) {
guard let url = URL(string: "https://toutyrater.github.io/basic/routing/") else {
guard let url = URL(string: "https://xtls.github.io/config/routing.html#routingobject") else {
return
}
NSWorkspace.shared.open(url)
}

@IBAction func goHelp2(_ sender: Any) {
guard let url = URL(string: "https://github.com/v2ray/domain-list-community") else {
guard let url = URL(string: "https://xtls.github.io/config/routing.html#routingobject") else {
return
}
NSWorkspace.shared.open(url)
Expand Down
8 changes: 4 additions & 4 deletions V2rayU/V2rayRouting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,14 @@ class RoutingItem: NSObject, NSCoding {
// parse default settings
func parseDefaultSettings() -> V2rayRouting {

var rules: [V2rayRoutingSettingRule] = []
var rules: [V2rayRoutingRule] = []

let (blockDomains, blockIps) = parseDomainOrIp(domainIpStr: self.block)
let (proxyDomains, proxyIps) = parseDomainOrIp(domainIpStr: self.proxy)
let (directDomains, directIps) = parseDomainOrIp(domainIpStr: self.direct)

// // rules
var ruleProxyDomain, ruleProxyIp, ruleDirectDomain, ruleDirectIp, ruleBlockDomain, ruleBlockIp, ruleDirectIpDefault, ruleDirectDomainDefault: V2rayRoutingSettingRule?
var ruleProxyDomain, ruleProxyIp, ruleDirectDomain, ruleDirectIp, ruleBlockDomain, ruleBlockIp, ruleDirectIpDefault, ruleDirectDomainDefault: V2rayRoutingRule?
// proxy
if proxyDomains.count > 0 {
ruleProxyDomain = getRoutingRule(outTag: "proxy", domain: proxyDomains, ip: nil, port: nil)
Expand Down Expand Up @@ -400,8 +400,8 @@ class RoutingItem: NSObject, NSCoding {
return settings
}

func getRoutingRule(outTag: String, domain:[String]?, ip: [String]?, port:String?) -> V2rayRoutingSettingRule {
var rule = V2rayRoutingSettingRule()
func getRoutingRule(outTag: String, domain:[String]?, ip: [String]?, port:String?) -> V2rayRoutingRule {
var rule = V2rayRoutingRule()
rule.outboundTag = outTag
rule.type = "field"
rule.domain = domain
Expand Down
26 changes: 23 additions & 3 deletions V2rayU/v2ray/v2rayStruct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,42 @@ struct V2rayRouting: Codable {
case IPIfNonMatch
case IPOnDemand
}

enum domainMatcher: String, Codable {
case hybrid
case linear
}

var domainStrategy: domainStrategy = .AsIs
var rules: [V2rayRoutingSettingRule] = []
var domainMatcher: domainMatcher? = .hybrid
var rules: [V2rayRoutingRule] = []
var balancers: [V2rayRoutingBalancer]? = []
}

struct V2rayRoutingSettingRule: Codable {
struct V2rayRoutingRule: Codable {
var domainMatcher: String? = "hybrid"
var type: String = "field"
var domain: [String]? = []
var ip: [String]? = []
var port: String?
var sourcePort: String?
var network: String?
var source: [String]?
var user: [String]?
var inboundTag: [String]?
var `protocol`: [String]? // ["http", "tls", "bittorrent"]
var outboundTag: String? = "direct"
var balancerTag: String? = "balancer"
}

struct V2rayRoutingBalancer: Codable {
var selector: [String]?
var strategy: V2rayRoutingBalancerStrategy?
var tag: String?
var fallbackTag: String?
}

struct V2rayRoutingBalancerStrategy: Codable {
var type: String? // type : "random" | "roundRobin" | "leastPing" | "leastLoad"
}

struct V2rayPolicy: Codable {
Expand Down

0 comments on commit a7202a4

Please sign in to comment.