Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions backend/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@ package backend

// ConnectParams — параметры подключения из frontend.
type ConnectParams struct {
PeerAddr string `json:"peerAddr"` // адрес:порт сервера
Password string `json:"password"` // пароль подключения
Hashes []string `json:"hashes"` // хеши VK
DeviceID string `json:"deviceId,omitempty"` // ID устройства
Workers int `json:"workers,omitempty"` // воркеры (кратно 9)
PeerAddr string `json:"peerAddr"` // адрес:порт сервера
Password string `json:"password"` // пароль подключения
Hashes []string `json:"hashes"` // хеши VK
DeviceID string `json:"deviceId,omitempty"` // ID устройства
Workers int `json:"workers,omitempty"` // воркеры (кратно 9)
CaptchaMode string `json:"captchaMode,omitempty"` // auto/rjs/wv
ObfsMode string `json:"obfsMode,omitempty"` // audio/video
ObfsMode string `json:"obfsMode,omitempty"` // audio/video
Fingerprint string `json:"fingerprint,omitempty"` // chrome/android/ios/safari/firefox
TurnTCP bool `json:"turnTcp,omitempty"` // использовать TCP транспорт
TurnTCP bool `json:"turnTcp,omitempty"` // использовать TCP транспорт
}

// ProfileData — данные сервера, хранятся в ~/.config/pwdtt/servers/<name>.json.
type ProfileData struct {
PeerAddr string `json:"peer"` // адрес:порт VPS сервера
Password string `json:"password"` // пароль подключения
Hashes []string `json:"hashes"` // хеши VK-звонков
Listen string `json:"listen"` // локальный адрес (по умолчанию 127.0.0.1:9000)
TurnHost string `json:"turn"` // переопределение IP TURN
TurnPort string `json:"port"` // переопределение порта TURN
DeviceID string `json:"device_id"` // уникальный ID устройства
TurnTCP bool `json:"turn_tcp"` // использовать TCP транспорт
PeerAddr string `json:"peer"` // адрес:порт VPS сервера
Password string `json:"password"` // пароль подключения
Hashes []string `json:"hashes"` // хеши VK-звонков
Workers int `json:"workers,omitempty"` // воркеры (кратно 9)
Listen string `json:"listen"` // локальный адрес (по умолчанию 127.0.0.1:9000)
TurnHost string `json:"turn"` // переопределение IP TURN
TurnPort string `json:"port"` // переопределение порта TURN
DeviceID string `json:"device_id"` // уникальный ID устройства
TurnTCP bool `json:"turn_tcp"` // использовать TCP транспорт
}

// AppSettings — настройки приложения, хранятся в ~/.config/pwdtt/config.json.
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/__tests__/serverStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ describe('serverStore', () => {
expect(all[0].name).toBe('A');
});

it('add: сохраняет мощность из профиля', () => {
serverStore.add({ name: 'A', host: '1.1.1.1:1111', password: 'pw', power: 18 });

expect(serverStore.getAll()[0].power).toBe(18);
});

