add or remove noise

This commit is contained in:
mhsanaei
2024-09-24 11:38:10 +02:00
parent cf6a8bd463
commit 4fdef3cfde
6 changed files with 125 additions and 68 deletions

View File

@@ -854,7 +854,7 @@ Outbound.FreedomSettings = class extends CommonClass {
timeout = 10,
redirect = '',
fragment = {},
noises = {}
noises = []
) {
super();
this.domainStrategy = domainStrategy;
@@ -864,13 +864,21 @@ Outbound.FreedomSettings = class extends CommonClass {
this.noises = noises;
}
addNoise() {
this.noises.push(new Outbound.FreedomSettings.Noise());
}
delNoise(index) {
this.noises.splice(index, 1);
}
static fromJson(json = {}) {
return new Outbound.FreedomSettings(
json.domainStrategy,
json.timeout,
json.redirect,
json.fragment ? Outbound.FreedomSettings.Fragment.fromJson(json.fragment) : undefined,
json.noises ? Outbound.FreedomSettings.Noises.fromJson(json.noises) : undefined,
json.noises ? json.noises.map(noise => Outbound.FreedomSettings.Noise.fromJson(noise)) : [new Outbound.FreedomSettings.Noise()],
);
}
@@ -880,10 +888,11 @@ Outbound.FreedomSettings = class extends CommonClass {
timeout: this.timeout,
redirect: this.redirect,
fragment: Object.keys(this.fragment).length === 0 ? undefined : this.fragment,
noises: Object.keys(this.noises).length === 0 ? undefined : this.noises,
noises: Outbound.FreedomSettings.Noise.toJsonArray(this.noises),
};
}
};
Outbound.FreedomSettings.Fragment = class extends CommonClass {
constructor(packets = '1-3', length = '', interval = '') {
super();
@@ -900,7 +909,8 @@ Outbound.FreedomSettings.Fragment = class extends CommonClass {
);
}
};
Outbound.FreedomSettings.Noises = class extends CommonClass {
Outbound.FreedomSettings.Noise = class extends CommonClass {
constructor(
type = 'rand',
packet = '10-20',
@@ -913,12 +923,24 @@ Outbound.FreedomSettings.Noises = class extends CommonClass {
}
static fromJson(json = {}) {
return new Outbound.FreedomSettings.Noises(
return new Outbound.FreedomSettings.Noise(
json.type,
json.packet,
json.delay,
);
}
toJson() {
return {
type: this.type,
packet: this.packet,
delay: this.delay,
};
}
static toJsonArray(noises) {
return noises.map(noise => noise.toJson());
}
};
Outbound.BlackholeSettings = class extends CommonClass {