Skip to content

Commit 1904a7b

Browse files
committed
better finalmask
1 parent 94c4bec commit 1904a7b

2 files changed

Lines changed: 65 additions & 52 deletions

File tree

web/assets/js/model/inbound.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ class SockoptStreamSettings extends XrayCommonClass {
969969
}
970970
}
971971

972-
class FinalMask extends XrayCommonClass {
972+
class UdpMask extends XrayCommonClass {
973973
constructor(type = 'salamander', settings = {}) {
974974
super();
975975
this.type = type;
@@ -997,20 +997,34 @@ class FinalMask extends XrayCommonClass {
997997
}
998998

999999
static fromJson(json = {}) {
1000-
return new FinalMask(
1000+
return new UdpMask(
10011001
json.type || 'salamander',
10021002
json.settings || {}
10031003
);
10041004
}
10051005

10061006
toJson() {
1007-
const result = {
1008-
type: this.type
1007+
return {
1008+
type: this.type,
1009+
settings: (this.settings && Object.keys(this.settings).length > 0) ? this.settings : undefined
1010+
};
1011+
}
1012+
}
1013+
1014+
class FinalMaskStreamSettings extends XrayCommonClass {
1015+
constructor(udp = []) {
1016+
super();
1017+
this.udp = Array.isArray(udp) ? udp.map(u => new UdpMask(u.type, u.settings)) : [new UdpMask(udp.type, udp.settings)];
1018+
}
1019+
1020+
static fromJson(json = {}) {
1021+
return new FinalMaskStreamSettings(json.udp || []);
1022+
}
1023+
1024+
toJson() {
1025+
return {
1026+
udp: this.udp.map(udp => udp.toJson())
10091027
};
1010-
if (this.settings && Object.keys(this.settings).length > 0) {
1011-
result.settings = this.settings;
1012-
}
1013-
return result;
10141028
}
10151029
}
10161030

@@ -1026,7 +1040,7 @@ class StreamSettings extends XrayCommonClass {
10261040
grpcSettings = new GrpcStreamSettings(),
10271041
httpupgradeSettings = new HttpUpgradeStreamSettings(),
10281042
xhttpSettings = new xHTTPStreamSettings(),
1029-
finalmask = { udp: [] },
1043+
finalmask = new FinalMaskStreamSettings(),
10301044
sockopt = undefined,
10311045
) {
10321046
super();
@@ -1046,10 +1060,7 @@ class StreamSettings extends XrayCommonClass {
10461060
}
10471061

10481062
addUdpMask(type = 'salamander') {
1049-
if (!this.finalmask.udp) {
1050-
this.finalmask.udp = [];
1051-
}
1052-
this.finalmask.udp.push(new FinalMask(type));
1063+
this.finalmask.udp.push(new UdpMask(type));
10531064
}
10541065

10551066
delUdpMask(index) {
@@ -1058,6 +1069,10 @@ class StreamSettings extends XrayCommonClass {
10581069
}
10591070
}
10601071

1072+
get hasFinalMask() {
1073+
return this.finalmask.udp && this.finalmask.udp.length > 0;
1074+
}
1075+
10611076
get isTls() {
10621077
return this.security === "tls";
10631078
}
@@ -1092,14 +1107,6 @@ class StreamSettings extends XrayCommonClass {
10921107
}
10931108

10941109
static fromJson(json = {}) {
1095-
let finalmask = { udp: [] };
1096-
if (json.finalmask) {
1097-
if (Array.isArray(json.finalmask)) {
1098-
finalmask.udp = json.finalmask.map(mask => FinalMask.fromJson(mask));
1099-
} else if (json.finalmask.udp) {
1100-
finalmask.udp = json.finalmask.udp.map(mask => FinalMask.fromJson(mask));
1101-
}
1102-
}
11031110
return new StreamSettings(
11041111
json.network,
11051112
json.security,
@@ -1112,7 +1119,7 @@ class StreamSettings extends XrayCommonClass {
11121119
GrpcStreamSettings.fromJson(json.grpcSettings),
11131120
HttpUpgradeStreamSettings.fromJson(json.httpupgradeSettings),
11141121
xHTTPStreamSettings.fromJson(json.xhttpSettings),
1115-
finalmask,
1122+
FinalMaskStreamSettings.fromJson(json.finalmask),
11161123
SockoptStreamSettings.fromJson(json.sockopt),
11171124
);
11181125
}
@@ -1131,9 +1138,7 @@ class StreamSettings extends XrayCommonClass {
11311138
grpcSettings: network === 'grpc' ? this.grpc.toJson() : undefined,
11321139
httpupgradeSettings: network === 'httpupgrade' ? this.httpupgrade.toJson() : undefined,
11331140
xhttpSettings: network === 'xhttp' ? this.xhttp.toJson() : undefined,
1134-
finalmask: (this.finalmask.udp && this.finalmask.udp.length > 0) ? {
1135-
udp: this.finalmask.udp.map(mask => mask.toJson())
1136-
} : undefined,
1141+
finalmask: this.hasFinalMask ? this.finalmask.toJson() : undefined,
11371142
sockopt: this.sockopt != undefined ? this.sockopt.toJson() : undefined,
11381143
};
11391144
}

web/assets/js/model/outbound.js

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ class SockoptStreamSettings extends CommonClass {
551551
}
552552
}
553553

554-
class FinalMask extends CommonClass {
554+
class UdpMask extends CommonClass {
555555
constructor(type = 'salamander', settings = {}) {
556556
super();
557557
this.type = type;
@@ -579,20 +579,34 @@ class FinalMask extends CommonClass {
579579
}
580580

581581
static fromJson(json = {}) {
582-
return new FinalMask(
582+
return new UdpMask(
583583
json.type || 'salamander',
584584
json.settings || {}
585585
);
586586
}
587587

588588
toJson() {
589-
const result = {
590-
type: this.type
589+
return {
590+
type: this.type,
591+
settings: (this.settings && Object.keys(this.settings).length > 0) ? this.settings : undefined
592+
};
593+
}
594+
}
595+
596+
class FinalMaskStreamSettings extends CommonClass {
597+
constructor(udp = []) {
598+
super();
599+
this.udp = Array.isArray(udp) ? udp.map(u => new UdpMask(u.type, u.settings)) : [new UdpMask(udp.type, udp.settings)];
600+
}
601+
602+
static fromJson(json = {}) {
603+
return new FinalMaskStreamSettings(json.udp || []);
604+
}
605+
606+
toJson() {
607+
return {
608+
udp: this.udp.map(udp => udp.toJson())
591609
};
592-
if (this.settings && Object.keys(this.settings).length > 0) {
593-
result.settings = this.settings;
594-
}
595-
return result;
596610
}
597611
}
598612

@@ -609,7 +623,7 @@ class StreamSettings extends CommonClass {
609623
httpupgradeSettings = new HttpUpgradeStreamSettings(),
610624
xhttpSettings = new xHTTPStreamSettings(),
611625
hysteriaSettings = new HysteriaStreamSettings(),
612-
finalmask = { udp: [] },
626+
finalmask = new FinalMaskStreamSettings(),
613627
sockopt = undefined,
614628
) {
615629
super();
@@ -629,10 +643,7 @@ class StreamSettings extends CommonClass {
629643
}
630644

631645
addUdpMask(type = 'salamander') {
632-
if (!this.finalmask.udp) {
633-
this.finalmask.udp = [];
634-
}
635-
this.finalmask.udp.push(new FinalMask(type));
646+
this.finalmask.udp.push(new UdpMask(type));
636647
}
637648

638649
delUdpMask(index) {
@@ -641,6 +652,10 @@ class StreamSettings extends CommonClass {
641652
}
642653
}
643654

655+
get hasFinalMask() {
656+
return this.finalmask.udp && this.finalmask.udp.length > 0;
657+
}
658+
644659
get isTls() {
645660
return this.security === 'tls';
646661
}
@@ -658,14 +673,6 @@ class StreamSettings extends CommonClass {
658673
}
659674

660675
static fromJson(json = {}) {
661-
let finalmask = { udp: [] };
662-
if (json.finalmask) {
663-
if (Array.isArray(json.finalmask)) {
664-
finalmask.udp = json.finalmask.map(mask => FinalMask.fromJson(mask));
665-
} else if (json.finalmask.udp) {
666-
finalmask.udp = json.finalmask.udp.map(mask => FinalMask.fromJson(mask));
667-
}
668-
}
669676
return new StreamSettings(
670677
json.network,
671678
json.security,
@@ -678,7 +685,7 @@ class StreamSettings extends CommonClass {
678685
HttpUpgradeStreamSettings.fromJson(json.httpupgradeSettings),
679686
xHTTPStreamSettings.fromJson(json.xhttpSettings),
680687
HysteriaStreamSettings.fromJson(json.hysteriaSettings),
681-
finalmask,
688+
FinalMaskStreamSettings.fromJson(json.finalmask),
682689
SockoptStreamSettings.fromJson(json.sockopt),
683690
);
684691
}
@@ -697,9 +704,7 @@ class StreamSettings extends CommonClass {
697704
httpupgradeSettings: network === 'httpupgrade' ? this.httpupgrade.toJson() : undefined,
698705
xhttpSettings: network === 'xhttp' ? this.xhttp.toJson() : undefined,
699706
hysteriaSettings: network === 'hysteria' ? this.hysteria.toJson() : undefined,
700-
finalmask: (this.finalmask.udp && this.finalmask.udp.length > 0) ? {
701-
udp: this.finalmask.udp.map(mask => mask.toJson())
702-
} : undefined,
707+
finalmask: this.hasFinalMask ? this.finalmask.toJson() : undefined,
703708
sockopt: this.sockopt != undefined ? this.sockopt.toJson() : undefined,
704709
};
705710
}
@@ -793,7 +798,7 @@ class Outbound extends CommonClass {
793798

794799
canEnableMux() {
795800
// Disable Mux if flow is set
796-
if (this.settings.flow && this.settings.flow !== '') {
801+
if (this.settings?.flow && this.settings.flow !== '') {
797802
this.mux.enabled = false;
798803
return false;
799804
}
@@ -1045,7 +1050,10 @@ class Outbound extends CommonClass {
10451050
stream.hysteria.disablePathMTUDiscovery = urlParams.get('disablePathMTUDiscovery') === 'true';
10461051
}
10471052
if (urlParams.has('obfs')) {
1048-
stream.udpmasks[0] = new UdpMask(urlParams.get('obfs'), urlParams.get('obfs-password'));
1053+
stream.finalmask = new FinalMaskStreamSettings([{
1054+
type: urlParams.get('obfs'),
1055+
settings: { password: urlParams.get('obfs-password') ?? '' }
1056+
}] );
10491057
}
10501058
if (urlParams.has('security')){
10511059
stream.security = urlParams.get('security');

0 commit comments

Comments
 (0)