it('add: несколько серверов', () => {
serverStore.add({ name: 'A', host: 'a:1', password: 'p1' });
serverStore.add({ name: 'B', host: 'b:2', password: 'p2' });
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/modals/Add-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default function AddServer({ onClose, onAdd }: Props) {
peer: host,
password,
hashes: hashes.filter(h => h.trim()),
workers: power,
turn: '',
port: '',
device_id: '',
Expand Down Expand Up @@ -138,7 +139,7 @@ export default function AddServer({ onClose, onAdd }: Props) {

<div className="as-slider-wrap">
<div className="as-slider-label">
<span>Мощность</span>
<span>Мощность (всего потоков)</span>
<span>{filledHashes === 0 ? 'нет хешей' : power}</span>
</div>
<input
Expand All @@ -148,7 +149,7 @@ export default function AddServer({ onClose, onAdd }: Props) {
disabled={filledHashes === 0}
style={{ '--v': filledHashes > 0 ? Math.round((Math.min(power, powerMax) - 9) / Math.max(powerMax - 9, 1) * 100) : 0 } as React.CSSProperties}
onChange={e => setPower(+e.target.value)}
aria-label="Мощность"
aria-label="Мощность — всего потоков, шаг 9"
/>
</div>

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/modals/Edit-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default function EditServer({ server, onClose, onSave, onDelete }: Props)
peer: updated.host,
password: updated.password,
hashes,
workers: power,
turn: '', port: '', device_id: '', listen: '',
turn_tcp: false,
});
Expand Down Expand Up @@ -127,7 +128,7 @@ export default function EditServer({ server, onClose, onSave, onDelete }: Props)

<div className="es-slider-wrap">
<div className="es-slider-label">
<span>Мощность</span>
<span>Мощность (всего потоков)</span>
<span>{filledHashes === 0 ? 'нет хешей' : power}</span>
</div>
<input
Expand All @@ -137,7 +138,7 @@ export default function EditServer({ server, onClose, onSave, onDelete }: Props)
disabled={filledHashes === 0}
style={{ '--v': filledHashes > 0 ? Math.round((Math.min(power, powerMax) - 9) / Math.max(powerMax - 9, 1) * 100) : 0 } as React.CSSProperties}
onChange={e => setPower(+e.target.value)}
aria-label="Мощность"
aria-label="Мощность — всего потоков, шаг 9"
/>
</div>

Expand Down
15 changes: 10 additions & 5 deletions frontend/src/pages/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,20 @@ export default function Connect() {
ListProfiles().then(profiles => {
if (!profiles) return;
const existing = serverStore.getAll();
const existingNames = new Set(existing.map(s => s.name));
const existingHosts = new Set(existing.map(s => s.host));
let changed = false;
for (const [name, p] of Object.entries(profiles)) {
if (existingNames.has(name)) continue;
const host = p.peer || '';
if (!host) continue;
if (existingHosts.has(host)) continue;
const stored = existing.find(s => s.name === name || s.host === host);
if (stored) {
if (p.workers && stored.power !== p.workers) {
serverStore.update({ ...stored, power: p.workers });
changed = true;
}
continue;
}
const h4: [string,string,string,string] = [p.hashes?.[0]??'', p.hashes?.[1]??'', p.hashes?.[2]??'', p.hashes?.[3]??''];
serverStore.add({ name, host, password: p.password ?? '', hashes: h4 });
serverStore.add({ name, host, password: p.password ?? '', hashes: h4, power: p.workers });
changed = true;
}
if (changed) {
Expand Down Expand Up @@ -287,6 +291,7 @@ export default function Connect() {
peer: consumed.host,
password: consumed.password,
hashes: h4 as unknown as string[],
workers: consumed.workers,
turn: '', port: consumed.port || '', device_id: '', listen: '', turn_tcp: false,
});
const s = serverStore.add({
Expand Down
2 changes: 2 additions & 0 deletions frontend/wailsjs/go/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export namespace backend {
peer: string;
password: string;
hashes: string[];
workers?: number;
listen: string;
turn: string;
port: string;
Expand All @@ -65,6 +66,7 @@ export namespace backend {
this.peer = source["peer"];
this.password = source["password"];
this.hashes = source["hashes"];
this.workers = source["workers"];
this.listen = source["listen"];
this.turn = source["turn"];
this.port = source["port"];
Expand Down
11 changes: 10 additions & 1 deletion tests/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func TestProfileData_MarshalRoundtrip(t *testing.T) {
PeerAddr: "1.2.3.4:5555",
Password: "secret",
Hashes: []string{"h1", "h2"},
Workers: 18,
Listen: "127.0.0.1:9000",
TurnHost: "turn.example.com",
TurnPort: "3478",
Expand All @@ -170,6 +171,9 @@ func TestProfileData_MarshalRoundtrip(t *testing.T) {
if len(got.Hashes) != 2 {
t.Errorf("Hashes length: got %d, want 2", len(got.Hashes))
}
if got.Workers != p.Workers {
t.Errorf("Workers: got %d, want %d", got.Workers, p.Workers)
}
if got.Listen != p.Listen {
t.Errorf("Listen: got %q, want %q", got.Listen, p.Listen)
}
Expand Down Expand Up @@ -212,6 +216,7 @@ func TestProfileData_JSONTags(t *testing.T) {
p := backend.ProfileData{
PeerAddr: "1.2.3.4:5555",
Password: "x",
Workers: 18,
DeviceID: "id",
}

Expand All @@ -220,7 +225,7 @@ func TestProfileData_JSONTags(t *testing.T) {
json.Unmarshal(data, &raw)

// Проверяем что JSON ключи соответствуют тегам
for _, key := range []string{"peer", "password", "hashes", "listen", "turn", "port", "device_id"} {
for _, key := range []string{"peer", "password", "hashes", "workers", "listen", "turn", "port", "device_id"} {
if _, ok := raw[key]; !ok {
t.Errorf("expected key %q in JSON output", key)
}
Expand All @@ -238,6 +243,7 @@ func TestProfileData_FromJSON(t *testing.T) {
"peer": "5.6.7.8:443",
"password": "pw",
"hashes": ["a"],
"workers": 18,
"listen": "0.0.0.0:1080",
"turn": "1.1.1.1",
"port": "8443",
Expand All @@ -252,6 +258,9 @@ func TestProfileData_FromJSON(t *testing.T) {
if p.PeerAddr != "5.6.7.8:443" {
t.Errorf("PeerAddr: got %q", p.PeerAddr)
}
if p.Workers != 18 {
t.Errorf("Workers: got %d, want 18", p.Workers)
}
if p.Listen != "0.0.0.0:1080" {
t.Errorf("Listen: got %q", p.Listen)
}
Expand Down